diff options
Diffstat (limited to 'include/my_pthread.h')
-rw-r--r-- | include/my_pthread.h | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/include/my_pthread.h b/include/my_pthread.h index 9e2c2111b8e..b4fe1203d2b 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -31,7 +31,7 @@ extern "C" { #if defined(__WIN__) typedef CRITICAL_SECTION pthread_mutex_t; -typedef HANDLE pthread_t; +typedef DWORD pthread_t; typedef struct thread_attr { DWORD dwStackSize ; DWORD dwCreatingFlag ; @@ -64,8 +64,7 @@ typedef struct { typedef int pthread_mutexattr_t; -#define win_pthread_self my_thread_var->pthread_self -#define pthread_self() win_pthread_self +#define pthread_self() GetCurrentThreadId() #define pthread_handler_t EXTERNC void * __cdecl typedef void * (__cdecl *pthread_handler)(void *); @@ -99,8 +98,7 @@ struct timespec { (ABSTIME).max_timeout_msec= (long)((NSEC)/1000000); \ } -void win_pthread_init(void); -int win_pthread_setspecific(void *A,void *B,uint length); + int win_pthread_mutex_trylock(pthread_mutex_t *mutex); int pthread_create(pthread_t *,pthread_attr_t *,pthread_handler,void *); int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr); @@ -117,42 +115,25 @@ int pthread_attr_destroy(pthread_attr_t *connect_att); struct tm *localtime_r(const time_t *timep,struct tm *tmp); struct tm *gmtime_r(const time_t *timep,struct tm *tmp); +void pthread_exit(void *a); +int pthread_join(pthread_t thread, void **value_ptr); -void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/ #define ETIMEDOUT 145 /* Win32 doesn't have this */ -#define getpid() GetCurrentThreadId() #define HAVE_LOCALTIME_R 1 #define _REENTRANT 1 #define HAVE_PTHREAD_ATTR_SETSTACKSIZE 1 -/* - Windows has two ways to use thread local storage. The most efficient - is using __declspec(thread), but that does not work properly when - used in a .dll that is loaded at runtime, after program load. So for - libmysql.dll and libmysqld.dll we define USE_TLS in order to use the - TlsXxx() API instead, which works in all cases. -*/ -#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_key_delete(A) TlsFree(A) +#define my_pthread_setspecific_ptr(T,V) (!TlsSetValue((T),(V))) +#define pthread_setspecific(A,B) (!TlsSetValue((A),(B))) #define pthread_getspecific(A) (TlsGetValue(A)) #define my_pthread_getspecific(T,A) ((T) TlsGetValue(A)) #define my_pthread_getspecific_ptr(T,V) ((T) TlsGetValue(V)) -#define my_pthread_setspecific_ptr(T,V) (!TlsSetValue((T),(V))) -#define pthread_setspecific(A,B) (!TlsSetValue((A),(B))) -#else -#define pthread_key(T,V) __declspec(thread) T V -#define pthread_key_create(A,B) pthread_dummy(0) -#define pthread_key_delete(A) pthread_dummy(0) -#define pthread_getspecific(A) (&(A)) -#define my_pthread_getspecific(T,A) (&(A)) -#define my_pthread_getspecific_ptr(T,V) (V) -#define my_pthread_setspecific_ptr(T,V) ((T)=(V),0) -#define pthread_setspecific(A,B) win_pthread_setspecific(&(A),(B),sizeof(A)) -#endif /* USE_TLS */ #define pthread_equal(A,B) ((A) == (B)) #define pthread_mutex_init(A,B) (InitializeCriticalSection(A),0) @@ -163,7 +144,6 @@ void pthread_exit(void *a); /* was #define pthread_exit(A) ExitThread(A)*/ #define my_pthread_setprio(A,B) SetThreadPriority(GetCurrentThread(), (B)) #define pthread_kill(A,B) pthread_dummy((A) ? 0 : ESRCH) -#define pthread_join(A,B) (WaitForSingleObject((A), INFINITE) != WAIT_OBJECT_0) /* Dummy defines for easier code */ #define pthread_attr_setdetachstate(A,B) pthread_dummy(0) |