Commit 830d3089 authored by monty@donna.mysql.com's avatar monty@donna.mysql.com
Browse files

Fix for SAFE_MUTEX on windows

parent 2780278f
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -1385,14 +1385,14 @@ and PHP's @strong{MySQL}-related functions
@item Price	@tab		$34.95
@end multitable
This book teaches you how to use @strong{MySQL} and @code{mSQL}, two popular and
robust database products that support key subsets of SQL on both Linux
and UNIX systems. Anyone who knows basic C, Java, Perl, or Python can
write a program to interact with a database, either as a stand-alone
application or through a Web page. This book takes you through the
whole process, from installation and configuration to programming
interfaces and basic administration.  Includes ample tutorial
material.
This book teaches you how to use @strong{MySQL} and @code{mSQL}, two
popular and robust database products that support key subsets of SQL on
both Linux and UNIX systems. Anyone who knows basic C, Java, Perl, or
Python can write a program to interact with a database, either as a
stand-alone application or through a Web page. This book takes you
through the whole process, from installation and configuration to
programming interfaces and basic administration.  Includes ample
tutorial material.
@multitable @columnfractions .3 .7
@item Title     @tab            @uref{http://shop.barnesandnoble.com/bookSearch/isbnInquiry.asp?isbn=0672319144,Sams Teach Yourself MySQL in 21 Days}
+1 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ void pthread_exit(unsigned A); /* was #define pthread_exit(A) ExitThread(A)*/
#define HAVE_PTHREAD_ATTR_SETSTACKSIZE

#ifdef USE_TLS					/* For LIBMYSQL.DLL */
#undef SAFE_MUTEX				/* This will cause conflicts */
#define pthread_key(T,V)  DWORD V
#define pthread_key_create(A,B) ((*A=TlsAlloc())==0xFFFFFFFF)
#define pthread_getspecific(A) (TlsGetValue(A))
+14 −1
Original line number Diff line number Diff line
@@ -77,10 +77,19 @@ void my_thread_global_end(void)

static long thread_id=0;

/*
  We can't use mutex_locks here if we re using windows as
  we may have compiled the program with SAFE_MUTEX, in which
  case the checking of mutex_locks will not work until
  the pthread_self thread specific variable is initialized.
*/

my_bool my_thread_init(void)
{
  struct st_my_thread_var *tmp;
#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX)
  pthread_mutex_lock(&THR_LOCK_lock);
#endif
#if !defined(__WIN__) || defined(USE_TLS)
  if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys))
  {
@@ -98,9 +107,11 @@ my_bool my_thread_init(void)
  pthread_setspecific(THR_KEY_mysys,tmp);

#else
  if (THR_KEY_mysys.id)   /* Allready initialized */
  if (THR_KEY_mysys.id)   /* Already initialized */
  {
#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX)
    pthread_mutex_unlock(&THR_LOCK_lock);
#endif
    return 0;
  }
  tmp= &THR_KEY_mysys;
@@ -108,7 +119,9 @@ my_bool my_thread_init(void)
  tmp->id= ++thread_id;
  pthread_mutex_init(&tmp->mutex,NULL);
  pthread_cond_init(&tmp->suspend, NULL);
#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX)
  pthread_mutex_unlock(&THR_LOCK_lock);
#endif
  return 0;
}

+4 −4
Original line number Diff line number Diff line
@@ -48,13 +48,13 @@ static pthread_handler_decl(pthread_start,param)
{
  pthread_handler func=((struct pthread_map *) param)->func;
  void *func_param=((struct pthread_map *) param)->param;
  my_thread_init();
  pthread_mutex_lock(&THR_LOCK_thread);	  /* Wait for beingthread to return */
  my_thread_init();			/* Will always succeed in windows */
  pthread_mutex_lock(&THR_LOCK_thread);	  /* Wait for beginthread to return */
  win_pthread_self=((struct pthread_map *) param)->pthreadself;
  pthread_mutex_unlock(&THR_LOCK_thread);
  free((char*) param);
  free((char*) param);			  /* Free param from create */
  pthread_exit((*func)(func_param));
  return 0;
  return 0;				  /* Safety */
}


+2 −3
Original line number Diff line number Diff line
@@ -218,9 +218,8 @@ int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint line)
  pthread_mutex_destroy(&mp->global);
  pthread_mutex_destroy(&mp->mutex);
#else
  if (pthread_mutex_destroy(&mp->global) || 
      pthread_mutex_destroy(&mp->mutex))
    error=1;
  error= (int) (pthread_mutex_destroy(&mp->global) || 
		pthread_mutex_destroy(&mp->mutex));
#endif
  return error;
}
Loading