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.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c
index 1d4219e7bfb..237eeefa325 100644
--- a/mysys/my_thr_init.c
+++ b/mysys/my_thr_init.c
@@ -44,12 +44,23 @@ pthread_mutexattr_t my_fast_mutexattr;
pthread_mutexattr_t my_errchk_mutexattr;
#endif
+/*
+ initialize thread environment
+
+ SYNOPSIS
+ my_thread_global_init()
+
+ RETURN
+ 0 ok
+ 1 error (Couldn't create THR_KEY_mysys)
+*/
+
my_bool my_thread_global_init(void)
{
- if (pthread_key_create(&THR_KEY_mysys,free))
+ if (pthread_key_create(&THR_KEY_mysys,0))
{
fprintf(stderr,"Can't initialize threads: error %d\n",errno);
- exit(1);
+ return 1;
}
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_init(&my_fast_mutexattr);
@@ -78,15 +89,18 @@ my_bool my_thread_global_init(void)
#ifndef HAVE_GETHOSTBYNAME_R
pthread_mutex_init(&LOCK_gethostbyname_r,MY_MUTEX_INIT_SLOW);
#endif
- return my_thread_init();
+ if (my_thread_init())
+ {
+ my_thread_global_end(); /* Clean up */
+ return 1;
+ }
+ return 0;
}
void my_thread_global_end(void)
{
-#if defined(USE_TLS)
- (void) TlsFree(THR_KEY_mysys);
-#endif
+ pthread_key_delete(THR_KEY_mysys);
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_destroy(&my_fast_mutexattr);
#endif
@@ -155,6 +169,9 @@ my_bool my_thread_init(void)
tmp= &THR_KEY_mysys;
#endif
tmp->id= ++thread_id;
+#if defined(__WIN__) && defined(EMBEDDED_LIBRARY)
+ tmp->thread_self= (pthread_t)getpid();
+#endif
pthread_mutex_init(&tmp->mutex,MY_MUTEX_INIT_FAST);
pthread_cond_init(&tmp->suspend, NULL);
tmp->init= 1;