summaryrefslogtreecommitdiff
path: root/mysys/my_thr_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'mysys/my_thr_init.c')
-rw-r--r--mysys/my_thr_init.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c
index 0e921bbe8a0..fcae18d4686 100644
--- a/mysys/my_thr_init.c
+++ b/mysys/my_thr_init.c
@@ -98,7 +98,7 @@ my_bool my_thread_global_init(void)
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_cond_init (&THR_COND_threads, NULL);
+ pthread_cond_init(&THR_COND_threads, NULL);
#if defined( __WIN__) || defined(OS2)
win_pthread_init();
#endif
@@ -131,7 +131,8 @@ void my_thread_global_end(void)
if (error == ETIMEDOUT || error == ETIME)
{
if (THR_thread_count)
- fprintf(stderr,"Error in my_thread_global_end(): %d threads didn't exit\n",
+ fprintf(stderr,
+ "Error in my_thread_global_end(): %d threads didn't exit\n",
THR_thread_count);
all_threads_killed= 0;
break;
@@ -170,10 +171,23 @@ void my_thread_global_end(void)
static long thread_id=0;
/*
- We can't use mutex_locks here if we are using windows as
- we may have compiled the program with SAFE_MUTEX, in which
- case the checking of mutex_locks will not work until
- the pthread_self thread specific variable is initialized.
+ Allocate thread specific memory for the thread, used by mysys and dbug
+
+ SYNOPSIS
+ my_thread_init()
+
+ NOTES
+ We can't use mutex_locks here if we are using windows as
+ we may have compiled the program with SAFE_MUTEX, in which
+ case the checking of mutex_locks will not work until
+ the pthread_self thread specific variable is initialized.
+
+ This function may called multiple times for a thread, for example
+ if one uses my_init() followed by mysql_server_init().
+
+ RETURN
+ 0 ok
+ 1 Fatal error; mysys/dbug functions can't be used
*/
my_bool my_thread_init(void)
@@ -225,11 +239,22 @@ end:
}
+/*
+ Deallocate memory used by the thread for book-keeping
+
+ SYNOPSIS
+ my_thread_end()
+
+ NOTE
+ This may be called multiple times for a thread.
+ This happens for example when one calls 'mysql_server_init()'
+ mysql_server_end() and then ends with a mysql_end().
+*/
+
void my_thread_end(void)
{
struct st_my_thread_var *tmp;
tmp= my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys);
- DBUG_ASSERT(tmp);
#ifdef EXTRA_DEBUG_THREADS
fprintf(stderr,"my_thread_end(): tmp: 0x%lx thread_id=%ld\n",
@@ -272,7 +297,6 @@ void my_thread_end(void)
#if (!defined(__WIN__) && !defined(OS2)) || defined(USE_TLS)
pthread_setspecific(THR_KEY_mysys,0);
#endif
-
}
struct st_my_thread_var *_my_thread_var(void)