summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorKonstantin Osipov <kostja@sun.com>2010-02-02 02:22:16 +0300
committerKonstantin Osipov <kostja@sun.com>2010-02-02 02:22:16 +0300
commit665100b69dfebe45e2d3b68116c6718560bf63b2 (patch)
treea19075577cf795c631e5ac514d6dac52880f9b86 /mysys
parent5eed6cc55db0f99aff7845397a824fb2f5ef069e (diff)
parent4e8d1c6bf30abfd45a993b058ff2a33d4671b73d (diff)
downloadmariadb-git-665100b69dfebe45e2d3b68116c6718560bf63b2.tar.gz
Merge next-mr -> next-4284.
Diffstat (limited to 'mysys')
-rw-r--r--mysys/.cvsignore10
-rw-r--r--mysys/charset.c16
-rw-r--r--mysys/default.c12
-rw-r--r--mysys/hash.c49
-rw-r--r--mysys/mf_iocache.c48
-rw-r--r--mysys/mf_iocache2.c6
-rw-r--r--mysys/mf_keycache.c65
-rw-r--r--mysys/mf_tempdir.c12
-rw-r--r--mysys/my_bitmap.c14
-rw-r--r--mysys/my_fopen.c16
-rw-r--r--mysys/my_gethostbyname.c8
-rw-r--r--mysys/my_getopt.c64
-rw-r--r--mysys/my_getsystime.c6
-rw-r--r--mysys/my_init.c188
-rw-r--r--mysys/my_largepage.c11
-rw-r--r--mysys/my_lib.c8
-rw-r--r--mysys/my_lock.c6
-rw-r--r--mysys/my_lockmem.c10
-rw-r--r--mysys/my_net.c6
-rw-r--r--mysys/my_open.c17
-rw-r--r--mysys/my_pread.c10
-rw-r--r--mysys/my_pthread.c20
-rw-r--r--mysys/my_sync.c4
-rw-r--r--mysys/my_thr_init.c190
-rw-r--r--mysys/my_winfile.c6
-rw-r--r--mysys/mysys_priv.h6
-rw-r--r--mysys/ptr_cmp.c24
-rw-r--r--mysys/safemalloc.c18
-rw-r--r--mysys/thr_alarm.c111
-rw-r--r--mysys/thr_lock.c150
-rw-r--r--mysys/thr_mutex.c11
-rw-r--r--mysys/typelib.c2
32 files changed, 715 insertions, 409 deletions
diff --git a/mysys/.cvsignore b/mysys/.cvsignore
deleted file mode 100644
index 056ecc2691c..00000000000
--- a/mysys/.cvsignore
+++ /dev/null
@@ -1,10 +0,0 @@
-.deps
-.libs
-Makefile
-Makefile.in
-st35l1t6
-test_charset
-test_thr_alarm
-test_thr_lock
-test_vsnprintf
-testhash
diff --git a/mysys/charset.c b/mysys/charset.c
index e216f665092..f05e8c71297 100644
--- a/mysys/charset.c
+++ b/mysys/charset.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -342,10 +342,10 @@ static my_bool my_read_charset_file(const char *filename, myf myflags)
!(buf= (uchar*) my_malloc(len,myflags)))
return TRUE;
- if ((fd=my_open(filename,O_RDONLY,myflags)) < 0)
+ if ((fd= mysql_file_open(key_file_charset, filename, O_RDONLY, myflags)) < 0)
goto error;
- tmp_len=my_read(fd, buf, len, myflags);
- my_close(fd,myflags);
+ tmp_len= mysql_file_read(fd, buf, len, myflags);
+ mysql_file_close(fd, myflags);
if (tmp_len != len)
goto error;
@@ -424,7 +424,7 @@ static my_bool init_available_charsets(myf myflags)
To make things thread safe we are not allowing other threads to interfere
while we may changing the cs_info_table
*/
- pthread_mutex_lock(&THR_LOCK_charset);
+ mysql_mutex_lock(&THR_LOCK_charset);
if (!charset_initialized)
{
bzero(&all_charsets,sizeof(all_charsets));
@@ -447,7 +447,7 @@ static my_bool init_available_charsets(myf myflags)
error= my_read_charset_file(fname,myflags);
charset_initialized=1;
}
- pthread_mutex_unlock(&THR_LOCK_charset);
+ mysql_mutex_unlock(&THR_LOCK_charset);
}
return error;
}
@@ -510,7 +510,7 @@ static CHARSET_INFO *get_internal_charset(uint cs_number, myf flags)
To make things thread safe we are not allowing other threads to interfere
while we may changing the cs_info_table
*/
- pthread_mutex_lock(&THR_LOCK_charset);
+ mysql_mutex_lock(&THR_LOCK_charset);
if (!(cs->state & (MY_CS_COMPILED|MY_CS_LOADED))) /* if CS is not in memory */
{
@@ -532,7 +532,7 @@ static CHARSET_INFO *get_internal_charset(uint cs_number, myf flags)
else
cs= NULL;
- pthread_mutex_unlock(&THR_LOCK_charset);
+ mysql_mutex_unlock(&THR_LOCK_charset);
}
return cs;
}
diff --git a/mysys/default.c b/mysys/default.c
index f7c18ed83eb..8c7dfe12047 100644
--- a/mysys/default.c
+++ b/mysys/default.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -687,7 +687,7 @@ static int search_default_file_with_ext(Process_option_func opt_handler,
static const char includedir_keyword[]= "includedir";
static const char include_keyword[]= "include";
const int max_recursion_level= 10;
- FILE *fp;
+ MYSQL_FILE *fp;
uint line=0;
my_bool found_group=0;
uint i;
@@ -727,10 +727,10 @@ static int search_default_file_with_ext(Process_option_func opt_handler,
}
}
#endif
- if (!(fp= my_fopen(name, O_RDONLY, MYF(0))))
+ if (!(fp= mysql_file_fopen(key_file_cnf, name, O_RDONLY, MYF(0))))
return 1; /* Ignore wrong files */
- while (fgets(buff, sizeof(buff) - 1, fp))
+ while (mysql_file_fgets(buff, sizeof(buff) - 1, fp))
{
line++;
/* Ignore comment and empty lines */
@@ -920,11 +920,11 @@ static int search_default_file_with_ext(Process_option_func opt_handler,
goto err;
}
}
- my_fclose(fp,MYF(0));
+ mysql_file_fclose(fp, MYF(0));
return(0);
err:
- my_fclose(fp,MYF(0));
+ mysql_file_fclose(fp, MYF(0));
return -1; /* Fatal error */
}
diff --git a/mysys/hash.c b/mysys/hash.c
index 6996b045d1c..5fa804ce7ce 100644
--- a/mysys/hash.c
+++ b/mysys/hash.c
@@ -33,16 +33,18 @@ typedef struct st_hash_info {
uchar *data; /* data for current entry */
} HASH_LINK;
-static uint my_hash_mask(size_t hashnr, size_t buffmax, size_t maxlength);
+static uint my_hash_mask(my_hash_value_type hashnr,
+ size_t buffmax, size_t maxlength);
static void movelink(HASH_LINK *array,uint pos,uint next_link,uint newlink);
static int hashcmp(const HASH *hash, HASH_LINK *pos, const uchar *key,
size_t length);
-static uint calc_hash(const HASH *hash, const uchar *key, size_t length)
+static my_hash_value_type calc_hash(const HASH *hash,
+ const uchar *key, size_t length)
{
ulong nr1=1, nr2=4;
hash->charset->coll->hash_sort(hash->charset,(uchar*) key,length,&nr1,&nr2);
- return nr1;
+ return (my_hash_value_type)nr1;
}
/**
@@ -179,7 +181,8 @@ my_hash_key(const HASH *hash, const uchar *record, size_t *length,
/* Calculate pos according to keys */
-static uint my_hash_mask(size_t hashnr, size_t buffmax, size_t maxlength)
+static uint my_hash_mask(my_hash_value_type hashnr, size_t buffmax,
+ size_t maxlength)
{
if ((hashnr & (buffmax-1)) < maxlength) return (hashnr & (buffmax-1));
return (hashnr & ((buffmax >> 1) -1));
@@ -200,7 +203,7 @@ static
#if !defined(__USLC__) && !defined(__sgi)
inline
#endif
-unsigned int rec_hashnr(HASH *hash,const uchar *record)
+my_hash_value_type rec_hashnr(HASH *hash,const uchar *record)
{
size_t length;
uchar *key= (uchar*) my_hash_key(hash, record, &length, 0);
@@ -214,6 +217,21 @@ uchar* my_hash_search(const HASH *hash, const uchar *key, size_t length)
return my_hash_first(hash, key, length, &state);
}
+uchar* my_hash_search_using_hash_value(const HASH *hash,
+ my_hash_value_type hash_value,
+ const uchar *key,
+ size_t length)
+{
+ HASH_SEARCH_STATE state;
+ return my_hash_first_from_hash_value(hash, hash_value,
+ key, length, &state);
+}
+
+my_hash_value_type my_calc_hash(const HASH *hash,
+ const uchar *key, size_t length)
+{
+ return calc_hash(hash, key, length ? length : hash->key_length);
+}
/*
Search after a record based on a key
@@ -224,14 +242,25 @@ uchar* my_hash_search(const HASH *hash, const uchar *key, size_t length)
uchar* my_hash_first(const HASH *hash, const uchar *key, size_t length,
HASH_SEARCH_STATE *current_record)
{
+ return my_hash_first_from_hash_value(hash,
+ calc_hash(hash, key, length ? length : hash->key_length),
+ key, length, current_record);
+}
+
+uchar* my_hash_first_from_hash_value(const HASH *hash,
+ my_hash_value_type hash_value,
+ const uchar *key,
+ size_t length,
+ HASH_SEARCH_STATE *current_record)
+{
HASH_LINK *pos;
uint flag,idx;
- DBUG_ENTER("my_hash_first");
+ DBUG_ENTER("my_hash_first_from_hash_value");
flag=1;
if (hash->records)
{
- idx= my_hash_mask(calc_hash(hash, key, length ? length : hash->key_length),
+ idx= my_hash_mask(hash_value,
hash->blength, hash->records);
do
{
@@ -331,7 +360,8 @@ static int hashcmp(const HASH *hash, HASH_LINK *pos, const uchar *key,
my_bool my_hash_insert(HASH *info, const uchar *record)
{
int flag;
- size_t idx,halfbuff,hash_nr,first_index;
+ size_t idx,halfbuff,first_index;
+ my_hash_value_type hash_nr;
uchar *UNINIT_VAR(ptr_to_rec),*UNINIT_VAR(ptr_to_rec2);
HASH_LINK *data,*empty,*UNINIT_VAR(gpos),*UNINIT_VAR(gpos2),*pos;
@@ -467,7 +497,8 @@ my_bool my_hash_insert(HASH *info, const uchar *record)
my_bool my_hash_delete(HASH *hash, uchar *record)
{
- uint blength,pos2,pos_hashnr,lastpos_hashnr,idx,empty_index;
+ uint blength,pos2,idx,empty_index;
+ my_hash_value_type pos_hashnr, lastpos_hashnr;
HASH_LINK *data,*lastpos,*gpos,*pos,*pos3,*empty;
DBUG_ENTER("my_hash_delete");
if (!hash->records)
diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c
index 1a47982b221..620ac667a8b 100644
--- a/mysys/mf_iocache.c
+++ b/mysys/mf_iocache.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -58,9 +58,9 @@ static void my_aiowait(my_aio_result *result);
#ifdef THREAD
#define lock_append_buffer(info) \
- pthread_mutex_lock(&(info)->append_buffer_lock)
+ mysql_mutex_lock(&(info)->append_buffer_lock)
#define unlock_append_buffer(info) \
- pthread_mutex_unlock(&(info)->append_buffer_lock)
+ mysql_mutex_unlock(&(info)->append_buffer_lock)
#else
#define lock_append_buffer(info)
#define unlock_append_buffer(info)
@@ -265,7 +265,8 @@ int init_io_cache(IO_CACHE *info, File file, size_t cachesize,
info->append_read_pos = info->write_pos = info->write_buffer;
info->write_end = info->write_buffer + info->buffer_length;
#ifdef THREAD
- pthread_mutex_init(&info->append_buffer_lock,MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_IO_CACHE_append_buffer_lock,
+ &info->append_buffer_lock, MY_MUTEX_INIT_FAST);
#endif
}
#if defined(SAFE_MUTEX) && defined(THREAD)
@@ -639,9 +640,10 @@ void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
DBUG_ASSERT(read_cache->type == READ_CACHE);
DBUG_ASSERT(!write_cache || (write_cache->type == WRITE_CACHE));
- pthread_mutex_init(&cshare->mutex, MY_MUTEX_INIT_FAST);
- pthread_cond_init(&cshare->cond, 0);
- pthread_cond_init(&cshare->cond_writer, 0);
+ mysql_mutex_init(key_IO_CACHE_SHARE_mutex,
+ &cshare->mutex, MY_MUTEX_INIT_FAST);
+ mysql_cond_init(key_IO_CACHE_SHARE_cond, &cshare->cond, 0);
+ mysql_cond_init(key_IO_CACHE_SHARE_cond_writer, &cshare->cond_writer, 0);
cshare->running_threads= num_threads;
cshare->total_threads= num_threads;
@@ -692,7 +694,7 @@ void remove_io_thread(IO_CACHE *cache)
if (cache == cshare->source_cache)
flush_io_cache(cache);
- pthread_mutex_lock(&cshare->mutex);
+ mysql_mutex_lock(&cshare->mutex);
DBUG_PRINT("io_cache_share", ("%s: 0x%lx",
(cache == cshare->source_cache) ?
"writer" : "reader", (long) cache));
@@ -715,18 +717,18 @@ void remove_io_thread(IO_CACHE *cache)
if (!--cshare->running_threads)
{
DBUG_PRINT("io_cache_share", ("the last running thread leaves, wake all"));
- pthread_cond_signal(&cshare->cond_writer);
- pthread_cond_broadcast(&cshare->cond);
+ mysql_cond_signal(&cshare->cond_writer);
+ mysql_cond_broadcast(&cshare->cond);
}
- pthread_mutex_unlock(&cshare->mutex);
+ mysql_mutex_unlock(&cshare->mutex);
if (!total)
{
DBUG_PRINT("io_cache_share", ("last thread removed, destroy share"));
- pthread_cond_destroy (&cshare->cond_writer);
- pthread_cond_destroy (&cshare->cond);
- pthread_mutex_destroy(&cshare->mutex);
+ mysql_cond_destroy (&cshare->cond_writer);
+ mysql_cond_destroy (&cshare->cond);
+ mysql_mutex_destroy(&cshare->mutex);
}
DBUG_VOID_RETURN;
@@ -767,7 +769,7 @@ static int lock_io_cache(IO_CACHE *cache, my_off_t pos)
DBUG_ENTER("lock_io_cache");
/* Enter the lock. */
- pthread_mutex_lock(&cshare->mutex);
+ mysql_mutex_lock(&cshare->mutex);
cshare->running_threads--;
DBUG_PRINT("io_cache_share", ("%s: 0x%lx pos: %lu running: %u",
(cache == cshare->source_cache) ?
@@ -784,7 +786,7 @@ static int lock_io_cache(IO_CACHE *cache, my_off_t pos)
while (cshare->running_threads)
{
DBUG_PRINT("io_cache_share", ("writer waits in lock"));
- pthread_cond_wait(&cshare->cond_writer, &cshare->mutex);
+ mysql_cond_wait(&cshare->cond_writer, &cshare->mutex);
}
DBUG_PRINT("io_cache_share", ("writer awoke, going to copy"));
@@ -796,7 +798,7 @@ static int lock_io_cache(IO_CACHE *cache, my_off_t pos)
if (!cshare->running_threads)
{
DBUG_PRINT("io_cache_share", ("waking writer"));
- pthread_cond_signal(&cshare->cond_writer);
+ mysql_cond_signal(&cshare->cond_writer);
}
/*
@@ -808,7 +810,7 @@ static int lock_io_cache(IO_CACHE *cache, my_off_t pos)
cshare->source_cache)
{
DBUG_PRINT("io_cache_share", ("reader waits in lock"));
- pthread_cond_wait(&cshare->cond, &cshare->mutex);
+ mysql_cond_wait(&cshare->cond, &cshare->mutex);
}
/*
@@ -850,7 +852,7 @@ static int lock_io_cache(IO_CACHE *cache, my_off_t pos)
cshare->running_threads)
{
DBUG_PRINT("io_cache_share", ("reader waits in lock"));
- pthread_cond_wait(&cshare->cond, &cshare->mutex);
+ mysql_cond_wait(&cshare->cond, &cshare->mutex);
}
/* If the block is not yet read, continue with a locked cache and read. */
@@ -872,7 +874,7 @@ static int lock_io_cache(IO_CACHE *cache, my_off_t pos)
Leave the lock. Do not call unlock_io_cache() later. The thread that
filled the buffer did this and marked all threads as running.
*/
- pthread_mutex_unlock(&cshare->mutex);
+ mysql_mutex_unlock(&cshare->mutex);
DBUG_RETURN(0);
}
@@ -915,8 +917,8 @@ static void unlock_io_cache(IO_CACHE *cache)
cshare->total_threads));
cshare->running_threads= cshare->total_threads;
- pthread_cond_broadcast(&cshare->cond);
- pthread_mutex_unlock(&cshare->mutex);
+ mysql_cond_broadcast(&cshare->cond);
+ mysql_mutex_unlock(&cshare->mutex);
DBUG_VOID_RETURN;
}
@@ -1837,7 +1839,7 @@ int end_io_cache(IO_CACHE *info)
/* Destroy allocated mutex */
info->type= TYPE_NOT_SET;
#ifdef THREAD
- pthread_mutex_destroy(&info->append_buffer_lock);
+ mysql_mutex_destroy(&info->append_buffer_lock);
#endif
}
DBUG_RETURN(error);
diff --git a/mysys/mf_iocache2.c b/mysys/mf_iocache2.c
index 705a3fc46ec..5e34bff2b51 100644
--- a/mysys/mf_iocache2.c
+++ b/mysys/mf_iocache2.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -82,7 +82,7 @@ my_off_t my_b_append_tell(IO_CACHE* info)
answer to the question.
*/
#ifdef THREAD
- pthread_mutex_lock(&info->append_buffer_lock);
+ mysql_mutex_lock(&info->append_buffer_lock);
#endif
#ifndef DBUG_OFF
/*
@@ -104,7 +104,7 @@ my_off_t my_b_append_tell(IO_CACHE* info)
#endif
res = info->end_of_file + (info->write_pos-info->append_read_pos);
#ifdef THREAD
- pthread_mutex_unlock(&info->append_buffer_lock);
+ mysql_mutex_unlock(&info->append_buffer_lock);
#endif
return res;
}
diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c
index 139a61da1f0..9cbe3a21bce 100644
--- a/mysys/mf_keycache.c
+++ b/mysys/mf_keycache.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -59,13 +59,13 @@
time only.
Before starting to wait on its condition variable with
- pthread_cond_wait(), the thread enters itself to a specific wait queue
+ mysql_cond_wait(), the thread enters itself to a specific wait queue
with link_into_queue() (double linked with '*next' + '**prev') or
wait_on_queue() (single linked with '*next').
Another thread, when releasing a resource, looks up the waiting thread
in the related wait queue. It sends a signal with
- pthread_cond_signal() to the waiting thread.
+ mysql_cond_signal() to the waiting thread.
NOTE: Depending on the particular wait situation, either the sending
thread removes the waiting thread from the wait queue with
@@ -128,8 +128,8 @@
accessing it;
to set this number equal to <N> add
#define MAX_THREADS <N>
- - to substitute calls of pthread_cond_wait for calls of
- pthread_cond_timedwait (wait with timeout set up);
+ - to substitute calls of mysql_cond_wait for calls of
+ mysql_cond_timedwait (wait with timeout set up);
this setting should be used only when you want to trap a deadlock
situation, which theoretically should not happen;
to set timeout equal to <T> seconds add
@@ -160,7 +160,7 @@
#define COND_FOR_SAVED 1
#define COND_FOR_READERS 2
-typedef pthread_cond_t KEYCACHE_CONDVAR;
+typedef mysql_cond_t KEYCACHE_CONDVAR;
/* descriptor of the page in the key cache block buffer */
struct st_keycache_page
@@ -227,7 +227,7 @@ KEY_CACHE *dflt_key_cache= &dflt_key_cache_var;
static int flush_all_key_blocks(KEY_CACHE *keycache);
#ifdef THREAD
static void wait_on_queue(KEYCACHE_WQUEUE *wqueue,
- pthread_mutex_t *mutex);
+ mysql_mutex_t *mutex);
static void release_whole_queue(KEYCACHE_WQUEUE *wqueue);
#else
#define wait_on_queue(wqueue, mutex) do {} while (0)
@@ -314,20 +314,20 @@ static long keycache_thread_id;
((uint) (((char*)(h)-(char *) keycache->hash_link_root)/sizeof(HASH_LINK)))
#if (defined(KEYCACHE_TIMEOUT) && !defined(__WIN__)) || defined(KEYCACHE_DEBUG)
-static int keycache_pthread_cond_wait(pthread_cond_t *cond,
- pthread_mutex_t *mutex);
+static int keycache_pthread_cond_wait(mysql_cond_t *cond,
+ mysql_mutex_t *mutex);
#else
-#define keycache_pthread_cond_wait pthread_cond_wait
+#define keycache_pthread_cond_wait(C, M) mysql_cond_wait(C, M)
#endif
#if defined(KEYCACHE_DEBUG)
-static int keycache_pthread_mutex_lock(pthread_mutex_t *mutex);
-static void keycache_pthread_mutex_unlock(pthread_mutex_t *mutex);
-static int keycache_pthread_cond_signal(pthread_cond_t *cond);
+static int keycache_pthread_mutex_lock(mysql_mutex_t *mutex);
+static void keycache_pthread_mutex_unlock(mysql_mutex_t *mutex);
+static int keycache_pthread_cond_signal(mysql_cond_t *cond);
#else
-#define keycache_pthread_mutex_lock pthread_mutex_lock
-#define keycache_pthread_mutex_unlock pthread_mutex_unlock
-#define keycache_pthread_cond_signal pthread_cond_signal
+#define keycache_pthread_mutex_lock(M) mysql_mutex_lock(M)
+#define keycache_pthread_mutex_unlock(M) mysql_mutex_unlock(M)
+#define keycache_pthread_cond_signal(C) mysql_cond_signal(C)
#endif /* defined(KEYCACHE_DEBUG) */
#if !defined(DBUG_OFF)
@@ -403,7 +403,8 @@ int init_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
keycache->cnt_for_resize_op= 0;
keycache->waiting_for_resize_cnt.last_thread= NULL;
keycache->in_init= 0;
- pthread_mutex_init(&keycache->cache_lock, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_KEY_CACHE_cache_lock,
+ &keycache->cache_lock, MY_MUTEX_INIT_FAST);
keycache->resize_queue.last_thread= NULL;
}
@@ -773,7 +774,7 @@ void end_key_cache(KEY_CACHE *keycache, my_bool cleanup)
if (cleanup)
{
- pthread_mutex_destroy(&keycache->cache_lock);
+ mysql_mutex_destroy(&keycache->cache_lock);
keycache->key_cache_inited= keycache->can_be_used= 0;
KEYCACHE_DEBUG_CLOSE;
}
@@ -888,7 +889,7 @@ static void unlink_from_queue(KEYCACHE_WQUEUE *wqueue,
*/
static void wait_on_queue(KEYCACHE_WQUEUE *wqueue,
- pthread_mutex_t *mutex)
+ mysql_mutex_t *mutex)
{
struct st_my_thread_var *last;
struct st_my_thread_var *thread= my_thread_var;
@@ -4166,7 +4167,7 @@ static int flush_all_key_blocks(KEY_CACHE *keycache)
do
{
- safe_mutex_assert_owner(&keycache->cache_lock);
+ mysql_mutex_assert_owner(&keycache->cache_lock);
total_found= 0;
/*
@@ -4407,8 +4408,8 @@ static void keycache_dump(KEY_CACHE *keycache)
#if defined(KEYCACHE_TIMEOUT) && !defined(__WIN__)
-static int keycache_pthread_cond_wait(pthread_cond_t *cond,
- pthread_mutex_t *mutex)
+static int keycache_pthread_cond_wait(mysql_cond_t *cond,
+ mysql_mutex_t *mutex)
{
int rc;
struct timeval now; /* time when we started waiting */
@@ -4435,7 +4436,7 @@ static int keycache_pthread_cond_wait(pthread_cond_t *cond,
fprintf(keycache_debug_log, "waiting...\n");
fflush(keycache_debug_log);
#endif
- rc= pthread_cond_timedwait(cond, mutex, &timeout);
+ rc= mysql_cond_timedwait(cond, mutex, &timeout);
KEYCACHE_THREAD_TRACE_BEGIN("finished waiting");
if (rc == ETIMEDOUT || rc == ETIME)
{
@@ -4456,12 +4457,12 @@ static int keycache_pthread_cond_wait(pthread_cond_t *cond,
}
#else
#if defined(KEYCACHE_DEBUG)
-static int keycache_pthread_cond_wait(pthread_cond_t *cond,
- pthread_mutex_t *mutex)
+static int keycache_pthread_cond_wait(mysql_cond_t *cond,
+ mysql_mutex_t *mutex)
{
int rc;
KEYCACHE_THREAD_TRACE_END("started waiting");
- rc= pthread_cond_wait(cond, mutex);
+ rc= mysql_cond_wait(cond, mutex);
KEYCACHE_THREAD_TRACE_BEGIN("finished waiting");
return rc;
}
@@ -4471,27 +4472,27 @@ static int keycache_pthread_cond_wait(pthread_cond_t *cond,
#if defined(KEYCACHE_DEBUG)
-static int keycache_pthread_mutex_lock(pthread_mutex_t *mutex)
+static int keycache_pthread_mutex_lock(mysql_mutex_t *mutex)
{
int rc;
- rc= pthread_mutex_lock(mutex);
+ rc= mysql_mutex_lock(mutex);
KEYCACHE_THREAD_TRACE_BEGIN("");
return rc;
}
-static void keycache_pthread_mutex_unlock(pthread_mutex_t *mutex)
+static void keycache_pthread_mutex_unlock(mysql_mutex_t *mutex)
{
KEYCACHE_THREAD_TRACE_END("");
- pthread_mutex_unlock(mutex);
+ mysql_mutex_unlock(mutex);
}
-static int keycache_pthread_cond_signal(pthread_cond_t *cond)
+static int keycache_pthread_cond_signal(mysql_cond_t *cond)
{
int rc;
KEYCACHE_THREAD_TRACE("signal");
- rc= pthread_cond_signal(cond);
+ rc= mysql_cond_signal(cond);
return rc;
}
diff --git a/mysys/mf_tempdir.c b/mysys/mf_tempdir.c
index f41bbab946f..5633182ab3a 100644
--- a/mysys/mf_tempdir.c
+++ b/mysys/mf_tempdir.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@ my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist)
DBUG_ENTER("init_tmpdir");
DBUG_PRINT("enter", ("pathlist: %s", pathlist ? pathlist : "NULL"));
- pthread_mutex_init(&tmpdir->mutex, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_TMPDIR_mutex, &tmpdir->mutex, MY_MUTEX_INIT_FAST);
if (my_init_dynamic_array(&tmpdir->full_list, sizeof(char*), 1, 5))
goto err;
if (!pathlist || !pathlist[0])
@@ -65,7 +65,7 @@ my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist)
err:
delete_dynamic(&tmpdir->full_list); /* Safe to free */
- pthread_mutex_destroy(&tmpdir->mutex);
+ mysql_mutex_destroy(&tmpdir->mutex);
DBUG_RETURN(TRUE);
}
@@ -75,10 +75,10 @@ char *my_tmpdir(MY_TMPDIR *tmpdir)
char *dir;
if (!tmpdir->max)
return tmpdir->list[0];
- pthread_mutex_lock(&tmpdir->mutex);
+ mysql_mutex_lock(&tmpdir->mutex);
dir=tmpdir->list[tmpdir->cur];
tmpdir->cur= (tmpdir->cur == tmpdir->max) ? 0 : tmpdir->cur+1;
- pthread_mutex_unlock(&tmpdir->mutex);
+ mysql_mutex_unlock(&tmpdir->mutex);
return dir;
}
@@ -90,6 +90,6 @@ void free_tmpdir(MY_TMPDIR *tmpdir)
for (i=0; i<=tmpdir->max; i++)
my_free(tmpdir->list[i], MYF(0));
delete_dynamic(&tmpdir->full_list);
- pthread_mutex_destroy(&tmpdir->mutex);
+ mysql_mutex_destroy(&tmpdir->mutex);
}
diff --git a/mysys/my_bitmap.c b/mysys/my_bitmap.c
index e127b2584ae..91370bd3727 100644
--- a/mysys/my_bitmap.c
+++ b/mysys/my_bitmap.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -87,7 +87,7 @@ static inline void bitmap_lock(MY_BITMAP *map __attribute__((unused)))
{
#ifdef THREAD
if (map->mutex)
- pthread_mutex_lock(map->mutex);
+ mysql_mutex_lock(map->mutex);
#endif
}
@@ -95,7 +95,7 @@ static inline void bitmap_unlock(MY_BITMAP *map __attribute__((unused)))
{
#ifdef THREAD
if (map->mutex)
- pthread_mutex_unlock(map->mutex);
+ mysql_mutex_unlock(map->mutex);
#endif
}
@@ -112,7 +112,7 @@ my_bool bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint n_bits,
if (thread_safe)
{
size_in_bytes= ALIGN_SIZE(size_in_bytes);
- extra= sizeof(pthread_mutex_t);
+ extra= sizeof(mysql_mutex_t);
}
map->mutex= 0;
#endif
@@ -121,8 +121,8 @@ my_bool bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint n_bits,
#ifdef THREAD
if (thread_safe)
{
- map->mutex= (pthread_mutex_t *) ((char*) buf + size_in_bytes);
- pthread_mutex_init(map->mutex, MY_MUTEX_INIT_FAST);
+ map->mutex= (mysql_mutex_t *) ((char*) buf + size_in_bytes);
+ mysql_mutex_init(key_BITMAP_mutex, map->mutex, MY_MUTEX_INIT_FAST);
}
#endif
}
@@ -148,7 +148,7 @@ void bitmap_free(MY_BITMAP *map)
{
#ifdef THREAD
if (map->mutex)
- pthread_mutex_destroy(map->mutex);
+ mysql_mutex_destroy(map->mutex);
#endif
my_free((char*) map->bitmap, MYF(0));
map->bitmap=0;
diff --git a/mysys/my_fopen.c b/mysys/my_fopen.c
index 879acac0111..3f2bc08df65 100644
--- a/mysys/my_fopen.c
+++ b/mysys/my_fopen.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -63,18 +63,18 @@ FILE *my_fopen(const char *filename, int flags, myf MyFlags)
thread_safe_increment(my_stream_opened,&THR_LOCK_open);
DBUG_RETURN(fd); /* safeguard */
}
- pthread_mutex_lock(&THR_LOCK_open);
+ mysql_mutex_lock(&THR_LOCK_open);
if ((my_file_info[filedesc].name= (char*)
my_strdup(filename,MyFlags)))
{
my_stream_opened++;
my_file_total_opened++;
my_file_info[filedesc].type= STREAM_BY_FOPEN;
- pthread_mutex_unlock(&THR_LOCK_open);
+ mysql_mutex_unlock(&THR_LOCK_open);
DBUG_PRINT("exit",("stream: 0x%lx", (long) fd));
DBUG_RETURN(fd);
}
- pthread_mutex_unlock(&THR_LOCK_open);
+ mysql_mutex_unlock(&THR_LOCK_open);
(void) my_fclose(fd,MyFlags);
my_errno=ENOMEM;
}
@@ -98,7 +98,7 @@ int my_fclose(FILE *fd, myf MyFlags)
DBUG_ENTER("my_fclose");
DBUG_PRINT("my",("stream: 0x%lx MyFlags: %d", (long) fd, MyFlags));
- pthread_mutex_lock(&THR_LOCK_open);
+ mysql_mutex_lock(&THR_LOCK_open);
file= my_fileno(fd);
#ifndef _WIN32
err= fclose(fd);
@@ -119,7 +119,7 @@ int my_fclose(FILE *fd, myf MyFlags)
my_file_info[file].type = UNOPEN;
my_free(my_file_info[file].name, MYF(MY_ALLOW_ZERO_PTR));
}
- pthread_mutex_unlock(&THR_LOCK_open);
+ mysql_mutex_unlock(&THR_LOCK_open);
DBUG_RETURN(err);
} /* my_fclose */
@@ -149,7 +149,7 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags)
}
else
{
- pthread_mutex_lock(&THR_LOCK_open);
+ mysql_mutex_lock(&THR_LOCK_open);
my_stream_opened++;
if ((uint) Filedes < (uint) my_file_limit)
{
@@ -163,7 +163,7 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags)
}
my_file_info[Filedes].type = STREAM_BY_FDOPEN;
}
- pthread_mutex_unlock(&THR_LOCK_open);
+ mysql_mutex_unlock(&THR_LOCK_open);
}
DBUG_PRINT("exit",("stream: 0x%lx", (long) fd));
diff --git a/mysys/my_gethostbyname.c b/mysys/my_gethostbyname.c
index 067fdfee9db..4b7e9054d61 100644
--- a/mysys/my_gethostbyname.c
+++ b/mysys/my_gethostbyname.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2004 MySQL AB
+/* Copyright (C) 2002, 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -79,7 +79,7 @@ struct hostent *my_gethostbyname_r(const char *name,
#else /* !HAVE_GETHOSTBYNAME_R */
#ifdef THREAD
-extern pthread_mutex_t LOCK_gethostbyname_r;
+extern mysql_mutex_t LOCK_gethostbyname_r;
#endif
/*
@@ -96,7 +96,7 @@ struct hostent *my_gethostbyname_r(const char *name,
int buflen, int *h_errnop)
{
struct hostent *hp;
- pthread_mutex_lock(&LOCK_gethostbyname_r);
+ mysql_mutex_lock(&LOCK_gethostbyname_r);
hp= gethostbyname(name);
*h_errnop= h_errno;
return hp;
@@ -104,7 +104,7 @@ struct hostent *my_gethostbyname_r(const char *name,
void my_gethostbyname_r_free()
{
- pthread_mutex_unlock(&LOCK_gethostbyname_r);
+ mysql_mutex_unlock(&LOCK_gethostbyname_r);
}
#endif /* !HAVE_GETHOSTBYNAME_R */
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index 2e8f09f14fd..f5854043459 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002-2006 MySQL AB
+/* Copyright (C) 2002-2006 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -91,16 +91,6 @@ static void default_reporter(enum loglevel level,
fflush(stderr);
}
-/*
- function: handle_options
-
- Sort options; put options first, until special end of options (--), or
- until end of argv. Parse options; check that the given option matches with
- one of the options in struct 'my_option', return error in case of ambiguous
- or unknown option. Check that option was given an argument if it requires
- one. Call function 'get_one_option()' once for each option.
-*/
-
static uchar** (*getopt_get_addr)(const char *, uint, const struct my_option *, int *);
void my_getopt_register_get_addr(uchar** (*func_addr)(const char *, uint,
@@ -109,6 +99,22 @@ void my_getopt_register_get_addr(uchar** (*func_addr)(const char *, uint,
getopt_get_addr= func_addr;
}
+/**
+ Handle command line options.
+ Sort options.
+ Put options first, until special end of options (--),
+ or until the end of argv. Parse options, check that the given option
+ matches with one of the options in struct 'my_option'.
+ Check that option was given an argument if it requires one
+ Call the optional 'get_one_option()' function once for each option.
+ @param [in, out] argc command line options (count)
+ @param [in, out] argv command line options (values)
+ @param [in] longopts descriptor of all valid options
+ @param [in] get_one_option optional callback function to process each option,
+ can be NULL.
+ @return error in case of ambiguous or unknown options,
+ 0 on success.
+*/
int handle_options(int *argc, char ***argv,
const struct my_option *longopts,
my_get_one_option get_one_option)
@@ -427,9 +433,9 @@ invalid value '%s'",
my_progname, optp->name, optend);
continue;
}
- if (get_one_option(optp->id, optp,
- *((my_bool*) value) ?
- (char*) "1" : disabled_my_option))
+ if (get_one_option && get_one_option(optp->id, optp,
+ *((my_bool*) value) ?
+ (char*) "1" : disabled_my_option))
return EXIT_ARGUMENT_INVALID;
continue;
}
@@ -438,17 +444,17 @@ invalid value '%s'",
else if (optp->arg_type == OPT_ARG &&
(((optp->var_type & GET_TYPE_MASK) == GET_BOOL) ||
(optp->var_type & GET_TYPE_MASK) == GET_ENUM))
- {
- if (optend == disabled_my_option)
- *((my_bool*) value)= (my_bool) 0;
- else
- {
- if (!optend) /* No argument -> enable option */
- *((my_bool*) value)= (my_bool) 1;
- else
- argument= optend;
- }
- }
+ {
+ if (optend == disabled_my_option)
+ init_one_value(optp, value, 0);
+ else
+ {
+ if (!optend) /* No argument -> enable option */
+ init_one_value(optp, value, 1);
+ else
+ argument= optend;
+ }
+ }
else if (optp->arg_type == REQUIRED_ARG && !optend)
{
/* Check if there are more arguments after this one,
@@ -493,7 +499,7 @@ invalid value '%s'",
optp->arg_type == NO_ARG)
{
*((my_bool*) optp->value)= (my_bool) 1;
- if (get_one_option(optp->id, optp, argument))
+ if (get_one_option && get_one_option(optp->id, optp, argument))
return EXIT_UNSPECIFIED_ERROR;
continue;
}
@@ -513,7 +519,7 @@ invalid value '%s'",
{
if (optp->var_type == GET_BOOL)
*((my_bool*) optp->value)= (my_bool) 1;
- if (get_one_option(optp->id, optp, argument))
+ if (get_one_option && get_one_option(optp->id, optp, argument))
return EXIT_UNSPECIFIED_ERROR;
continue;
}
@@ -539,7 +545,7 @@ invalid value '%s'",
my_progname, argument, optp->name);
return error;
}
- if (get_one_option(optp->id, optp, argument))
+ if (get_one_option && get_one_option(optp->id, optp, argument))
return EXIT_UNSPECIFIED_ERROR;
break;
}
@@ -563,7 +569,7 @@ invalid value '%s'",
my_progname, argument, optp->name);
return error;
}
- if (get_one_option(optp->id, optp, argument))
+ if (get_one_option && get_one_option(optp->id, optp, argument))
return EXIT_UNSPECIFIED_ERROR;
(*argc)--; /* option handled (short or long), decrease argument count */
diff --git a/mysys/my_getsystime.c b/mysys/my_getsystime.c
index b692b18bfc7..81bb3e15298 100644
--- a/mysys/my_getsystime.c
+++ b/mysys/my_getsystime.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004 MySQL AB
+/* Copyright (C) 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -168,7 +168,7 @@ ulonglong my_micro_time_and_time(time_t *time_arg)
static time_t cur_time= 0;
hrtime_t cur_gethrtime;
- pthread_mutex_lock(&THR_LOCK_time);
+ mysql_mutex_lock(&THR_LOCK_time);
cur_gethrtime= gethrtime();
if ((cur_gethrtime - prev_gethrtime) > DELTA_FOR_SECONDS)
{
@@ -176,7 +176,7 @@ ulonglong my_micro_time_and_time(time_t *time_arg)
prev_gethrtime= cur_gethrtime;
}
*time_arg= cur_time;
- pthread_mutex_unlock(&THR_LOCK_time);
+ mysql_mutex_unlock(&THR_LOCK_time);
return cur_gethrtime/1000;
#else
ulonglong newtime;
diff --git a/mysys/my_init.c b/mysys/my_init.c
index c4fda599481..fa68bb2b1cb 100644
--- a/mysys/my_init.c
+++ b/mysys/my_init.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -43,6 +43,8 @@ static void netware_init();
#endif
my_bool my_init_done= 0;
+/** True if @c my_basic_init() has been called. */
+my_bool my_basic_init_done= 0;
uint mysys_usage_id= 0; /* Incremented for each my_init() */
ulong my_thread_stack_size= 65536;
@@ -57,28 +59,35 @@ static ulong atoi_octal(const char *str)
return (ulong) tmp;
}
-
-/*
- Init my_sys functions and my_sys variabels
-
- SYNOPSIS
- my_init()
-
- RETURN
- 0 ok
- 1 Couldn't initialize environment
+MYSQL_FILE *mysql_stdin= NULL;
+static MYSQL_FILE instrumented_stdin;
+
+/**
+ Perform a limited initialisation of mysys.
+ This initialisation is sufficient to:
+ - allocate memory,
+ - read configuration files,
+ - parse command lines arguments.
+ To complete the mysys initialisation,
+ call my_init().
+ @return 0 on success
*/
-
-my_bool my_init(void)
+my_bool my_basic_init(void)
{
- char * str;
- if (my_init_done)
+ if (my_basic_init_done)
return 0;
- my_init_done=1;
+ my_basic_init_done= 1;
+
mysys_usage_id++;
my_umask= 0660; /* Default umask for new files */
my_umask_dir= 0700; /* Default umask for new directories */
+
init_glob_errs();
+
+ instrumented_stdin.m_file= stdin;
+ instrumented_stdin.m_psi= NULL; /* not yet instrumented */
+ mysql_stdin= & instrumented_stdin;
+
#if defined(THREAD)
if (my_thread_global_init())
return 1;
@@ -94,6 +103,38 @@ my_bool my_init(void)
#if defined(HAVE_PTHREAD_INIT)
pthread_init(); /* Must be called before DBUG_ENTER */
#endif
+ if (my_thread_basic_global_init())
+ return 1;
+#endif
+
+ return 0;
+}
+
+
+/*
+ Init my_sys functions and my_sys variabels
+
+ SYNOPSIS
+ my_init()
+
+ RETURN
+ 0 ok
+ 1 Couldn't initialize environment
+*/
+
+my_bool my_init(void)
+{
+ char * str;
+ if (my_init_done)
+ return 0;
+ my_init_done= 1;
+
+ if (my_basic_init())
+ return 1;
+
+#ifdef THREAD
+ if (my_thread_global_init())
+ return 1;
#if !defined( __WIN__) && !defined(__NETWARE__)
sigfillset(&my_signals); /* signals blocked by mf_brkhant */
#endif
@@ -239,6 +280,7 @@ Voluntary context switches %ld, Involuntary context switches %ld\n",
WSACleanup();
#endif /* __WIN__ */
my_init_done=0;
+ my_basic_init_done= 0;
} /* my_end */
@@ -538,3 +580,117 @@ static void netware_init()
DBUG_VOID_RETURN;
}
#endif /* __NETWARE__ */
+
+#ifdef HAVE_PSI_INTERFACE
+
+#if !defined(HAVE_PREAD) && !defined(_WIN32)
+PSI_mutex_key key_my_file_info_mutex;
+#endif /* !defined(HAVE_PREAD) && !defined(_WIN32) */
+
+#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
+PSI_mutex_key key_LOCK_localtime_r;
+#endif /* !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) */
+
+#ifndef HAVE_GETHOSTBYNAME_R
+PSI_mutex_key key_LOCK_gethostbyname_r;
+#endif /* HAVE_GETHOSTBYNAME_R */
+
+PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock,
+ key_IO_CACHE_SHARE_mutex, key_KEY_CACHE_cache_lock, key_LOCK_alarm,
+ key_my_thread_var_mutex, key_THR_LOCK_charset, key_THR_LOCK_heap,
+ key_THR_LOCK_isam, key_THR_LOCK_lock, key_THR_LOCK_malloc,
+ key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net,
+ key_THR_LOCK_open, key_THR_LOCK_threads, key_THR_LOCK_time,
+ key_TMPDIR_mutex;
+
+static PSI_mutex_info all_mysys_mutexes[]=
+{
+#if defined(THREAD) && !defined(HAVE_PREAD) && !defined(_WIN32)
+ { &key_my_file_info_mutex, "st_my_file_info:mutex", 0},
+#endif /* !defined(HAVE_PREAD) && !defined(_WIN32) */
+#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
+ { &key_LOCK_localtime_r, "LOCK_localtime_r", PSI_FLAG_GLOBAL},
+#endif /* !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) */
+#ifndef HAVE_GETHOSTBYNAME_R
+ { &key_LOCK_gethostbyname_r, "LOCK_gethostbyname_r", PSI_FLAG_GLOBAL},
+#endif /* HAVE_GETHOSTBYNAME_R */
+ { &key_BITMAP_mutex, "BITMAP::mutex", 0},
+ { &key_IO_CACHE_append_buffer_lock, "IO_CACHE::append_buffer_lock", 0},
+ { &key_IO_CACHE_SHARE_mutex, "IO_CACHE::SHARE_mutex", 0},
+ { &key_KEY_CACHE_cache_lock, "KEY_CACHE::cache_lock", 0},
+ { &key_LOCK_alarm, "LOCK_alarm", PSI_FLAG_GLOBAL},
+ { &key_my_thread_var_mutex, "my_thread_var::mutex", 0},
+ { &key_THR_LOCK_charset, "THR_LOCK_charset", PSI_FLAG_GLOBAL},
+ { &key_THR_LOCK_heap, "THR_LOCK_heap", PSI_FLAG_GLOBAL},
+ { &key_THR_LOCK_isam, "THR_LOCK_isam", PSI_FLAG_GLOBAL},
+ { &key_THR_LOCK_lock, "THR_LOCK_lock", PSI_FLAG_GLOBAL},
+ { &key_THR_LOCK_malloc, "THR_LOCK_malloc", PSI_FLAG_GLOBAL},
+ { &key_THR_LOCK_mutex, "THR_LOCK::mutex", 0},
+ { &key_THR_LOCK_myisam, "THR_LOCK_myisam", PSI_FLAG_GLOBAL},
+ { &key_THR_LOCK_net, "THR_LOCK_net", PSI_FLAG_GLOBAL},
+ { &key_THR_LOCK_open, "THR_LOCK_open", PSI_FLAG_GLOBAL},
+ { &key_THR_LOCK_threads, "THR_LOCK_threads", PSI_FLAG_GLOBAL},
+ { &key_THR_LOCK_time, "THR_LOCK_time", PSI_FLAG_GLOBAL},
+ { &key_TMPDIR_mutex, "TMPDIR_mutex", PSI_FLAG_GLOBAL}
+};
+
+PSI_cond_key key_COND_alarm, key_IO_CACHE_SHARE_cond,
+ key_IO_CACHE_SHARE_cond_writer, key_my_thread_var_suspend,
+ key_THR_COND_threads;
+
+static PSI_cond_info all_mysys_conds[]=
+{
+ { &key_COND_alarm, "COND_alarm", PSI_FLAG_GLOBAL},
+ { &key_IO_CACHE_SHARE_cond, "IO_CACHE_SHARE::cond", 0},
+ { &key_IO_CACHE_SHARE_cond_writer, "IO_CACHE_SHARE::cond_writer", 0},
+ { &key_my_thread_var_suspend, "my_thread_var::suspend", 0},
+ { &key_THR_COND_threads, "THR_COND_threads", 0}
+};
+
+#ifdef USE_ALARM_THREAD
+PSI_thread_key key_thread_alarm;
+
+static PSI_thread_info all_mysys_threads[]=
+{
+ { &key_thread_alarm, "alarm", PSI_FLAG_GLOBAL}
+};
+#endif /* USE_ALARM_THREAD */
+
+#ifdef HUGETLB_USE_PROC_MEMINFO
+PSI_file_key key_file_proc_meminfo;
+#endif /* HUGETLB_USE_PROC_MEMINFO */
+PSI_file_key key_file_charset, key_file_cnf;
+
+static PSI_file_info all_mysys_files[]=
+{
+#ifdef HUGETLB_USE_PROC_MEMINFO
+ { &key_file_proc_meminfo, "proc_meminfo", 0},
+#endif /* HUGETLB_USE_PROC_MEMINFO */
+ { &key_file_charset, "charset", 0},
+ { &key_file_cnf, "cnf", 0}
+};
+
+void my_init_mysys_psi_keys()
+{
+ const char* category= "mysys";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= sizeof(all_mysys_mutexes)/sizeof(all_mysys_mutexes[0]);
+ PSI_server->register_mutex(category, all_mysys_mutexes, count);
+
+ count= sizeof(all_mysys_conds)/sizeof(all_mysys_conds[0]);
+ PSI_server->register_cond(category, all_mysys_conds, count);
+
+#ifdef USE_ALARM_THREAD
+ count= sizeof(all_mysys_threads)/sizeof(all_mysys_threads[0]);
+ PSI_server->register_thread(category, all_mysys_threads, count);
+#endif /* USE_ALARM_THREAD */
+
+ count= sizeof(all_mysys_files)/sizeof(all_mysys_files[0]);
+ PSI_server->register_file(category, all_mysys_files, count);
+}
+#endif /* HAVE_PSI_INTERFACE */
+
diff --git a/mysys/my_largepage.c b/mysys/my_largepage.c
index d96e1048fd0..e65d3a0a5f5 100644
--- a/mysys/my_largepage.c
+++ b/mysys/my_largepage.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004 MySQL AB
+/* Copyright (C) 2004 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -91,19 +91,20 @@ void my_large_free(uchar* ptr, myf my_flags __attribute__((unused)))
uint my_get_large_page_size_int(void)
{
- FILE *f;
+ MYSQL_FILE *f;
uint size = 0;
char buf[256];
DBUG_ENTER("my_get_large_page_size_int");
- if (!(f = my_fopen("/proc/meminfo", O_RDONLY, MYF(MY_WME))))
+ if (!(f= mysql_file_fopen(key_file_proc_meminfo, "/proc/meminfo",
+ O_RDONLY, MYF(MY_WME))))
goto finish;
- while (fgets(buf, sizeof(buf), f))
+ while (mysql_file_fgets(buf, sizeof(buf), f))
if (sscanf(buf, "Hugepagesize: %u kB", &size))
break;
- my_fclose(f, MYF(MY_WME));
+ mysql_file_fclose(f, MYF(MY_WME));
finish:
DBUG_RETURN(size * 1024);
diff --git a/mysys/my_lib.c b/mysys/my_lib.c
index dcc1263f383..0113d1498df 100644
--- a/mysys/my_lib.c
+++ b/mysys/my_lib.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -110,7 +110,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,MyFlags));
#if defined(THREAD) && !defined(HAVE_READDIR_R)
- pthread_mutex_lock(&THR_LOCK_open);
+ mysql_mutex_lock(&THR_LOCK_open);
#endif
dirp = opendir(directory_file_name(tmp_path,(char *) path));
@@ -173,7 +173,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
(void) closedir(dirp);
#if defined(THREAD) && !defined(HAVE_READDIR_R)
- pthread_mutex_unlock(&THR_LOCK_open);
+ mysql_mutex_unlock(&THR_LOCK_open);
#endif
result->dir_entry= (FILEINFO *)dir_entries_storage->buffer;
result->number_off_files= dir_entries_storage->elements;
@@ -185,7 +185,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
error:
#if defined(THREAD) && !defined(HAVE_READDIR_R)
- pthread_mutex_unlock(&THR_LOCK_open);
+ mysql_mutex_unlock(&THR_LOCK_open);
#endif
my_errno=errno;
if (dirp)
diff --git a/mysys/my_lock.c b/mysys/my_lock.c
index 62f39bd3b71..1436c845286 100644
--- a/mysys/my_lock.c
+++ b/mysys/my_lock.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -206,8 +206,8 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length,
else
timeout_sec= WIN_LOCK_INFINITE;
- if(win_lock(fd, locktype, start, length, timeout_sec) == 0)
- DBUG_RETURN(0);
+ if (win_lock(fd, locktype, start, length, timeout_sec) == 0)
+ DBUG_RETURN(0);
}
#else
#if defined(HAVE_FCNTL)
diff --git a/mysys/my_lockmem.c b/mysys/my_lockmem.c
index f2c6d52a382..1b582783d33 100644
--- a/mysys/my_lockmem.c
+++ b/mysys/my_lockmem.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -66,9 +66,9 @@ uchar *my_malloc_lock(uint size,myf MyFlags)
element->list.data=(uchar*) element;
element->page=ptr;
element->size=size;
- pthread_mutex_lock(&THR_LOCK_malloc);
+ mysql_mutex_lock(&THR_LOCK_malloc);
mem_list=list_add(mem_list,&element->list);
- pthread_mutex_unlock(&THR_LOCK_malloc);
+ mysql_mutex_unlock(&THR_LOCK_malloc);
}
DBUG_RETURN(ptr);
}
@@ -79,7 +79,7 @@ void my_free_lock(uchar *ptr,myf Myflags __attribute__((unused)))
LIST *list;
struct st_mem_list *element=0;
- pthread_mutex_lock(&THR_LOCK_malloc);
+ mysql_mutex_lock(&THR_LOCK_malloc);
for (list=mem_list ; list ; list=list->next)
{
element=(struct st_mem_list*) list->data;
@@ -90,7 +90,7 @@ void my_free_lock(uchar *ptr,myf Myflags __attribute__((unused)))
break;
}
}
- pthread_mutex_unlock(&THR_LOCK_malloc);
+ mysql_mutex_unlock(&THR_LOCK_malloc);
if (element)
my_free((uchar*) element,MYF(0));
free(ptr); /* Free even if not locked */
diff --git a/mysys/my_net.c b/mysys/my_net.c
index 81d977210f8..e584e541175 100644
--- a/mysys/my_net.c
+++ b/mysys/my_net.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -35,8 +35,8 @@
void my_inet_ntoa(struct in_addr in, char *buf)
{
char *ptr;
- pthread_mutex_lock(&THR_LOCK_net);
+ mysql_mutex_lock(&THR_LOCK_net);
ptr=inet_ntoa(in);
strmov(buf,ptr);
- pthread_mutex_unlock(&THR_LOCK_net);
+ mysql_mutex_unlock(&THR_LOCK_net);
}
diff --git a/mysys/my_open.c b/mysys/my_open.c
index 79a4da242f9..a50baf2c417 100644
--- a/mysys/my_open.c
+++ b/mysys/my_open.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -70,7 +70,7 @@ int my_close(File fd, myf MyFlags)
DBUG_ENTER("my_close");
DBUG_PRINT("my",("fd: %d MyFlags: %d",fd, MyFlags));
- pthread_mutex_lock(&THR_LOCK_open);
+ mysql_mutex_lock(&THR_LOCK_open);
#ifndef _WIN32
do
{
@@ -90,12 +90,12 @@ int my_close(File fd, myf MyFlags)
{
my_free(my_file_info[fd].name, MYF(0));
#if defined(THREAD) && !defined(HAVE_PREAD) && !defined(_WIN32)
- pthread_mutex_destroy(&my_file_info[fd].mutex);
+ mysql_mutex_destroy(&my_file_info[fd].mutex);
#endif
my_file_info[fd].type = UNOPEN;
}
my_file_opened--;
- pthread_mutex_unlock(&THR_LOCK_open);
+ mysql_mutex_unlock(&THR_LOCK_open);
DBUG_RETURN(err);
} /* my_close */
@@ -134,20 +134,21 @@ File my_register_filename(File fd, const char *FileName, enum file_type
}
else
{
- pthread_mutex_lock(&THR_LOCK_open);
+ mysql_mutex_lock(&THR_LOCK_open);
if ((my_file_info[fd].name = (char*) my_strdup(FileName,MyFlags)))
{
my_file_opened++;
my_file_total_opened++;
my_file_info[fd].type = type_of_file;
#if defined(THREAD) && !defined(HAVE_PREAD) && !defined(_WIN32)
- pthread_mutex_init(&my_file_info[fd].mutex,MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_my_file_info_mutex, &my_file_info[fd].mutex,
+ MY_MUTEX_INIT_FAST);
#endif
- pthread_mutex_unlock(&THR_LOCK_open);
+ mysql_mutex_unlock(&THR_LOCK_open);
DBUG_PRINT("exit",("fd: %d",fd));
DBUG_RETURN(fd);
}
- pthread_mutex_unlock(&THR_LOCK_open);
+ mysql_mutex_unlock(&THR_LOCK_open);
my_errno= ENOMEM;
}
(void) my_close(fd, MyFlags);
diff --git a/mysys/my_pread.c b/mysys/my_pread.c
index eaabcb1b728..d0a0ddaec66 100644
--- a/mysys/my_pread.c
+++ b/mysys/my_pread.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -60,12 +60,12 @@ size_t my_pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset,
{
errno= 0; /* Linux, Windows don't reset this on EOF/success */
#if !defined (HAVE_PREAD) && !defined (_WIN32)
- pthread_mutex_lock(&my_file_info[Filedes].mutex);
+ mysql_mutex_lock(&my_file_info[Filedes].mutex);
readbytes= (uint) -1;
error= (lseek(Filedes, offset, MY_SEEK_SET) == (my_off_t) -1 ||
(readbytes= read(Filedes, Buffer, Count)) != Count);
save_errno= errno;
- pthread_mutex_unlock(&my_file_info[Filedes].mutex);
+ mysql_mutex_unlock(&my_file_info[Filedes].mutex);
if (error)
errno= save_errno;
#else
@@ -150,10 +150,10 @@ size_t my_pwrite(File Filedes, const uchar *Buffer, size_t Count,
#if !defined (HAVE_PREAD) && !defined (_WIN32)
int error;
writtenbytes= (size_t) -1;
- pthread_mutex_lock(&my_file_info[Filedes].mutex);
+ mysql_mutex_lock(&my_file_info[Filedes].mutex);
error= (lseek(Filedes, offset, MY_SEEK_SET) != (my_off_t) -1 &&
(writtenbytes= write(Filedes, Buffer, Count)) == Count);
- pthread_mutex_unlock(&my_file_info[Filedes].mutex);
+ mysql_mutex_unlock(&my_file_info[Filedes].mutex);
if (error)
break;
#elif defined (_WIN32)
diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c
index fd1798ab203..b6b7e7db857 100644
--- a/mysys/my_pthread.c
+++ b/mysys/my_pthread.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -96,7 +96,7 @@ int my_sigwait(const sigset_t *set,int *sig)
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
-extern pthread_mutex_t LOCK_localtime_r;
+extern mysql_mutex_t LOCK_localtime_r;
#endif
@@ -104,10 +104,10 @@ extern pthread_mutex_t LOCK_localtime_r;
struct tm *localtime_r(const time_t *clock, struct tm *res)
{
struct tm *tmp;
- pthread_mutex_lock(&LOCK_localtime_r);
+ mysql_mutex_lock(&LOCK_localtime_r);
tmp=localtime(clock);
*res= *tmp;
- pthread_mutex_unlock(&LOCK_localtime_r);
+ mysql_mutex_unlock(&LOCK_localtime_r);
return res;
}
#endif
@@ -121,10 +121,10 @@ struct tm *localtime_r(const time_t *clock, struct tm *res)
struct tm *gmtime_r(const time_t *clock, struct tm *res)
{
struct tm *tmp;
- pthread_mutex_lock(&LOCK_localtime_r);
+ mysql_mutex_lock(&LOCK_localtime_r);
tmp= gmtime(clock);
*res= *tmp;
- pthread_mutex_unlock(&LOCK_localtime_r);
+ mysql_mutex_unlock(&LOCK_localtime_r);
return res;
}
#endif
@@ -317,14 +317,14 @@ int sigwait(sigset_t *setp, int *sigp)
pthread_t sigwait_thread_id;
inited=1;
sigemptyset(&pending_set);
- pthread_mutex_init(&LOCK_sigwait,MY_MUTEX_INIT_FAST);
- pthread_cond_init(&COND_sigwait,NULL);
+ pthread_mutex_init(&LOCK_sigwait, MY_MUTEX_INIT_FAST);
+ pthread_cond_init(&COND_sigwait, NULL);
pthread_attr_init(&thr_attr);
pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_PROCESS);
pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);
pthread_attr_setstacksize(&thr_attr,8196);
- pthread_create(&sigwait_thread_id,&thr_attr,sigwait_thread,setp);
+ pthread_create(&sigwait_thread_id, &thr_attr, sigwait_thread, setp);
pthread_attr_destroy(&thr_attr);
}
@@ -351,7 +351,7 @@ int sigwait(sigset_t *setp, int *sigp)
return 0;
}
}
- pthread_cond_wait(&COND_sigwait,&LOCK_sigwait);
+ pthread_cond_wait(&COND_sigwait, &LOCK_sigwait);
}
return 0;
}
diff --git a/mysys/my_sync.c b/mysys/my_sync.c
index 7b2112fa032..6497ae59159 100644
--- a/mysys/my_sync.c
+++ b/mysys/my_sync.c
@@ -103,11 +103,11 @@ static const char cur_dir_name[]= {FN_CURLIB, 0};
int my_sync_dir(const char *dir_name, myf my_flags)
{
#ifdef NEED_EXPLICIT_SYNC_DIR
- DBUG_ENTER("my_sync_dir");
- DBUG_PRINT("my",("Dir: '%s' my_flags: %d", dir_name, my_flags));
File dir_fd;
int res= 0;
const char *correct_dir_name;
+ DBUG_ENTER("my_sync_dir");
+ DBUG_PRINT("my",("Dir: '%s' my_flags: %d", dir_name, my_flags));
/* Sometimes the path does not contain an explicit directory */
correct_dir_name= (dir_name[0] == 0) ? cur_dir_name : dir_name;
/*
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c
index ba59c483012..b3d7d63b197 100644
--- a/mysys/my_thr_init.c
+++ b/mysys/my_thr_init.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -24,17 +24,17 @@
#ifdef THREAD
pthread_key(struct st_my_thread_var*, THR_KEY_mysys);
-pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open,
- THR_LOCK_lock,THR_LOCK_isam,THR_LOCK_myisam,THR_LOCK_heap,
- THR_LOCK_net, THR_LOCK_charset, THR_LOCK_threads, THR_LOCK_time;
-pthread_cond_t THR_COND_threads;
+mysql_mutex_t THR_LOCK_malloc, THR_LOCK_open,
+ THR_LOCK_lock, THR_LOCK_isam, THR_LOCK_myisam, THR_LOCK_heap,
+ THR_LOCK_net, THR_LOCK_charset, THR_LOCK_threads, THR_LOCK_time;
+mysql_cond_t THR_COND_threads;
uint THR_thread_count= 0;
uint my_thread_end_wait_time= 5;
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
-pthread_mutex_t LOCK_localtime_r;
+mysql_mutex_t LOCK_localtime_r;
#endif
#ifndef HAVE_GETHOSTBYNAME_R
-pthread_mutex_t LOCK_gethostbyname_r;
+mysql_mutex_t LOCK_gethostbyname_r;
#endif
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_t my_fast_mutexattr;
@@ -65,6 +65,84 @@ nptl_pthread_exit_hack_handler(void *arg __attribute((unused)))
static uint get_thread_lib(void);
+/** True if @c my_thread_basic_global_init() has been called. */
+static my_bool my_thread_basic_global_init_done= 0;
+
+/**
+ Perform a minimal initialisation of mysys, when compiled with threads.
+ The initialisation performed is sufficient to:
+ - allocate memory
+ - perform file operations
+ - use charsets
+ - use my_errno
+ @sa my_basic_init
+ @sa my_thread_basic_global_reinit
+*/
+my_bool my_thread_basic_global_init(void)
+{
+ int pth_ret;
+
+ if (my_thread_basic_global_init_done)
+ return 0;
+ my_thread_basic_global_init_done= 1;
+
+ mysql_mutex_init(key_THR_LOCK_malloc, &THR_LOCK_malloc, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_THR_LOCK_open, &THR_LOCK_open, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_THR_LOCK_charset, &THR_LOCK_charset, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_THR_LOCK_threads, &THR_LOCK_threads, MY_MUTEX_INIT_FAST);
+
+ if ((pth_ret= pthread_key_create(&THR_KEY_mysys, NULL)) != 0)
+ {
+ fprintf(stderr, "Can't initialize threads: error %d\n", pth_ret);
+ return 1;
+ }
+
+ if (my_thread_init())
+ return 1;
+
+ return 0;
+}
+
+/**
+ Re-initialize components initialized early with @c my_thread_basic_global_init.
+ Some mutexes were initialized before the instrumentation.
+ Destroy + create them again, now that the instrumentation
+ is in place.
+ This is safe, since this function() is called before creating new threads,
+ so the mutexes are not in use.
+*/
+void my_thread_basic_global_reinit(void)
+{
+ struct st_my_thread_var *tmp;
+
+ DBUG_ASSERT(my_thread_basic_global_init_done);
+
+#ifdef HAVE_PSI_INTERFACE
+ my_init_mysys_psi_keys();
+#endif
+
+ mysql_mutex_destroy(&THR_LOCK_malloc);
+ mysql_mutex_init(key_THR_LOCK_malloc, &THR_LOCK_malloc, MY_MUTEX_INIT_FAST);
+
+ mysql_mutex_destroy(&THR_LOCK_open);
+ mysql_mutex_init(key_THR_LOCK_open, &THR_LOCK_open, MY_MUTEX_INIT_FAST);
+
+ mysql_mutex_destroy(&THR_LOCK_charset);
+ mysql_mutex_init(key_THR_LOCK_charset, &THR_LOCK_charset, MY_MUTEX_INIT_FAST);
+
+ mysql_mutex_destroy(&THR_LOCK_threads);
+ mysql_mutex_init(key_THR_LOCK_threads, &THR_LOCK_threads, MY_MUTEX_INIT_FAST);
+
+ tmp= my_pthread_getspecific(struct st_my_thread_var*, THR_KEY_mysys);
+ DBUG_ASSERT(tmp);
+
+ mysql_mutex_destroy(&tmp->mutex);
+ mysql_mutex_init(key_my_thread_var_mutex, &tmp->mutex, MY_MUTEX_INIT_FAST);
+
+ mysql_cond_destroy(&tmp->suspend);
+ mysql_cond_init(key_my_thread_var_suspend, &tmp->suspend, NULL);
+}
+
/*
initialize thread environment
@@ -78,14 +156,10 @@ static uint get_thread_lib(void);
my_bool my_thread_global_init(void)
{
- int pth_ret;
- thd_lib_detected= get_thread_lib();
-
- if ((pth_ret= pthread_key_create(&THR_KEY_mysys, NULL)) != 0)
- {
- fprintf(stderr,"Can't initialize threads: error %d\n", pth_ret);
+ if (my_thread_basic_global_init())
return 1;
- }
+
+ thd_lib_detected= get_thread_lib();
#ifdef TARGET_OS_LINUX
/*
@@ -137,23 +211,20 @@ my_bool my_thread_global_init(void)
PTHREAD_MUTEX_ERRORCHECK);
#endif
- pthread_mutex_init(&THR_LOCK_malloc,MY_MUTEX_INIT_FAST);
- pthread_mutex_init(&THR_LOCK_open,MY_MUTEX_INIT_FAST);
- pthread_mutex_init(&THR_LOCK_lock,MY_MUTEX_INIT_FAST);
- pthread_mutex_init(&THR_LOCK_isam,MY_MUTEX_INIT_SLOW);
- pthread_mutex_init(&THR_LOCK_myisam,MY_MUTEX_INIT_SLOW);
- pthread_mutex_init(&THR_LOCK_heap,MY_MUTEX_INIT_FAST);
- pthread_mutex_init(&THR_LOCK_net,MY_MUTEX_INIT_FAST);
- pthread_mutex_init(&THR_LOCK_charset,MY_MUTEX_INIT_FAST);
- pthread_mutex_init(&THR_LOCK_threads,MY_MUTEX_INIT_FAST);
- pthread_mutex_init(&THR_LOCK_time,MY_MUTEX_INIT_FAST);
- pthread_cond_init(&THR_COND_threads, NULL);
+ mysql_mutex_init(key_THR_LOCK_lock, &THR_LOCK_lock, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_THR_LOCK_isam, &THR_LOCK_isam, MY_MUTEX_INIT_SLOW);
+ mysql_mutex_init(key_THR_LOCK_myisam, &THR_LOCK_myisam, MY_MUTEX_INIT_SLOW);
+ mysql_mutex_init(key_THR_LOCK_heap, &THR_LOCK_heap, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_THR_LOCK_net, &THR_LOCK_net, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_THR_LOCK_time, &THR_LOCK_time, MY_MUTEX_INIT_FAST);
+ mysql_cond_init(key_THR_COND_threads, &THR_COND_threads, NULL);
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
- pthread_mutex_init(&LOCK_localtime_r,MY_MUTEX_INIT_SLOW);
+ mysql_mutex_init(key_LOCK_localtime_r, &LOCK_localtime_r, MY_MUTEX_INIT_SLOW);
#endif
#ifndef HAVE_GETHOSTBYNAME_R
- pthread_mutex_init(&LOCK_gethostbyname_r,MY_MUTEX_INIT_SLOW);
+ mysql_mutex_init(key_LOCK_gethostbyname_r,
+ &LOCK_gethostbyname_r, MY_MUTEX_INIT_SLOW);
#endif
#ifdef _MSC_VER
@@ -175,11 +246,11 @@ void my_thread_global_end(void)
my_bool all_threads_killed= 1;
set_timespec(abstime, my_thread_end_wait_time);
- pthread_mutex_lock(&THR_LOCK_threads);
+ mysql_mutex_lock(&THR_LOCK_threads);
while (THR_thread_count > 0)
{
- int error= pthread_cond_timedwait(&THR_COND_threads, &THR_LOCK_threads,
- &abstime);
+ int error= mysql_cond_timedwait(&THR_COND_threads, &THR_LOCK_threads,
+ &abstime);
if (error == ETIMEDOUT || error == ETIME)
{
#ifdef HAVE_PTHREAD_KILL
@@ -197,7 +268,7 @@ void my_thread_global_end(void)
break;
}
}
- pthread_mutex_unlock(&THR_LOCK_threads);
+ mysql_mutex_unlock(&THR_LOCK_threads);
pthread_key_delete(THR_KEY_mysys);
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
@@ -206,25 +277,25 @@ void my_thread_global_end(void)
#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
pthread_mutexattr_destroy(&my_errorcheck_mutexattr);
#endif
- pthread_mutex_destroy(&THR_LOCK_malloc);
- pthread_mutex_destroy(&THR_LOCK_open);
- pthread_mutex_destroy(&THR_LOCK_lock);
- pthread_mutex_destroy(&THR_LOCK_isam);
- pthread_mutex_destroy(&THR_LOCK_myisam);
- pthread_mutex_destroy(&THR_LOCK_heap);
- pthread_mutex_destroy(&THR_LOCK_net);
- pthread_mutex_destroy(&THR_LOCK_time);
- pthread_mutex_destroy(&THR_LOCK_charset);
+ mysql_mutex_destroy(&THR_LOCK_malloc);
+ mysql_mutex_destroy(&THR_LOCK_open);
+ mysql_mutex_destroy(&THR_LOCK_lock);
+ mysql_mutex_destroy(&THR_LOCK_isam);
+ mysql_mutex_destroy(&THR_LOCK_myisam);
+ mysql_mutex_destroy(&THR_LOCK_heap);
+ mysql_mutex_destroy(&THR_LOCK_net);
+ mysql_mutex_destroy(&THR_LOCK_time);
+ mysql_mutex_destroy(&THR_LOCK_charset);
if (all_threads_killed)
{
- pthread_mutex_destroy(&THR_LOCK_threads);
- pthread_cond_destroy(&THR_COND_threads);
+ mysql_mutex_destroy(&THR_LOCK_threads);
+ mysql_cond_destroy(&THR_COND_threads);
}
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
- pthread_mutex_destroy(&LOCK_localtime_r);
+ mysql_mutex_destroy(&LOCK_localtime_r);
#endif
#ifndef HAVE_GETHOSTBYNAME_R
- pthread_mutex_destroy(&LOCK_gethostbyname_r);
+ mysql_mutex_destroy(&LOCK_gethostbyname_r);
#endif
}
@@ -280,17 +351,17 @@ my_bool my_thread_init(void)
}
pthread_setspecific(THR_KEY_mysys,tmp);
tmp->pthread_self= pthread_self();
- pthread_mutex_init(&tmp->mutex,MY_MUTEX_INIT_FAST);
- pthread_cond_init(&tmp->suspend, NULL);
- tmp->init= 1;
+ mysql_mutex_init(key_my_thread_var_mutex, &tmp->mutex, MY_MUTEX_INIT_FAST);
+ mysql_cond_init(key_my_thread_var_suspend, &tmp->suspend, NULL);
tmp->stack_ends_here= (char*)&tmp +
STACK_DIRECTION * (long)my_thread_stack_size;
- pthread_mutex_lock(&THR_LOCK_threads);
+ mysql_mutex_lock(&THR_LOCK_threads);
tmp->id= ++thread_id;
++THR_thread_count;
- pthread_mutex_unlock(&THR_LOCK_threads);
+ mysql_mutex_unlock(&THR_LOCK_threads);
+ tmp->init= 1;
#ifndef DBUG_OFF
/* Generate unique name for thread */
(void) my_thread_name();
@@ -322,6 +393,17 @@ void my_thread_end(void)
fprintf(stderr,"my_thread_end(): tmp: 0x%lx pthread_self: 0x%lx thread_id: %ld\n",
(long) tmp, (long) pthread_self(), tmp ? (long) tmp->id : 0L);
#endif
+
+#ifdef HAVE_PSI_INTERFACE
+ /*
+ Remove the instrumentation for this thread.
+ This must be done before trashing st_my_thread_var,
+ because the LF_HASH depends on it.
+ */
+ if (PSI_server)
+ PSI_server->delete_current_thread();
+#endif
+
if (tmp && tmp->init)
{
#if !defined(DBUG_OFF)
@@ -335,9 +417,9 @@ void my_thread_end(void)
#endif
#if !defined(__bsdi__) && !defined(__OpenBSD__)
/* bsdi and openbsd 3.5 dumps core here */
- pthread_cond_destroy(&tmp->suspend);
+ mysql_cond_destroy(&tmp->suspend);
#endif
- pthread_mutex_destroy(&tmp->mutex);
+ mysql_mutex_destroy(&tmp->mutex);
free(tmp);
/*
@@ -346,11 +428,11 @@ void my_thread_end(void)
my_thread_end and thus freed all memory they have allocated in
my_thread_init() and DBUG_xxxx
*/
- pthread_mutex_lock(&THR_LOCK_threads);
+ mysql_mutex_lock(&THR_LOCK_threads);
DBUG_ASSERT(THR_thread_count != 0);
if (--THR_thread_count == 0)
- pthread_cond_signal(&THR_COND_threads);
- pthread_mutex_unlock(&THR_LOCK_threads);
+ mysql_cond_signal(&THR_COND_threads);
+ mysql_mutex_unlock(&THR_LOCK_threads);
}
pthread_setspecific(THR_KEY_mysys,0);
}
diff --git a/mysys/my_winfile.c b/mysys/my_winfile.c
index 6a2cda5ba29..6c0b191ca2c 100644
--- a/mysys/my_winfile.c
+++ b/mysys/my_winfile.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2008 MySQL AB
+/* Copyright (C) 2008 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -57,7 +57,7 @@ File my_open_osfhandle(HANDLE handle, int oflag)
uint i;
DBUG_ENTER("my_open_osfhandle");
- pthread_mutex_lock(&THR_LOCK_open);
+ mysql_mutex_lock(&THR_LOCK_open);
for(i= MY_FILE_MIN; i < my_file_limit;i++)
{
if(my_file_info[i].fhandle == 0)
@@ -70,7 +70,7 @@ File my_open_osfhandle(HANDLE handle, int oflag)
break;
}
}
- pthread_mutex_unlock(&THR_LOCK_open);
+ mysql_mutex_unlock(&THR_LOCK_open);
if(offset == -1)
errno= EMFILE; /* to many file handles open */
DBUG_RETURN(offset);
diff --git a/mysys/mysys_priv.h b/mysys/mysys_priv.h
index 5c5bd6c2908..3a663dfefbf 100644
--- a/mysys/mysys_priv.h
+++ b/mysys/mysys_priv.h
@@ -59,9 +59,9 @@ extern PSI_thread_key key_thread_alarm;
#endif /* HAVE_PSI_INTERFACE */
-extern pthread_mutex_t THR_LOCK_malloc, THR_LOCK_open, THR_LOCK_keycache;
-extern pthread_mutex_t THR_LOCK_lock, THR_LOCK_isam, THR_LOCK_net;
-extern pthread_mutex_t THR_LOCK_charset, THR_LOCK_time;
+extern mysql_mutex_t THR_LOCK_malloc, THR_LOCK_open, THR_LOCK_keycache;
+extern mysql_mutex_t THR_LOCK_lock, THR_LOCK_isam, THR_LOCK_net;
+extern mysql_mutex_t THR_LOCK_charset, THR_LOCK_time;
#else /* THREAD */
#include <my_no_pthread.h>
#endif /* THREAD */
diff --git a/mysys/ptr_cmp.c b/mysys/ptr_cmp.c
index 24ab6a1ea9c..2005e3eb2b7 100644
--- a/mysys/ptr_cmp.c
+++ b/mysys/ptr_cmp.c
@@ -22,16 +22,39 @@
#include "mysys_priv.h"
#include <myisampack.h>
+#ifdef TARGET_OS_SOLARIS
+/*
+ * On Solaris, memcmp() is normally faster than the unrolled ptr_compare_N
+ * functions, as memcmp() is usually a platform-specific implementation
+ * written in assembler, provided in /usr/lib/libc/libc_hwcap*.so.1.
+ * This implementation is also usually faster than the built-in memcmp
+ * supplied by GCC, so it is recommended to build with "-fno-builtin-memcmp"
+ * in CFLAGS if building with GCC on Solaris.
+ */
+
+#include <string.h>
+
+static int native_compare(size_t *length, unsigned char **a, unsigned char **b)
+{
+ return memcmp(*a, *b, *length);
+}
+
+#else /* TARGET_OS_SOLARIS */
+
static int ptr_compare(size_t *compare_length, uchar **a, uchar **b);
static int ptr_compare_0(size_t *compare_length, uchar **a, uchar **b);
static int ptr_compare_1(size_t *compare_length, uchar **a, uchar **b);
static int ptr_compare_2(size_t *compare_length, uchar **a, uchar **b);
static int ptr_compare_3(size_t *compare_length, uchar **a, uchar **b);
+#endif /* TARGET_OS_SOLARIS */
/* Get a pointer to a optimal byte-compare function for a given size */
qsort2_cmp get_ptr_compare (size_t size)
{
+#ifdef TARGET_OS_SOLARIS
+ return (qsort2_cmp) native_compare;
+#else
if (size < 4)
return (qsort2_cmp) ptr_compare;
switch (size & 3) {
@@ -41,6 +64,7 @@ qsort2_cmp get_ptr_compare (size_t size)
case 3: return (qsort2_cmp) ptr_compare_3;
}
return 0; /* Impossible */
+#endif /* TARGET_OS_SOLARIS */
}
diff --git a/mysys/safemalloc.c b/mysys/safemalloc.c
index c484f1d4c54..675fa62380a 100644
--- a/mysys/safemalloc.c
+++ b/mysys/safemalloc.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -178,7 +178,7 @@ void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags)
irem->prev= NULL;
/* Add this remember structure to the linked list */
- pthread_mutex_lock(&THR_LOCK_malloc);
+ mysql_mutex_lock(&THR_LOCK_malloc);
if ((irem->next= sf_malloc_root))
sf_malloc_root->prev= irem;
sf_malloc_root= irem;
@@ -188,7 +188,7 @@ void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags)
if (sf_malloc_cur_memory > sf_malloc_max_memory)
sf_malloc_max_memory= sf_malloc_cur_memory;
sf_malloc_count++;
- pthread_mutex_unlock(&THR_LOCK_malloc);
+ mysql_mutex_unlock(&THR_LOCK_malloc);
/* Set the memory to the aribtrary wierd value */
if ((MyFlags & MY_ZEROFILL) || !sf_malloc_quick)
@@ -291,7 +291,7 @@ void _myfree(void *ptr, const char *filename, uint lineno, myf myflags)
}
/* Remove this structure from the linked list */
- pthread_mutex_lock(&THR_LOCK_malloc);
+ mysql_mutex_lock(&THR_LOCK_malloc);
if (irem->prev)
irem->prev->next= irem->next;
else
@@ -302,7 +302,7 @@ void _myfree(void *ptr, const char *filename, uint lineno, myf myflags)
/* Handle the statistics */
sf_malloc_cur_memory-= irem->datasize;
sf_malloc_count--;
- pthread_mutex_unlock(&THR_LOCK_malloc);
+ mysql_mutex_unlock(&THR_LOCK_malloc);
#ifndef HAVE_purify
/* Mark this data as free'ed */
@@ -365,7 +365,7 @@ void TERMINATE(FILE *file, uint flag)
{
struct st_irem *irem;
DBUG_ENTER("TERMINATE");
- pthread_mutex_lock(&THR_LOCK_malloc);
+ mysql_mutex_lock(&THR_LOCK_malloc);
/*
Report the difference between number of calls to
@@ -428,7 +428,7 @@ void TERMINATE(FILE *file, uint flag)
DBUG_PRINT("safe",("Maximum memory usage: %lu bytes (%luk)",
(ulong) sf_malloc_max_memory,
(ulong) (sf_malloc_max_memory + 1023L) /1024L));
- pthread_mutex_unlock(&THR_LOCK_malloc);
+ mysql_mutex_unlock(&THR_LOCK_malloc);
DBUG_VOID_RETURN;
}
@@ -505,7 +505,7 @@ int _sanity(const char *filename, uint lineno)
reg2 int flag=0;
uint count=0;
- pthread_mutex_lock(&THR_LOCK_malloc);
+ mysql_mutex_lock(&THR_LOCK_malloc);
#ifndef PEDANTIC_SAFEMALLOC
if (sf_malloc_tampered && (int) sf_malloc_count < 0)
sf_malloc_count=0;
@@ -513,7 +513,7 @@ int _sanity(const char *filename, uint lineno)
count=sf_malloc_count;
for (irem= sf_malloc_root; irem != NULL && count-- ; irem= irem->next)
flag+= _checkchunk (irem, filename, lineno);
- pthread_mutex_unlock(&THR_LOCK_malloc);
+ mysql_mutex_unlock(&THR_LOCK_malloc);
if (count || irem)
{
const char *format="Error: Safemalloc link list destroyed, discovered at '%s:%d'";
diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c
index 9ab862fa755..8ee89cfb55d 100644
--- a/mysys/thr_alarm.c
+++ b/mysys/thr_alarm.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -15,6 +15,7 @@
/* To avoid problems with alarms in debug code, we disable DBUG here */
#define FORCE_DBUG_OFF
+#include "mysys_priv.h"
#include <my_global.h>
#if defined(THREAD) && !defined(DONT_USE_THR_ALARM)
@@ -43,8 +44,8 @@ static sig_handler process_alarm_part2(int sig);
#if !defined(__WIN__)
-static pthread_mutex_t LOCK_alarm;
-static pthread_cond_t COND_alarm;
+static mysql_mutex_t LOCK_alarm;
+static mysql_cond_t COND_alarm;
static sigset_t full_signal_set;
static QUEUE alarm_queue;
static uint max_used_alarms=0;
@@ -52,7 +53,7 @@ pthread_t alarm_thread;
#ifdef USE_ALARM_THREAD
static void *alarm_handler(void *arg);
-#define reschedule_alarms() pthread_cond_signal(&COND_alarm)
+#define reschedule_alarms() mysql_cond_signal(&COND_alarm)
#else
#define reschedule_alarms() pthread_kill(alarm_thread,THR_SERVER_ALARM)
#endif
@@ -75,8 +76,8 @@ void init_thr_alarm(uint max_alarms)
init_queue(&alarm_queue,max_alarms+1,offsetof(ALARM,expire_time),0,
compare_ulong,NullS);
sigfillset(&full_signal_set); /* Neaded to block signals */
- pthread_mutex_init(&LOCK_alarm,MY_MUTEX_INIT_FAST);
- pthread_cond_init(&COND_alarm,NULL);
+ mysql_mutex_init(key_LOCK_alarm, &LOCK_alarm, MY_MUTEX_INIT_FAST);
+ mysql_cond_init(key_COND_alarm, &COND_alarm, NULL);
if (thd_lib_detected == THD_LIB_LT)
thr_client_alarm= SIGALRM;
else
@@ -97,7 +98,8 @@ void init_thr_alarm(uint max_alarms)
pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_PROCESS);
pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);
pthread_attr_setstacksize(&thr_attr,8196);
- pthread_create(&alarm_thread,&thr_attr,alarm_handler,NULL);
+ mysql_thread_create(key_thread_alarm,
+ &alarm_thread, &thr_attr, alarm_handler, NULL);
pthread_attr_destroy(&thr_attr);
}
#elif defined(USE_ONE_SIGNAL_HAND)
@@ -117,14 +119,14 @@ void init_thr_alarm(uint max_alarms)
void resize_thr_alarm(uint max_alarms)
{
- pthread_mutex_lock(&LOCK_alarm);
+ mysql_mutex_lock(&LOCK_alarm);
/*
It's ok not to shrink the queue as there may be more pending alarms than
than max_alarms
*/
if (alarm_queue.elements < max_alarms)
resize_queue(&alarm_queue,max_alarms+1);
- pthread_mutex_unlock(&LOCK_alarm);
+ mysql_mutex_unlock(&LOCK_alarm);
}
@@ -162,12 +164,12 @@ my_bool thr_alarm(thr_alarm_t *alrm, uint sec, ALARM *alarm_data)
#ifndef USE_ONE_SIGNAL_HAND
pthread_sigmask(SIG_BLOCK,&full_signal_set,&old_mask);
#endif
- pthread_mutex_lock(&LOCK_alarm); /* Lock from threads & alarms */
+ mysql_mutex_lock(&LOCK_alarm); /* Lock from threads & alarms */
if (alarm_aborted > 0)
{ /* No signal thread */
DBUG_PRINT("info", ("alarm aborted"));
*alrm= 0; /* No alarm */
- pthread_mutex_unlock(&LOCK_alarm);
+ mysql_mutex_unlock(&LOCK_alarm);
#ifndef USE_ONE_SIGNAL_HAND
pthread_sigmask(SIG_SETMASK,&old_mask,NULL);
#endif
@@ -183,7 +185,7 @@ my_bool thr_alarm(thr_alarm_t *alrm, uint sec, ALARM *alarm_data)
DBUG_PRINT("info", ("alarm queue full"));
fprintf(stderr,"Warning: thr_alarm queue is full\n");
*alrm= 0; /* No alarm */
- pthread_mutex_unlock(&LOCK_alarm);
+ mysql_mutex_unlock(&LOCK_alarm);
#ifndef USE_ONE_SIGNAL_HAND
pthread_sigmask(SIG_SETMASK,&old_mask,NULL);
#endif
@@ -198,7 +200,7 @@ my_bool thr_alarm(thr_alarm_t *alrm, uint sec, ALARM *alarm_data)
{
DBUG_PRINT("info", ("failed my_malloc()"));
*alrm= 0; /* No alarm */
- pthread_mutex_unlock(&LOCK_alarm);
+ mysql_mutex_unlock(&LOCK_alarm);
#ifndef USE_ONE_SIGNAL_HAND
pthread_sigmask(SIG_SETMASK,&old_mask,NULL);
#endif
@@ -226,7 +228,7 @@ my_bool thr_alarm(thr_alarm_t *alrm, uint sec, ALARM *alarm_data)
else
reschedule_alarms(); /* Reschedule alarms */
}
- pthread_mutex_unlock(&LOCK_alarm);
+ mysql_mutex_unlock(&LOCK_alarm);
#ifndef USE_ONE_SIGNAL_HAND
pthread_sigmask(SIG_SETMASK,&old_mask,NULL);
#endif
@@ -251,7 +253,7 @@ void thr_end_alarm(thr_alarm_t *alarmed)
#ifndef USE_ONE_SIGNAL_HAND
pthread_sigmask(SIG_BLOCK,&full_signal_set,&old_mask);
#endif
- pthread_mutex_lock(&LOCK_alarm);
+ mysql_mutex_lock(&LOCK_alarm);
alarm_data= (ALARM*) ((uchar*) *alarmed - offsetof(ALARM,alarmed));
for (i=0 ; i < alarm_queue.elements ; i++)
@@ -276,7 +278,7 @@ void thr_end_alarm(thr_alarm_t *alarmed)
DBUG_PRINT("warning",("Didn't find alarm 0x%lx in queue\n",
(long) *alarmed));
}
- pthread_mutex_unlock(&LOCK_alarm);
+ mysql_mutex_unlock(&LOCK_alarm);
#ifndef USE_ONE_SIGNAL_HAND
pthread_sigmask(SIG_SETMASK,&old_mask,NULL);
#endif
@@ -319,14 +321,14 @@ sig_handler process_alarm(int sig __attribute__((unused)))
#ifndef USE_ALARM_THREAD
pthread_sigmask(SIG_SETMASK,&full_signal_set,&old_mask);
- pthread_mutex_lock(&LOCK_alarm);
+ mysql_mutex_lock(&LOCK_alarm);
#endif
process_alarm_part2(sig);
#ifndef USE_ALARM_THREAD
#if defined(DONT_REMEMBER_SIGNAL) && !defined(USE_ONE_SIGNAL_HAND)
my_sigset(THR_SERVER_ALARM,process_alarm);
#endif
- pthread_mutex_unlock(&LOCK_alarm);
+ mysql_mutex_unlock(&LOCK_alarm);
pthread_sigmask(SIG_SETMASK,&old_mask,NULL);
#endif
return;
@@ -434,7 +436,7 @@ void end_thr_alarm(my_bool free_structures)
DBUG_ENTER("end_thr_alarm");
if (alarm_aborted != 1) /* If memory not freed */
{
- pthread_mutex_lock(&LOCK_alarm);
+ mysql_mutex_lock(&LOCK_alarm);
DBUG_PRINT("info",("Resheduling %d waiting alarms",alarm_queue.elements));
alarm_aborted= -1; /* mark aborted */
if (alarm_queue.elements || (alarm_thread_running && free_structures))
@@ -454,21 +456,21 @@ void end_thr_alarm(my_bool free_structures)
set_timespec(abstime, 10); /* Wait up to 10 seconds */
while (alarm_thread_running)
{
- int error= pthread_cond_timedwait(&COND_alarm, &LOCK_alarm, &abstime);
+ int error= mysql_cond_timedwait(&COND_alarm, &LOCK_alarm, &abstime);
if (error == ETIME || error == ETIMEDOUT)
break; /* Don't wait forever */
}
delete_queue(&alarm_queue);
alarm_aborted= 1;
- pthread_mutex_unlock(&LOCK_alarm);
+ mysql_mutex_unlock(&LOCK_alarm);
if (!alarm_thread_running) /* Safety */
{
- pthread_mutex_destroy(&LOCK_alarm);
- pthread_cond_destroy(&COND_alarm);
+ mysql_mutex_destroy(&LOCK_alarm);
+ mysql_cond_destroy(&COND_alarm);
}
}
else
- pthread_mutex_unlock(&LOCK_alarm);
+ mysql_mutex_unlock(&LOCK_alarm);
}
DBUG_VOID_RETURN;
}
@@ -483,7 +485,7 @@ void thr_alarm_kill(my_thread_id thread_id)
uint i;
if (alarm_aborted)
return;
- pthread_mutex_lock(&LOCK_alarm);
+ mysql_mutex_lock(&LOCK_alarm);
for (i=0 ; i < alarm_queue.elements ; i++)
{
if (((ALARM*) queue_element(&alarm_queue,i))->thread_id == thread_id)
@@ -495,13 +497,13 @@ void thr_alarm_kill(my_thread_id thread_id)
break;
}
}
- pthread_mutex_unlock(&LOCK_alarm);
+ mysql_mutex_unlock(&LOCK_alarm);
}
void thr_alarm_info(ALARM_INFO *info)
{
- pthread_mutex_lock(&LOCK_alarm);
+ mysql_mutex_lock(&LOCK_alarm);
info->next_alarm_time= 0;
info->max_used_alarms= max_used_alarms;
if ((info->active_alarms= alarm_queue.elements))
@@ -512,7 +514,7 @@ void thr_alarm_info(ALARM_INFO *info)
time_diff= (long) (alarm_data->expire_time - now);
info->next_alarm_time= (ulong) (time_diff < 0 ? 0 : time_diff);
}
- pthread_mutex_unlock(&LOCK_alarm);
+ mysql_mutex_unlock(&LOCK_alarm);
}
/*
@@ -549,7 +551,7 @@ static void *alarm_handler(void *arg __attribute__((unused)))
#endif
my_thread_init();
alarm_thread_running= 1;
- pthread_mutex_lock(&LOCK_alarm);
+ mysql_mutex_lock(&LOCK_alarm);
for (;;)
{
if (alarm_queue.elements)
@@ -564,7 +566,7 @@ static void *alarm_handler(void *arg __attribute__((unused)))
abstime.tv_sec=sleep_time;
abstime.tv_nsec=0;
next_alarm_expire_time= sleep_time;
- if ((error=pthread_cond_timedwait(&COND_alarm,&LOCK_alarm,&abstime)) &&
+ if ((error= mysql_cond_timedwait(&COND_alarm, &LOCK_alarm, &abstime)) &&
error != ETIME && error != ETIMEDOUT)
{
#ifdef MAIN
@@ -579,7 +581,7 @@ static void *alarm_handler(void *arg __attribute__((unused)))
else
{
next_alarm_expire_time= ~ (time_t) 0;
- if ((error=pthread_cond_wait(&COND_alarm,&LOCK_alarm)))
+ if ((error= mysql_cond_wait(&COND_alarm, &LOCK_alarm)))
{
#ifdef MAIN
printf("Got error: %d from ptread_cond_wait (errno: %d)\n",
@@ -591,8 +593,8 @@ static void *alarm_handler(void *arg __attribute__((unused)))
}
bzero((char*) &alarm_thread,sizeof(alarm_thread)); /* For easy debugging */
alarm_thread_running= 0;
- pthread_cond_signal(&COND_alarm);
- pthread_mutex_unlock(&LOCK_alarm);
+ mysql_cond_signal(&COND_alarm);
+ mysql_mutex_unlock(&LOCK_alarm);
pthread_exit(0);
return 0; /* Impossible */
}
@@ -694,8 +696,8 @@ void resize_thr_alarm(uint max_alarms)
#ifdef MAIN
#if defined(THREAD) && !defined(DONT_USE_THR_ALARM)
-static pthread_cond_t COND_thread_count;
-static pthread_mutex_t LOCK_thread_count;
+static mysql_cond_t COND_thread_count;
+static mysql_mutex_t LOCK_thread_count;
static uint thread_count;
#ifdef HPUX10
@@ -782,10 +784,10 @@ static void *test_thread(void *arg)
thr_end_alarm(&got_alarm);
fflush(stdout);
}
- pthread_mutex_lock(&LOCK_thread_count);
+ mysql_mutex_lock(&LOCK_thread_count);
thread_count--;
- pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */
- pthread_mutex_unlock(&LOCK_thread_count);
+ mysql_cond_signal(&COND_thread_count); /* Tell main we are ready */
+ mysql_mutex_unlock(&LOCK_thread_count);
free((uchar*) arg);
return 0;
}
@@ -812,9 +814,9 @@ static void *signal_hand(void *arg __attribute__((unused)))
my_thread_init();
pthread_detach_this_thread();
init_thr_alarm(10); /* Setup alarm handler */
- pthread_mutex_lock(&LOCK_thread_count); /* Required by bsdi */
- pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */
- pthread_mutex_unlock(&LOCK_thread_count);
+ mysql_mutex_lock(&LOCK_thread_count); /* Required by bsdi */
+ mysql_cond_signal(&COND_thread_count); /* Tell main we are ready */
+ mysql_mutex_unlock(&LOCK_thread_count);
sigemptyset(&set); /* Catch all signals */
sigaddset(&set,SIGINT);
@@ -885,8 +887,8 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused)))
{
DBUG_PUSH(argv[1]+2);
}
- pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST);
- pthread_cond_init(&COND_thread_count,NULL);
+ mysql_mutex_init(0, &LOCK_thread_count, MY_MUTEX_INIT_FAST);
+ mysql_cond_init(0, &COND_thread_count, NULL);
/* Start a alarm handling thread */
sigemptyset(&set);
@@ -913,10 +915,11 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused)))
pthread_attr_setstacksize(&thr_attr,65536L);
/* Start signal thread and wait for it to start */
- pthread_mutex_lock(&LOCK_thread_count);
- pthread_create(&tid,&thr_attr,signal_hand,NULL);
- pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
- pthread_mutex_unlock(&LOCK_thread_count);
+ mysql_mutex_lock(&LOCK_thread_count);
+ mysql_thread_create(0,
+ &tid, &thr_attr, signal_hand, NULL);
+ mysql_cond_wait(&COND_thread_count, &LOCK_thread_count);
+ mysql_mutex_unlock(&LOCK_thread_count);
DBUG_PRINT("info",("signal thread created"));
thr_setconcurrency(3);
@@ -926,32 +929,34 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused)))
{
param=(int*) malloc(sizeof(int));
*param= i;
- pthread_mutex_lock(&LOCK_thread_count);
- if ((error=pthread_create(&tid,&thr_attr,test_thread,(void*) param)))
+ mysql_mutex_lock(&LOCK_thread_count);
+ if ((error= mysql_thread_create(0,
+ &tid, &thr_attr, test_thread,
+ (void*) param)))
{
printf("Can't create thread %d, error: %d\n",i,error);
exit(1);
}
thread_count++;
- pthread_mutex_unlock(&LOCK_thread_count);
+ mysql_mutex_unlock(&LOCK_thread_count);
}
pthread_attr_destroy(&thr_attr);
- pthread_mutex_lock(&LOCK_thread_count);
+ mysql_mutex_lock(&LOCK_thread_count);
thr_alarm_info(&alarm_info);
printf("Main_thread: Alarms: %u max_alarms: %u next_alarm_time: %lu\n",
alarm_info.active_alarms, alarm_info.max_used_alarms,
alarm_info.next_alarm_time);
while (thread_count)
{
- pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
+ mysql_cond_wait(&COND_thread_count, &LOCK_thread_count);
if (thread_count == 1)
{
printf("Calling end_thr_alarm. This should cancel the last thread\n");
end_thr_alarm(0);
}
}
- pthread_mutex_unlock(&LOCK_thread_count);
+ mysql_mutex_unlock(&LOCK_thread_count);
thr_alarm_info(&alarm_info);
end_thr_alarm(1);
printf("Main_thread: Alarms: %u max_alarms: %u next_alarm_time: %lu\n",
diff --git a/mysys/thr_lock.c b/mysys/thr_lock.c
index a6bc128f32a..6d62476ecf3 100644
--- a/mysys/thr_lock.c
+++ b/mysys/thr_lock.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -94,7 +94,7 @@ enum thr_lock_type thr_upgraded_concurrent_insert_lock = TL_WRITE;
LIST *thr_lock_thread_list; /* List of threads in use */
ulong max_write_lock_count= ~(ulong) 0L;
-static inline pthread_cond_t *get_cond(void)
+static inline mysql_cond_t *get_cond(void)
{
return &my_thread_var->suspend;
}
@@ -316,16 +316,16 @@ void thr_lock_init(THR_LOCK *lock)
{
DBUG_ENTER("thr_lock_init");
bzero((char*) lock,sizeof(*lock));
- pthread_mutex_init(&lock->mutex,MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_THR_LOCK_mutex, &lock->mutex, MY_MUTEX_INIT_FAST);
lock->read.last= &lock->read.data;
lock->read_wait.last= &lock->read_wait.data;
lock->write_wait.last= &lock->write_wait.data;
lock->write.last= &lock->write.data;
- pthread_mutex_lock(&THR_LOCK_lock); /* Add to locks in use */
+ mysql_mutex_lock(&THR_LOCK_lock); /* Add to locks in use */
lock->list.data=(void*) lock;
thr_lock_thread_list=list_add(thr_lock_thread_list,&lock->list);
- pthread_mutex_unlock(&THR_LOCK_lock);
+ mysql_mutex_unlock(&THR_LOCK_lock);
DBUG_VOID_RETURN;
}
@@ -333,10 +333,10 @@ void thr_lock_init(THR_LOCK *lock)
void thr_lock_delete(THR_LOCK *lock)
{
DBUG_ENTER("thr_lock_delete");
- pthread_mutex_lock(&THR_LOCK_lock);
+ mysql_mutex_lock(&THR_LOCK_lock);
thr_lock_thread_list=list_delete(thr_lock_thread_list,&lock->list);
- pthread_mutex_unlock(&THR_LOCK_lock);
- pthread_mutex_destroy(&lock->mutex);
+ mysql_mutex_unlock(&THR_LOCK_lock);
+ mysql_mutex_destroy(&lock->mutex);
DBUG_VOID_RETURN;
}
@@ -392,7 +392,7 @@ wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data,
my_bool in_wait_list)
{
struct st_my_thread_var *thread_var= my_thread_var;
- pthread_cond_t *cond= &thread_var->suspend;
+ mysql_cond_t *cond= &thread_var->suspend;
struct timespec wait_timeout;
enum enum_thr_lock_result result= THR_LOCK_ABORTED;
my_bool can_deadlock= test(data->owner->info->n_cursors);
@@ -443,9 +443,9 @@ wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data,
while (!thread_var->abort || in_wait_list)
{
int rc= (can_deadlock ?
- pthread_cond_timedwait(cond, &data->lock->mutex,
- &wait_timeout) :
- pthread_cond_wait(cond, &data->lock->mutex));
+ mysql_cond_timedwait(cond, &data->lock->mutex,
+ &wait_timeout) :
+ mysql_cond_wait(cond, &data->lock->mutex));
/*
We must break the wait if one of the following occurs:
- the connection has been aborted (!thread_var->abort), but
@@ -501,13 +501,13 @@ wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data,
(*data->lock->get_status)(data->status_param, 0);
check_locks(data->lock,"got wait_for_lock",0);
}
- pthread_mutex_unlock(&data->lock->mutex);
+ mysql_mutex_unlock(&data->lock->mutex);
/* The following must be done after unlock of lock->mutex */
- pthread_mutex_lock(&thread_var->mutex);
+ mysql_mutex_lock(&thread_var->mutex);
thread_var->current_mutex= 0;
thread_var->current_cond= 0;
- pthread_mutex_unlock(&thread_var->mutex);
+ mysql_mutex_unlock(&thread_var->mutex);
proc_info_hook(NULL, old_proc_info, __func__, __FILE__, __LINE__);
@@ -529,7 +529,7 @@ thr_lock(THR_LOCK_DATA *data, THR_LOCK_OWNER *owner,
data->cond=0; /* safety */
data->type=lock_type;
data->owner= owner; /* Must be reset ! */
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
DBUG_PRINT("lock",("data: 0x%lx thread: 0x%lx lock: 0x%lx type: %d",
(long) data, data->owner->info->thread_id,
(long) lock, (int) lock_type));
@@ -785,7 +785,7 @@ thr_lock(THR_LOCK_DATA *data, THR_LOCK_OWNER *owner,
/* Can't get lock yet; Wait for it */
DBUG_RETURN(wait_for_lock(wait_queue, data, 0));
end:
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_RETURN(result);
}
@@ -807,7 +807,7 @@ static inline void free_all_read_locks(THR_LOCK *lock,
do
{
- pthread_cond_t *cond=data->cond;
+ mysql_cond_t *cond= data->cond;
if ((int) data->type == (int) TL_READ_NO_INSERT)
{
if (using_concurrent_insert)
@@ -832,7 +832,7 @@ static inline void free_all_read_locks(THR_LOCK *lock,
data->owner->info->thread_id));
/* purecov: end */
data->cond=0; /* Mark thread free */
- pthread_cond_signal(cond);
+ mysql_cond_signal(cond);
} while ((data=data->next));
*lock->read_wait.last=0;
if (!lock->read_wait.data)
@@ -849,7 +849,7 @@ void thr_unlock(THR_LOCK_DATA *data)
DBUG_ENTER("thr_unlock");
DBUG_PRINT("lock",("data: 0x%lx thread: 0x%lx lock: 0x%lx",
(long) data, data->owner->info->thread_id, (long) lock));
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
check_locks(lock,"start of release lock",0);
if (((*data->prev)=data->next)) /* remove from lock-list */
@@ -881,7 +881,7 @@ void thr_unlock(THR_LOCK_DATA *data)
data->type=TL_UNLOCK; /* Mark unlocked */
check_locks(lock,"after releasing lock",1);
wake_up_waiters(lock);
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_VOID_RETURN;
}
@@ -940,9 +940,9 @@ static void wake_up_waiters(THR_LOCK *lock)
data->type, data->owner->info->thread_id));
/* purecov: end */
{
- pthread_cond_t *cond=data->cond;
+ mysql_cond_t *cond= data->cond;
data->cond=0; /* Mark thread free */
- pthread_cond_signal(cond); /* Start waiting thread */
+ mysql_cond_signal(cond); /* Start waiting thread */
}
if (data->type != TL_WRITE_ALLOW_WRITE ||
!lock->write_wait.data ||
@@ -983,7 +983,7 @@ static void wake_up_waiters(THR_LOCK *lock)
goto end;
}
do {
- pthread_cond_t *cond=data->cond;
+ mysql_cond_t *cond= data->cond;
if (((*data->prev)=data->next)) /* remove from wait-list */
data->next->prev= data->prev;
else
@@ -993,7 +993,7 @@ static void wake_up_waiters(THR_LOCK *lock)
lock->write.last= &data->next;
data->next=0; /* Only one write lock */
data->cond=0; /* Mark thread free */
- pthread_cond_signal(cond); /* Start waiting thread */
+ mysql_cond_signal(cond); /* Start waiting thread */
} while (lock_type == TL_WRITE_ALLOW_WRITE &&
(data=lock->write_wait.data) &&
data->type == TL_WRITE_ALLOW_WRITE);
@@ -1180,19 +1180,19 @@ void thr_abort_locks(THR_LOCK *lock, my_bool upgrade_lock)
{
THR_LOCK_DATA *data;
DBUG_ENTER("thr_abort_locks");
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
for (data=lock->read_wait.data; data ; data=data->next)
{
data->type=TL_UNLOCK; /* Mark killed */
/* It's safe to signal the cond first: we're still holding the mutex. */
- pthread_cond_signal(data->cond);
+ mysql_cond_signal(data->cond);
data->cond=0; /* Removed from list */
}
for (data=lock->write_wait.data; data ; data=data->next)
{
data->type=TL_UNLOCK;
- pthread_cond_signal(data->cond);
+ mysql_cond_signal(data->cond);
data->cond=0;
}
lock->read_wait.last= &lock->read_wait.data;
@@ -1200,7 +1200,7 @@ void thr_abort_locks(THR_LOCK *lock, my_bool upgrade_lock)
lock->read_wait.data=lock->write_wait.data=0;
if (upgrade_lock && lock->write.data)
lock->write.data->type=TL_WRITE_ONLY;
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_VOID_RETURN;
}
@@ -1217,7 +1217,7 @@ my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread_id)
my_bool found= FALSE;
DBUG_ENTER("thr_abort_locks_for_thread");
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
for (data= lock->read_wait.data; data ; data= data->next)
{
if (data->owner->info->thread_id == thread_id) /* purecov: tested */
@@ -1226,7 +1226,7 @@ my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread_id)
data->type= TL_UNLOCK; /* Mark killed */
/* It's safe to signal the cond first: we're still holding the mutex. */
found= TRUE;
- pthread_cond_signal(data->cond);
+ mysql_cond_signal(data->cond);
data->cond= 0; /* Removed from list */
if (((*data->prev)= data->next))
@@ -1242,7 +1242,7 @@ my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread_id)
DBUG_PRINT("info",("Aborting write-wait lock"));
data->type= TL_UNLOCK;
found= TRUE;
- pthread_cond_signal(data->cond);
+ mysql_cond_signal(data->cond);
data->cond= 0;
if (((*data->prev)= data->next))
@@ -1252,7 +1252,7 @@ my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread_id)
}
}
wake_up_waiters(lock);
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_RETURN(found);
}
@@ -1301,7 +1301,7 @@ void thr_downgrade_write_lock(THR_LOCK_DATA *in_data,
#endif
DBUG_ENTER("thr_downgrade_write_only_lock");
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
DBUG_ASSERT(old_lock_type == TL_WRITE_ONLY);
DBUG_ASSERT(old_lock_type > new_lock_type);
in_data->type= new_lock_type;
@@ -1393,7 +1393,7 @@ void thr_downgrade_write_lock(THR_LOCK_DATA *in_data,
next= data->next;
if (start_writers && data->type == new_lock_type)
{
- pthread_cond_t *cond= data->cond;
+ mysql_cond_t *cond= data->cond;
/*
It is ok to start this waiter.
Move from being first in wait queue to be last in write queue.
@@ -1407,7 +1407,7 @@ void thr_downgrade_write_lock(THR_LOCK_DATA *in_data,
data->next= 0;
check_locks(lock, "Started write lock after downgrade",0);
data->cond= 0;
- pthread_cond_signal(cond);
+ mysql_cond_signal(cond);
}
else
{
@@ -1447,7 +1447,7 @@ void thr_downgrade_write_lock(THR_LOCK_DATA *in_data,
if (new_lock_type != TL_WRITE_ALLOW_READ ||
data->type != TL_READ_NO_INSERT)
{
- pthread_cond_t *cond= data->cond;
+ mysql_cond_t *cond= data->cond;
if (((*data->prev)= data->next))
data->next->prev= data->prev;
else
@@ -1460,13 +1460,13 @@ void thr_downgrade_write_lock(THR_LOCK_DATA *in_data,
lock->read_no_write_count++;
check_locks(lock, "Started read lock after downgrade",0);
data->cond= 0;
- pthread_cond_signal(cond);
+ mysql_cond_signal(cond);
}
}
}
check_locks(lock,"after starting waiters after downgrading lock",0);
#endif
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_VOID_RETURN;
}
@@ -1478,10 +1478,10 @@ my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data,
THR_LOCK *lock=data->lock;
DBUG_ENTER("thr_upgrade_write_delay_lock");
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
if (data->type == TL_UNLOCK || data->type >= TL_WRITE_LOW_PRIORITY)
{
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_RETURN(data->type == TL_UNLOCK); /* Test if Aborted */
}
check_locks(lock,"before upgrading lock",0);
@@ -1495,7 +1495,7 @@ my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data,
{ /* We have the lock */
if (data->lock->get_status)
(*data->lock->get_status)(data->status_param, 0);
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_RETURN(0);
}
@@ -1528,10 +1528,10 @@ my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data)
enum thr_lock_type write_lock_type;
DBUG_ENTER("thr_reschedule_write_lock");
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
if (!lock->read_wait.data) /* No waiting read locks */
{
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_RETURN(0);
}
@@ -1553,7 +1553,7 @@ my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data)
lock->write_wait.data=data;
free_all_read_locks(lock,0);
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
DBUG_RETURN(thr_upgrade_write_delay_lock(data, write_lock_type));
}
@@ -1588,13 +1588,13 @@ void thr_print_locks(void)
LIST *list;
uint count=0;
- pthread_mutex_lock(&THR_LOCK_lock);
+ mysql_mutex_lock(&THR_LOCK_lock);
puts("Current locks:");
for (list= thr_lock_thread_list; list && count++ < MAX_THREADS;
list= list_rest(list))
{
THR_LOCK *lock=(THR_LOCK*) list->data;
- pthread_mutex_lock(&lock->mutex);
+ mysql_mutex_lock(&lock->mutex);
printf("lock: 0x%lx:",(ulong) lock);
if ((lock->write_wait.data || lock->read_wait.data) &&
(! lock->read.data && ! lock->write.data))
@@ -1612,11 +1612,11 @@ void thr_print_locks(void)
thr_print_lock("write_wait",&lock->write_wait);
thr_print_lock("read",&lock->read);
thr_print_lock("read_wait",&lock->read_wait);
- pthread_mutex_unlock(&lock->mutex);
+ mysql_mutex_unlock(&lock->mutex);
puts("");
}
fflush(stdout);
- pthread_mutex_unlock(&THR_LOCK_lock);
+ mysql_mutex_unlock(&THR_LOCK_lock);
}
#endif /* THREAD */
@@ -1677,8 +1677,8 @@ int lock_counts[]= {sizeof(test_0)/sizeof(struct st_test),
};
-static pthread_cond_t COND_thread_count;
-static pthread_mutex_t LOCK_thread_count;
+static mysql_cond_t COND_thread_count;
+static mysql_mutex_t LOCK_thread_count;
static uint thread_count;
static ulong sum=0;
@@ -1730,7 +1730,7 @@ static void *test_thread(void *arg)
data[i].type= tests[param][i].lock_type;
}
thr_multi_lock(multi_locks, lock_counts[param], &owner);
- pthread_mutex_lock(&LOCK_thread_count);
+ mysql_mutex_lock(&LOCK_thread_count);
{
int tmp=rand() & 7; /* Do something from 0-2 sec */
if (tmp == 0)
@@ -1744,16 +1744,16 @@ static void *test_thread(void *arg)
sum+=k;
}
}
- pthread_mutex_unlock(&LOCK_thread_count);
+ mysql_mutex_unlock(&LOCK_thread_count);
thr_multi_unlock(multi_locks,lock_counts[param]);
}
printf("Thread %s (%d) ended\n",my_thread_name(),param); fflush(stdout);
thr_print_locks();
- pthread_mutex_lock(&LOCK_thread_count);
+ mysql_mutex_lock(&LOCK_thread_count);
thread_count--;
- pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */
- pthread_mutex_unlock(&LOCK_thread_count);
+ mysql_cond_signal(&COND_thread_count); /* Tell main we are ready */
+ mysql_mutex_unlock(&LOCK_thread_count);
free((uchar*) arg);
return 0;
}
@@ -1770,15 +1770,15 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused)))
printf("Main thread: %s\n",my_thread_name());
- if ((error=pthread_cond_init(&COND_thread_count,NULL)))
+ if ((error= mysql_cond_init(0, &COND_thread_count, NULL)))
{
- fprintf(stderr,"Got error: %d from pthread_cond_init (errno: %d)",
+ fprintf(stderr, "Got error: %d from mysql_cond_init (errno: %d)",
error,errno);
exit(1);
}
- if ((error=pthread_mutex_init(&LOCK_thread_count,MY_MUTEX_INIT_FAST)))
+ if ((error= mysql_mutex_init(0, &LOCK_thread_count, MY_MUTEX_INIT_FAST)))
{
- fprintf(stderr,"Got error: %d from pthread_cond_init (errno: %d)",
+ fprintf(stderr, "Got error: %d from mysql_cond_init (errno: %d)",
error,errno);
exit(1);
}
@@ -1820,33 +1820,35 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused)))
param=(int*) malloc(sizeof(int));
*param=i;
- if ((error=pthread_mutex_lock(&LOCK_thread_count)))
+ if ((error= mysql_mutex_lock(&LOCK_thread_count)))
{
- fprintf(stderr,"Got error: %d from pthread_mutex_lock (errno: %d)",
- error,errno);
+ fprintf(stderr, "Got error: %d from mysql_mutex_lock (errno: %d)",
+ error, errno);
exit(1);
}
- if ((error=pthread_create(&tid,&thr_attr,test_thread,(void*) param)))
+ if ((error= mysql_thread_create(0,
+ &tid, &thr_attr, test_thread,
+ (void*) param)))
{
- fprintf(stderr,"Got error: %d from pthread_create (errno: %d)\n",
- error,errno);
- pthread_mutex_unlock(&LOCK_thread_count);
+ fprintf(stderr, "Got error: %d from mysql_thread_create (errno: %d)\n",
+ error, errno);
+ mysql_mutex_unlock(&LOCK_thread_count);
exit(1);
}
thread_count++;
- pthread_mutex_unlock(&LOCK_thread_count);
+ mysql_mutex_unlock(&LOCK_thread_count);
}
pthread_attr_destroy(&thr_attr);
- if ((error=pthread_mutex_lock(&LOCK_thread_count)))
- fprintf(stderr,"Got error: %d from pthread_mutex_lock\n",error);
+ if ((error= mysql_mutex_lock(&LOCK_thread_count)))
+ fprintf(stderr, "Got error: %d from mysql_mutex_lock\n", error);
while (thread_count)
{
- if ((error=pthread_cond_wait(&COND_thread_count,&LOCK_thread_count)))
- fprintf(stderr,"Got error: %d from pthread_cond_wait\n",error);
+ if ((error= mysql_cond_wait(&COND_thread_count, &LOCK_thread_count)))
+ fprintf(stderr, "Got error: %d from mysql_cond_wait\n", error);
}
- if ((error=pthread_mutex_unlock(&LOCK_thread_count)))
- fprintf(stderr,"Got error: %d from pthread_mutex_unlock\n",error);
+ if ((error= mysql_mutex_unlock(&LOCK_thread_count)))
+ fprintf(stderr, "Got error: %d from mysql_mutex_unlock\n", error);
for (i=0 ; i < (int) array_elements(locks) ; i++)
thr_lock_delete(locks+i);
#ifdef EXTRA_DEBUG
diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c
index 8f9928026ba..db35d5a13a6 100644
--- a/mysys/thr_mutex.c
+++ b/mysys/thr_mutex.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -39,6 +39,7 @@
#endif
#endif /* DO_NOT_REMOVE_THREAD_WRAPPERS */
+/* Not instrumented */
static pthread_mutex_t THR_LOCK_mutex;
static ulong safe_mutex_count= 0; /* Number of mutexes created */
#ifdef SAFE_MUTEX_DETECT_DESTROY
@@ -85,7 +86,9 @@ int safe_mutex_init(safe_mutex_t *mp,
pthread_mutex_unlock(&THR_LOCK_mutex);
}
#else
- thread_safe_increment(safe_mutex_count, &THR_LOCK_mutex);
+ pthread_mutex_lock(&THR_LOCK_mutex);
+ safe_mutex_count++;
+ pthread_mutex_unlock(&THR_LOCK_mutex);
#endif /* SAFE_MUTEX_DETECT_DESTROY */
return 0;
}
@@ -344,7 +347,9 @@ int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint line)
mp->info= NULL; /* Get crash if double free */
}
#else
- thread_safe_sub(safe_mutex_count, 1, &THR_LOCK_mutex);
+ pthread_mutex_lock(&THR_LOCK_mutex);
+ safe_mutex_count--;
+ pthread_mutex_unlock(&THR_LOCK_mutex);
#endif /* SAFE_MUTEX_DETECT_DESTROY */
return error;
}
diff --git a/mysys/typelib.c b/mysys/typelib.c
index a0fe8a96a89..cb72c91e20d 100644
--- a/mysys/typelib.c
+++ b/mysys/typelib.c
@@ -184,7 +184,7 @@ my_ulonglong find_typeset(char *x, TYPELIB *lib, int *err)
i= x;
while (*x && *x != field_separator)
x++;
- if (x[0] && x[1]) // skip separator if found
+ if (x[0] && x[1]) /* skip separator if found */
x++;
if ((find= find_type(i, lib, 2 | 8) - 1) < 0)
DBUG_RETURN(0);