From 2ec2fa6d08b9720307e8bc85aaa797fd05b565a2 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 25 Jan 2007 20:10:31 +0200 Subject: 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 include/my_global.h: Fixed to be same as in 5.1 include/my_pthread.h: Move things around to be more in line with rest of code include/thr_alarm.h: extern of thr_client_alarm mysys/default.c: Fixed two wrong pointer incrementations. mysys/my_pthread.c: Cleanup: Use variable thr_client_alarm mysys/my_thr_init.c: Detect thread library at startup mysys/thr_alarm.c: Set thr_client_alarm depending on which thread library we are using sql/mysqld.cc: Move get_thread_lib to mysys/my_pthread.c --- mysys/default.c | 4 ++-- mysys/my_pthread.c | 4 +++- mysys/my_thr_init.c | 20 ++++++++++++++++++++ mysys/thr_alarm.c | 26 +++++++++++++------------- 4 files changed, 38 insertions(+), 16 deletions(-) (limited to 'mysys') 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 */ -- cgit v1.2.1 From cdf6001aeb24d7085ab5f053b31858d95c382e06 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 30 Jan 2007 18:52:26 +0200 Subject: 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 include/my_global.h: Fixed to be same as in 5.1 include/my_pthread.h: Move things around to be more in line with rest of code mysys/default.c: Fixed two wrong pointer incrementations. mysys/my_pthread.c: Cleanup: Use variable thr_client_alarm mysys/my_thr_init.c: Detect thread library at startup. Set also thr_client_alarm signal here, so that we get it in init_signals() in mysqld mysys/thr_alarm.c: Set thr_client_alarm depending on which thread library we are using sql/mysqld.cc: Move get_thread_lib to mysys/my_pthread.c --- mysys/default.c | 4 ++-- mysys/my_pthread.c | 5 ++++- mysys/my_thr_init.c | 25 +++++++++++++++++++++++++ mysys/thr_alarm.c | 21 ++++++++------------- 4 files changed, 39 insertions(+), 16 deletions(-) (limited to 'mysys') 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..fd716448e43 100644 --- a/mysys/my_pthread.c +++ b/mysys/my_pthread.c @@ -32,6 +32,7 @@ #endif uint thd_lib_detected; +uint thr_client_alarm; #ifndef my_pthread_setprio void my_pthread_setprio(pthread_t thread_id,int prior) @@ -322,7 +323,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..5729f27b7a7 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -21,6 +21,7 @@ #include "mysys_priv.h" #include +#include #ifdef THREAD #ifdef USE_TLS @@ -44,6 +45,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 +60,12 @@ pthread_mutexattr_t my_errchk_mutexattr; my_bool my_thread_global_init(void) { + thd_lib_detected= get_thread_lib(); + if (thd_lib_detected == THD_LIB_LT) + thr_client_alarm= SIGALRM; + else + thr_client_alarm= SIGUSR1; + if (pthread_key_create(&THR_KEY_mysys,0)) { fprintf(stderr,"Can't initialize threads: error %d\n",errno); @@ -276,4 +285,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..fd1e48d730a 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -82,8 +82,7 @@ void init_thr_alarm(uint max_alarms) 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 +103,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 +284,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 +331,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 +355,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 +943,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 +1015,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 */ -- cgit v1.2.1