mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
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
This commit is contained in:
@ -322,29 +322,6 @@ typedef struct st_io_cache_share
|
||||
my_bool alloced;
|
||||
#endif
|
||||
} 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
|
||||
|
||||
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,
|
||||
extern int _my_b_read(IO_CACHE *info,byte *Buffer,uint Count);
|
||||
#ifdef THREAD
|
||||
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);
|
||||
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
|
||||
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);
|
||||
|
@ -424,8 +424,12 @@ int _my_b_read(register IO_CACHE *info, byte *Buffer, uint Count)
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
|
||||
#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);
|
||||
pthread_mutex_init(&s->mutex, MY_MUTEX_INIT_FAST);
|
||||
@ -436,20 +440,46 @@ int init_io_cache_share(IO_CACHE *info, IO_CACHE_SHARE *s, uint num_threads)
|
||||
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))
|
||||
return -1;
|
||||
pthread_mutex_lock(&info->share->mutex);
|
||||
if (! info->share->count--)
|
||||
pthread_cond_signal(&info->share->cond);
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
my_off_t pos_in_file;
|
||||
int length,diff_length,read_len;
|
||||
uint length,diff_length,read_len;
|
||||
DBUG_ENTER("_my_b_read_r");
|
||||
|
||||
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)
|
||||
Buffer+=read_len;
|
||||
Count-=read_len;
|
||||
}
|
||||
|
||||
#define IO_ROUND_UP(X) (((X)+IO_SIZE-1) & ~(IO_SIZE-1))
|
||||
#define IO_ROUND_DN(X) ( (X) & ~(IO_SIZE-1))
|
||||
|
||||
while (Count) {
|
||||
int cnt, len;
|
||||
while (Count)
|
||||
{
|
||||
uint cnt, len;
|
||||
|
||||
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=(length <= info->read_length) ?
|
||||
length= ((length <= info->read_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))
|
||||
{
|
||||
info->share->active=info;
|
||||
if (info->seek_not_done) /* File touched, do seek */
|
||||
VOID(my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)));
|
||||
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->pos_in_file=pos_in_file;
|
||||
unlock_io_cache(info);
|
||||
@ -494,7 +521,7 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
|
||||
info->seek_not_done=0;
|
||||
if (info->error)
|
||||
{
|
||||
info->error=read_len;
|
||||
info->error=(int) read_len;
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
cnt=(len > Count) ? Count : len;
|
||||
@ -508,6 +535,7 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
Do sequential read from the SEQ_READ_APPEND cache
|
||||
we do this in three stages:
|
||||
@ -1072,13 +1100,11 @@ int end_io_cache(IO_CACHE *info)
|
||||
#ifdef THREAD
|
||||
/* simple protection against multi-close: destroying share first */
|
||||
if (info->share)
|
||||
if (pthread_cond_destroy (& info->share->cond) |
|
||||
pthread_mutex_destroy(& info->share->mutex))
|
||||
{
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
else
|
||||
pthread_cond_destroy(&info->share->cond);
|
||||
pthread_mutex_destroy(&info->share->mutex);
|
||||
info->share=0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((pre_close=info->pre_close))
|
||||
|
Reference in New Issue
Block a user