| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#if defined(_WIN32) |
| 21 |
|
| 22 |
#undef SAFE_MUTEX |
| 23 |
#include "mysys_priv.h" |
| 24 |
#include <m_string.h> |
| 25 |
#include <process.h> |
| 26 |
#include <sys/timeb.h> |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
static DWORD get_milliseconds(const struct timespec *abstime) |
| 34 |
{ |
| 35 |
struct timespec current_time; |
| 36 |
long long ms; |
| 37 |
|
| 38 |
if (abstime == NULL) |
| 39 |
return INFINITE; |
| 40 |
|
| 41 |
set_timespec_nsec(current_time, 0); |
| 42 |
ms= (abstime->tv_sec - current_time.tv_sec)*1000LL + |
| 43 |
(abstime->tv_nsec - current_time.tv_nsec)/1000000LL; |
| 44 |
if(ms < 0 ) |
| 45 |
ms= 0; |
| 46 |
if(ms > UINT_MAX) |
| 47 |
ms= INFINITE; |
| 48 |
return (DWORD)ms; |
| 49 |
} |
| 50 |
|
| 51 |
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) |
| 52 |
{ |
| 53 |
InitializeConditionVariable(cond); |
| 54 |
return 0; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
int pthread_cond_destroy(pthread_cond_t *cond) |
| 59 |
{ |
| 60 |
return 0; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
int pthread_cond_broadcast(pthread_cond_t *cond) |
| 65 |
{ |
| 66 |
WakeAllConditionVariable(cond); |
| 67 |
return 0; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
int pthread_cond_signal(pthread_cond_t *cond) |
| 72 |
{ |
| 73 |
WakeConditionVariable(cond); |
| 74 |
return 0; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, |
| 79 |
const struct timespec *abstime) |
| 80 |
{ |
| 81 |
DWORD timeout= get_milliseconds(abstime); |
| 82 |
if (!SleepConditionVariableCS(cond, mutex, timeout)) |
| 83 |
return ETIMEDOUT; |
| 84 |
return 0; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) |
| 89 |
{ |
| 90 |
return pthread_cond_timedwait(cond, mutex, NULL); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
int pthread_attr_init(pthread_attr_t *connect_att) |
| 95 |
{ |
| 96 |
connect_att->dwStackSize = 0; |
| 97 |
connect_att->dwCreatingFlag = 0; |
| 98 |
return 0; |
| 99 |
} |
| 100 |
|
| 101 |
int pthread_attr_setstacksize(pthread_attr_t *connect_att,size_t stack) |
| 102 |
{ |
| 103 |
DBUG_ASSERT(stack < UINT_MAX); |
| 104 |
connect_att->dwStackSize=(DWORD)stack; |
| 105 |
return 0; |
| 106 |
} |
| 107 |
|
| 108 |
int pthread_attr_destroy(pthread_attr_t *connect_att) |
| 109 |
{ |
| 110 |
bzero((uchar*) connect_att,sizeof(*connect_att)); |
| 111 |
return 0; |
| 112 |
} |
| 113 |
|
| 114 |
#endif |