summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authormonty@donna.mysql.com <>2000-09-20 19:37:07 +0300
committermonty@donna.mysql.com <>2000-09-20 19:37:07 +0300
commit830d30896066b325d1ee0769ca116efdaef602f2 (patch)
treedf5d441bed10a34a5a2157ad96f60a04046960b8 /mysys
parent2780278f35ae9ec1a73fb4d5ecedecf9f44d0c8b (diff)
downloadmariadb-git-830d30896066b325d1ee0769ca116efdaef602f2.tar.gz
Fix for SAFE_MUTEX on windows
Diffstat (limited to 'mysys')
-rw-r--r--mysys/my_thr_init.c15
-rw-r--r--mysys/my_winthread.c8
-rw-r--r--mysys/thr_mutex.c5
3 files changed, 20 insertions, 8 deletions
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c
index d879da8e65d..6b75444f3fc 100644
--- a/mysys/my_thr_init.c
+++ b/mysys/my_thr_init.c
@@ -77,10 +77,19 @@ void my_thread_global_end(void)
static long thread_id=0;
+/*
+ We can't use mutex_locks here if we re 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.
+*/
+
my_bool my_thread_init(void)
{
struct st_my_thread_var *tmp;
+#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))
{
@@ -98,9 +107,11 @@ my_bool my_thread_init(void)
pthread_setspecific(THR_KEY_mysys,tmp);
#else
- if (THR_KEY_mysys.id) /* Allready initialized */
+ if (THR_KEY_mysys.id) /* Already initialized */
{
+#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX)
pthread_mutex_unlock(&THR_LOCK_lock);
+#endif
return 0;
}
tmp= &THR_KEY_mysys;
@@ -108,7 +119,9 @@ my_bool my_thread_init(void)
tmp->id= ++thread_id;
pthread_mutex_init(&tmp->mutex,NULL);
pthread_cond_init(&tmp->suspend, NULL);
+#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX)
pthread_mutex_unlock(&THR_LOCK_lock);
+#endif
return 0;
}
diff --git a/mysys/my_winthread.c b/mysys/my_winthread.c
index 7a1e1365325..e410121af98 100644
--- a/mysys/my_winthread.c
+++ b/mysys/my_winthread.c
@@ -48,13 +48,13 @@ static pthread_handler_decl(pthread_start,param)
{
pthread_handler func=((struct pthread_map *) param)->func;
void *func_param=((struct pthread_map *) param)->param;
- my_thread_init();
- pthread_mutex_lock(&THR_LOCK_thread); /* Wait for beingthread to return */
+ my_thread_init(); /* Will always succeed in windows */
+ pthread_mutex_lock(&THR_LOCK_thread); /* Wait for beginthread to return */
win_pthread_self=((struct pthread_map *) param)->pthreadself;
pthread_mutex_unlock(&THR_LOCK_thread);
- free((char*) param);
+ free((char*) param); /* Free param from create */
pthread_exit((*func)(func_param));
- return 0;
+ return 0; /* Safety */
}
diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c
index 9d9c3a1ce08..73d1d24d9a4 100644
--- a/mysys/thr_mutex.c
+++ b/mysys/thr_mutex.c
@@ -218,9 +218,8 @@ int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint line)
pthread_mutex_destroy(&mp->global);
pthread_mutex_destroy(&mp->mutex);
#else
- if (pthread_mutex_destroy(&mp->global) ||
- pthread_mutex_destroy(&mp->mutex))
- error=1;
+ error= (int) (pthread_mutex_destroy(&mp->global) ||
+ pthread_mutex_destroy(&mp->mutex));
#endif
return error;
}