MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:jani Date:January 22 2007 12:32am
Subject:bk commit into 4.0 tree (jani:1.2206) BUG#16995
View as plain text  
Below is the list of changes that have just been committed into a local
4.0 repository of jani. When jani does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-01-22 02:32:07+02:00, jani@stripped +8 -0
  Fix for configure to detect library correctly.
  Fix to check library in use during runtime.
  Fix for Bug#16995, "idle connections not being killed due to timeout when NPTL is used".

  BUILD/SETUP.sh@stripped, 2007-01-22 02:32:06+02:00, jani@stripped +2 -2
    To avoid warnings during compilation.

  configure.in@stripped, 2007-01-22 02:32:06+02:00, jani@stripped +98 -61
    Fixed configure so that it can correctly detect
    between NPTL and Linuxthreads.

  include/my_global.h@stripped, 2007-01-22 02:32:06+02:00, jani@stripped +5 -2
    Fix for Linuxthreads.

  include/my_pthread.h@stripped, 2007-01-22 02:32:06+02:00, jani@stripped +31 -10
    Added defines for different libraries that can be detected.
    Currently only 'other', 'nptl', and 'lt' (linuxthreads) are
    being used.
    
    changed sigset() and signal() to my_sigset() and my_signal()

  include/thr_alarm.h@stripped, 2007-01-22 02:32:06+02:00, jani@stripped +0 -5
    Removed defines for Linuxthreads. This is now detected during
    runtime and handled in the thr_alarm.c

  mysys/my_pthread.c@stripped, 2007-01-22 02:32:06+02:00, jani@stripped +3 -1
    Runtime check for library.

  mysys/thr_alarm.c@stripped, 2007-01-22 02:32:06+02:00, jani@stripped +42 -51
    Runtime checks for library and corresponding
    signals.

  sql/mysqld.cc@stripped, 2007-01-22 02:32:06+02:00, jani@stripped +34 -19
    Added function for detecting thread library in use
    during start-up.
    
    THR_KILL_SIGNAL removed, setting signals during runtime.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	jani
# Host:	a88-113-38-195.elisa-laajakaista.fi
# Root:	/home/my/bk/mysql-4.0

--- 1.340/configure.in	2007-01-22 02:32:10 +02:00
+++ 1.341/configure.in	2007-01-22 02:32:10 +02:00
@@ -388,15 +388,16 @@
 if expr "$target_os" : "[[Ll]]inux.*" > /dev/null
 then
   MYSQLD_DEFAULT_SWITCHES="--skip-locking"
-  IS_LINUX="true"
+  TARGET_LINUX="true"
   AC_MSG_RESULT("yes");
+  AC_DEFINE([TARGET_OS_LINUX], [1], [Whether we build for Linux])
 else
   MYSQLD_DEFAULT_SWITCHES=""
-  IS_LINUX="false"
+  TARGET_LINUX="false"
   AC_MSG_RESULT("no");
 fi
 AC_SUBST(MYSQLD_DEFAULT_SWITCHES)
-AC_SUBST(IS_LINUX)
+AC_SUBST(TARGET_LINUX)
 
 dnl Find paths to some shell programs
 AC_PATH_PROG(LN, ln, ln)
@@ -576,7 +577,7 @@
 # (this is true on the MySQL build machines to avoid NSS problems)
 #
 
-if test "$IS_LINUX" = "true" -a "$static_nss" = ""
+if test "$TARGET_LINUX" = "true" -a "$static_nss" = ""
 then
   tmp=`nm /usr/lib/libc.a  | grep _nss_files_getaliasent_r`
   if test -n "$tmp"
@@ -827,7 +828,7 @@
 ])
 AC_SUBST(WRAPLIBS)
 
-if test "$IS_LINUX" = "true"; then
+if test "$TARGET_LINUX" = "true"; then
   AC_MSG_CHECKING([for atomic operations])
 
   AC_LANG_SAVE
@@ -870,7 +871,7 @@
     [ USE_PSTACK=no ])
   pstack_libs=
   pstack_dirs=
-  if test "$USE_PSTACK" = yes -a "$IS_LINUX" = "true" -a "$BASE_MACHINE_TYPE" = "i386" -a "$with_mit_threads" = "no"
+  if test "$USE_PSTACK" = yes -a "$TARGET_LINUX" = "true" -a "$BASE_MACHINE_TYPE" = "i386" -a "$with_mit_threads" = "no"
   then
     have_libiberty= have_libbfd=
     my_save_LIBS="$LIBS"
@@ -1239,63 +1240,98 @@
 # Hack for DEC-UNIX (OSF1)
 if test "$with_named_thread" = "no" -a "$with_mit_threads" = "no"
 then
-  # Look for LinuxThreads.
-  AC_MSG_CHECKING("LinuxThreads")
-    grepres=`grep Linuxthreads /usr/include/pthread.h 2>/dev/null | wc -l`
-    getconfres=`which getconf >/dev/null && getconf GNU_LIBPTHREAD_VERSION | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ |grep LINUXTHREADS | wc -l || echo 0`
-    if test "$grepres" -gt 0 -o "$getconfres" -gt 0
+    AC_MSG_CHECKING("Linux threads")
+    if test "$TARGET_LINUX" = "true"
     then
-      AC_MSG_RESULT("Found")
-      AC_DEFINE(HAVE_LINUXTHREADS)
-      # Linux 2.0 sanity check
-      AC_TRY_COMPILE([#include <sched.h>], [int a = sched_get_priority_min(1);], ,
-      AC_MSG_ERROR([Syntax error in sched.h. Change _P to __P in the /usr/include/sched.h file. See the Installation chapter in the Reference Manual]))
-      # RedHat 5.0 does not work with dynamic linking of this. -static also
-      # gives a speed increase in linux so it does not hurt on other systems.
-      with_named_thread="-lpthread"
-    else
-      AC_MSG_RESULT("Not found")
-      # If this is a linux machine we should barf
-      AC_MSG_CHECKING("NPTL")
-      if test "$IS_LINUX" = "true"
-      then
-        getconfres=`which getconf >/dev/null && getconf GNU_LIBPTHREAD_VERSION | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ |grep NPTL | wc -l || echo 0`
-        if test "$getconfres" -gt 0
+        AC_MSG_RESULT("starting")
+        # use getconf to check glibc contents
+        AC_MSG_CHECKING("getconf GNU_LIBPTHREAD_VERSION")
+        case `getconf GNU_LIBPTHREAD_VERSION | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ` in
+        NPTL* )
+                AC_MSG_RESULT("NPTL")
+                AC_DEFINE([HAVE_NPTL], [1], [NPTL threads implementation])
+                with_named_thread="-lpthread"
+                ;;
+        LINUXTHREADS* )
+                AC_MSG_RESULT("Linuxthreads")
+                AC_DEFINE([HAVE_LINUXTHREADS], [1],
+                      [Whether we are using Xavier Leroy's LinuxThreads])
+                with_named_thread="-lpthread"
+                ;;
+        * )
+                AC_MSG_RESULT("unknown")
+                ;;
+        esac
+        if test "$with_named_thread" = "no"
         then
-          AC_DEFINE(HAVE_LINUXTHREADS) dnl All this code predates NPTL, so "have linuxthreads" is a poor name.
-          with_named_thread="-lpthread"
+          # old method, check headers
+          # Look for LinuxThreads.
+          AC_MSG_CHECKING("LinuxThreads in header file comment")
+          res=`grep Linuxthreads /usr/include/pthread.h 2>/dev/null | wc -l`
+          if test "$res" -gt 0
+          then
+            AC_MSG_RESULT("Found")
+            AC_DEFINE([HAVE_LINUXTHREADS], [1],
+                  [Whether we are using Xavier Leroy's LinuxThreads])
+            # Linux 2.0 sanity check
+            AC_TRY_COMPILE([#include <sched.h>], [int a = sched_get_priority_min(1);], ,
+            AC_MSG_ERROR([Syntax error in sched.h. Change _P to __P in the /usr/include/sched.h file. See the Installation chapter in the Reference Manual]))
+            # RedHat 5.0 does not work with dynamic linking of this. -static also
+            # gives a speed increase in linux so it does not hurt on other systems.
+            with_named_thread="-lpthread"
+          else
+            AC_MSG_RESULT("Not found")
+            # If this is a linux machine we should barf
+            AC_MSG_ERROR([This is a Linux system without a working getconf,
+and Linuxthreads was not found. Please install it (or a new glibc) and try again.
+See the Installation chapter in the Reference Manual for more information.])
+          fi
         else
-          AC_MSG_ERROR([This is a Linux system and neither Linuxthreads nor NPTL were
-found. Please install Linuxthreads or a new glibc and try 
-again.  See the Installation chapter in the Reference Manual for 
-more information.])
+          AC_MSG_RESULT("no need to check headers")
         fi
-      else
-	AC_MSG_CHECKING("DEC threads")
-        if test -f /usr/shlib/libpthread.so -a -f /usr/lib/libmach.a -a -f /usr/ccs/lib/cmplrs/cc/libexc.a
-	then
-	  with_named_thread="-lpthread -lmach -lexc"
-	  CFLAGS="$CFLAGS -D_REENTRANT"
-	  CXXFLAGS="$CXXFLAGS -D_REENTRANT"
-	  AC_DEFINE(HAVE_DEC_THREADS)
-	  AC_MSG_RESULT("yes")
-	else
-	  AC_MSG_RESULT("no")
-	  AC_MSG_CHECKING("DEC 3.2 threads")
-          if test -f /usr/shlib/libpthreads.so -a -f /usr/lib/libmach.a -a -f /usr/ccs/lib/cmplrs/cc/libexc.a
-	  then
-	    with_named_thread="-lpthreads -lmach -lc_r"
-	    AC_DEFINE(HAVE_DEC_THREADS)
-	    AC_DEFINE(HAVE_DEC_3_2_THREADS)
-            with_osf32_threads="yes"
-            MYSQLD_DEFAULT_SWITCHES="--skip-thread-priority"
-	    AC_MSG_RESULT("yes")
-	  else
-	    AC_MSG_RESULT("no")
-          fi
-	fi
-     fi
-   fi
+        AC_MSG_CHECKING("for pthread_create in -lpthread");
+        ac_save_LIBS="$LIBS"
+        LIBS="$LIBS -lpthread"
+        AC_TRY_LINK( [#include <pthread.h>],
+              [ (void) pthread_create((pthread_t*) 0,(pthread_attr_t*) 0, 0, 0); ],
+              AC_MSG_RESULT("yes"),
+              [ AC_MSG_RESULT("no")
+                AC_MSG_ERROR([
+This is a Linux system claiming to support threads, either Linuxthreads or NPTL, but linking a test program failed.
+Please install one of these (or a new glibc) and try again.
+See the Installation chapter in the Reference Manual for more information.]) ]
+              )
+        LIBS="$ac_save_LIBS"
+    else
+        AC_MSG_RESULT("no")
+    fi  # "$TARGET_LINUX"
+fi  # "$with_named_thread" = "no" -a "$with_mit_threads" = "no"
+
+if test "$with_named_thread" = "no" -a "$with_mit_threads" = "no"
+then
+  AC_MSG_CHECKING("DEC threads")
+  if test -f /usr/shlib/libpthread.so -a -f /usr/lib/libmach.a -a -f /usr/ccs/lib/cmplrs/cc/libexc.a
+  then
+    with_named_thread="-lpthread -lmach -lexc"
+    CFLAGS="$CFLAGS -D_REENTRANT"
+    CXXFLAGS="$CXXFLAGS -D_REENTRANT"
+    AC_DEFINE(HAVE_DEC_THREADS)
+    AC_MSG_RESULT("yes")
+  else
+    AC_MSG_RESULT("no")
+    AC_MSG_CHECKING("DEC 3.2 threads")
+    if test -f /usr/shlib/libpthreads.so -a -f /usr/lib/libmach.a -a -f /usr/ccs/lib/cmplrs/cc/libexc.a
+    then
+      with_named_thread="-lpthreads -lmach -lc_r"
+      AC_DEFINE(HAVE_DEC_THREADS)
+      AC_DEFINE(HAVE_DEC_3_2_THREADS)
+      with_osf32_threads="yes"
+      MYSQLD_DEFAULT_SWITCHES="--skip-thread-priority"
+      AC_MSG_RESULT("yes")
+    else
+      AC_MSG_RESULT("no")
+    fi
+  fi
 fi
 
 
@@ -1720,7 +1756,7 @@
 AC_SUBST(COMPILATION_COMMENT)
 
 AC_MSG_CHECKING("need of special linking flags")
-if test "$IS_LINUX" = "true" -a "$ac_cv_prog_gcc" = "yes" -a "$all_is_static" != "yes"
+if test "$TARGET_LINUX" = "true" -a "$ac_cv_prog_gcc" = "yes" -a "$all_is_static" != "yes"
 then
   LDFLAGS="$LDFLAGS -rdynamic"
   AC_MSG_RESULT("-rdynamic")
@@ -1873,6 +1909,7 @@
  tell atod memcpy memmove \
  setupterm strcasecmp sighold vidattr lrand48 localtime_r \
  sigset sigthreadmask pthread_sigmask pthread_setprio pthread_setprio_np \
+ sigaction sigemptyset sigaddset \
  pthread_setschedparam pthread_attr_setprio pthread_attr_setschedparam \
  pthread_attr_create pthread_getsequence_np pthread_attr_setstacksize \
  pthread_attr_getstacksize pthread_key_delete \
@@ -1884,7 +1921,7 @@
 # Sanity check: We chould not have any fseeko symbol unless
 # large_file_support=yes
 AC_CHECK_FUNCS(fseeko,
-[if test "$large_file_support" = no -a "$IS_LINUX" = "true";
+[if test "$large_file_support" = no -a "$TARGET_LINUX" = "true";
 then
   AC_MSG_ERROR("Found fseeko symbol but large_file_support is not enabled!");
 fi]

--- 1.66/include/my_pthread.h	2007-01-22 02:32:10 +02:00
+++ 1.67/include/my_pthread.h	2007-01-22 02:32:10 +02:00
@@ -28,6 +28,14 @@
 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
@@ -286,8 +294,8 @@
 #undef HAVE_PTHREAD_RWLOCK_RDLOCK
 #undef HAVE_SNPRINTF
 
-#define sigset(A,B) pthread_signal((A),(void (*)(int)) (B))
-#define signal(A,B) pthread_signal((A),(void (*)(int)) (B))
+#define my_sigset(A,B) pthread_signal((A),(void (*)(int)) (B))
+#define my_signal(A,B) pthread_signal((A),(void (*)(int)) (B))
 #define my_pthread_attr_setprio(A,B)
 #endif /* defined(PTHREAD_SCOPE_GLOBAL) && !defined(PTHREAD_SCOPE_SYSTEM) */
 
@@ -324,14 +332,27 @@
 #if !defined(HAVE_SIGWAIT) && !defined(HAVE_mit_thread) && !defined(HAVE_rts_threads) && !defined(sigwait) && !defined(alpha_linux_port) && !defined(HAVE_NONPOSIX_SIGWAIT) && !defined(HAVE_DEC_3_2_THREADS) && !defined(_AIX)
 int sigwait(sigset_t *setp, int *sigp);		/* Use our implemention */
 #endif
-#if !defined(HAVE_SIGSET) && !defined(HAVE_mit_thread) && !defined(sigset)
-#define sigset(A,B) do { struct sigaction s; sigset_t set;              \
-                         sigemptyset(&set);                             \
-                         s.sa_handler = (B);                            \
-                         s.sa_mask    = set;                            \
-                         s.sa_flags   = 0;                              \
-                         sigaction((A), &s, (struct sigaction *) NULL); \
+
+/*
+  We define my_sigset() and use that instead of the system sigset() so that
+  we can favor an implementation based on sigaction(). On some systems, such
+  as Mac OS X, sigset() results in flags such as SA_RESTART being set, and
+  we want to make sure that no such flags are set.
+*/
+#if defined(HAVE_SIGACTION) && !defined(my_sigset)
+#define my_sigset(A,B) do { struct sigaction s; sigset_t set; int rc;      \
+                            DBUG_ASSERT((A) != 0);                         \
+                            sigemptyset(&set);                             \
+                            s.sa_handler = (B);                            \
+                            s.sa_mask    = set;                            \
+                            s.sa_flags   = 0;                              \
+                            rc= sigaction((A), &s, (struct sigaction *) NULL); \
+                            DBUG_ASSERT(rc == 0);                          \
                        } while (0)
+#elif defined(HAVE_SIGSET) && !defined(my_sigset)
+#define my_sigset(A,B) sigset((A),(B))
+#elif !defined(my_sigset)
+#define my_sigset(A,B) signal((A),(B))
 #endif
 
 #ifndef my_pthread_setprio
@@ -416,7 +437,7 @@
 #undef	pthread_detach_this_thread
 #define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(tmp); }
 #undef sigset
-#define sigset(A,B) pthread_signal((A),(void (*)(int)) (B))
+#define my_sigset(A,B) pthread_signal((A),(void (*)(int)) (B))
 #endif
 
 #if ((defined(HAVE_PTHREAD_ATTR_CREATE) && !defined(HAVE_SIGWAIT)) || defined(HAVE_DEC_3_2_THREADS)) && !defined(HAVE_CTHREADS_WRAPPER)

--- 1.16/include/thr_alarm.h	2007-01-22 02:32:10 +02:00
+++ 1.17/include/thr_alarm.h	2007-01-22 02:32:10 +02:00
@@ -25,11 +25,6 @@
 #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

--- 1.39/mysys/my_pthread.c	2007-01-22 02:32:10 +02:00
+++ 1.40/mysys/my_pthread.c	2007-01-22 02:32:10 +02:00
@@ -31,6 +31,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)
 {
@@ -320,7 +322,7 @@
       sigaction(i, &sact, (struct sigaction*) 0);
     }
   }
-  sigaddset(set,THR_CLIENT_ALARM);
+  sigaddset(set, thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1);
   pthread_sigmask(SIG_UNBLOCK,(sigset_t*) set,(sigset_t*) 0);
   alarm_thread=pthread_self();			/* For thr_alarm */
 

--- 1.41/mysys/thr_alarm.c	2007-01-22 02:32:10 +02:00
+++ 1.42/mysys/thr_alarm.c	2007-01-22 02:32:10 +02:00
@@ -59,9 +59,7 @@
 #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)
@@ -77,21 +75,16 @@
   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 */
+  sigfillset(&full_signal_set);			/* Needed 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
+#ifndef USE_ALARM_THREAD
+  if (thd_lib_detected != THD_LIB_LT)
+#endif
   {
-    struct sigaction sact;
-    sact.sa_flags = 0;
-    sact.sa_handler = thread_alarm;
-    sigaction(THR_CLIENT_ALARM, &sact, (struct sigaction*) 0);
+    my_sigset(thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1,
+	      thread_alarm);
   }
-#endif
-#endif
   sigemptyset(&s);
   sigaddset(&s, THR_SERVER_ALARM);
   alarm_thread=pthread_self();
@@ -109,13 +102,15 @@
   }
 #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
+  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);
-  sigset(THR_SERVER_ALARM,process_alarm);
 #endif
   DBUG_VOID_RETURN;
 }
@@ -163,7 +158,7 @@
 
   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"));
@@ -249,7 +244,7 @@
       if (alarm_data->malloced)
 	my_free((gptr) alarm_data,MYF(0));
       found++;
-#ifndef DBUG_OFF
+#ifdef DBUG_OFF
       break;
 #endif
     }
@@ -258,10 +253,11 @@
   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));
+      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);
@@ -283,18 +279,18 @@
   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
-    sigset(THR_CLIENT_ALARM,process_alarm);	/* int. thread system calls */
+    my_sigset(thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1,
+              process_alarm);	/* int. thread system calls */
 #endif
     return;
   }
-#endif
 
   /*
     We have to do do the handling of the alarm in a sub function,
@@ -310,7 +306,7 @@
   process_alarm_part2(sig);
 #ifndef USE_ALARM_THREAD
 #if defined(DONT_REMEMBER_SIGNAL) && !defined(USE_ONE_SIGNAL_HAND)
-  sigset(THR_SERVER_ALARM,process_alarm);
+  my_sigset(THR_SERVER_ALARM, process_alarm);
 #endif
   pthread_mutex_unlock(&LOCK_alarm);
   pthread_sigmask(SIG_SETMASK,&old_mask,NULL);
@@ -338,7 +334,8 @@
 	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,
+			 thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1))
 	{
 #ifdef MAIN
 	  printf("Warning: pthread_kill couldn't find thread!!!\n");
@@ -362,7 +359,8 @@
 	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,
+			 thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1))
 	{
 #ifdef MAIN
 	  printf("Warning: pthread_kill couldn't find thread!!!\n");
@@ -439,16 +437,13 @@
 	if (error == ETIME || error == ETIMEDOUT)
 	  break;				/* Don't wait forever */
       }
-      if (!alarm_queue.elements)
+      delete_queue(&alarm_queue);
+      alarm_aborted= 1;
+      pthread_mutex_unlock(&LOCK_alarm);
+      if (!alarm_thread_running)		/* Safety */
       {
-	delete_queue(&alarm_queue);
-	alarm_aborted= 1;
-	pthread_mutex_unlock(&LOCK_alarm);
-	if (!alarm_thread_running)		/* Safety */
-	{
-	  pthread_mutex_destroy(&LOCK_alarm);
-	  pthread_cond_destroy(&COND_alarm);
-	}
+        pthread_mutex_destroy(&LOCK_alarm);
+        pthread_cond_destroy(&COND_alarm);
       }
     }
     else
@@ -505,17 +500,15 @@
   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 */
+  my_sigset(sig, thread_alarm);		/* int. thread system calls */
 #endif
 }
-#endif
 
 
 #ifdef HAVE_TIMESPEC_TS_SEC
@@ -916,7 +909,7 @@
   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 */
+  my_sigset(sig, print_signal_warning);         /* int. thread system calls */
 #endif
 #ifndef OS2
   if (sig == SIGALRM)
@@ -943,9 +936,7 @@
   sigaddset(&set,SIGINT);
   sigaddset(&set,SIGQUIT);
   sigaddset(&set,SIGTERM);
-#if THR_CLIENT_ALARM != SIGHUP
   sigaddset(&set,SIGHUP);
-#endif
 #ifdef SIGTSTP
   sigaddset(&set,SIGTSTP);
 #endif
@@ -957,7 +948,7 @@
 #endif
 #endif /* OS2 */
   printf("server alarm: %d  thread alarm: %d\n",
-	 THR_SERVER_ALARM,THR_CLIENT_ALARM);
+	 THR_SERVER_ALARM, thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1);
   DBUG_PRINT("info",("Starting signal and alarm handling thread"));
   for(;;)
   {
@@ -1029,11 +1020,11 @@
   sigaddset(&set,SIGTSTP);
 #endif
   sigaddset(&set,THR_SERVER_ALARM);
-  sigdelset(&set,THR_CLIENT_ALARM);
+  sigdelset(&set, thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1);
   (void) pthread_sigmask(SIG_SETMASK,&set,NULL);
 #ifdef NOT_USED
   sigemptyset(&set);
-  sigaddset(&set,THR_CLIENT_ALARM);
+  sigaddset(&set, thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1);
   VOID(pthread_sigmask(SIG_UNBLOCK, &set, (sigset_t*) 0));
 #endif
 #endif /* OS2 */
@@ -1083,8 +1074,8 @@
     }
   }
   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);

--- 1.530/sql/mysqld.cc	2007-01-22 02:32:10 +02:00
+++ 1.531/sql/mysqld.cc	2007-01-22 02:32:10 +02:00
@@ -177,12 +177,6 @@
 } /* cplusplus */
 
 
-#if defined(HAVE_LINUXTHREADS)
-#define THR_KILL_SIGNAL SIGINT
-#else
-#define THR_KILL_SIGNAL SIGUSR2		// Can't use this with LinuxThreads
-#endif
-
 #ifdef HAVE_GLIBC2_STYLE_GETHOSTBYNAME_R
 #include <sys/types.h>
 #else
@@ -505,6 +499,7 @@
 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
@@ -544,7 +539,8 @@
     DBUG_PRINT("info",("Waiting for select_thread"));
 
 #ifndef DONT_USE_THR_ALARM
-    if (pthread_kill(select_thread,THR_CLIENT_ALARM))
+    if (pthread_kill(select_thread,
+		     thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1))
       break;					// allready dead
 #endif
     set_timespec(abstime, 2);
@@ -844,7 +840,7 @@
 		      sig,my_thread_id());
   }
 #ifdef DONT_REMEMBER_SIGNAL
-  sigset(sig,print_signal_warning);		/* int. thread system calls */
+  my_sigset(sig, print_signal_warning);         /* int. thread system calls */
 #endif
 #if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__)
   if (sig == SIGALRM)
@@ -1841,8 +1837,11 @@
   DBUG_ENTER("init_signals");
 
   if (test_flags & TEST_SIGINT)
-    sigset(THR_KILL_SIGNAL,end_thread_signal);
-  sigset(THR_SERVER_ALARM,print_signal_warning); // Should never be called!
+  {
+    my_sigset(thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2,
+              end_thread_signal);
+  }
+  my_sigset(THR_SERVER_ALARM, print_signal_warning); // Should never be called!
 
   if (!(test_flags & TEST_NO_STACKTRACE) || (test_flags & TEST_CORE_ON_SIGNAL))
   {
@@ -1877,7 +1876,7 @@
 #endif
   (void) sigemptyset(&set);
 #ifdef THREAD_SPECIFIC_SIGPIPE
-  sigset(SIGPIPE,abort_thread);
+  my_sigset(SIGPIPE, abort_thread);
   sigaddset(&set,SIGPIPE);
 #else
   (void) signal(SIGPIPE,SIG_IGN);		// Can't know which thread
@@ -1903,8 +1902,12 @@
 #endif
   sigaddset(&set,THR_SERVER_ALARM);
   if (test_flags & TEST_SIGINT)
-    sigdelset(&set,THR_KILL_SIGNAL);		// May be SIGINT
-  sigdelset(&set,THR_CLIENT_ALARM);		// For alarms
+  {
+    // May be SIGINT
+    sigdelset(&set, thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2);
+  }
+  // For alarms
+  sigdelset(&set, thd_lib_detected == THD_LIB_LT ? SIGALRM : SIGUSR1);
   sigprocmask(SIG_SETMASK,&set,NULL);
   pthread_sigmask(SIG_SETMASK,&set,NULL);
   DBUG_VOID_RETURN;
@@ -1959,24 +1962,20 @@
   */
   init_thr_alarm(max_connections +
 		 global_system_variables.max_insert_delayed_threads + 10);
-#if SIGINT != THR_KILL_SIGNAL
-  if (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
     (void) pthread_sigmask(SIG_UNBLOCK,&set,NULL);
   }
-#endif
   (void) sigemptyset(&set);			// Setup up SIGINT for debug
 #ifdef USE_ONE_SIGNAL_HAND
   (void) sigaddset(&set,THR_SERVER_ALARM);	// For alarms
 #endif
 #ifndef IGNORE_SIGHUP_SIGQUIT
   (void) sigaddset(&set,SIGQUIT);
-#if THR_CLIENT_ALARM != SIGHUP
   (void) sigaddset(&set,SIGHUP);
 #endif
-#endif
   (void) sigaddset(&set,SIGTERM);
   (void) sigaddset(&set,SIGTSTP);
 
@@ -2236,8 +2235,8 @@
   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
   {
     // fix timezone for daylight saving
@@ -5546,6 +5545,22 @@
     (void) my_write(file, (byte*) buff, (uint) (end-buff),MYF(MY_WME));
     (void) my_close(file, MYF(0));
   }
+}
+
+
+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;
 }
 
 

--- 1.75/include/my_global.h	2007-01-22 02:32:10 +02:00
+++ 1.76/include/my_global.h	2007-01-22 02:32:10 +02:00
@@ -97,7 +97,7 @@
 
 
 /* Fix problem with S_ISLNK() on Linux */
-#if defined(HAVE_LINUXTHREADS)
+#if defined(TARGET_OS_LINUX) || defined(__GLIBC__)
 #undef  _GNU_SOURCE
 #define _GNU_SOURCE 1
 #endif
@@ -348,7 +348,10 @@
 #endif
 
 /* Define some useful general macros */
-#if !defined(max)
+#if defined(__cplusplus) && defined(__GNUC__)
+#define max(a, b)     ((a) >? (b))
+#define min(a, b)     ((a) <? (b))
+#elif !defined(max)
 #define max(a, b)	((a) > (b) ? (a) : (b))
 #define min(a, b)	((a) < (b) ? (a) : (b))
 #endif

--- 1.24/BUILD/SETUP.sh	2007-01-22 02:32:10 +02:00
+++ 1.25/BUILD/SETUP.sh	2007-01-22 02:32:10 +02:00
@@ -39,8 +39,8 @@
 c_warnings="$global_warnings -Wunused"
 cxx_warnings="$global_warnings -Woverloaded-virtual -Wsign-promo -Wreorder -Wctor-dtor-privacy -Wnon-virtual-dtor"
 
-alpha_cflags="-mcpu=ev6 -Wa,-mev6"	# Not used yet
-pentium_cflags="-mcpu=pentiumpro"
+#alpha_cflags="-mcpu=ev6 -Wa,-mev6"	# Not used yet
+#pentium_cflags="-mcpu=pentiumpro"
 sparc_cflags=""
 
 # be as fast as we can be without losing our ability to backtrace
Thread
bk commit into 4.0 tree (jani:1.2206) BUG#16995jani22 Jan