Commit bc54ae2c authored by unknown's avatar unknown

Fix for HPUX 11 and pthread_mutex_lock


include/my_pthread.h:
  Fix for HPUX 11 and pthread_mutex_lock (merge from 4.0)
mysys/my_pthread.c:
  Fix for HPUX 11 and pthread_mutex_lock (merge from 4.0)
parent 53be5587
...@@ -46931,6 +46931,8 @@ not yet 100% confident in this code. ...@@ -46931,6 +46931,8 @@ not yet 100% confident in this code.
@item @item
Fixed problem with @code{UNSIGNED BIGINT} on AIX (again). Fixed problem with @code{UNSIGNED BIGINT} on AIX (again).
@item @item
Fixed bug in pthread_mutex_trylock() on HPUX 11.0
@item
Multithreaded stress tests for InnoDB. Multithreaded stress tests for InnoDB.
@end itemize @end itemize
...@@ -850,8 +850,8 @@ case $SYSTEM_TYPE in ...@@ -850,8 +850,8 @@ case $SYSTEM_TYPE in
;; ;;
*hpux10.20*) *hpux10.20*)
echo "Enabling workarounds for hpux 10.20" echo "Enabling workarounds for hpux 10.20"
CFLAGS="$CFLAGS -DHAVE_BROKEN_SNPRINTF -DSIGNALS_DONT_BREAK_READ -DDO_NOT_REMOVE_THREAD_WRAPPERS -DHPUX -DSIGNAL_WITH_VIO_CLOSE -DHAVE_BROKEN_PTHREAD_COND_TIMEDWAIT" CFLAGS="$CFLAGS -DHAVE_BROKEN_SNPRINTF -DSIGNALS_DONT_BREAK_READ -DDO_NOT_REMOVE_THREAD_WRAPPERS -DHPUX -DSIGNAL_WITH_VIO_CLOSE -DHAVE_BROKEN_PTHREAD_COND_TIMEDWAIT -DHAVE_POSIX1003_4a_MUTEX"
CXXFLAGS="$CXXFLAGS -DHAVE_BROKEN_SNPRINTF -D_INCLUDE_LONGLONG -DSIGNALS_DONT_BREAK_READ -DDO_NOT_REMOVE_THREAD_WRAPPERS -DHPUX -DSIGNAL_WITH_VIO_CLOSE -DHAVE_BROKEN_PTHREAD_COND_TIMEDWAIT" CXXFLAGS="$CXXFLAGS -DHAVE_BROKEN_SNPRINTF -D_INCLUDE_LONGLONG -DSIGNALS_DONT_BREAK_READ -DDO_NOT_REMOVE_THREAD_WRAPPERS -DHPUX -DSIGNAL_WITH_VIO_CLOSE -DHAVE_BROKEN_PTHREAD_COND_TIMEDWAIT HAVE_POSIX1003_4a_MUTEX"
if test "$with_named_thread" = "no" if test "$with_named_thread" = "no"
then then
echo "Using --with-named-thread=-lpthread" echo "Using --with-named-thread=-lpthread"
......
...@@ -133,16 +133,17 @@ void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/ ...@@ -133,16 +133,17 @@ void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/
#define pthread_equal(A,B) ((A) == (B)) #define pthread_equal(A,B) ((A) == (B))
#ifdef OS2 #ifdef OS2
int pthread_mutex_init (pthread_mutex_t *, const pthread_mutexattr_t *); extern int pthread_mutex_init (pthread_mutex_t *, const pthread_mutexattr_t *);
int pthread_mutex_lock (pthread_mutex_t *); extern int pthread_mutex_lock (pthread_mutex_t *);
int pthread_mutex_unlock (pthread_mutex_t *); extern int pthread_mutex_unlock (pthread_mutex_t *);
int pthread_mutex_destroy (pthread_mutex_t *); extern int pthread_mutex_destroy (pthread_mutex_t *);
#define my_pthread_setprio(A,B) DosSetPriority(PRTYS_THREAD,PRTYC_NOCHANGE, B, A) #define my_pthread_setprio(A,B) DosSetPriority(PRTYS_THREAD,PRTYC_NOCHANGE, B, A)
#define pthread_kill(A,B) raise(B) #define pthread_kill(A,B) raise(B)
#define pthread_exit(A) pthread_dummy() #define pthread_exit(A) pthread_dummy()
#else #else
#define pthread_mutex_init(A,B) InitializeCriticalSection(A) #define pthread_mutex_init(A,B) InitializeCriticalSection(A)
#define pthread_mutex_lock(A) (EnterCriticalSection(A),0) #define pthread_mutex_lock(A) (EnterCriticalSection(A),0)
#define pthread_mutex_trylock(A) (WaitForSingleObject((A), 0) == WAIT_TIMEOUT)
#define pthread_mutex_unlock(A) LeaveCriticalSection(A) #define pthread_mutex_unlock(A) LeaveCriticalSection(A)
#define pthread_mutex_destroy(A) DeleteCriticalSection(A) #define pthread_mutex_destroy(A) DeleteCriticalSection(A)
#define my_pthread_setprio(A,B) SetThreadPriority(GetCurrentThread(), (B)) #define my_pthread_setprio(A,B) SetThreadPriority(GetCurrentThread(), (B))
...@@ -430,11 +431,14 @@ struct tm *localtime_r(const time_t *clock, struct tm *res); ...@@ -430,11 +431,14 @@ struct tm *localtime_r(const time_t *clock, struct tm *res);
#if defined(HPUX) && !defined(DONT_REMAP_PTHREAD_FUNCTIONS) #if defined(HPUX) && !defined(DONT_REMAP_PTHREAD_FUNCTIONS)
#undef pthread_cond_timedwait #undef pthread_cond_timedwait
#undef pthread_mutex_trylock
#define pthread_cond_timedwait(a,b,c) my_pthread_cond_timedwait((a),(b),(c)) #define pthread_cond_timedwait(a,b,c) my_pthread_cond_timedwait((a),(b),(c))
#define pthread_mutex_trylock(a) my_pthread_mutex_trylock((a))
int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
struct timespec *abstime); struct timespec *abstime);
#endif
#if defined(HAVE_POSIX1003_4a_MUTEX) && !defined(DONT_REMAP_PTHREAD_FUNCTIONS)
#undef pthread_mutex_trylock
#define pthread_mutex_trylock(a) my_pthread_mutex_trylock((a))
int my_pthread_mutex_trylock(pthread_mutex_t *mutex); int my_pthread_mutex_trylock(pthread_mutex_t *mutex);
#endif #endif
...@@ -468,6 +472,7 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp, ...@@ -468,6 +472,7 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
#undef pthread_mutex_t #undef pthread_mutex_t
#undef pthread_cond_wait #undef pthread_cond_wait
#undef pthread_cond_timedwait #undef pthread_cond_timedwait
#undef pthread_mutex_trylock
#define pthread_mutex_init(A,B) safe_mutex_init((A),(B)) #define pthread_mutex_init(A,B) safe_mutex_init((A),(B))
#define pthread_mutex_lock(A) safe_mutex_lock((A),__FILE__,__LINE__) #define pthread_mutex_lock(A) safe_mutex_lock((A),__FILE__,__LINE__)
#define pthread_mutex_unlock(A) safe_mutex_unlock((A),__FILE__,__LINE__) #define pthread_mutex_unlock(A) safe_mutex_unlock((A),__FILE__,__LINE__)
...@@ -476,6 +481,9 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp, ...@@ -476,6 +481,9 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
#define pthread_cond_timedwait(A,B,C) safe_cond_timedwait((A),(B),(C),__FILE__,__LINE__) #define pthread_cond_timedwait(A,B,C) safe_cond_timedwait((A),(B),(C),__FILE__,__LINE__)
#define pthread_mutex_trylock(A) pthread_mutex_lock(A) #define pthread_mutex_trylock(A) pthread_mutex_lock(A)
#define pthread_mutex_t safe_mutex_t #define pthread_mutex_t safe_mutex_t
#define safe_mutex_assert_owner(mp) DBUG_ASSERT((mp)->count > 0 && pthread_equal(pthread_self(),(mp)->thread))
#else
#define safe_mutex_assert_owner(mp)
#endif /* SAFE_MUTEX */ #endif /* SAFE_MUTEX */
/* READ-WRITE thread locking */ /* READ-WRITE thread locking */
...@@ -486,6 +494,8 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp, ...@@ -486,6 +494,8 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
#define my_rwlock_init(A,B) pthread_mutex_init((A),(B)) #define my_rwlock_init(A,B) pthread_mutex_init((A),(B))
#define rw_rdlock(A) pthread_mutex_lock((A)) #define rw_rdlock(A) pthread_mutex_lock((A))
#define rw_wrlock(A) pthread_mutex_lock((A)) #define rw_wrlock(A) pthread_mutex_lock((A))
#define rw_tryrdlock(A) pthread_mutex_trylock((A))
#define rw_trywrlock(A) pthread_mutex_trylock((A))
#define rw_unlock(A) pthread_mutex_unlock((A)) #define rw_unlock(A) pthread_mutex_unlock((A))
#define rwlock_destroy(A) pthread_mutex_destroy((A)) #define rwlock_destroy(A) pthread_mutex_destroy((A))
#elif defined(HAVE_PTHREAD_RWLOCK_RDLOCK) #elif defined(HAVE_PTHREAD_RWLOCK_RDLOCK)
...@@ -493,6 +503,8 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp, ...@@ -493,6 +503,8 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
#define my_rwlock_init(A,B) pthread_rwlock_init((A),(B)) #define my_rwlock_init(A,B) pthread_rwlock_init((A),(B))
#define rw_rdlock(A) pthread_rwlock_rdlock(A) #define rw_rdlock(A) pthread_rwlock_rdlock(A)
#define rw_wrlock(A) pthread_rwlock_wrlock(A) #define rw_wrlock(A) pthread_rwlock_wrlock(A)
#define rw_tryrdlock(A) pthread_rwlock_tryrdlock((A))
#define rw_trywrlock(A) pthread_rwlock_trywrlock((A))
#define rw_unlock(A) pthread_rwlock_unlock(A) #define rw_unlock(A) pthread_rwlock_unlock(A)
#define rwlock_destroy(A) pthread_rwlock_destroy(A) #define rwlock_destroy(A) pthread_rwlock_destroy(A)
#elif defined(HAVE_RWLOCK_INIT) #elif defined(HAVE_RWLOCK_INIT)
...@@ -513,14 +525,18 @@ typedef struct _my_rw_lock_t { ...@@ -513,14 +525,18 @@ typedef struct _my_rw_lock_t {
#define rw_lock_t my_rw_lock_t #define rw_lock_t my_rw_lock_t
#define rw_rdlock(A) my_rw_rdlock((A)) #define rw_rdlock(A) my_rw_rdlock((A))
#define rw_wrlock(A) my_rw_wrlock((A)) #define rw_wrlock(A) my_rw_wrlock((A))
#define rw_tryrdlock(A) my_rw_tryrdlock((A))
#define rw_trywrlock(A) my_rw_trywrlock((A))
#define rw_unlock(A) my_rw_unlock((A)) #define rw_unlock(A) my_rw_unlock((A))
#define rwlock_destroy(A) my_rwlock_destroy((A)) #define rwlock_destroy(A) my_rwlock_destroy((A))
extern int my_rwlock_init( my_rw_lock_t *, void * ); extern int my_rwlock_init(my_rw_lock_t *, void *);
extern int my_rwlock_destroy( my_rw_lock_t * ); extern int my_rwlock_destroy(my_rw_lock_t *);
extern int my_rw_rdlock( my_rw_lock_t * ); extern int my_rw_rdlock(my_rw_lock_t *);
extern int my_rw_wrlock( my_rw_lock_t * ); extern int my_rw_wrlock(my_rw_lock_t *);
extern int my_rw_unlock( my_rw_lock_t * ); extern int my_rw_unlock(my_rw_lock_t *);
extern int my_rw_tryrdlock(my_rw_lock_t *);
extern int my_rw_trywrlock(my_rw_lock_t *);
#endif /* USE_MUTEX_INSTEAD_OF_RW_LOCKS */ #endif /* USE_MUTEX_INSTEAD_OF_RW_LOCKS */
#define GETHOSTBYADDR_BUFF_SIZE 2048 #define GETHOSTBYADDR_BUFF_SIZE 2048
......
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000 MySQL AB
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public modify it under the terms of the GNU Library General Public
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
/* Functions to get threads more portable */ /* Functions to get threads more portable */
#define DONT_REMAP_PTHREAD_FUNCTIONS
#include "mysys_priv.h" #include "mysys_priv.h"
#ifdef THREAD #ifdef THREAD
#include <signal.h> #include <signal.h>
...@@ -372,16 +374,33 @@ int pthread_signal(int sig, void (*func)()) ...@@ -372,16 +374,33 @@ int pthread_signal(int sig, void (*func)())
sigaction(sig, &sact, (struct sigaction*) 0); sigaction(sig, &sact, (struct sigaction*) 0);
return 0; return 0;
} }
#endif #endif
/****************************************************************************
The following functions fixes that all pthread functions should work
according to latest posix standard
****************************************************************************/
/* Undefined wrappers set my_pthread.h so that we call os functions */
#undef pthread_mutex_init
#undef pthread_mutex_lock
#undef pthread_mutex_unlock
#undef pthread_mutex_destroy
#undef pthread_mutex_wait
#undef pthread_mutex_timedwait
#undef pthread_mutex_t
#undef pthread_cond_wait
#undef pthread_cond_timedwait
#undef pthread_mutex_trylock
#undef pthread_mutex_t
#undef pthread_cond_t
/***************************************************************************** /*****************************************************************************
** Patches for AIX and DEC OSF/1 3.2 ** Patches for AIX and DEC OSF/1 3.2
*****************************************************************************/ *****************************************************************************/
#if (defined(HAVE_NONPOSIX_PTHREAD_MUTEX_INIT) && !defined(HAVE_UNIXWARE7_THREADS)) || defined(HAVE_DEC_3_2_THREADS) #if (defined(HAVE_NONPOSIX_PTHREAD_MUTEX_INIT) && !defined(HAVE_UNIXWARE7_THREADS)) || defined(HAVE_DEC_3_2_THREADS)
#undef pthread_mutex_init
#undef pthread_cond_init
#include <netdb.h> #include <netdb.h>
...@@ -407,13 +426,20 @@ int my_pthread_cond_init(pthread_cond_t *mp, const pthread_condattr_t *attr) ...@@ -407,13 +426,20 @@ int my_pthread_cond_init(pthread_cond_t *mp, const pthread_condattr_t *attr)
#endif #endif
/* Change functions on HP to work according to POSIX */
/*****************************************************************************
Patches for HPUX
We need these because the pthread_mutex.. code returns -1 on error,
instead of the error code.
Note that currently we only remap pthread_ functions used by MySQL.
If we are depending on the value for some other pthread_xxx functions,
this has to be added here.
****************************************************************************/
#if defined(HPUX) || defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT) #if defined(HPUX) || defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT)
#undef pthread_cond_timedwait
int my_pthread_cond_timedwait(pthread_cond_t *cond, int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
pthread_mutex_t *mutex,
struct timespec *abstime) struct timespec *abstime)
{ {
int error=pthread_cond_timedwait(cond, mutex, abstime); int error=pthread_cond_timedwait(cond, mutex, abstime);
...@@ -429,7 +455,7 @@ int my_pthread_cond_timedwait(pthread_cond_t *cond, ...@@ -429,7 +455,7 @@ int my_pthread_cond_timedwait(pthread_cond_t *cond,
#endif #endif
#ifdef HPUX #ifdef HAVE_POSIX1003_4a_MUTEX
/* /*
In HP-UX-10.20 and other old Posix 1003.4a Draft 4 implementations In HP-UX-10.20 and other old Posix 1003.4a Draft 4 implementations
pthread_mutex_trylock returns 1 on success, not 0 like pthread_mutex_trylock returns 1 on success, not 0 like
...@@ -447,32 +473,29 @@ int my_pthread_cond_timedwait(pthread_cond_t *cond, ...@@ -447,32 +473,29 @@ int my_pthread_cond_timedwait(pthread_cond_t *cond,
-1 | [EINVAL] | The value specified by mutex is invalid. -1 | [EINVAL] | The value specified by mutex is invalid.
*/ */
/* We defined pthread_mutex_trylock as a macro in my_pthread.h, we have
to undef it here to prevent infinite recursion! Note that this comment
documents the pushed bugfix, not just the the code itself here. That is why
this comment is good here.
*/
#undef pthread_mutex_trylock
/* /*
This function returns 0 if we are able successfully lock the mutex. If Convert pthread_mutex_trylock to return values according to latest POSIX
the mutex cannot be locked or there is an error, then returns != 0
RETURN VALUES
0 If we are able successfully lock the mutex.
EBUSY Mutex was locked by another thread
# Other error number returned by pthread_mutex_trylock()
(Not likely)
*/ */
int my_pthread_mutex_trylock(pthread_mutex_t *mutex) int my_pthread_mutex_trylock(pthread_mutex_t *mutex)
{ {
int error = pthread_mutex_trylock(mutex); int error= pthread_mutex_trylock(mutex);
if (error == 1) if (error == 1)
return 0; /* success */ return 0; /* Got lock on mutex */
if (error == 0) /* Someon else is locking mutex */
if (error == -1) return EBUSY;
error=errno; /* parameter invalid */ if (error == -1) /* Safety if the lib is fixed */
error= errno; /* Probably invalid parameter */
return 1; /* we were not able to lock the mutex */ return error;
} }
#endif #endif /* HAVE_POSIX1003_4a_MUTEX */
/* Some help functions */ /* Some help functions */
......
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