diff options
author | Vladislav Vaintroub <vvaintroub@mysql.com> | 2009-09-30 03:22:57 +0200 |
---|---|---|
committer | Vladislav Vaintroub <vvaintroub@mysql.com> | 2009-09-30 03:22:57 +0200 |
commit | 2bc1930c6c40b964fce9c698a1ca75da3138ad63 (patch) | |
tree | 8e7150c7ea9c0ffce7f59ab3f3836d63c8a574ea /mysys | |
parent | 28a7d5042b264136438cb87e76498b8cbd583e7a (diff) | |
download | mariadb-git-2bc1930c6c40b964fce9c698a1ca75da3138ad63.tar.gz |
Windows improvements : manual backport of
htttp://lists.mysql.com/commits/50957?f=plain
Always use TLS functions instead of __declspec(thread) to access
thread local storage variables.
The change removes the necessity to recomplile the same source
files twice - with USE_TLS for DLLs and without USE_TLS for EXEs.
Real benefit of this change is better readability and maintainability
of TLS functions within MySQL.
There is a performance loss using TlsXXX functions compared to __declspec
but the difference is negligible in practice. In a sysbench-like benchmark
I ran with with TlsGetValue, pthread_[get|set]_specific was called 600000000
times and took 0.17sec of total 35min CPU time, or 0.008%.
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/my_thr_init.c | 21 | ||||
-rw-r--r-- | mysys/my_winthread.c | 7 |
2 files changed, 0 insertions, 28 deletions
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 2278c467f32..2c346145cf5 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -23,11 +23,7 @@ #include <signal.h> #ifdef THREAD -#ifdef USE_TLS pthread_key(struct st_my_thread_var*, THR_KEY_mysys); -#else -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_threads, THR_LOCK_time; @@ -258,7 +254,6 @@ my_bool my_thread_init(void) (ulong) pthread_self()); #endif -#if !defined(__WIN__) || defined(USE_TLS) if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys)) { #ifdef EXTRA_DEBUG_THREADS @@ -273,15 +268,6 @@ my_bool my_thread_init(void) goto end; } pthread_setspecific(THR_KEY_mysys,tmp); - -#else /* defined(__WIN__) && !(defined(USE_TLS) */ - /* - Skip initialization if the thread specific variable is already initialized - */ - if (THR_KEY_mysys.id) - goto end; - tmp= &THR_KEY_mysys; -#endif #if defined(__WIN__) && defined(EMBEDDED_LIBRARY) tmp->pthread_self= (pthread_t) getpid(); #else @@ -342,11 +328,7 @@ void my_thread_end(void) pthread_cond_destroy(&tmp->suspend); #endif pthread_mutex_destroy(&tmp->mutex); -#if !defined(__WIN__) || defined(USE_TLS) free(tmp); -#else - tmp->init= 0; -#endif /* Decrement counter for number of running threads. We are using this @@ -360,10 +342,7 @@ void my_thread_end(void) pthread_cond_signal(&THR_COND_threads); pthread_mutex_unlock(&THR_LOCK_threads); } - /* The following free has to be done, even if my_thread_var() is 0 */ -#if !defined(__WIN__) || defined(USE_TLS) pthread_setspecific(THR_KEY_mysys,0); -#endif } struct st_my_thread_var *_my_thread_var(void) diff --git a/mysys/my_winthread.c b/mysys/my_winthread.c index e94369bec32..543e1787fb6 100644 --- a/mysys/my_winthread.c +++ b/mysys/my_winthread.c @@ -129,12 +129,5 @@ void pthread_exit(void *a) _endthread(); } -/* This is neaded to get the macro pthread_setspecific to work */ - -int win_pthread_setspecific(void *a,void *b,uint length) -{ - memcpy(a,b,length); - return 0; -} #endif |