|
1 /* Copyright (c) 2009 The Khronos Group Inc. |
|
2 * |
|
3 * Permission is hereby granted, free of charge, to any person obtaining a |
|
4 * copy of this software and/or associated documentation files (the |
|
5 * "Materials"), to deal in the Materials without restriction, including |
|
6 * without limitation the rights to use, copy, modify, merge, publish, |
|
7 * distribute, sublicense, and/or sell copies of the Materials, and to |
|
8 * permit persons to whom the Materials are furnished to do so, subject to |
|
9 * the following conditions: |
|
10 * |
|
11 * The above copyright notice and this permission notice shall be included |
|
12 * in all copies or substantial portions of the Materials. |
|
13 * |
|
14 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
|
18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
20 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
21 */ |
|
22 |
|
23 #ifndef OWF_MESSAGEQUEUE_H_ |
|
24 #define OWF_MESSAGEQUEUE_H_ |
|
25 |
|
26 #include "owftypes.h" |
|
27 #include "owfsemaphore.h" |
|
28 #include "owfmutex.h" |
|
29 |
|
30 |
|
31 #ifdef __cplusplus |
|
32 extern "C" { |
|
33 #endif |
|
34 |
|
35 |
|
36 typedef struct { |
|
37 OWFuint id; |
|
38 void* data; |
|
39 } OWF_MESSAGE; |
|
40 |
|
41 typedef struct _MSGQUE { |
|
42 OWFint read; |
|
43 OWFint write; |
|
44 } OWF_MESSAGE_QUEUE; |
|
45 |
|
46 /* |
|
47 * Destroy message queue |
|
48 * |
|
49 * \param queue Message queue to destroy |
|
50 */ |
|
51 OWF_API_CALL void |
|
52 OWF_MessageQueue_Destroy(OWF_MESSAGE_QUEUE* queue); |
|
53 |
|
54 /* |
|
55 * Initialize message queue |
|
56 * |
|
57 * \param queue Message queue to initialize |
|
58 * \return 0 if initialization succeeded, < 0 otherwise |
|
59 * |
|
60 */ |
|
61 OWF_API_CALL OWFint |
|
62 OWF_MessageQueue_Init(OWF_MESSAGE_QUEUE* queue); |
|
63 |
|
64 /* |
|
65 * Insert message into message queue (send it to |
|
66 * THE other side) |
|
67 * |
|
68 * \param queue Message queue |
|
69 * \param msg Message to send |
|
70 * \param data Message contents |
|
71 * |
|
72 */ |
|
73 OWF_API_CALL void |
|
74 OWF_Message_Send(OWF_MESSAGE_QUEUE* queue, |
|
75 OWFuint msg, |
|
76 void* data); |
|
77 /* |
|
78 * Wait for message |
|
79 * |
|
80 * \param queue Message queue |
|
81 * \param msg Where to store the received message |
|
82 * \param timeout Time to wait for the message (microseconds) |
|
83 * |
|
84 * \return < 0 if error occurred, 0 if no message was received within |
|
85 * given period of time, > 0 otherwise; received message is stored into |
|
86 * OWF_MESSAGE structure pointed by the msg param |
|
87 * |
|
88 */ |
|
89 OWF_API_CALL OWFint |
|
90 OWF_Message_Wait(OWF_MESSAGE_QUEUE* queue, |
|
91 OWF_MESSAGE* msg, |
|
92 OWFint timeout); |
|
93 |
|
94 |
|
95 #ifdef __cplusplus |
|
96 } |
|
97 #endif |
|
98 |
|
99 |
|
100 #endif |