| 1 |
#ifndef WIN32COND_H |
| 2 |
#define WIN32COND_H |
| 3 |
|
| 4 |
/** |
| 5 |
* pthread_cond API for Win32 |
| 6 |
* |
| 7 |
* ACE(TM), TAO(TM), CIAO(TM), DAnCE>(TM), and CoSMIC(TM) (henceforth |
| 8 |
* referred to as "DOC software") are copyrighted by Douglas C. Schmidt |
| 9 |
* and his research group at Washington University, University of California, |
| 10 |
* Irvine, and Vanderbilt University, Copyright (c) 1993-2009, all rights |
| 11 |
* reserved. |
| 12 |
* |
| 13 |
* Since DOC software is open-source, freely available software, you are free |
| 14 |
* to use, modify, copy, and distribute--perpetually and irrevocably--the DOC |
| 15 |
* software source code and object code produced from the source, as well as |
| 16 |
* copy and distribute modified versions of this software. You must, however, |
| 17 |
* include this copyright statement along with any code built using DOC |
| 18 |
* software that you release. |
| 19 |
* |
| 20 |
* No copyright statement needs to be provided if you just ship binary |
| 21 |
* executables of your software products. |
| 22 |
* |
| 23 |
* See "Strategies for Implementing POSIX Condition Variables on Win32" at |
| 24 |
* http://www.cs.wustl.edu/~schmidt/win32-cv-1.html |
| 25 |
*/ |
| 26 |
|
| 27 |
#include <windows.h> |
| 28 |
|
| 29 |
typedef struct |
| 30 |
{ |
| 31 |
long waiters_count_; |
| 32 |
// Number of waiting threads. |
| 33 |
|
| 34 |
CRITICAL_SECTION waiters_count_lock_; |
| 35 |
// Serialize access to <waiters_count_>. |
| 36 |
|
| 37 |
HANDLE sema_; |
| 38 |
// Semaphore used to queue up threads waiting for the condition to |
| 39 |
// become signaled. |
| 40 |
|
| 41 |
HANDLE waiters_done_; |
| 42 |
// An auto-reset event used by the broadcast/signal thread to wait |
| 43 |
// for all the waiting thread(s) to wake up and be released from the |
| 44 |
// semaphore. |
| 45 |
|
| 46 |
size_t was_broadcast_; |
| 47 |
// Keeps track of whether we were broadcasting or signaling. This |
| 48 |
// allows us to optimize the code if we're just signaling. |
| 49 |
} win32_cond_t; |
| 50 |
|
| 51 |
#ifdef __cplusplus |
| 52 |
extern "C" { |
| 53 |
#endif |
| 54 |
|
| 55 |
int win32_cond_init(win32_cond_t *cv); |
| 56 |
int win32_cond_destroy(win32_cond_t *cv); |
| 57 |
int win32_cond_wait(win32_cond_t *cv, HANDLE *external_mutex); |
| 58 |
int win32_cond_signal(win32_cond_t *cv); |
| 59 |
int win32_cond_broadcast(win32_cond_t *cv); |
| 60 |
|
| 61 |
#ifdef __cplusplus |
| 62 |
} |
| 63 |
#endif |
| 64 |
|
| 65 |
#endif |