[RFC/PATCH] MSVC: Windows-native implementation of pthread_cond_broadcast
- From
- Zoltán Füzesi <zfuzesi@eaglet.hu>
- Date
- Jan 29, 2010, 19:26 UTC
- Message-ID
- <1264793213-8805-1-git-send-email-zfuzesi@eaglet.hu>
- In-Reply-To
- <4B62CEAB.5050608@viscovery.net>
Threaded grep feature relies on this function, but its implementation was missing from the Win32 Pthreads API.
Signed-off-by: Zoltán Füzesi <zfuzesi@eaglet.hu> --- Johannes, how about this? I haven't tested it.
compat/win32/pthread.c | 12 ++++++++++++ compat/win32/pthread.h | 2 ++ 2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/compat/win32/pthread.c b/compat/win32/pthread.c index 631c0a4..498b552 100644 --- a/compat/win32/pthread.c +++ b/compat/win32/pthread.c @@ -108,3 +108,15 @@ int pthread_cond_signal(pthread_cond_t *cond) else return 0; } + +int pthread_cond_broadcast(pthread_cond_t *cond) +{ + LONG prev_count; + while (cond->waiters) { + if (!ReleaseSemaphore(cond->sema, 1, &prev_count)) + return err_win_to_posix(GetLastError()); + if (prev_count == LONG_MAX - 1) + break; + } + return 0; +} diff --git a/compat/win32/pthread.h b/compat/win32/pthread.h index b8e1bcb..11426f5 100644 --- a/compat/win32/pthread.h +++ b/compat/win32/pthread.h @@ -44,6 +44,8 @@ extern int pthread_cond_wait(pthread_cond_t *cond, CRITICAL_SECTION *mutex); extern int pthread_cond_signal(pthread_cond_t *cond); +extern int pthread_cond_broadcast(pthread_cond_t *cond); + /* * Simple thread creation implementation using pthread API */
-- 1.7.0.rc0.48.gdace5.dirty