Commit 262a2ab5 authored by Sergei Golubchik's avatar Sergei Golubchik

monty's cleanup of my_thr_init.c

and collateral changes
parent d32b537e
...@@ -27,8 +27,10 @@ wait/synch/mutex/mysys/THR_LOCK::mutex ...@@ -27,8 +27,10 @@ wait/synch/mutex/mysys/THR_LOCK::mutex
wait/synch/mutex/mysys/THR_LOCK_charset wait/synch/mutex/mysys/THR_LOCK_charset
wait/synch/mutex/mysys/THR_LOCK_heap wait/synch/mutex/mysys/THR_LOCK_heap
wait/synch/mutex/mysys/THR_LOCK_isam wait/synch/mutex/mysys/THR_LOCK_isam
wait/synch/mutex/mysys/THR_LOCK_lock
wait/synch/mutex/mysys/THR_LOCK_malloc wait/synch/mutex/mysys/THR_LOCK_malloc
wait/synch/mutex/mysys/THR_LOCK_myisam wait/synch/mutex/mysys/THR_LOCK_myisam
wait/synch/mutex/mysys/THR_LOCK_myisam_mmap
wait/synch/mutex/mysys/THR_LOCK_net wait/synch/mutex/mysys/THR_LOCK_net
wait/synch/mutex/mysys/THR_LOCK_open wait/synch/mutex/mysys/THR_LOCK_open
wait/synch/mutex/mysys/THR_LOCK_threads wait/synch/mutex/mysys/THR_LOCK_threads
......
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. /* Copyright (c) 2000, 2011 Oracle and/or its affiliates.
Copyright 2008-2011 Monty Program Ab
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -61,6 +62,77 @@ static uint get_thread_lib(void); ...@@ -61,6 +62,77 @@ static uint get_thread_lib(void);
static my_bool my_thread_global_init_done= 0; static my_bool my_thread_global_init_done= 0;
/*
These are mutexes not used by safe_mutex or my_thr_init.c
We want to free these earlier than other mutex so that safe_mutex
can detect if all mutex and memory is freed properly.
*/
static void my_thread_init_common_mutex(void)
{
mysql_mutex_init(key_THR_LOCK_open, &THR_LOCK_open, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_THR_LOCK_lock, &THR_LOCK_lock, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_THR_LOCK_isam, &THR_LOCK_isam, MY_MUTEX_INIT_SLOW);
mysql_mutex_init(key_THR_LOCK_myisam, &THR_LOCK_myisam, MY_MUTEX_INIT_SLOW);
mysql_mutex_init(key_THR_LOCK_myisam_mmap, &THR_LOCK_myisam_mmap, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_THR_LOCK_heap, &THR_LOCK_heap, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_THR_LOCK_net, &THR_LOCK_net, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_THR_LOCK_charset, &THR_LOCK_charset, MY_MUTEX_INIT_FAST);
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
mysql_mutex_init(key_LOCK_localtime_r, &LOCK_localtime_r, MY_MUTEX_INIT_SLOW);
#endif
}
void my_thread_destroy_common_mutex(void)
{
mysql_mutex_destroy(&THR_LOCK_open);
mysql_mutex_destroy(&THR_LOCK_lock);
mysql_mutex_destroy(&THR_LOCK_isam);
mysql_mutex_destroy(&THR_LOCK_myisam);
mysql_mutex_destroy(&THR_LOCK_myisam_mmap);
mysql_mutex_destroy(&THR_LOCK_heap);
mysql_mutex_destroy(&THR_LOCK_net);
mysql_mutex_destroy(&THR_LOCK_charset);
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
mysql_mutex_destroy(&LOCK_localtime_r);
#endif
}
/*
These mutexes are used by my_thread_init() and after
my_thread_destroy_mutex()
*/
static void my_thread_init_internal_mutex(void)
{
mysql_mutex_init(key_THR_LOCK_threads, &THR_LOCK_threads, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_THR_LOCK_malloc, &THR_LOCK_malloc, MY_MUTEX_INIT_FAST);
mysql_cond_init(key_THR_COND_threads, &THR_COND_threads, NULL);
}
void my_thread_destroy_internal_mutex(void)
{
mysql_mutex_destroy(&THR_LOCK_threads);
mysql_mutex_destroy(&THR_LOCK_malloc);
mysql_cond_destroy(&THR_COND_threads);
}
static void my_thread_init_thr_mutex(struct st_my_thread_var *var)
{
mysql_mutex_init(key_my_thread_var_mutex, &var->mutex, MY_MUTEX_INIT_FAST);
mysql_cond_init(key_my_thread_var_suspend, &var->suspend, NULL);
}
static void my_thread_destory_thr_mutex(struct st_my_thread_var *var)
{
mysql_mutex_destroy(&var->mutex);
mysql_cond_destroy(&var->suspend);
}
/** /**
Re-initialize components initialized early with @c my_thread_global_init. Re-initialize components initialized early with @c my_thread_global_init.
Some mutexes were initialized before the instrumentation. Some mutexes were initialized before the instrumentation.
...@@ -79,41 +151,17 @@ void my_thread_global_reinit(void) ...@@ -79,41 +151,17 @@ void my_thread_global_reinit(void)
my_init_mysys_psi_keys(); my_init_mysys_psi_keys();
#endif #endif
mysql_mutex_destroy(&THR_LOCK_isam); my_thread_destroy_common_mutex();
mysql_mutex_init(key_THR_LOCK_isam, &THR_LOCK_isam, MY_MUTEX_INIT_SLOW); my_thread_init_common_mutex();
mysql_mutex_destroy(&THR_LOCK_heap); my_thread_destroy_internal_mutex();
mysql_mutex_init(key_THR_LOCK_heap, &THR_LOCK_heap, MY_MUTEX_INIT_FAST); my_thread_init_internal_mutex();
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);
mysql_mutex_destroy(&THR_LOCK_open);
mysql_mutex_init(key_THR_LOCK_open, &THR_LOCK_open, MY_MUTEX_INIT_FAST);
mysql_mutex_destroy(&THR_LOCK_charset);
mysql_mutex_init(key_THR_LOCK_charset, &THR_LOCK_charset, MY_MUTEX_INIT_FAST);
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); tmp= my_pthread_getspecific(struct st_my_thread_var*, THR_KEY_mysys);
DBUG_ASSERT(tmp); DBUG_ASSERT(tmp);
mysql_mutex_destroy(&tmp->mutex); my_thread_destory_thr_mutex(tmp);
mysql_mutex_init(key_my_thread_var_mutex, &tmp->mutex, MY_MUTEX_INIT_FAST); my_thread_init_thr_mutex(tmp);
mysql_cond_destroy(&tmp->suspend);
mysql_cond_init(key_my_thread_var_suspend, &tmp->suspend, NULL);
} }
/* /*
...@@ -131,6 +179,8 @@ my_bool my_thread_global_init(void) ...@@ -131,6 +179,8 @@ my_bool my_thread_global_init(void)
{ {
int pth_ret; int pth_ret;
/* Normally this should never be called twice */
DBUG_ASSERT(my_thread_global_init_done == 0);
if (my_thread_global_init_done) if (my_thread_global_init_done)
return 0; return 0;
my_thread_global_init_done= 1; my_thread_global_init_done= 1;
...@@ -141,10 +191,8 @@ my_bool my_thread_global_init(void) ...@@ -141,10 +191,8 @@ my_bool my_thread_global_init(void)
return 1; return 1;
} }
mysql_mutex_init(key_THR_LOCK_malloc, &THR_LOCK_malloc, MY_MUTEX_INIT_FAST); /* Mutex used by my_thread_init() and after my_thread_destroy_mutex() */
mysql_mutex_init(key_THR_LOCK_open, &THR_LOCK_open, MY_MUTEX_INIT_FAST); my_thread_init_internal_mutex();
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()) if (my_thread_init())
return 1; return 1;
...@@ -178,26 +226,16 @@ my_bool my_thread_global_init(void) ...@@ -178,26 +226,16 @@ my_bool my_thread_global_init(void)
} }
#endif /* TARGET_OS_LINUX */ #endif /* TARGET_OS_LINUX */
mysql_mutex_init(key_THR_LOCK_lock, &THR_LOCK_lock, MY_MUTEX_INIT_FAST); my_thread_init_common_mutex();
mysql_mutex_init(key_THR_LOCK_isam, &THR_LOCK_isam, MY_MUTEX_INIT_SLOW);
mysql_mutex_init(key_THR_LOCK_myisam, &THR_LOCK_myisam, MY_MUTEX_INIT_SLOW);
mysql_mutex_init(key_THR_LOCK_myisam_mmap, &THR_LOCK_myisam_mmap, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_THR_LOCK_heap, &THR_LOCK_heap, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_THR_LOCK_net, &THR_LOCK_net, MY_MUTEX_INIT_FAST);
mysql_cond_init(key_THR_COND_threads, &THR_COND_threads, NULL);
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
mysql_mutex_init(key_LOCK_localtime_r, &LOCK_localtime_r, MY_MUTEX_INIT_SLOW);
#endif
#ifdef _MSC_VER
install_sigabrt_handler();
#endif
return 0; return 0;
} }
/**
End the mysys thread system. Called when ending the last thread
*/
void my_thread_global_end(void) void my_thread_global_end(void)
{ {
struct timespec abstime; struct timespec abstime;
...@@ -228,24 +266,17 @@ void my_thread_global_end(void) ...@@ -228,24 +266,17 @@ void my_thread_global_end(void)
} }
mysql_mutex_unlock(&THR_LOCK_threads); mysql_mutex_unlock(&THR_LOCK_threads);
mysql_mutex_destroy(&THR_LOCK_malloc); my_thread_destroy_common_mutex();
mysql_mutex_destroy(&THR_LOCK_open);
mysql_mutex_destroy(&THR_LOCK_lock); /*
mysql_mutex_destroy(&THR_LOCK_isam); Only destroy the mutex & conditions if we don't have other threads around
mysql_mutex_destroy(&THR_LOCK_myisam); that could use them.
mysql_mutex_destroy(&THR_LOCK_myisam_mmap); */
mysql_mutex_destroy(&THR_LOCK_heap);
mysql_mutex_destroy(&THR_LOCK_net);
mysql_mutex_destroy(&THR_LOCK_charset);
if (all_threads_killed) if (all_threads_killed)
{ {
mysql_mutex_destroy(&THR_LOCK_threads);
mysql_cond_destroy(&THR_COND_threads);
}
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
mysql_mutex_destroy(&LOCK_localtime_r);
#endif
pthread_key_delete(THR_KEY_mysys); pthread_key_delete(THR_KEY_mysys);
my_thread_destroy_internal_mutex();
}
my_thread_global_init_done= 0; my_thread_global_init_done= 0;
} }
...@@ -277,8 +308,7 @@ my_bool my_thread_init(void) ...@@ -277,8 +308,7 @@ my_bool my_thread_init(void)
my_bool error=0; my_bool error=0;
#ifdef EXTRA_DEBUG_THREADS #ifdef EXTRA_DEBUG_THREADS
fprintf(stderr,"my_thread_init(): pthread_self: 0x%lx\n", fprintf(stderr,"my_thread_init(): pthread_self: %p\n", pthread_self());
(ulong) pthread_self());
#endif #endif
if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys)) if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys))
...@@ -301,8 +331,7 @@ my_bool my_thread_init(void) ...@@ -301,8 +331,7 @@ my_bool my_thread_init(void)
} }
pthread_setspecific(THR_KEY_mysys,tmp); pthread_setspecific(THR_KEY_mysys,tmp);
tmp->pthread_self= pthread_self(); tmp->pthread_self= pthread_self();
mysql_mutex_init(key_my_thread_var_mutex, &tmp->mutex, MY_MUTEX_INIT_FAST); my_thread_init_thr_mutex(tmp);
mysql_cond_init(key_my_thread_var_suspend, &tmp->suspend, NULL);
tmp->stack_ends_here= (char*)&tmp + tmp->stack_ends_here= (char*)&tmp +
STACK_DIRECTION * (long)my_thread_stack_size; STACK_DIRECTION * (long)my_thread_stack_size;
...@@ -340,8 +369,8 @@ void my_thread_end(void) ...@@ -340,8 +369,8 @@ void my_thread_end(void)
tmp= my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys); tmp= my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys);
#ifdef EXTRA_DEBUG_THREADS #ifdef EXTRA_DEBUG_THREADS
fprintf(stderr,"my_thread_end(): tmp: 0x%lx pthread_self: 0x%lx thread_id: %ld\n", fprintf(stderr,"my_thread_end(): tmp: %p pthread_self: %p thread_id: %ld\n",
(long) tmp, (long) pthread_self(), tmp ? (long) tmp->id : 0L); tmp, pthread_self(), tmp ? (long) tmp->id : 0L);
#endif #endif
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
...@@ -368,8 +397,7 @@ void my_thread_end(void) ...@@ -368,8 +397,7 @@ void my_thread_end(void)
tmp->dbug=0; tmp->dbug=0;
} }
#endif #endif
mysql_cond_destroy(&tmp->suspend); my_thread_destory_thr_mutex(tmp);
mysql_mutex_destroy(&tmp->mutex);
/* /*
Decrement counter for number of running threads. We are using this Decrement counter for number of running threads. We are using this
......
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
#include <process.h> #include <process.h>
#include <signal.h> #include <signal.h>
static void install_sigabrt_handler(void);
struct thread_start_parameter struct thread_start_parameter
{ {
pthread_handler func; pthread_handler func;
......
...@@ -336,8 +336,6 @@ int main(int argc __attribute__((unused)), ...@@ -336,8 +336,6 @@ int main(int argc __attribute__((unused)),
thr_setconcurrency(2); thr_setconcurrency(2);
#endif #endif
my_thread_global_init();
if (ma_control_file_open(TRUE, TRUE)) if (ma_control_file_open(TRUE, TRUE))
{ {
fprintf(stderr, "Can't init control file (%d)\n", errno); fprintf(stderr, "Can't init control file (%d)\n", errno);
...@@ -551,6 +549,7 @@ err: ...@@ -551,6 +549,7 @@ err:
if (maria_log_remove(maria_data_root)) if (maria_log_remove(maria_data_root))
exit(1); exit(1);
my_end(0);
return(exit_status()); return(exit_status());
} }
......
...@@ -1214,11 +1214,12 @@ void do_all_tests() ...@@ -1214,11 +1214,12 @@ void do_all_tests()
test_file_instrumentation_leak(); test_file_instrumentation_leak();
} }
int main(int, char **) int main(int argc, char **argv)
{ {
plan(153); plan(153);
MY_INIT("pfs-t"); MY_INIT(argv[0]);
do_all_tests(); do_all_tests();
my_end(0);
return 0; return 0;
} }
...@@ -206,11 +206,12 @@ void do_all_tests() ...@@ -206,11 +206,12 @@ void do_all_tests()
PFS_atomic::cleanup(); PFS_atomic::cleanup();
} }
int main(int, char **) int main(int argc, char **argv)
{ {
plan(8); plan(8);
MY_INIT("pfs_instr-oom-t"); MY_INIT(argv[0]);
do_all_tests(); do_all_tests();
my_end(0);
return 0; return 0;
} }
...@@ -410,11 +410,12 @@ void do_all_tests() ...@@ -410,11 +410,12 @@ void do_all_tests()
PFS_atomic::cleanup(); PFS_atomic::cleanup();
} }
int main(int, char **) int main(int argc, char **argv)
{ {
plan(102); plan(102);
MY_INIT("pfs_instr-t"); MY_INIT(argv[0]);
do_all_tests(); do_all_tests();
my_end(0);
return 0; return 0;
} }
...@@ -54,11 +54,13 @@ void do_all_tests() ...@@ -54,11 +54,13 @@ void do_all_tests()
PFS_atomic::cleanup(); PFS_atomic::cleanup();
} }
int main(int, char **) int main(int argc, char **argv)
{ {
plan(6); plan(6);
MY_INIT("pfs_instr_info-oom-t"); MY_INIT(argv[0]);
do_all_tests(); do_all_tests();
my_end(0);
return 0; return 0;
} }
...@@ -568,11 +568,13 @@ void do_all_tests() ...@@ -568,11 +568,13 @@ void do_all_tests()
PFS_atomic::cleanup(); PFS_atomic::cleanup();
} }
int main(int, char **) int main(int argc, char **argv)
{ {
plan(196); plan(196);
MY_INIT("pfs_instr_info-t"); MY_INIT(argv[0]);
do_all_tests(); do_all_tests();
my_end(0);
return 0; return 0;
} }
...@@ -24,11 +24,11 @@ ...@@ -24,11 +24,11 @@
#define BASE64_ROWS 4 /* Number of ok(..) */ #define BASE64_ROWS 4 /* Number of ok(..) */
int int
main(void) main(int argc,char *argv[])
{ {
int i, cmp; int i, cmp;
size_t j, k, l, dst_len, needed_length; size_t j, k, l, dst_len, needed_length;
MY_INIT("base64-t"); MY_INIT(argv[0]);
plan(BASE64_LOOP_COUNT * BASE64_ROWS); plan(BASE64_LOOP_COUNT * BASE64_ROWS);
...@@ -92,5 +92,6 @@ main(void) ...@@ -92,5 +92,6 @@ main(void)
(uint) src_len, (uint) dst_len); (uint) src_len, (uint) dst_len);
} }
} }
my_end(0);
return exit_status(); return exit_status();
} }
...@@ -519,12 +519,12 @@ error: ...@@ -519,12 +519,12 @@ error:
return TRUE; return TRUE;
} }
int main() int main(int argc,char *argv[])
{ {
int i; int i;
int const min_size = 1; int const min_size = 1;
int const max_size = MAX_TESTED_BITMAP_SIZE; int const max_size = MAX_TESTED_BITMAP_SIZE;
MY_INIT("bitmap-t"); MY_INIT(argv[0]);
plan((max_size - min_size)/7+1); plan((max_size - min_size)/7+1);
...@@ -535,5 +535,6 @@ int main() ...@@ -535,5 +535,6 @@ int main()
*/ */
for (i= min_size; i < max_size; i+=7) for (i= min_size; i < max_size; i+=7)
ok(do_test(i) == 0, "bitmap size %d", i); ok(do_test(i) == 0, "bitmap size %d", i);
my_end(0);
return exit_status(); return exit_status();
} }
...@@ -17,10 +17,10 @@ ...@@ -17,10 +17,10 @@
#include <my_sys.h> #include <my_sys.h>
#include "tap.h" #include "tap.h"
int main(void) int main(int argc,char *argv[])
{ {
void *p; void *p;
MY_INIT("my_malloc-t"); MY_INIT(argv[0]);
plan(4); plan(4);
...@@ -38,6 +38,7 @@ int main(void) ...@@ -38,6 +38,7 @@ int main(void)
ok((my_free(p), 1), "Free NULL pointer."); ok((my_free(p), 1), "Free NULL pointer.");
my_end(0);
return exit_status(); return exit_status();
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment