VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/os2/sems-os2.cpp@ 8245

Last change on this file since 8245 was 8245, checked in by vboxsync, 16 years ago

rebranding: IPRT files again.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.1 KB
Line 
1/* $Id: sems-os2.cpp 8245 2008-04-21 17:24:28Z vboxsync $ */
2/** @file
3 * IPRT - Semaphores, OS/2.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#define INCL_DOSSEMAPHORES
36#define INCL_ERRORS
37#include <os2.h>
38#undef RT_MAX
39
40#include <iprt/semaphore.h>
41#include <iprt/assert.h>
42#include <iprt/err.h>
43
44
45/** Converts semaphore to OS/2 handle. */
46#define SEM2HND(Sem) ((LHANDLE)(uintptr_t)Sem)
47
48
49RTDECL(int) RTSemEventCreate(PRTSEMEVENT pEventSem)
50{
51 /*
52 * Create the semaphore.
53 * (Auto reset, not signaled, private event object.)
54 */
55 HEV hev;
56 int rc = DosCreateEventSem(NULL, &hev, DCE_AUTORESET | DCE_POSTONE, 0);
57 if (!rc)
58 {
59 *pEventSem = (RTSEMEVENT)(void *)hev;
60 return VINF_SUCCESS;
61 }
62 return RTErrConvertFromOS2(rc);
63}
64
65
66RTDECL(int) RTSemEventDestroy(RTSEMEVENT EventSem)
67{
68 /*
69 * Close semaphore handle.
70 */
71 int rc = DosCloseEventSem(SEM2HND(EventSem));
72 if (!rc)
73 return VINF_SUCCESS;
74 AssertMsgFailed(("Destroy EventSem %p failed, rc=%d\n", EventSem, rc));
75 return RTErrConvertFromOS2(rc);
76}
77
78
79RTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies)
80{
81 /*
82 * Wait for condition.
83 */
84 int rc = DosWaitEventSem(SEM2HND(EventSem), cMillies == RT_INDEFINITE_WAIT ? SEM_INDEFINITE_WAIT : cMillies);
85 switch (rc)
86 {
87 case NO_ERROR: return VINF_SUCCESS;
88 case ERROR_SEM_TIMEOUT:
89 case ERROR_TIMEOUT: return VERR_TIMEOUT;
90 case ERROR_INTERRUPT: return VERR_INTERRUPTED;
91 default:
92 {
93 AssertMsgFailed(("Wait on EventSem %p failed, rc=%d\n", EventSem, rc));
94 return RTErrConvertFromOS2(rc);
95 }
96 }
97}
98
99
100RTDECL(int) RTSemEventSignal(RTSEMEVENT EventSem)
101{
102 /*
103 * Signal the object.
104 */
105 int rc = DosPostEventSem(SEM2HND(EventSem));
106 switch (rc)
107 {
108 case NO_ERROR:
109 case ERROR_ALREADY_POSTED:
110 case ERROR_TOO_MANY_POSTS:
111 return VINF_SUCCESS;
112 default:
113 return RTErrConvertFromOS2(rc);
114 }
115}
116
117
118
119
120RTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI pEventMultiSem)
121{
122 /*
123 * Create the semaphore.
124 * (Manual reset, not signaled, private event object.)
125 */
126 HEV hev;
127 int rc = DosCreateEventSem(NULL, &hev, 0, FALSE);
128 if (!rc)
129 {
130 *pEventMultiSem = (RTSEMEVENTMULTI)(void *)hev;
131 return VINF_SUCCESS;
132 }
133 return RTErrConvertFromOS2(rc);
134}
135
136
137RTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI EventMultiSem)
138{
139 /*
140 * Close semaphore handle.
141 */
142 int rc = DosCloseEventSem(SEM2HND(EventMultiSem));
143 if (!rc)
144 return VINF_SUCCESS;
145 AssertMsgFailed(("Destroy EventMultiSem %p failed, rc=%d\n", EventMultiSem, rc));
146 return RTErrConvertFromOS2(rc);
147}
148
149
150RTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI EventMultiSem)
151{
152 /*
153 * Signal the object.
154 */
155 int rc = DosPostEventSem(SEM2HND(EventMultiSem));
156 switch (rc)
157 {
158 case NO_ERROR:
159 case ERROR_ALREADY_POSTED:
160 case ERROR_TOO_MANY_POSTS:
161 return VINF_SUCCESS;
162 default:
163 return RTErrConvertFromOS2(rc);
164 }
165}
166
167
168RTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI EventMultiSem)
169{
170 /*
171 * Reset the object.
172 */
173 ULONG ulIgnore;
174 int rc = DosResetEventSem(SEM2HND(EventMultiSem), &ulIgnore);
175 switch (rc)
176 {
177 case NO_ERROR:
178 case ERROR_ALREADY_RESET:
179 return VINF_SUCCESS;
180 default:
181 return RTErrConvertFromOS2(rc);
182 }
183}
184
185
186RTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies)
187{
188 /*
189 * Wait for condition.
190 */
191 int rc = DosWaitEventSem(SEM2HND(EventMultiSem), cMillies == RT_INDEFINITE_WAIT ? SEM_INDEFINITE_WAIT : cMillies);
192 switch (rc)
193 {
194 case NO_ERROR: return VINF_SUCCESS;
195 case ERROR_SEM_TIMEOUT:
196 case ERROR_TIMEOUT: return VERR_TIMEOUT;
197 case ERROR_INTERRUPT: return VERR_INTERRUPTED;
198 default:
199 {
200 AssertMsgFailed(("Wait on EventMultiSem %p failed, rc=%d\n", EventMultiSem, rc));
201 return RTErrConvertFromOS2(rc);
202 }
203 }
204}
205
206
207
208
209RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX pMutexSem)
210{
211 /*
212 * Create the semaphore.
213 */
214 HMTX hmtx;
215 int rc = DosCreateMutexSem(NULL, &hmtx, 0, FALSE);
216 if (!rc)
217 {
218 *pMutexSem = (RTSEMMUTEX)(void *)hmtx;
219 return VINF_SUCCESS;
220 }
221
222 return RTErrConvertFromOS2(rc);
223}
224
225
226RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem)
227{
228 /*
229 * Close semaphore handle.
230 */
231 int rc = DosCloseMutexSem(SEM2HND(MutexSem));
232 if (!rc)
233 return VINF_SUCCESS;
234 AssertMsgFailed(("Destroy MutexSem %p failed, rc=%d\n", MutexSem, rc));
235 return RTErrConvertFromOS2(rc);
236}
237
238
239RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies)
240{
241 /*
242 * Lock mutex semaphore.
243 */
244 int rc = DosRequestMutexSem(SEM2HND(MutexSem), cMillies == RT_INDEFINITE_WAIT ? SEM_INDEFINITE_WAIT : cMillies);
245 switch (rc)
246 {
247 case NO_ERROR: return VINF_SUCCESS;
248 case ERROR_SEM_TIMEOUT:
249 case ERROR_TIMEOUT: return VERR_TIMEOUT;
250 case ERROR_INTERRUPT: return VERR_INTERRUPTED;
251 case ERROR_SEM_OWNER_DIED: return VERR_SEM_OWNER_DIED;
252 default:
253 {
254 AssertMsgFailed(("Wait on MutexSem %p failed, rc=%d\n", MutexSem, rc));
255 return RTErrConvertFromOS2(rc);
256 }
257 }
258}
259
260RTDECL(int) RTSemMutexRelease(RTSEMMUTEX MutexSem)
261{
262 /*
263 * Unlock mutex semaphore.
264 */
265 int rc = DosReleaseMutexSem(SEM2HND(MutexSem));
266 if (!rc)
267 return VINF_SUCCESS;
268 AssertMsgFailed(("Release MutexSem %p failed, rc=%d\n", MutexSem, rc));
269 return RTErrConvertFromOS2(rc);
270}
271
272
273
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette