Commit ecd2bbc2 authored by unknown's avatar unknown

Made lock_io_cache() and unlock_io_cache() as functions.


VC++Files/mysql.dsw:
  Turn on EOLN_NATIVE flag
VC++Files/mysql.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/client/mysql.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/client/mysqladmin.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/client/mysqlclient.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/client/mysqlclient.dsw:
  Turn on EOLN_NATIVE flag
VC++Files/client/mysqldump.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/client/mysqlimport.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/client/mysqlshow.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/dbug/dbug.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/dbug/dbug.dsw:
  Turn on EOLN_NATIVE flag
VC++Files/heap/heap.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/innobase/innobase.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/isam/isam.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/isam/isam.dsw:
  Turn on EOLN_NATIVE flag
VC++Files/isamchk/isamchk.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/libmysql/libmySQL.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/libmysql/libmysql.dsw:
  Turn on EOLN_NATIVE flag
VC++Files/libmysqltest/myTest.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/libmysqltest/mytest.dsw:
  Turn on EOLN_NATIVE flag
VC++Files/merge/merge.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/merge/merge.dsw:
  Turn on EOLN_NATIVE flag
VC++Files/myisam/myisam.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/myisamchk/myisamchk.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/myisamlog/myisamlog.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/myisammrg/myisammrg.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/myisampack/myisampack.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/mysqlbinlog/mysqlbinlog.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/mysqlcheck/mysqlcheck.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/mysqlmanager/MySqlManager.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/mysqlmanager/mysqlmanager.dsw:
  Turn on EOLN_NATIVE flag
VC++Files/mysqlshutdown/myshutdown.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/mysqlshutdown/mysqlshutdown.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/mysqlwatch/mysqlwatch.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/mysys/mysys.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/mysys/mysys.dsw:
  Turn on EOLN_NATIVE flag
VC++Files/pack_isam/pack_isam.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/perror/perror.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/regex/regex.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/regex/regex.dsw:
  Turn on EOLN_NATIVE flag
VC++Files/replace/replace.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/sql/mysqld.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/sql/mysqldmax.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/strings/noMASM/strings.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/strings/strings.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/test1/test1.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/thr_insert_test/thr_insert_test.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/thr_test/thr_test.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/vio/vio.dsp:
  Turn on EOLN_NATIVE flag
VC++Files/zlib/zlib.dsp:
  Turn on EOLN_NATIVE flag
parent 6b26191a
...@@ -322,29 +322,6 @@ typedef struct st_io_cache_share ...@@ -322,29 +322,6 @@ typedef struct st_io_cache_share
my_bool alloced; my_bool alloced;
#endif #endif
} IO_CACHE_SHARE; } IO_CACHE_SHARE;
#define lock_io_cache(info) \
( \
(errno=pthread_mutex_lock(&((info)->share->mutex))) ? -1 : ( \
(info)->share->count ? ( \
--((info)->share->count), \
pthread_cond_wait(&((info)->share->cond), \
&((info)->share->mutex)), \
(++((info)->share->count) ? \
pthread_mutex_unlock(&((info)->share->mutex)) : 0)) \
: 1 ) \
)
#define unlock_io_cache(info) \
( \
pthread_cond_broadcast(&((info)->share->cond)), \
pthread_mutex_unlock (&((info)->share->mutex)) \
)
/* -- to catch errors
#else
#define lock_io_cache(info)
#define unlock_io_cache(info)
*/
#endif #endif
typedef struct st_io_cache /* Used when cacheing files */ typedef struct st_io_cache /* Used when cacheing files */
...@@ -686,9 +663,11 @@ extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type, ...@@ -686,9 +663,11 @@ extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
extern int _my_b_read(IO_CACHE *info,byte *Buffer,uint Count); extern int _my_b_read(IO_CACHE *info,byte *Buffer,uint Count);
#ifdef THREAD #ifdef THREAD
extern int _my_b_read_r(IO_CACHE *info,byte *Buffer,uint Count); extern int _my_b_read_r(IO_CACHE *info,byte *Buffer,uint Count);
extern int init_io_cache_share(IO_CACHE *info, extern void init_io_cache_share(IO_CACHE *info,
IO_CACHE_SHARE *s, uint num_threads); IO_CACHE_SHARE *s, uint num_threads);
extern int remove_io_thread(IO_CACHE *info); extern void remove_io_thread(IO_CACHE *info);
int lock_io_cache(IO_CACHE *);
void unlock_io_cache(IO_CACHE *);
#endif #endif
extern int _my_b_seq_read(IO_CACHE *info,byte *Buffer,uint Count); extern int _my_b_seq_read(IO_CACHE *info,byte *Buffer,uint Count);
extern int _my_b_net_read(IO_CACHE *info,byte *Buffer,uint Count); extern int _my_b_net_read(IO_CACHE *info,byte *Buffer,uint Count);
......
...@@ -424,32 +424,62 @@ int _my_b_read(register IO_CACHE *info, byte *Buffer, uint Count) ...@@ -424,32 +424,62 @@ int _my_b_read(register IO_CACHE *info, byte *Buffer, uint Count)
DBUG_RETURN(0); DBUG_RETURN(0);
} }
#ifdef THREAD #ifdef THREAD
int init_io_cache_share(IO_CACHE *info, IO_CACHE_SHARE *s, uint num_threads)
/* Initialzie multi-thread usage of the IO cache */
void init_io_cache_share(IO_CACHE *info, IO_CACHE_SHARE *s, uint num_threads)
{ {
DBUG_ASSERT(info->type == READ_CACHE); DBUG_ASSERT(info->type == READ_CACHE);
pthread_mutex_init(& s->mutex, MY_MUTEX_INIT_FAST); pthread_mutex_init(&s->mutex, MY_MUTEX_INIT_FAST);
pthread_cond_init (& s->cond, 0); pthread_cond_init(&s->cond, 0);
s->count=num_threads; s->count=num_threads;
s->active=0; /* to catch errors */ s->active=0; /* to catch errors */
info->share=s; info->share=s;
info->read_function=_my_b_read_r; info->read_function=_my_b_read_r;
} }
int remove_io_thread(IO_CACHE *info) void remove_io_thread(IO_CACHE *info)
{ {
if (errno=pthread_mutex_lock(& info->share->mutex)) pthread_mutex_lock(&info->share->mutex);
return -1;
if (! info->share->count--) if (! info->share->count--)
pthread_cond_signal(& info->share->cond); pthread_cond_signal(&info->share->cond);
pthread_mutex_unlock(& info->share->mutex); pthread_mutex_unlock(&info->share->mutex);
}
int lock_io_cache(IO_CACHE *info)
{
pthread_mutex_lock(&info->share->mutex);
if (!info->share->count)
return 1;
info->share->count--;
pthread_cond_wait(&((info)->share->cond), &((info)->share->mutex));
if (!++info->share->count)
return 1;
pthread_mutex_unlock(&info->share->mutex);
return 0; return 0;
} }
void unlock_io_cache(IO_CACHE *info)
{
pthread_cond_broadcast(&info->share->cond);
pthread_mutex_unlock(&info->share->mutex);
}
/*
Read from the io cache in a thread safe manner
*/
#define IO_ROUND_UP(X) (((X)+IO_SIZE-1) & ~(IO_SIZE-1))
#define IO_ROUND_DN(X) ( (X) & ~(IO_SIZE-1))
int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count) int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
{ {
my_off_t pos_in_file; my_off_t pos_in_file;
int length,diff_length,read_len; uint length,diff_length,read_len;
DBUG_ENTER("_my_b_read_r"); DBUG_ENTER("_my_b_read_r");
if ((read_len=(uint) (info->read_end-info->read_pos))) if ((read_len=(uint) (info->read_end-info->read_pos)))
...@@ -459,26 +489,23 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count) ...@@ -459,26 +489,23 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
Buffer+=read_len; Buffer+=read_len;
Count-=read_len; Count-=read_len;
} }
while (Count)
#define IO_ROUND_UP(X) (((X)+IO_SIZE-1) & ~(IO_SIZE-1)) {
#define IO_ROUND_DN(X) ( (X) & ~(IO_SIZE-1)) uint cnt, len;
while (Count) {
int cnt, len;
pos_in_file= info->pos_in_file + (uint)(info->read_end - info->buffer); pos_in_file= info->pos_in_file + (uint)(info->read_end - info->buffer);
diff_length= pos_in_file & (IO_SIZE-1); diff_length= (uint) (pos_in_file & (IO_SIZE-1));
length=IO_ROUND_UP(Count+diff_length)-diff_length; length=IO_ROUND_UP(Count+diff_length)-diff_length;
length=(length <= info->read_length) ? length= ((length <= info->read_length) ?
length + IO_ROUND_DN(info->read_length - length) : length + IO_ROUND_DN(info->read_length - length) :
length - IO_ROUND_UP(length - info->read_length) ; length - IO_ROUND_UP(length - info->read_length)) ;
if (lock_io_cache(info)) if (lock_io_cache(info))
{ {
info->share->active=info; info->share->active=info;
if (info->seek_not_done) /* File touched, do seek */ if (info->seek_not_done) /* File touched, do seek */
VOID(my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0))); VOID(my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)));
len=my_read(info->file,info->buffer, length, info->myflags); len=my_read(info->file,info->buffer, length, info->myflags);
info->read_end=info->buffer + (len == -1 ? 0 : len); info->read_end=info->buffer + (len == (uint) -1 ? 0 : len);
info->error=(len == length ? 0 : len); info->error=(len == length ? 0 : len);
info->pos_in_file=pos_in_file; info->pos_in_file=pos_in_file;
unlock_io_cache(info); unlock_io_cache(info);
...@@ -494,7 +521,7 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count) ...@@ -494,7 +521,7 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
info->seek_not_done=0; info->seek_not_done=0;
if (info->error) if (info->error)
{ {
info->error=read_len; info->error=(int) read_len;
DBUG_RETURN(1); DBUG_RETURN(1);
} }
cnt=(len > Count) ? Count : len; cnt=(len > Count) ? Count : len;
...@@ -508,6 +535,7 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count) ...@@ -508,6 +535,7 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
} }
#endif #endif
/* /*
Do sequential read from the SEQ_READ_APPEND cache Do sequential read from the SEQ_READ_APPEND cache
we do this in three stages: we do this in three stages:
...@@ -1072,13 +1100,11 @@ int end_io_cache(IO_CACHE *info) ...@@ -1072,13 +1100,11 @@ int end_io_cache(IO_CACHE *info)
#ifdef THREAD #ifdef THREAD
/* simple protection against multi-close: destroying share first */ /* simple protection against multi-close: destroying share first */
if (info->share) if (info->share)
if (pthread_cond_destroy (& info->share->cond) | {
pthread_mutex_destroy(& info->share->mutex)) pthread_cond_destroy(&info->share->cond);
{ pthread_mutex_destroy(&info->share->mutex);
DBUG_RETURN(1); info->share=0;
} }
else
info->share=0;
#endif #endif
if ((pre_close=info->pre_close)) if ((pre_close=info->pre_close))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment