22 #include "mysys_priv.h"
26 static void install_sigabrt_handler(
void);
28 struct thread_start_parameter
41 win_pthread_mutex_trylock(pthread_mutex_t *mutex)
43 if (TryEnterCriticalSection(mutex))
46 if (mutex->RecursionCount > 1){
47 LeaveCriticalSection(mutex);
55 static unsigned int __stdcall pthread_start(
void *p)
57 struct thread_start_parameter *par= (
struct thread_start_parameter *)p;
58 pthread_handler func= par->func;
66 int pthread_create(pthread_t *thread_id,
const pthread_attr_t *attr,
67 pthread_handler func,
void *param)
70 struct thread_start_parameter *par;
71 unsigned int stack_size;
73 DBUG_ENTER(
"pthread_create");
75 par= (
struct thread_start_parameter *)malloc(
sizeof(*par));
81 stack_size= attr?attr->dwStackSize:0;
83 handle= _beginthreadex(NULL, stack_size , pthread_start, par, 0, thread_id);
86 DBUG_PRINT(
"info", (
"thread id=%u",*thread_id));
89 CloseHandle((HANDLE)handle);
95 (
"Can't create thread to handle request (error %d)",error_no));
96 DBUG_RETURN(error_no);
100 void pthread_exit(
void *a)
105 int pthread_join(pthread_t thread,
void **value_ptr)
110 handle= OpenThread(SYNCHRONIZE, FALSE, thread);
117 ret= WaitForSingleObject(handle, INFINITE);
119 if(ret != WAIT_OBJECT_0)
134 int pthread_cancel(pthread_t thread)
140 handle= OpenThread(THREAD_TERMINATE, FALSE, thread);
143 ok= TerminateThread(handle,0);
157 int my_pthread_once(my_pthread_once_t *once_control,
158 void (*init_routine)(
void))
167 if (*once_control == MY_PTHREAD_ONCE_DONE)
170 state= InterlockedCompareExchange(once_control, MY_PTHREAD_ONCE_INPROGRESS,
171 MY_PTHREAD_ONCE_INIT);
175 case MY_PTHREAD_ONCE_INIT:
178 *once_control= MY_PTHREAD_ONCE_DONE;
181 case MY_PTHREAD_ONCE_INPROGRESS:
183 while(*once_control == MY_PTHREAD_ONCE_INPROGRESS)
188 case MY_PTHREAD_ONCE_DONE: