Loading include/my_pthread.h +9 −0 Original line number Diff line number Diff line Loading @@ -701,6 +701,15 @@ extern uint my_thread_end_wait_time; Keep track of shutdown,signal, and main threads so that my_end() will not report errors with them */ /* 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 Loading include/thr_alarm.h +3 −5 Original line number Diff line number Diff line Loading @@ -24,11 +24,6 @@ extern "C" { #ifndef USE_ALARM_THREAD #define USE_ONE_SIGNAL_HAND /* One must call process_alarm */ #endif #ifdef HAVE_LINUXTHREADS #define THR_CLIENT_ALARM SIGALRM #else #define THR_CLIENT_ALARM SIGUSR1 #endif #ifdef HAVE_rts_threads #undef USE_ONE_SIGNAL_HAND #define USE_ALARM_THREAD Loading Loading @@ -90,6 +85,9 @@ typedef struct st_alarm { my_bool malloced; } ALARM; extern uint thr_client_alarm; extern pthread_t alarm_thread; #define thr_alarm_init(A) (*(A))=0 #define thr_alarm_in_use(A) (*(A)!= 0) void init_thr_alarm(uint max_alarm); Loading mysys/my_pthread.c +5 −5 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ uint thd_lib_detected= 0; uint thd_lib_detected; #ifndef my_pthread_setprio void my_pthread_setprio(pthread_t thread_id,int prior) { Loading @@ -51,8 +53,6 @@ int my_pthread_getprio(pthread_t thread_id) int policy; if (!pthread_getschedparam(thread_id,&policy,&tmp_sched_param)) { DBUG_PRINT("thread",("policy: %d priority: %d", policy,tmp_sched_param.sched_priority)); return tmp_sched_param.sched_priority; } #endif Loading Loading @@ -314,8 +314,6 @@ void sigwait_handle_sig(int sig) pthread_mutex_unlock(&LOCK_sigwait); } extern pthread_t alarm_thread; void *sigwait_thread(void *set_arg) { sigset_t *set=(sigset_t*) set_arg; Loading @@ -334,7 +332,9 @@ void *sigwait_thread(void *set_arg) sigaction(i, &sact, (struct sigaction*) 0); } } sigaddset(set,THR_CLIENT_ALARM); /* 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 */ Loading mysys/my_thr_init.c +21 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include "mysys_priv.h" #include <m_string.h> #include <signal.h> #ifdef THREAD #ifdef USE_TLS Loading Loading @@ -63,6 +64,8 @@ nptl_pthread_exit_hack_handler(void *arg __attribute((unused))) #endif static uint get_thread_lib(void); /* initialize thread environment Loading @@ -76,6 +79,8 @@ nptl_pthread_exit_hack_handler(void *arg __attribute((unused))) 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); Loading Loading @@ -395,4 +400,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 */ mysys/thr_alarm.c +22 −22 Original line number Diff line number Diff line Loading @@ -34,6 +34,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; Loading @@ -56,9 +57,7 @@ static void *alarm_handler(void *arg); #define reschedule_alarms() pthread_kill(alarm_thread,THR_SERVER_ALARM) #endif #if THR_CLIENT_ALARM != SIGALRM || defined(USE_ALARM_THREAD) static sig_handler thread_alarm(int sig __attribute__((unused))); #endif static int compare_ulong(void *not_used __attribute__((unused)), byte *a_ptr,byte* b_ptr) Loading @@ -77,9 +76,13 @@ void init_thr_alarm(uint max_alarms) sigfillset(&full_signal_set); /* Neaded to block signals */ pthread_mutex_init(&LOCK_alarm,MY_MUTEX_INIT_FAST); pthread_cond_init(&COND_alarm,NULL); #if THR_CLIENT_ALARM != SIGALRM || defined(USE_ALARM_THREAD) my_sigset(THR_CLIENT_ALARM,thread_alarm); thr_client_alarm= thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1; #ifndef USE_ALARM_THREAD if (thd_lib_detected != THD_LIB_LT) #endif { my_sigset(thr_client_alarm, thread_alarm); } sigemptyset(&s); sigaddset(&s, THR_SERVER_ALARM); alarm_thread=pthread_self(); Loading @@ -97,10 +100,11 @@ void init_thr_alarm(uint max_alarms) } #elif defined(USE_ONE_SIGNAL_HAND) pthread_sigmask(SIG_BLOCK, &s, NULL); /* used with sigwait() */ #if THR_SERVER_ALARM == THR_CLIENT_ALARM my_sigset(THR_CLIENT_ALARM,process_alarm); /* Linuxthreads */ if (thd_lib_detected == THD_LIB_LT) { my_sigset(thr_client_alarm, process_alarm); /* Linuxthreads */ pthread_sigmask(SIG_UNBLOCK, &s, NULL); #endif } #else my_sigset(THR_SERVER_ALARM, process_alarm); pthread_sigmask(SIG_UNBLOCK, &s, NULL); Loading Loading @@ -273,18 +277,17 @@ sig_handler process_alarm(int sig __attribute__((unused))) This must be first as we can't call DBUG inside an alarm for a normal thread */ #if THR_SERVER_ALARM == THR_CLIENT_ALARM if (!pthread_equal(pthread_self(),alarm_thread)) if (thd_lib_detected == THD_LIB_LT && !pthread_equal(pthread_self(),alarm_thread)) { #if defined(MAIN) && !defined(__bsdi__) printf("thread_alarm in process_alarm\n"); fflush(stdout); #endif #ifdef DONT_REMEMBER_SIGNAL my_sigset(THR_CLIENT_ALARM,process_alarm); /* int. thread system calls */ my_sigset(thr_client_alarm, process_alarm); /* int. thread system calls */ #endif return; } #endif /* We have to do do the handling of the alarm in a sub function, Loading Loading @@ -328,7 +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, THR_CLIENT_ALARM)) pthread_kill(alarm_data->thread, thr_client_alarm)) { #ifdef MAIN printf("Warning: pthread_kill couldn't find thread!!!\n"); Loading @@ -352,7 +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, THR_CLIENT_ALARM)) pthread_kill(alarm_data->thread, thr_client_alarm)) { #ifdef MAIN printf("Warning: pthread_kill couldn't find thread!!!\n"); Loading Loading @@ -488,7 +491,7 @@ void thr_alarm_info(ALARM_INFO *info) ARGSUSED */ #if THR_CLIENT_ALARM != SIGALRM || defined(USE_ALARM_THREAD) static sig_handler thread_alarm(int sig) { #ifdef MAIN Loading @@ -498,7 +501,6 @@ static sig_handler thread_alarm(int sig) my_sigset(sig,thread_alarm); /* int. thread system calls */ #endif } #endif #ifdef HAVE_TIMESPEC_TS_SEC Loading Loading @@ -784,9 +786,7 @@ static void *signal_hand(void *arg __attribute__((unused))) sigaddset(&set,SIGINT); sigaddset(&set,SIGQUIT); sigaddset(&set,SIGTERM); #if THR_CLIENT_ALARM != SIGHUP sigaddset(&set,SIGHUP); #endif #ifdef SIGTSTP sigaddset(&set,SIGTSTP); #endif Loading @@ -797,7 +797,7 @@ static void *signal_hand(void *arg __attribute__((unused))) puts("Starting signal handling thread"); #endif printf("server alarm: %d thread alarm: %d\n", THR_SERVER_ALARM,THR_CLIENT_ALARM); THR_SERVER_ALARM, thr_client_alarm); DBUG_PRINT("info",("Starting signal and alarm handling thread")); for(;;) { Loading Loading @@ -865,11 +865,11 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) sigaddset(&set,SIGTSTP); #endif sigaddset(&set,THR_SERVER_ALARM); sigdelset(&set,THR_CLIENT_ALARM); sigdelset(&set, thr_client_alarm); (void) pthread_sigmask(SIG_SETMASK,&set,NULL); #ifdef NOT_USED sigemptyset(&set); sigaddset(&set,THR_CLIENT_ALARM); sigaddset(&set, thr_client_alarm); VOID(pthread_sigmask(SIG_UNBLOCK, &set, (sigset_t*) 0)); #endif Loading Loading
include/my_pthread.h +9 −0 Original line number Diff line number Diff line Loading @@ -701,6 +701,15 @@ extern uint my_thread_end_wait_time; Keep track of shutdown,signal, and main threads so that my_end() will not report errors with them */ /* 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 Loading
include/thr_alarm.h +3 −5 Original line number Diff line number Diff line Loading @@ -24,11 +24,6 @@ extern "C" { #ifndef USE_ALARM_THREAD #define USE_ONE_SIGNAL_HAND /* One must call process_alarm */ #endif #ifdef HAVE_LINUXTHREADS #define THR_CLIENT_ALARM SIGALRM #else #define THR_CLIENT_ALARM SIGUSR1 #endif #ifdef HAVE_rts_threads #undef USE_ONE_SIGNAL_HAND #define USE_ALARM_THREAD Loading Loading @@ -90,6 +85,9 @@ typedef struct st_alarm { my_bool malloced; } ALARM; extern uint thr_client_alarm; extern pthread_t alarm_thread; #define thr_alarm_init(A) (*(A))=0 #define thr_alarm_in_use(A) (*(A)!= 0) void init_thr_alarm(uint max_alarm); Loading
mysys/my_pthread.c +5 −5 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ uint thd_lib_detected= 0; uint thd_lib_detected; #ifndef my_pthread_setprio void my_pthread_setprio(pthread_t thread_id,int prior) { Loading @@ -51,8 +53,6 @@ int my_pthread_getprio(pthread_t thread_id) int policy; if (!pthread_getschedparam(thread_id,&policy,&tmp_sched_param)) { DBUG_PRINT("thread",("policy: %d priority: %d", policy,tmp_sched_param.sched_priority)); return tmp_sched_param.sched_priority; } #endif Loading Loading @@ -314,8 +314,6 @@ void sigwait_handle_sig(int sig) pthread_mutex_unlock(&LOCK_sigwait); } extern pthread_t alarm_thread; void *sigwait_thread(void *set_arg) { sigset_t *set=(sigset_t*) set_arg; Loading @@ -334,7 +332,9 @@ void *sigwait_thread(void *set_arg) sigaction(i, &sact, (struct sigaction*) 0); } } sigaddset(set,THR_CLIENT_ALARM); /* 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 */ Loading
mysys/my_thr_init.c +21 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include "mysys_priv.h" #include <m_string.h> #include <signal.h> #ifdef THREAD #ifdef USE_TLS Loading Loading @@ -63,6 +64,8 @@ nptl_pthread_exit_hack_handler(void *arg __attribute((unused))) #endif static uint get_thread_lib(void); /* initialize thread environment Loading @@ -76,6 +79,8 @@ nptl_pthread_exit_hack_handler(void *arg __attribute((unused))) 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); Loading Loading @@ -395,4 +400,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 */
mysys/thr_alarm.c +22 −22 Original line number Diff line number Diff line Loading @@ -34,6 +34,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; Loading @@ -56,9 +57,7 @@ static void *alarm_handler(void *arg); #define reschedule_alarms() pthread_kill(alarm_thread,THR_SERVER_ALARM) #endif #if THR_CLIENT_ALARM != SIGALRM || defined(USE_ALARM_THREAD) static sig_handler thread_alarm(int sig __attribute__((unused))); #endif static int compare_ulong(void *not_used __attribute__((unused)), byte *a_ptr,byte* b_ptr) Loading @@ -77,9 +76,13 @@ void init_thr_alarm(uint max_alarms) sigfillset(&full_signal_set); /* Neaded to block signals */ pthread_mutex_init(&LOCK_alarm,MY_MUTEX_INIT_FAST); pthread_cond_init(&COND_alarm,NULL); #if THR_CLIENT_ALARM != SIGALRM || defined(USE_ALARM_THREAD) my_sigset(THR_CLIENT_ALARM,thread_alarm); thr_client_alarm= thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1; #ifndef USE_ALARM_THREAD if (thd_lib_detected != THD_LIB_LT) #endif { my_sigset(thr_client_alarm, thread_alarm); } sigemptyset(&s); sigaddset(&s, THR_SERVER_ALARM); alarm_thread=pthread_self(); Loading @@ -97,10 +100,11 @@ void init_thr_alarm(uint max_alarms) } #elif defined(USE_ONE_SIGNAL_HAND) pthread_sigmask(SIG_BLOCK, &s, NULL); /* used with sigwait() */ #if THR_SERVER_ALARM == THR_CLIENT_ALARM my_sigset(THR_CLIENT_ALARM,process_alarm); /* Linuxthreads */ if (thd_lib_detected == THD_LIB_LT) { my_sigset(thr_client_alarm, process_alarm); /* Linuxthreads */ pthread_sigmask(SIG_UNBLOCK, &s, NULL); #endif } #else my_sigset(THR_SERVER_ALARM, process_alarm); pthread_sigmask(SIG_UNBLOCK, &s, NULL); Loading Loading @@ -273,18 +277,17 @@ sig_handler process_alarm(int sig __attribute__((unused))) This must be first as we can't call DBUG inside an alarm for a normal thread */ #if THR_SERVER_ALARM == THR_CLIENT_ALARM if (!pthread_equal(pthread_self(),alarm_thread)) if (thd_lib_detected == THD_LIB_LT && !pthread_equal(pthread_self(),alarm_thread)) { #if defined(MAIN) && !defined(__bsdi__) printf("thread_alarm in process_alarm\n"); fflush(stdout); #endif #ifdef DONT_REMEMBER_SIGNAL my_sigset(THR_CLIENT_ALARM,process_alarm); /* int. thread system calls */ my_sigset(thr_client_alarm, process_alarm); /* int. thread system calls */ #endif return; } #endif /* We have to do do the handling of the alarm in a sub function, Loading Loading @@ -328,7 +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, THR_CLIENT_ALARM)) pthread_kill(alarm_data->thread, thr_client_alarm)) { #ifdef MAIN printf("Warning: pthread_kill couldn't find thread!!!\n"); Loading @@ -352,7 +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, THR_CLIENT_ALARM)) pthread_kill(alarm_data->thread, thr_client_alarm)) { #ifdef MAIN printf("Warning: pthread_kill couldn't find thread!!!\n"); Loading Loading @@ -488,7 +491,7 @@ void thr_alarm_info(ALARM_INFO *info) ARGSUSED */ #if THR_CLIENT_ALARM != SIGALRM || defined(USE_ALARM_THREAD) static sig_handler thread_alarm(int sig) { #ifdef MAIN Loading @@ -498,7 +501,6 @@ static sig_handler thread_alarm(int sig) my_sigset(sig,thread_alarm); /* int. thread system calls */ #endif } #endif #ifdef HAVE_TIMESPEC_TS_SEC Loading Loading @@ -784,9 +786,7 @@ static void *signal_hand(void *arg __attribute__((unused))) sigaddset(&set,SIGINT); sigaddset(&set,SIGQUIT); sigaddset(&set,SIGTERM); #if THR_CLIENT_ALARM != SIGHUP sigaddset(&set,SIGHUP); #endif #ifdef SIGTSTP sigaddset(&set,SIGTSTP); #endif Loading @@ -797,7 +797,7 @@ static void *signal_hand(void *arg __attribute__((unused))) puts("Starting signal handling thread"); #endif printf("server alarm: %d thread alarm: %d\n", THR_SERVER_ALARM,THR_CLIENT_ALARM); THR_SERVER_ALARM, thr_client_alarm); DBUG_PRINT("info",("Starting signal and alarm handling thread")); for(;;) { Loading Loading @@ -865,11 +865,11 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) sigaddset(&set,SIGTSTP); #endif sigaddset(&set,THR_SERVER_ALARM); sigdelset(&set,THR_CLIENT_ALARM); sigdelset(&set, thr_client_alarm); (void) pthread_sigmask(SIG_SETMASK,&set,NULL); #ifdef NOT_USED sigemptyset(&set); sigaddset(&set,THR_CLIENT_ALARM); sigaddset(&set, thr_client_alarm); VOID(pthread_sigmask(SIG_UNBLOCK, &set, (sigset_t*) 0)); #endif Loading