diff options
author | unknown <msvensson@neptunus.(none)> | 2007-02-06 14:45:08 +0100 |
---|---|---|
committer | unknown <msvensson@neptunus.(none)> | 2007-02-06 14:45:08 +0100 |
commit | 56820e1cdc0185617386bd06f0e54714ecf004d8 (patch) | |
tree | 431e053716f1d6cf66bf0eaeec8d5024b1b1b24e /mysys | |
parent | cbace0b7b46b5515ee92ee5313d4a98b6e0232d9 (diff) | |
parent | d3c1511a36f0c82f2aa707d74068d76fe84060bc (diff) | |
download | mariadb-git-56820e1cdc0185617386bd06f0e54714ecf004d8.tar.gz |
Merge neptunus.(none):/home/msvensson/mysql/mysql-5.0
into neptunus.(none):/home/msvensson/mysql/mysql-5.0-maint
Makefile.am:
Auto merged
configure.in:
Auto merged
mysql-test/mysql-test-run.pl:
Auto merged
mysys/default.c:
Auto merged
sql/item.cc:
Auto merged
sql/item_cmpfunc.cc:
Auto merged
sql/item_cmpfunc.h:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/mysqld.cc:
Auto merged
sql/sql_parse.cc:
Auto merged
sql/sql_select.cc:
Auto merged
mysql-test/r/select.result:
Manual merge
mysql-test/t/select.test:
Manual merge
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/my_pthread.c | 8 | ||||
-rw-r--r-- | mysys/my_thr_init.c | 21 | ||||
-rw-r--r-- | mysys/thr_alarm.c | 51 | ||||
-rw-r--r-- | mysys/thr_alarm.c.rej | 220 |
4 files changed, 273 insertions, 27 deletions
diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c index fe3480ea10f..b9da9d4817a 100644 --- a/mysys/my_pthread.c +++ b/mysys/my_pthread.c @@ -29,6 +29,8 @@ #define SCHED_POLICY SCHED_OTHER #endif +uint thd_lib_detected; + #ifndef my_pthread_setprio void my_pthread_setprio(pthread_t thread_id,int prior) { @@ -315,8 +317,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; @@ -335,7 +335,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 */ diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index c5105dc4e1e..67ab1e4a38a 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -20,6 +20,7 @@ #include "mysys_priv.h" #include <m_string.h> +#include <signal.h> #ifdef THREAD #ifdef USE_TLS @@ -63,6 +64,8 @@ pthread_handler_t nptl_pthread_exit_hack_handler(void *arg) #endif +static uint get_thread_lib(void); + /* initialize thread environment @@ -76,6 +79,8 @@ pthread_handler_t nptl_pthread_exit_hack_handler(void *arg) 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); @@ -392,4 +397,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 acb4ac5dbf9..d11883a4ea4 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -35,6 +35,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; @@ -57,9 +58,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) @@ -78,9 +77,16 @@ 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); + 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(thr_client_alarm, thread_alarm); + } sigemptyset(&s); sigaddset(&s, THR_SERVER_ALARM); alarm_thread=pthread_self(); @@ -98,10 +104,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 */ - pthread_sigmask(SIG_UNBLOCK, &s, NULL); -#endif + if (thd_lib_detected == THD_LIB_LT) + { + my_sigset(thr_client_alarm, process_alarm); /* Linuxthreads */ + pthread_sigmask(SIG_UNBLOCK, &s, NULL); + } #else my_sigset(THR_SERVER_ALARM, process_alarm); pthread_sigmask(SIG_UNBLOCK, &s, NULL); @@ -152,7 +159,7 @@ my_bool thr_alarm(thr_alarm_t *alrm, uint sec, ALARM *alarm_data) now=(ulong) time((time_t*) 0); pthread_sigmask(SIG_BLOCK,&full_signal_set,&old_mask); - pthread_mutex_lock(&LOCK_alarm); /* Lock from threads & alarms */ + pthread_mutex_lock(&LOCK_alarm); /* Lock from threads & alarms */ if (alarm_aborted > 0) { /* No signal thread */ DBUG_PRINT("info", ("alarm aborted")); @@ -272,18 +279,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\n"); fflush(stdout); + 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, @@ -327,7 +333,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"); @@ -351,7 +357,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"); @@ -488,7 +494,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 @@ -498,7 +504,6 @@ static sig_handler thread_alarm(int sig) my_sigset(sig,thread_alarm); /* int. thread system calls */ #endif } -#endif #ifdef HAVE_TIMESPEC_TS_SEC @@ -926,9 +931,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 @@ -940,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,THR_CLIENT_ALARM); + THR_SERVER_ALARM, thr_client_alarm); DBUG_PRINT("info",("Starting signal and alarm handling thread")); for(;;) { @@ -1012,11 +1015,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 #endif /* OS2 */ @@ -1066,8 +1069,8 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) } } pthread_mutex_unlock(&LOCK_thread_count); - end_thr_alarm(1); thr_alarm_info(&alarm_info); + end_thr_alarm(1); printf("Main_thread: Alarms: %u max_alarms: %u next_alarm_time: %lu\n", alarm_info.active_alarms, alarm_info.max_used_alarms, alarm_info.next_alarm_time); diff --git a/mysys/thr_alarm.c.rej b/mysys/thr_alarm.c.rej new file mode 100644 index 00000000000..c991121052e --- /dev/null +++ b/mysys/thr_alarm.c.rej @@ -0,0 +1,220 @@ +*************** +*** 76,96 **** + alarm_aborted=0; + init_queue(&alarm_queue,max_alarms+1,offsetof(ALARM,expire_time),0, + compare_ulong,NullS); +! 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) +! #if defined(HAVE_mit_thread) +! sigset(THR_CLIENT_ALARM,thread_alarm); /* int. thread system calls */ +! #else + { +! struct sigaction sact; +! sact.sa_flags = 0; +! sact.sa_handler = thread_alarm; +! sigaction(THR_CLIENT_ALARM, &sact, (struct sigaction*) 0); + } +- #endif +- #endif + sigemptyset(&s); + sigaddset(&s, THR_SERVER_ALARM); + alarm_thread=pthread_self(); +--- 74,89 ---- + alarm_aborted=0; + init_queue(&alarm_queue,max_alarms+1,offsetof(ALARM,expire_time),0, + compare_ulong,NullS); +! sigfillset(&full_signal_set); /* Needed to block signals */ + pthread_mutex_init(&LOCK_alarm,MY_MUTEX_INIT_FAST); + pthread_cond_init(&COND_alarm,NULL); +! #ifndef USE_ALARM_THREAD +! if (thd_lib_detected != THD_LIB_LT) +! #endif + { +! my_sigset(thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1, +! thread_alarm); + } + sigemptyset(&s); + sigaddset(&s, THR_SERVER_ALARM); + alarm_thread=pthread_self(); +*************** +*** 108,120 **** + } + #elif defined(USE_ONE_SIGNAL_HAND) + pthread_sigmask(SIG_BLOCK, &s, NULL); /* used with sigwait() */ +! #if THR_SERVER_ALARM == THR_CLIENT_ALARM +! sigset(THR_CLIENT_ALARM,process_alarm); /* Linuxthreads */ +! pthread_sigmask(SIG_UNBLOCK, &s, NULL); +! #endif + #else + pthread_sigmask(SIG_UNBLOCK, &s, NULL); +- sigset(THR_SERVER_ALARM,process_alarm); + #endif + DBUG_VOID_RETURN; + } +--- 101,115 ---- + } + #elif defined(USE_ONE_SIGNAL_HAND) + 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 */ +! pthread_sigmask(SIG_UNBLOCK, &s, NULL); +! } + #else ++ my_sigset(THR_SERVER_ALARM, process_alarm); + pthread_sigmask(SIG_UNBLOCK, &s, NULL); + #endif + DBUG_VOID_RETURN; + } +*************** +*** 240,246 **** + if (alarm_data->malloced) + my_free((gptr) alarm_data,MYF(0)); + found++; +! #ifndef DBUG_OFF + break; + #endif + } +--- 235,241 ---- + if (alarm_data->malloced) + my_free((gptr) alarm_data,MYF(0)); + found++; +! #ifdef DBUG_OFF + break; + #endif + } +*************** +*** 249,258 **** + if (!found) + { + if (*alarmed) +! fprintf(stderr,"Warning: Didn't find alarm %lx in queue of %d alarms\n", +! (long) *alarmed, alarm_queue.elements); +! DBUG_PRINT("warning",("Didn't find alarm %lx in queue\n", +! (long) *alarmed)); + } + pthread_mutex_unlock(&LOCK_alarm); + pthread_sigmask(SIG_SETMASK,&old_mask,NULL); +--- 244,254 ---- + if (!found) + { + if (*alarmed) +! fprintf(stderr, +! "Warning: Didn't find alarm 0x%lx in queue of %d alarms\n", +! (long) *alarmed, alarm_queue.elements); +! DBUG_PRINT("warning",("Didn't find alarm 0x%lx in queue\n", +! (long) *alarmed)); + } + pthread_mutex_unlock(&LOCK_alarm); + pthread_sigmask(SIG_SETMASK,&old_mask,NULL); +*************** +*** 274,291 **** + 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 defined(MAIN) && !defined(__bsdi__) +! printf("thread_alarm\n"); fflush(stdout); + #endif + #ifdef DONT_REMEMBER_SIGNAL +! 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, +--- 270,287 ---- + This must be first as we can't call DBUG inside an alarm for a normal 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(thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1, +! process_alarm); /* int. thread system calls */ + #endif + return; + } + + /* + We have to do do the handling of the alarm in a sub function, +*************** +*** 301,307 **** + process_alarm_part2(sig); + #ifndef USE_ALARM_THREAD + #if defined(DONT_REMEMBER_SIGNAL) && !defined(USE_ONE_SIGNAL_HAND) +! sigset(THR_SERVER_ALARM,process_alarm); + #endif + pthread_mutex_unlock(&LOCK_alarm); + pthread_sigmask(SIG_SETMASK,&old_mask,NULL); +--- 297,303 ---- + process_alarm_part2(sig); + #ifndef USE_ALARM_THREAD + #if defined(DONT_REMEMBER_SIGNAL) && !defined(USE_ONE_SIGNAL_HAND) +! my_sigset(THR_SERVER_ALARM, process_alarm); + #endif + pthread_mutex_unlock(&LOCK_alarm); + pthread_sigmask(SIG_SETMASK,&old_mask,NULL); +*************** +*** 504,520 **** + ARGSUSED + */ + +- #if THR_CLIENT_ALARM != SIGALRM || defined(USE_ALARM_THREAD) + static sig_handler thread_alarm(int sig) + { + #ifdef MAIN + printf("thread_alarm\n"); fflush(stdout); + #endif + #ifdef DONT_REMEMBER_SIGNAL +! sigset(sig,thread_alarm); /* int. thread system calls */ + #endif + } +- #endif + + + #ifdef HAVE_TIMESPEC_TS_SEC +--- 499,513 ---- + ARGSUSED + */ + + static sig_handler thread_alarm(int sig) + { + #ifdef MAIN + printf("thread_alarm\n"); fflush(stdout); + #endif + #ifdef DONT_REMEMBER_SIGNAL +! my_sigset(sig, thread_alarm); /* int. thread system calls */ + #endif + } + + + #ifdef HAVE_TIMESPEC_TS_SEC +*************** +*** 915,921 **** + printf("Warning: Got signal %d from thread %s\n",sig,my_thread_name()); + fflush(stdout); + #ifdef DONT_REMEMBER_SIGNAL +! sigset(sig,print_signal_warning); /* int. thread system calls */ + #endif + #ifndef OS2 + if (sig == SIGALRM) +--- 908,914 ---- + printf("Warning: Got signal %d from thread %s\n",sig,my_thread_name()); + fflush(stdout); + #ifdef DONT_REMEMBER_SIGNAL +! my_sigset(sig, print_signal_warning); /* int. thread system calls */ + #endif + #ifndef OS2 + if (sig == SIGALRM) |