diff options
author | jani@ua141d10.elisa.omakaista.fi <> | 2007-01-25 20:10:31 +0200 |
---|---|---|
committer | jani@ua141d10.elisa.omakaista.fi <> | 2007-01-25 20:10:31 +0200 |
commit | 0b4ee9e5b8cee5af84295d76345d917788ebe294 (patch) | |
tree | cb5306aa3b4e8ff2601826fc23c817fbc370292b | |
parent | ff58749b290dc8f5f8e78ce7b5a73d7efecc610a (diff) | |
download | mariadb-git-0b4ee9e5b8cee5af84295d76345d917788ebe294.tar.gz |
Cleanup of thread-type (linuxthread or NTPL) detection code
Move get_thread_lib to mysys/my_pthread.c
Set 'thr_client_alarm' to signal number used by thr_alarm to give alarms
-rw-r--r-- | include/my_global.h | 5 | ||||
-rw-r--r-- | include/my_pthread.h | 16 | ||||
-rw-r--r-- | include/thr_alarm.h | 2 | ||||
-rw-r--r-- | mysys/default.c | 4 | ||||
-rw-r--r-- | mysys/my_pthread.c | 4 | ||||
-rw-r--r-- | mysys/my_thr_init.c | 20 | ||||
-rw-r--r-- | mysys/thr_alarm.c | 26 | ||||
-rw-r--r-- | sql/mysqld.cc | 34 |
8 files changed, 58 insertions, 53 deletions
diff --git a/include/my_global.h b/include/my_global.h index e6bf9a9b840..f0e600e386d 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -348,10 +348,7 @@ int __void__; #endif /* Define some useful general macros */ -#if defined(__cplusplus) && defined(__GNUC__) -#define max(a, b) ((a) >? (b)) -#define min(a, b) ((a) <? (b)) -#elif !defined(max) +#if !defined(max) #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) #endif diff --git a/include/my_pthread.h b/include/my_pthread.h index e1a7ecab4ab..9d5e78bba44 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -28,14 +28,6 @@ extern "C" { #endif /* __cplusplus */ -/* Thread library */ - -#define THD_LIB_OTHER 1 -#define THD_LIB_NPTL 2 -#define THD_LIB_LT 4 - -extern uint thd_lib_detected; - #if defined(__WIN__) || defined(OS2) #ifdef OS2 @@ -684,6 +676,14 @@ extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const)); */ extern pthread_t shutdown_th, main_th, signal_th; +/* Which kind of thread library is in use */ + +#define THD_LIB_OTHER 1 +#define THD_LIB_NPTL 2 +#define THD_LIB_LT 4 + +extern uint thd_lib_detected; + /* statistics_xxx functions are for not essential statistic */ #ifndef thread_safe_increment diff --git a/include/thr_alarm.h b/include/thr_alarm.h index 0c26a67acf4..ef6aaf49f77 100644 --- a/include/thr_alarm.h +++ b/include/thr_alarm.h @@ -93,6 +93,8 @@ typedef struct st_alarm { my_bool malloced; } ALARM; +extern uint thr_client_alarm; + #define thr_alarm_init(A) (*(A))=0 #define thr_alarm_in_use(A) (*(A)!= 0) void init_thr_alarm(uint max_alarm); diff --git a/mysys/default.c b/mysys/default.c index 25e283a9650..911f516dad8 100644 --- a/mysys/default.c +++ b/mysys/default.c @@ -282,7 +282,7 @@ static int search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, { char **ext; - for (ext= (char**) f_extensions; *ext; *ext++) + for (ext= (char**) f_extensions; *ext; ext++) { int error; if ((error= search_default_file_with_ext(args, alloc, dir, *ext, @@ -543,7 +543,7 @@ void print_defaults(const char *conf_file, const char **groups) #endif for (dirs=default_directories ; *dirs; dirs++) { - for (ext= (char**) f_extensions; *ext; *ext++) + for (ext= (char**) f_extensions; *ext; ext++) { const char *pos; char *end; diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c index 3eaf27844b2..19766a2d195 100644 --- a/mysys/my_pthread.c +++ b/mysys/my_pthread.c @@ -322,7 +322,9 @@ void *sigwait_thread(void *set_arg) sigaction(i, &sact, (struct sigaction*) 0); } } - sigaddset(set, thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1); + /* Ensure that init_thr_alarm() is called */ + DBUG_ASSERT(thr_client_alarm); + sigaddset(set, thr_client_alarm); pthread_sigmask(SIG_UNBLOCK,(sigset_t*) set,(sigset_t*) 0); alarm_thread=pthread_self(); /* For thr_alarm */ diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 878a861bc94..51b31f78a1c 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -44,6 +44,8 @@ pthread_mutexattr_t my_fast_mutexattr; pthread_mutexattr_t my_errchk_mutexattr; #endif +static uint get_thread_lib(void); + /* initialize thread environment @@ -57,6 +59,8 @@ pthread_mutexattr_t my_errchk_mutexattr; my_bool my_thread_global_init(void) { + thd_lib_detected= get_thread_lib(); + if (pthread_key_create(&THR_KEY_mysys,0)) { fprintf(stderr,"Can't initialize threads: error %d\n",errno); @@ -276,4 +280,20 @@ const char *my_thread_name(void) } #endif /* DBUG_OFF */ + +static uint get_thread_lib(void) +{ + char buff[64]; + +#ifdef _CS_GNU_LIBPTHREAD_VERSION + confstr(_CS_GNU_LIBPTHREAD_VERSION, buff, sizeof(buff)); + + if (!strncasecmp(buff, "NPTL", 4)) + return THD_LIB_NPTL; + if (!strncasecmp(buff, "linuxthreads", 12)) + return THD_LIB_LT; +#endif + return THD_LIB_OTHER; +} + #endif /* THREAD */ diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c index 54480b3908d..8f342e269de 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -37,6 +37,7 @@ #define ETIME ETIMEDOUT #endif +uint thr_client_alarm; static int alarm_aborted=1; /* No alarm thread */ my_bool thr_alarm_inited= 0; volatile my_bool alarm_thread_running= 0; @@ -78,12 +79,15 @@ void init_thr_alarm(uint max_alarms) sigfillset(&full_signal_set); /* Needed to block signals */ pthread_mutex_init(&LOCK_alarm,MY_MUTEX_INIT_FAST); pthread_cond_init(&COND_alarm,NULL); + if (thd_lib_detected == THD_LIB_LT) + thr_client_alarm= SIGALRM; + else + thr_client_alarm= SIGUSR1; #ifndef USE_ALARM_THREAD if (thd_lib_detected != THD_LIB_LT) #endif { - my_sigset(thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1, - thread_alarm); + my_sigset(thr_client_alarm, thread_alarm); } sigemptyset(&s); sigaddset(&s, THR_SERVER_ALARM); @@ -104,8 +108,7 @@ void init_thr_alarm(uint max_alarms) pthread_sigmask(SIG_BLOCK, &s, NULL); /* used with sigwait() */ if (thd_lib_detected == THD_LIB_LT) { - my_sigset(thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1, - process_alarm); /* Linuxthreads */ + my_sigset(thr_client_alarm, process_alarm); /* Linuxthreads */ pthread_sigmask(SIG_UNBLOCK, &s, NULL); } #else @@ -286,8 +289,7 @@ sig_handler process_alarm(int sig __attribute__((unused))) printf("thread_alarm in process_alarm\n"); fflush(stdout); #endif #ifdef DONT_REMEMBER_SIGNAL - my_sigset(thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1, - process_alarm); /* int. thread system calls */ + my_sigset(thr_client_alarm, process_alarm); /* int. thread system calls */ #endif return; } @@ -334,8 +336,7 @@ static sig_handler process_alarm_part2(int sig __attribute__((unused))) alarm_data=(ALARM*) queue_element(&alarm_queue,i); alarm_data->alarmed=1; /* Info to thread */ if (pthread_equal(alarm_data->thread,alarm_thread) || - pthread_kill(alarm_data->thread, - thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1)) + pthread_kill(alarm_data->thread, thr_client_alarm)) { #ifdef MAIN printf("Warning: pthread_kill couldn't find thread!!!\n"); @@ -359,8 +360,7 @@ static sig_handler process_alarm_part2(int sig __attribute__((unused))) alarm_data->alarmed=1; /* Info to thread */ DBUG_PRINT("info",("sending signal to waiting thread")); if (pthread_equal(alarm_data->thread,alarm_thread) || - pthread_kill(alarm_data->thread, - thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1)) + pthread_kill(alarm_data->thread, thr_client_alarm)) { #ifdef MAIN printf("Warning: pthread_kill couldn't find thread!!!\n"); @@ -948,7 +948,7 @@ static void *signal_hand(void *arg __attribute__((unused))) #endif #endif /* OS2 */ printf("server alarm: %d thread alarm: %d\n", - THR_SERVER_ALARM, thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1); + THR_SERVER_ALARM, thr_client_alarm); DBUG_PRINT("info",("Starting signal and alarm handling thread")); for(;;) { @@ -1020,11 +1020,11 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) sigaddset(&set,SIGTSTP); #endif sigaddset(&set,THR_SERVER_ALARM); - sigdelset(&set, thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1); + sigdelset(&set, thr_client_alarm); (void) pthread_sigmask(SIG_SETMASK,&set,NULL); #ifdef NOT_USED sigemptyset(&set); - sigaddset(&set, thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1); + sigaddset(&set, thr_client_alarm); VOID(pthread_sigmask(SIG_UNBLOCK, &set, (sigset_t*) 0)); #endif #endif /* OS2 */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index d70fe9a1c32..43d76f28007 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -459,6 +459,7 @@ pthread_cond_t COND_refresh,COND_thread_count, COND_slave_stopped, pthread_cond_t COND_thread_cache,COND_flush_thread_cache; pthread_t signal_thread; pthread_attr_t connection_attrib; +static uint thr_kill_signal; #ifdef __WIN__ #undef getpid @@ -499,7 +500,6 @@ static void clean_up(bool print_message); static void clean_up_mutexes(void); static int test_if_case_insensitive(const char *dir_name); static void create_pid_file(); -static uint get_thread_lib(void); /**************************************************************************** ** Code to end mysqld @@ -539,8 +539,7 @@ static void close_connections(void) DBUG_PRINT("info",("Waiting for select_thread")); #ifndef DONT_USE_THR_ALARM - if (pthread_kill(select_thread, - thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1)) + if (pthread_kill(select_thread, thr_client_alarm)) break; // allready dead #endif set_timespec(abstime, 2); @@ -1838,8 +1837,7 @@ static void init_signals(void) if (test_flags & TEST_SIGINT) { - my_sigset(thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2, - end_thread_signal); + my_sigset(thr_kill_signal, end_thread_signal); } my_sigset(THR_SERVER_ALARM, print_signal_warning); // Should never be called! @@ -1904,10 +1902,10 @@ static void init_signals(void) if (test_flags & TEST_SIGINT) { // May be SIGINT - sigdelset(&set, thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2); + sigdelset(&set, thr_kill_signal); } // For alarms - sigdelset(&set, thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1); + sigdelset(&set, thr_client_alarm); sigprocmask(SIG_SETMASK,&set,NULL); pthread_sigmask(SIG_SETMASK,&set,NULL); DBUG_VOID_RETURN; @@ -1962,7 +1960,7 @@ extern "C" void *signal_hand(void *arg __attribute__((unused))) */ init_thr_alarm(max_connections + global_system_variables.max_insert_delayed_threads + 10); - if (thd_lib_detected != THD_LIB_LT && test_flags & TEST_SIGINT) + if (thd_lib_detected != THD_LIB_LT && (test_flags & TEST_SIGINT)) { (void) sigemptyset(&set); // Setup up SIGINT for debug (void) sigaddset(&set,SIGINT); // For debugging @@ -2235,7 +2233,6 @@ int main(int argc, char **argv) MY_INIT(argv[0]); // init my_sys library & pthreads tzset(); // Set tzname - thd_lib_detected= get_thread_lib(); start_time=time((time_t*) 0); #ifdef OS2 { @@ -2253,6 +2250,9 @@ int main(int argc, char **argv) } #endif + /* Set signal used to kill MySQL */ + thr_kill_signal= thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2; + /* Init mutexes for the global MYSQL_LOG objects. As safe_mutex depends on what MY_INIT() does, we can't init the mutexes of @@ -5548,22 +5548,6 @@ static void create_pid_file() } -static uint get_thread_lib(void) -{ - char buff[64]; - -#ifdef _CS_GNU_LIBPTHREAD_VERSION - confstr(_CS_GNU_LIBPTHREAD_VERSION, buff, sizeof(buff)); - - if (!strncasecmp(buff, "NPTL", 4)) - return THD_LIB_NPTL; - else if (!strncasecmp(buff, "linuxthreads", 12)) - return THD_LIB_LT; -#endif - return THD_LIB_OTHER; -} - - /***************************************************************************** Instantiate templates *****************************************************************************/ |