diff options
author | unknown <monty@narttu.mysql.fi> | 2006-11-29 23:07:15 +0200 |
---|---|---|
committer | unknown <monty@narttu.mysql.fi> | 2006-11-29 23:07:15 +0200 |
commit | c0c013e5b75b88081b6a8a693a777aaf6a574a66 (patch) | |
tree | 0db898dfb17cf8ad28801621ce4c81f19c7e9cc9 /mysys/my_thr_init.c | |
parent | 6bcbd7df1e3402fbc8b6730868115a2bb253f7a7 (diff) | |
parent | 42fd48da99b2ba2641697ebb567af555fb270e9e (diff) | |
download | mariadb-git-c0c013e5b75b88081b6a8a693a777aaf6a574a66.tar.gz |
Merge mysql.com:/home/my/mysql-5.0
into mysql.com:/home/my/mysql-5.1
BitKeeper/etc/ignore:
auto-union
include/heap.h:
Auto merged
include/my_pthread.h:
Auto merged
mysql-test/r/show_check.result:
Auto merged
mysql-test/r/type_bit.result:
Auto merged
sql/item_sum.cc:
Auto merged
sql/set_var.cc:
Auto merged
sql/sql_select.cc:
Auto merged
storage/heap/ha_heap.cc:
Auto merged
mysys/my_thr_init.c:
Manual merge
sql/mysqld.cc:
Manual merge
sql/sql_class.h:
Manual merge
sql/table.cc:
Manual merge
Diffstat (limited to 'mysys/my_thr_init.c')
-rw-r--r-- | mysys/my_thr_init.c | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 9013cd6e79d..39f1c2bc4b9 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -30,7 +30,10 @@ pthread_key(struct st_my_thread_var, THR_KEY_mysys); #endif /* USE_TLS */ 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_net, THR_LOCK_charset, THR_LOCK_threads; +pthread_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; #endif @@ -79,7 +82,7 @@ my_bool my_thread_global_init(void) #endif #ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP /* - Set mutex type to "errorcheck" a.k.a "adaptive" + Set mutex type to "errorcheck" */ pthread_mutexattr_init(&my_errorcheck_mutexattr); pthread_mutexattr_settype(&my_errorcheck_mutexattr, @@ -94,7 +97,7 @@ my_bool my_thread_global_init(void) 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); -#if defined( __WIN__) +#if defined( __WIN__) || defined(OS2) win_pthread_init(); #endif #if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) @@ -114,6 +117,25 @@ my_bool my_thread_global_init(void) void my_thread_global_end(void) { + struct timespec abstime; + set_timespec(abstime, my_thread_end_wait_time); + my_bool all_threads_killed= 1; + + pthread_mutex_lock(&THR_LOCK_threads); + while (THR_thread_count) + { + int error= pthread_cond_timedwait(&THR_COND_threads, &THR_LOCK_threads, + &abstime); + if (error == ETIMEDOUT || error == ETIME) + { + if (THR_thread_count) + fprintf(stderr,"error in my_thread_global_end(): %d threads didn't exit\n", + THR_thread_count); + all_threads_killed= 0; + } + } + pthread_mutex_unlock(&THR_LOCK_threads); + pthread_key_delete(THR_KEY_mysys); #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP pthread_mutexattr_destroy(&my_fast_mutexattr); @@ -129,6 +151,11 @@ void my_thread_global_end(void) pthread_mutex_destroy(&THR_LOCK_heap); pthread_mutex_destroy(&THR_LOCK_net); pthread_mutex_destroy(&THR_LOCK_charset); + if (all_threads_killed) + { + pthread_mutex_destroy(&THR_LOCK_threads); + pthread_cond_destroy (&THR_COND_threads); + } #if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) pthread_mutex_destroy(&LOCK_localtime_r); #endif @@ -154,9 +181,6 @@ my_bool my_thread_init(void) #ifdef EXTRA_DEBUG_THREADS fprintf(stderr,"my_thread_init(): thread_id=%ld\n",pthread_self()); #endif -#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX) - pthread_mutex_lock(&THR_LOCK_lock); -#endif #if !defined(__WIN__) || defined(USE_TLS) if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys)) @@ -174,7 +198,7 @@ my_bool my_thread_init(void) } pthread_setspecific(THR_KEY_mysys,tmp); -#else +#else /* defined(__WIN__) && !(defined(USE_TLS) */ /* Skip initialization if the thread specific variable is already initialized */ @@ -182,7 +206,6 @@ my_bool my_thread_init(void) goto end; tmp= &THR_KEY_mysys; #endif - tmp->id= ++thread_id; #if defined(__WIN__) && defined(EMBEDDED_LIBRARY) tmp->thread_self= (pthread_t)getpid(); #endif @@ -190,10 +213,11 @@ my_bool my_thread_init(void) pthread_cond_init(&tmp->suspend, NULL); tmp->init= 1; + pthread_mutex_lock(&THR_LOCK_threads); + tmp->id= ++thread_id; + ++THR_thread_count; + pthread_mutex_unlock(&THR_LOCK_threads); end: -#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX) - pthread_mutex_unlock(&THR_LOCK_lock); -#endif return error; } @@ -232,6 +256,10 @@ void my_thread_end(void) #if !defined(__WIN__) || defined(USE_TLS) pthread_setspecific(THR_KEY_mysys,0); #endif + pthread_mutex_lock(&THR_LOCK_threads); + if (--THR_thread_count == 0) + pthread_cond_signal(&THR_COND_threads); + pthread_mutex_unlock(&THR_LOCK_threads); } struct st_my_thread_var *_my_thread_var(void) |