|
1 |
|
2 /* Copyright (c) 2009 The Khronos Group Inc. |
|
3 * |
|
4 * Permission is hereby granted, free of charge, to any person obtaining a |
|
5 * copy of this software and/or associated documentation files (the |
|
6 * "Materials"), to deal in the Materials without restriction, including |
|
7 * without limitation the rights to use, copy, modify, merge, publish, |
|
8 * distribute, sublicense, and/or sell copies of the Materials, and to |
|
9 * permit persons to whom the Materials are furnished to do so, subject to |
|
10 * the following conditions: |
|
11 * |
|
12 * The above copyright notice and this permission notice shall be included |
|
13 * in all copies or substantial portions of the Materials. |
|
14 * |
|
15 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
|
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
21 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
22 */ |
|
23 |
|
24 #ifndef OWFCOND_H_ |
|
25 #define OWFCOND_H_ |
|
26 |
|
27 #include "owftypes.h" |
|
28 #include "owfmutex.h" |
|
29 |
|
30 |
|
31 #ifdef __cplusplus |
|
32 extern "C" { |
|
33 #endif |
|
34 |
|
35 |
|
36 typedef void* OWF_COND; |
|
37 |
|
38 /*! \brief Initialize a condition variable |
|
39 * |
|
40 * \param cond |
|
41 * \param mutex mutex to be used when wait is called |
|
42 * |
|
43 * \return true or false depending whether initialization |
|
44 * succeeded or not |
|
45 */ |
|
46 OWF_API_CALL OWFboolean |
|
47 OWF_Cond_Init(OWF_COND* cond, OWF_MUTEX mutex); |
|
48 |
|
49 /*! \brief Destroy a condition variable |
|
50 * |
|
51 * \cond cond variable |
|
52 */ |
|
53 OWF_API_CALL void |
|
54 OWF_Cond_Destroy(OWF_COND* cond); |
|
55 |
|
56 /*! \brief Block on a condition variable |
|
57 * |
|
58 * \param cond |
|
59 * \param timeout maximum time to wait in nanoseconds |
|
60 * |
|
61 * Cond must be initialized with OWF_Cond_Init. Caller MUST hold |
|
62 * the mutex specified upon initialization. Call will block on |
|
63 * the cond and release mutex until cond is signalled. After cond |
|
64 * is signalled the mutex is regained. |
|
65 * |
|
66 * The call will not block if timeout equals to zero. If timeout is |
|
67 * greater than zero, the call will not return until 'timeout' |
|
68 * nanoseconds has elapsed or cond is signalled. It timeout equal to |
|
69 * OWF_FOREVER, the call returns only after cond is signalled. |
|
70 */ |
|
71 OWF_API_CALL OWFboolean |
|
72 OWF_Cond_Wait(OWF_COND cond, OWFtime timeout); |
|
73 |
|
74 /*! \brief Signal a condition variable |
|
75 * |
|
76 * \param cond |
|
77 * |
|
78 * Only one of waiters for cond will be woke-up |
|
79 */ |
|
80 OWF_API_CALL OWFboolean |
|
81 OWF_Cond_Signal(OWF_COND cond); |
|
82 |
|
83 /*! \brief Signal a condition variable |
|
84 * |
|
85 * \param cond |
|
86 * |
|
87 * Wake-up all waiters of cond. |
|
88 */ |
|
89 OWF_API_CALL OWFboolean |
|
90 OWF_Cond_SignalAll(OWF_COND cond); |
|
91 |
|
92 |
|
93 #ifdef __cplusplus |
|
94 } |
|
95 #endif |
|
96 |
|
97 |
|
98 |
|
99 #endif /* OWFCOND_H_ */ |