diff options
Diffstat (limited to 'mysys/my_thr_init.c')
-rw-r--r-- | mysys/my_thr_init.c | 140 |
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; |