summaryrefslogtreecommitdiff
path: root/mysys/my_thr_init.c
diff options
context:
space:
mode:
authorMagne Mahre <magne.mahre@oracle.com>2011-03-01 13:03:31 +0100
committerMagne Mahre <magne.mahre@oracle.com>2011-03-01 13:03:31 +0100
commitc4715a807690d68c5dfe3f8e36e2ac916d9f37a5 (patch)
tree4d9a20cb9667d0482370dd73a32cf5c74f73289e /mysys/my_thr_init.c
parent901226b66a73c8d5a3d2de9dd12c0e810c316728 (diff)
downloadmariadb-git-c4715a807690d68c5dfe3f8e36e2ac916d9f37a5.tar.gz
Bug#11765237 - 58179: CANNOT START MYSQLD WITH APP VERIFIER
Bug#11763065 - 55730: KILL_SERVER() CALLS SETEVENT ON A NULL HANDLE, SMEM_EVENT_CONNECT_REQUEST Application Verifier is a Microsoft tool used for detecting certain classes of programming errors. In particular, MS Windows OS resource usage is monitored for wrong usage (handles, thread local storage, critical sections, ...) In MySQL 5.5.x, an error was introduced where an object on thread local storage was used before the TLS and the object was created. The fix has been to move the mysys initialization to an earlier stage in the boot process when built for Windows. For non-win builds, the init already happens early. Some un-tangling of calls to my_init(), my_basic_init() and my_thread_global_init() was done. There is no longer a need to do init in steps, so the full my_init() is called instead of my_init_basic(). In addition, Bug#11763065 was fixed. The event handle 'smem_event_connect_request' is only created if 'opt_enable_shared_memory' is set. When killing the server, an event was flagged on the handle unconditionally. Added a test, so it will only be flagged if created. include/my_pthread.h: my_thread_basic_global_init is no longer necessary, and the my_thread_basic_global_reinit function is renamed to reflect that it now reinits mutexes and condvars originating from my_thread_global_init mysys/my_thr_init.c: Reorganized code.
Diffstat (limited to 'mysys/my_thr_init.c')
-rw-r--r--mysys/my_thr_init.c140
1 files changed, 69 insertions, 71 deletions
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c
index a672d8af818..1482ff28975 100644
--- a/mysys/my_thr_init.c
+++ b/mysys/my_thr_init.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
+/* Copyright (c) 2000, 2011 Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -66,86 +66,40 @@ nptl_pthread_exit_hack_handler(void *arg __attribute((unused)))
static uint get_thread_lib(void);
-/** True if @c my_thread_basic_global_init() has been called. */
-static my_bool my_thread_basic_global_init_done= 0;
+/** True if @c my_thread_global_init() has been called. */
+static my_bool my_thread_global_init_done= 0;
-/**
- Perform a minimal initialisation of mysys, when compiled with threads.
- The initialisation performed is sufficient to:
- - allocate memory
- - perform file operations
- - use charsets
- - use my_errno
- @sa my_basic_init
- @sa my_thread_basic_global_reinit
-*/
-my_bool my_thread_basic_global_init(void)
-{
- int pth_ret;
-
- if (my_thread_basic_global_init_done)
- return 0;
- my_thread_basic_global_init_done= 1;
-
-#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
- /*
- Set mutex type to "fast" a.k.a "adaptive"
-
- In this case the thread may steal the mutex from some other thread
- that is waiting for the same mutex. This will save us some
- context switches but may cause a thread to 'starve forever' while
- waiting for the mutex (not likely if the code within the mutex is
- short).
- */
- pthread_mutexattr_init(&my_fast_mutexattr);
- pthread_mutexattr_settype(&my_fast_mutexattr,
- PTHREAD_MUTEX_ADAPTIVE_NP);
-#endif
-
-#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
- /*
- Set mutex type to "errorcheck"
- */
- pthread_mutexattr_init(&my_errorcheck_mutexattr);
- pthread_mutexattr_settype(&my_errorcheck_mutexattr,
- PTHREAD_MUTEX_ERRORCHECK);
-#endif
-
- mysql_mutex_init(key_THR_LOCK_malloc, &THR_LOCK_malloc, MY_MUTEX_INIT_FAST);
- mysql_mutex_init(key_THR_LOCK_open, &THR_LOCK_open, MY_MUTEX_INIT_FAST);
- mysql_mutex_init(key_THR_LOCK_charset, &THR_LOCK_charset, MY_MUTEX_INIT_FAST);
- mysql_mutex_init(key_THR_LOCK_threads, &THR_LOCK_threads, MY_MUTEX_INIT_FAST);
-
- if ((pth_ret= pthread_key_create(&THR_KEY_mysys, NULL)) != 0)
- {
- fprintf(stderr, "Can't initialize threads: error %d\n", pth_ret);
- return 1;
- }
-
- if (my_thread_init())
- return 1;
-
- return 0;
-}
/**
- Re-initialize components initialized early with @c my_thread_basic_global_init.
+ Re-initialize components initialized early with @c my_thread_global_init.
Some mutexes were initialized before the instrumentation.
Destroy + create them again, now that the instrumentation
is in place.
This is safe, since this function() is called before creating new threads,
so the mutexes are not in use.
*/
-void my_thread_basic_global_reinit(void)
+void my_thread_global_reinit(void)
{
struct st_my_thread_var *tmp;
- DBUG_ASSERT(my_thread_basic_global_init_done);
+ DBUG_ASSERT(my_thread_global_init_done);
#ifdef HAVE_PSI_INTERFACE
my_init_mysys_psi_keys();
#endif
+ mysql_mutex_destroy(&THR_LOCK_isam);
+ mysql_mutex_init(key_THR_LOCK_isam, &THR_LOCK_isam, MY_MUTEX_INIT_SLOW);
+
+ mysql_mutex_destroy(&THR_LOCK_heap);
+ mysql_mutex_init(key_THR_LOCK_heap, &THR_LOCK_heap, MY_MUTEX_INIT_FAST);
+
+ mysql_mutex_destroy(&THR_LOCK_net);
+ mysql_mutex_init(key_THR_LOCK_net, &THR_LOCK_net, MY_MUTEX_INIT_FAST);
+
+ mysql_mutex_destroy(&THR_LOCK_myisam);
+ mysql_mutex_init(key_THR_LOCK_myisam, &THR_LOCK_myisam, MY_MUTEX_INIT_SLOW);
+
mysql_mutex_destroy(&THR_LOCK_malloc);
mysql_mutex_init(key_THR_LOCK_malloc, &THR_LOCK_malloc, MY_MUTEX_INIT_FAST);
@@ -158,6 +112,9 @@ void my_thread_basic_global_reinit(void)
mysql_mutex_destroy(&THR_LOCK_threads);
mysql_mutex_init(key_THR_LOCK_threads, &THR_LOCK_threads, MY_MUTEX_INIT_FAST);
+ mysql_cond_destroy(&THR_COND_threads);
+ mysql_cond_init(key_THR_COND_threads, &THR_COND_threads, NULL);
+
tmp= my_pthread_getspecific(struct st_my_thread_var*, THR_KEY_mysys);
DBUG_ASSERT(tmp);
@@ -181,7 +138,48 @@ void my_thread_basic_global_reinit(void)
my_bool my_thread_global_init(void)
{
- if (my_thread_basic_global_init())
+ int pth_ret;
+
+ if (my_thread_global_init_done)
+ return 0;
+ my_thread_global_init_done= 1;
+
+#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
+ /*
+ Set mutex type to "fast" a.k.a "adaptive"
+
+ In this case the thread may steal the mutex from some other thread
+ that is waiting for the same mutex. This will save us some
+ context switches but may cause a thread to 'starve forever' while
+ waiting for the mutex (not likely if the code within the mutex is
+ short).
+ */
+ pthread_mutexattr_init(&my_fast_mutexattr);
+ pthread_mutexattr_settype(&my_fast_mutexattr,
+ PTHREAD_MUTEX_ADAPTIVE_NP);
+#endif
+
+#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
+ /*
+ Set mutex type to "errorcheck"
+ */
+ pthread_mutexattr_init(&my_errorcheck_mutexattr);
+ pthread_mutexattr_settype(&my_errorcheck_mutexattr,
+ PTHREAD_MUTEX_ERRORCHECK);
+#endif
+
+ if ((pth_ret= pthread_key_create(&THR_KEY_mysys, NULL)) != 0)
+ {
+ fprintf(stderr, "Can't initialize threads: error %d\n", pth_ret);
+ return 1;
+ }
+
+ mysql_mutex_init(key_THR_LOCK_malloc, &THR_LOCK_malloc, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_THR_LOCK_open, &THR_LOCK_open, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_THR_LOCK_charset, &THR_LOCK_charset, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_THR_LOCK_threads, &THR_LOCK_threads, MY_MUTEX_INIT_FAST);
+
+ if (my_thread_init())
return 1;
thd_lib_detected= get_thread_lib();
@@ -233,11 +231,11 @@ my_bool my_thread_global_init(void)
install_sigabrt_handler();
#endif
- if (my_thread_init())
- {
- my_thread_global_end(); /* Clean up */
- return 1;
- }
+// if (my_thread_init())
+// {
+// my_thread_global_end(); /* Clean up */
+// return 1;
+// }
return 0;
}
@@ -300,7 +298,7 @@ void my_thread_global_end(void)
mysql_mutex_destroy(&LOCK_gethostbyname_r);
#endif
- my_thread_basic_global_init_done= 0;
+ my_thread_global_init_done= 0;
}
static my_thread_id thread_id= 0;