1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

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%.
This commit is contained in:
Vladislav Vaintroub
2009-09-30 03:22:57 +02:00
parent 1ab2577461
commit e6090f10bb
8 changed files with 15 additions and 87 deletions

View File

@ -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)