Commit 622cbf39 authored by unknown's avatar unknown

Merge chilla.local:/home/mydev/mysql-4.0-axmrg

into  chilla.local:/home/mydev/mysql-4.1-axmrg


include/my_global.h:
  Auto merged
include/my_pthread.h:
  Auto merged
include/thr_alarm.h:
  Auto merged
mysys/default.c:
  Auto merged
mysys/my_pthread.c:
  Auto merged
mysys/thr_alarm.c:
  Auto merged
mysys/my_thr_init.c:
  Manual merged
sql/mysqld.cc:
  Manual merged
parents 79fe1494 fb02a22b
...@@ -415,10 +415,7 @@ int __void__; ...@@ -415,10 +415,7 @@ int __void__;
#endif #endif
/* Define some useful general macros */ /* Define some useful general macros */
#if defined(__cplusplus) && defined(__GNUC__) #if !defined(max)
#define max(a, b) ((a) >? (b))
#define min(a, b) ((a) <? (b))
#elif !defined(max)
#define max(a, b) ((a) > (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b))
#endif #endif
......
...@@ -28,14 +28,6 @@ ...@@ -28,14 +28,6 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #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) #if defined(__WIN__) || defined(OS2)
#ifdef OS2 #ifdef OS2
...@@ -684,6 +676,15 @@ extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const)); ...@@ -684,6 +676,15 @@ extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const));
*/ */
extern pthread_t shutdown_th, main_th, signal_th; 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;
extern uint thr_client_alarm;
/* statistics_xxx functions are for not essential statistic */ /* statistics_xxx functions are for not essential statistic */
#ifndef thread_safe_increment #ifndef thread_safe_increment
......
...@@ -93,6 +93,8 @@ typedef struct st_alarm { ...@@ -93,6 +93,8 @@ typedef struct st_alarm {
my_bool malloced; my_bool malloced;
} ALARM; } ALARM;
extern uint thr_client_alarm;
#define thr_alarm_init(A) (*(A))=0 #define thr_alarm_init(A) (*(A))=0
#define thr_alarm_in_use(A) (*(A)!= 0) #define thr_alarm_in_use(A) (*(A)!= 0)
void init_thr_alarm(uint max_alarm); void init_thr_alarm(uint max_alarm);
......
...@@ -309,7 +309,7 @@ static int search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, ...@@ -309,7 +309,7 @@ static int search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc,
{ {
char **ext; char **ext;
for (ext= (char**) f_extensions; *ext; *ext++) for (ext= (char**) f_extensions; *ext; ext++)
{ {
int error; int error;
if ((error= search_default_file_with_ext(args, alloc, dir, *ext, if ((error= search_default_file_with_ext(args, alloc, dir, *ext,
...@@ -709,7 +709,7 @@ void print_defaults(const char *conf_file, const char **groups) ...@@ -709,7 +709,7 @@ void print_defaults(const char *conf_file, const char **groups)
#endif #endif
for (dirs=default_directories ; *dirs; dirs++) for (dirs=default_directories ; *dirs; dirs++)
{ {
for (ext= (char**) f_extensions; *ext; *ext++) for (ext= (char**) f_extensions; *ext; ext++)
{ {
const char *pos; const char *pos;
char *end; char *end;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#endif #endif
uint thd_lib_detected; uint thd_lib_detected;
uint thr_client_alarm;
#ifndef my_pthread_setprio #ifndef my_pthread_setprio
void my_pthread_setprio(pthread_t thread_id,int prior) void my_pthread_setprio(pthread_t thread_id,int prior)
...@@ -338,7 +339,9 @@ void *sigwait_thread(void *set_arg) ...@@ -338,7 +339,9 @@ void *sigwait_thread(void *set_arg)
sigaction(i, &sact, (struct sigaction*) 0); 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); pthread_sigmask(SIG_UNBLOCK,(sigset_t*) set,(sigset_t*) 0);
alarm_thread=pthread_self(); /* For thr_alarm */ alarm_thread=pthread_self(); /* For thr_alarm */
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "mysys_priv.h" #include "mysys_priv.h"
#include <m_string.h> #include <m_string.h>
#include <signal.h>
#ifdef THREAD #ifdef THREAD
#ifdef USE_TLS #ifdef USE_TLS
...@@ -44,6 +45,8 @@ pthread_mutexattr_t my_fast_mutexattr; ...@@ -44,6 +45,8 @@ pthread_mutexattr_t my_fast_mutexattr;
pthread_mutexattr_t my_errorcheck_mutexattr; pthread_mutexattr_t my_errorcheck_mutexattr;
#endif #endif
static uint get_thread_lib(void);
/* /*
initialize thread environment initialize thread environment
...@@ -57,6 +60,12 @@ pthread_mutexattr_t my_errorcheck_mutexattr; ...@@ -57,6 +60,12 @@ pthread_mutexattr_t my_errorcheck_mutexattr;
my_bool my_thread_global_init(void) 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)) if (pthread_key_create(&THR_KEY_mysys,0))
{ {
fprintf(stderr,"Can't initialize threads: error %d\n",errno); fprintf(stderr,"Can't initialize threads: error %d\n",errno);
...@@ -290,4 +299,20 @@ const char *my_thread_name(void) ...@@ -290,4 +299,20 @@ const char *my_thread_name(void)
} }
#endif /* DBUG_OFF */ #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 */ #endif /* THREAD */
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#define ETIME ETIMEDOUT #define ETIME ETIMEDOUT
#endif #endif
uint thr_client_alarm;
static int alarm_aborted=1; /* No alarm thread */ static int alarm_aborted=1; /* No alarm thread */
my_bool thr_alarm_inited= 0; my_bool thr_alarm_inited= 0;
volatile my_bool alarm_thread_running= 0; volatile my_bool alarm_thread_running= 0;
...@@ -77,12 +78,15 @@ void init_thr_alarm(uint max_alarms) ...@@ -77,12 +78,15 @@ void init_thr_alarm(uint max_alarms)
sigfillset(&full_signal_set); /* Neaded to block signals */ sigfillset(&full_signal_set); /* Neaded to block signals */
pthread_mutex_init(&LOCK_alarm,MY_MUTEX_INIT_FAST); pthread_mutex_init(&LOCK_alarm,MY_MUTEX_INIT_FAST);
pthread_cond_init(&COND_alarm,NULL); 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 #ifndef USE_ALARM_THREAD
if (thd_lib_detected != THD_LIB_LT) if (thd_lib_detected != THD_LIB_LT)
#endif #endif
{ {
my_sigset(thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1, my_sigset(thr_client_alarm, thread_alarm);
thread_alarm);
} }
sigemptyset(&s); sigemptyset(&s);
sigaddset(&s, THR_SERVER_ALARM); sigaddset(&s, THR_SERVER_ALARM);
...@@ -103,8 +107,7 @@ void init_thr_alarm(uint max_alarms) ...@@ -103,8 +107,7 @@ void init_thr_alarm(uint max_alarms)
pthread_sigmask(SIG_BLOCK, &s, NULL); /* used with sigwait() */ pthread_sigmask(SIG_BLOCK, &s, NULL); /* used with sigwait() */
if (thd_lib_detected == THD_LIB_LT) if (thd_lib_detected == THD_LIB_LT)
{ {
my_sigset(thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1, my_sigset(thr_client_alarm, process_alarm); /* Linuxthreads */
process_alarm); /* Linuxthreads */
pthread_sigmask(SIG_UNBLOCK, &s, NULL); pthread_sigmask(SIG_UNBLOCK, &s, NULL);
} }
#else #else
...@@ -284,8 +287,7 @@ sig_handler process_alarm(int sig __attribute__((unused))) ...@@ -284,8 +287,7 @@ sig_handler process_alarm(int sig __attribute__((unused)))
printf("thread_alarm in process_alarm\n"); fflush(stdout); printf("thread_alarm in process_alarm\n"); fflush(stdout);
#endif #endif
#ifdef DONT_REMEMBER_SIGNAL #ifdef DONT_REMEMBER_SIGNAL
my_sigset(thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1, my_sigset(thr_client_alarm, process_alarm); /* int. thread system calls */
process_alarm); /* int. thread system calls */
#endif #endif
return; return;
} }
...@@ -332,8 +334,7 @@ static sig_handler process_alarm_part2(int sig __attribute__((unused))) ...@@ -332,8 +334,7 @@ static sig_handler process_alarm_part2(int sig __attribute__((unused)))
alarm_data=(ALARM*) queue_element(&alarm_queue,i); alarm_data=(ALARM*) queue_element(&alarm_queue,i);
alarm_data->alarmed=1; /* Info to thread */ alarm_data->alarmed=1; /* Info to thread */
if (pthread_equal(alarm_data->thread,alarm_thread) || if (pthread_equal(alarm_data->thread,alarm_thread) ||
pthread_kill(alarm_data->thread, pthread_kill(alarm_data->thread, thr_client_alarm))
thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1))
{ {
#ifdef MAIN #ifdef MAIN
printf("Warning: pthread_kill couldn't find thread!!!\n"); printf("Warning: pthread_kill couldn't find thread!!!\n");
...@@ -357,8 +358,7 @@ static sig_handler process_alarm_part2(int sig __attribute__((unused))) ...@@ -357,8 +358,7 @@ static sig_handler process_alarm_part2(int sig __attribute__((unused)))
alarm_data->alarmed=1; /* Info to thread */ alarm_data->alarmed=1; /* Info to thread */
DBUG_PRINT("info",("sending signal to waiting thread")); DBUG_PRINT("info",("sending signal to waiting thread"));
if (pthread_equal(alarm_data->thread,alarm_thread) || if (pthread_equal(alarm_data->thread,alarm_thread) ||
pthread_kill(alarm_data->thread, pthread_kill(alarm_data->thread, thr_client_alarm))
thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1))
{ {
#ifdef MAIN #ifdef MAIN
printf("Warning: pthread_kill couldn't find thread!!!\n"); printf("Warning: pthread_kill couldn't find thread!!!\n");
...@@ -947,7 +947,7 @@ static void *signal_hand(void *arg __attribute__((unused))) ...@@ -947,7 +947,7 @@ static void *signal_hand(void *arg __attribute__((unused)))
#endif #endif
#endif /* OS2 */ #endif /* OS2 */
printf("server alarm: %d thread alarm: %d\n", 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")); DBUG_PRINT("info",("Starting signal and alarm handling thread"));
for(;;) for(;;)
{ {
...@@ -1019,11 +1019,11 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) ...@@ -1019,11 +1019,11 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused)))
sigaddset(&set,SIGTSTP); sigaddset(&set,SIGTSTP);
#endif #endif
sigaddset(&set,THR_SERVER_ALARM); 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); (void) pthread_sigmask(SIG_SETMASK,&set,NULL);
#ifdef NOT_USED #ifdef NOT_USED
sigemptyset(&set); 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)); VOID(pthread_sigmask(SIG_UNBLOCK, &set, (sigset_t*) 0));
#endif #endif
#endif /* OS2 */ #endif /* OS2 */
......
...@@ -450,6 +450,7 @@ pthread_cond_t COND_refresh,COND_thread_count, COND_slave_stopped, ...@@ -450,6 +450,7 @@ pthread_cond_t COND_refresh,COND_thread_count, COND_slave_stopped,
pthread_cond_t COND_thread_cache,COND_flush_thread_cache; pthread_cond_t COND_thread_cache,COND_flush_thread_cache;
pthread_t signal_thread; pthread_t signal_thread;
pthread_attr_t connection_attrib; pthread_attr_t connection_attrib;
static uint thr_kill_signal;
/* replication parameters, if master_host is not NULL, we are a slave */ /* replication parameters, if master_host is not NULL, we are a slave */
uint master_port= MYSQL_PORT, master_connect_retry = 60; uint master_port= MYSQL_PORT, master_connect_retry = 60;
...@@ -581,7 +582,6 @@ static void clean_up_mutexes(void); ...@@ -581,7 +582,6 @@ static void clean_up_mutexes(void);
static void wait_for_signal_thread_to_end(void); static void wait_for_signal_thread_to_end(void);
static int test_if_case_insensitive(const char *dir_name); static int test_if_case_insensitive(const char *dir_name);
static void create_pid_file(); static void create_pid_file();
static uint get_thread_lib(void);
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
/**************************************************************************** /****************************************************************************
...@@ -621,8 +621,7 @@ static void close_connections(void) ...@@ -621,8 +621,7 @@ static void close_connections(void)
DBUG_PRINT("info",("Waiting for select thread")); DBUG_PRINT("info",("Waiting for select thread"));
#ifndef DONT_USE_THR_ALARM #ifndef DONT_USE_THR_ALARM
if (pthread_kill(select_thread, if (pthread_kill(select_thread, thr_client_alarm))
thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1))
break; // allready dead break; // allready dead
#endif #endif
set_timespec(abstime, 2); set_timespec(abstime, 2);
...@@ -2046,8 +2045,7 @@ static void init_signals(void) ...@@ -2046,8 +2045,7 @@ static void init_signals(void)
if (test_flags & TEST_SIGINT) if (test_flags & TEST_SIGINT)
{ {
my_sigset(thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2, my_sigset(thr_kill_signal, end_thread_signal);
end_thread_signal);
} }
my_sigset(THR_SERVER_ALARM,print_signal_warning); // Should never be called! my_sigset(THR_SERVER_ALARM,print_signal_warning); // Should never be called!
...@@ -2107,10 +2105,10 @@ static void init_signals(void) ...@@ -2107,10 +2105,10 @@ static void init_signals(void)
if (test_flags & TEST_SIGINT) if (test_flags & TEST_SIGINT)
{ {
// May be SIGINT // May be SIGINT
sigdelset(&set, thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2); sigdelset(&set, thr_kill_signal);
} }
// For alarms // For alarms
sigdelset(&set, thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1); sigdelset(&set, thr_client_alarm);
sigprocmask(SIG_SETMASK,&set,NULL); sigprocmask(SIG_SETMASK,&set,NULL);
pthread_sigmask(SIG_SETMASK,&set,NULL); pthread_sigmask(SIG_SETMASK,&set,NULL);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
...@@ -2166,7 +2164,7 @@ extern "C" void *signal_hand(void *arg __attribute__((unused))) ...@@ -2166,7 +2164,7 @@ extern "C" void *signal_hand(void *arg __attribute__((unused)))
*/ */
init_thr_alarm(max_connections + init_thr_alarm(max_connections +
global_system_variables.max_insert_delayed_threads + 10); 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) sigemptyset(&set); // Setup up SIGINT for debug
(void) sigaddset(&set,SIGINT); // For debugging (void) sigaddset(&set,SIGINT); // For debugging
...@@ -3139,6 +3137,9 @@ int main(int argc, char **argv) ...@@ -3139,6 +3137,9 @@ int main(int argc, char **argv)
MY_INIT(argv[0]); // init my_sys library & pthreads MY_INIT(argv[0]); // init my_sys library & pthreads
/* Set signal used to kill MySQL */
thr_kill_signal= thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2;
#ifdef _CUSTOMSTARTUPCONFIG_ #ifdef _CUSTOMSTARTUPCONFIG_
if (_cust_check_startup()) if (_cust_check_startup())
{ {
...@@ -3147,7 +3148,6 @@ int main(int argc, char **argv) ...@@ -3147,7 +3148,6 @@ int main(int argc, char **argv)
} }
#endif #endif
thd_lib_detected= get_thread_lib();
if (init_common_variables(MYSQL_CONFIG_NAME, if (init_common_variables(MYSQL_CONFIG_NAME,
argc, argv, load_default_groups)) argc, argv, load_default_groups))
unireg_abort(1); // Will do exit unireg_abort(1); // Will do exit
...@@ -7024,22 +7024,6 @@ static void create_pid_file() ...@@ -7024,22 +7024,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 Instantiate templates
*****************************************************************************/ *****************************************************************************/
......
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