Loading include/my_pthread.h +8 −6 Original line number Diff line number Diff line Loading @@ -94,17 +94,19 @@ typedef void * (__cdecl *pthread_handler)(void *); __int64 i64; }; struct timespec { union ft64 start; union ft64 tv; /* The max timeout value in millisecond for pthread_cond_timedwait */ long timeout_msec; long max_timeout_msec; }; #define set_timespec(ABSTIME,SEC) { \ GetSystemTimeAsFileTime(&((ABSTIME).start.ft)); \ (ABSTIME).timeout_msec= (long)((SEC)*1000); \ GetSystemTimeAsFileTime(&((ABSTIME).tv.ft)); \ (ABSTIME).tv.i64+= (__int64)(SEC)*10000000; \ (ABSTIME).max_timeout_msec= (long)((SEC)*1000); \ } #define set_timespec_nsec(ABSTIME,NSEC) { \ GetSystemTimeAsFileTime(&((ABSTIME).start.ft)); \ (ABSTIME).timeout_msec= (long)((NSEC)/1000000); \ GetSystemTimeAsFileTime(&((ABSTIME).tv.ft)); \ (ABSTIME).tv.i64+= (__int64)(NSEC)/100; \ (ABSTIME).max_timeout_msec= (long)((NSEC)/1000000); \ } void win_pthread_init(void); Loading mysys/my_wincond.c +10 −9 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) return 0 ; } int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, struct timespec *abstime) { Loading @@ -61,22 +62,22 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, GetSystemTimeAsFileTime(&now.ft); /* - subtract start time from current time(values are in 100ns units Calculate time left to abstime - subtract start time from current time(values are in 100ns units) - convert to millisec by dividing with 10000 - subtract time since start from max timeout */ timeout= abstime->timeout_msec - (long)((now.i64 - abstime->start.i64) / 10000); timeout= (long)((abstime->tv.i64 - now.i64) / 10000); /* Don't allow the timeout to be negative */ if (timeout < 0) timeout= 0L; /* Make sure the calucated time does not exceed original timeout Make sure the calucated timeout does not exceed original timeout value which could cause "wait for ever" if system time changes */ if (timeout > abstime->timeout_msec) timeout= abstime->timeout_msec; if (timeout > abstime->max_timeout_msec) timeout= abstime->max_timeout_msec; InterlockedIncrement(&cond->waiting); LeaveCriticalSection(mutex); Loading Loading
include/my_pthread.h +8 −6 Original line number Diff line number Diff line Loading @@ -94,17 +94,19 @@ typedef void * (__cdecl *pthread_handler)(void *); __int64 i64; }; struct timespec { union ft64 start; union ft64 tv; /* The max timeout value in millisecond for pthread_cond_timedwait */ long timeout_msec; long max_timeout_msec; }; #define set_timespec(ABSTIME,SEC) { \ GetSystemTimeAsFileTime(&((ABSTIME).start.ft)); \ (ABSTIME).timeout_msec= (long)((SEC)*1000); \ GetSystemTimeAsFileTime(&((ABSTIME).tv.ft)); \ (ABSTIME).tv.i64+= (__int64)(SEC)*10000000; \ (ABSTIME).max_timeout_msec= (long)((SEC)*1000); \ } #define set_timespec_nsec(ABSTIME,NSEC) { \ GetSystemTimeAsFileTime(&((ABSTIME).start.ft)); \ (ABSTIME).timeout_msec= (long)((NSEC)/1000000); \ GetSystemTimeAsFileTime(&((ABSTIME).tv.ft)); \ (ABSTIME).tv.i64+= (__int64)(NSEC)/100; \ (ABSTIME).max_timeout_msec= (long)((NSEC)/1000000); \ } void win_pthread_init(void); Loading
mysys/my_wincond.c +10 −9 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) return 0 ; } int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, struct timespec *abstime) { Loading @@ -61,22 +62,22 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, GetSystemTimeAsFileTime(&now.ft); /* - subtract start time from current time(values are in 100ns units Calculate time left to abstime - subtract start time from current time(values are in 100ns units) - convert to millisec by dividing with 10000 - subtract time since start from max timeout */ timeout= abstime->timeout_msec - (long)((now.i64 - abstime->start.i64) / 10000); timeout= (long)((abstime->tv.i64 - now.i64) / 10000); /* Don't allow the timeout to be negative */ if (timeout < 0) timeout= 0L; /* Make sure the calucated time does not exceed original timeout Make sure the calucated timeout does not exceed original timeout value which could cause "wait for ever" if system time changes */ if (timeout > abstime->timeout_msec) timeout= abstime->timeout_msec; if (timeout > abstime->max_timeout_msec) timeout= abstime->max_timeout_msec; InterlockedIncrement(&cond->waiting); LeaveCriticalSection(mutex); Loading