Commit cdf6001a authored by unknown's avatar unknown
Browse files

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
parent 454c763c
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -348,10 +348,7 @@ int __void__;
#endif

/* Define some useful general macros */
#if defined(__cplusplus) && defined(__GNUC__)
#define max(a, b)     ((a) >? (b))
#define min(a, b)     ((a) <? (b))
#elif !defined(max)
#if !defined(max)
#define max(a, b)	((a) > (b) ? (a) : (b))
#define min(a, b)	((a) < (b) ? (a) : (b))
#endif
+9 −8
Original line number Diff line number Diff line
@@ -28,14 +28,6 @@
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
@@ -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;

/* 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 */

#ifndef thread_safe_increment
+2 −2
Original line number Diff line number Diff line
@@ -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;
+4 −1
Original line number Diff line number Diff line
@@ -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 */

+25 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@

#include "mysys_priv.h"
#include <m_string.h>
#include <signal.h>

#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 */
Loading