VirtualBox

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

Last change on this file since 628 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1/* $Id: sems-os2.cpp 1 1970-01-01 00:00:00Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime - Semaphores, OS/2.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define INCL_DOSSEMAPHORES
27#define INCL_ERRORS
28#include <os2.h>
29#undef RT_MAX
30
31#include <iprt/semaphore.h>
32#include <iprt/assert.h>
33#include <iprt/err.h>
34
35
36/** Converts semaphore to OS/2 handle. */
37#define SEM2HND(Sem) ((LHANDLE)(uintptr_t)Sem)
38
39
40RTDECL(int) RTSemEventCreate(PRTSEMEVENT pEventSem)
41{
42 /*
43 * Create the semaphore.
44 * (Auto reset, not signaled, private event object.)
45 */
46 HEV hev;
47 int rc = DosCreateEventSem(NULL, &hev, DCE_AUTORESET | DCE_POSTONE, 0);
48 if (!rc)
49 {
50 *pEventSem = (RTSEMEVENT)(void *)hev;
51 return VINF_SUCCESS;
52 }
53 return RTErrConvertFromOS2(rc);
54}
55
56
57RTDECL(int) RTSemEventDestroy(RTSEMEVENT EventSem)
58{
59 /*
60 * Close semaphore handle.
61 */
62 int rc = DosCloseEventSem(SEM2HND(EventSem));
63 if (!rc)
64 return VINF_SUCCESS;
65 AssertMsgFailed(("Destroy EventSem %p failed, rc=%d\n", EventSem, rc));
66 return RTErrConvertFromOS2(rc);
67}
68
69
70RTDECL(int) RTSemEventWaitNoResume(RTSEMEVENT EventSem, unsigned cMillies)
71{
72 /*
73 * Wait for condition.
74 */
75 int rc = DosWaitEventSem(SEM2HND(EventSem), cMillies == RT_INDEFINITE_WAIT ? SEM_INDEFINITE_WAIT : cMillies);
76 switch (rc)
77 {
78 case NO_ERROR: return VINF_SUCCESS;
79 case ERROR_SEM_TIMEOUT:
80 case ERROR_TIMEOUT: return VERR_TIMEOUT;
81 case ERROR_INTERRUPT: return VERR_INTERRUPTED;
82 default:
83 {
84 AssertMsgFailed(("Wait on EventSem %p failed, rc=%d\n", EventSem, rc));
85 return RTErrConvertFromOS2(rc);
86 }
87 }
88}
89
90
91RTDECL(int) RTSemEventSignal(RTSEMEVENT EventSem)
92{
93 /*
94 * Signal the object.
95 */
96 int rc = DosPostEventSem(SEM2HND(EventSem));
97 switch (rc)
98 {
99 case NO_ERROR:
100 case ERROR_ALREADY_POSTED:
101 case ERROR_TOO_MANY_POSTS:
102 return VINF_SUCCESS;
103 default:
104 return RTErrConvertFromOS2(rc);
105 }
106}
107
108
109
110
111RTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI pEventMultiSem)
112{
113 /*
114 * Create the semaphore.
115 * (Manual reset, not signaled, private event object.)
116 */
117 HEV hev;
118 int rc = DosCreateEventSem(NULL, &hev, 0, FALSE);
119 if (!rc)
120 {
121 *pEventMultiSem = (RTSEMEVENTMULTI)(void *)hev;
122 return VINF_SUCCESS;
123 }
124 return RTErrConvertFromOS2(rc);
125}
126
127
128RTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI EventMultiSem)
129{
130 /*
131 * Close semaphore handle.
132 */
133 int rc = DosCloseEventSem(SEM2HND(EventMultiSem));
134 if (!rc)
135 return VINF_SUCCESS;
136 AssertMsgFailed(("Destroy EventMultiSem %p failed, rc=%d\n", EventMultiSem, rc));
137 return RTErrConvertFromOS2(rc);
138}
139
140
141RTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI EventMultiSem)
142{
143 /*
144 * Signal the object.
145 */
146 int rc = DosPostEventSem(SEM2HND(EventMultiSem));
147 switch (rc)
148 {
149 case NO_ERROR:
150 case ERROR_ALREADY_POSTED:
151 case ERROR_TOO_MANY_POSTS:
152 return VINF_SUCCESS;
153 default:
154 return RTErrConvertFromOS2(rc);
155 }
156}
157
158
159RTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI EventMultiSem)
160{
161 /*
162 * Reset the object.
163 */
164 ULONG ulIgnore;
165 int rc = DosResetEventSem(SEM2HND(EventMultiSem), &ulIgnore);
166 switch (rc)
167 {
168 case NO_ERROR:
169 case ERROR_ALREADY_RESET:
170 return VINF_SUCCESS;
171 default:
172 return RTErrConvertFromOS2(rc);
173 }
174}
175
176
177RTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies)
178{
179 /*
180 * Wait for condition.
181 */
182 int rc = DosWaitEventSem(SEM2HND(EventMultiSem), cMillies == RT_INDEFINITE_WAIT ? SEM_INDEFINITE_WAIT : cMillies);
183 switch (rc)
184 {
185 case NO_ERROR: return VINF_SUCCESS;
186 case ERROR_SEM_TIMEOUT:
187 case ERROR_TIMEOUT: return VERR_TIMEOUT;
188 case ERROR_INTERRUPT: return VERR_INTERRUPTED;
189 default:
190 {
191 AssertMsgFailed(("Wait on EventMultiSem %p failed, rc=%d\n", EventMultiSem, rc));
192 return RTErrConvertFromOS2(rc);
193 }
194 }
195}
196
197
198
199
200RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX pMutexSem)
201{
202 /*
203 * Create the semaphore.
204 */
205 HMTX hmtx;
206 int rc = DosCreateMutexSem(NULL, &hmtx, 0, FALSE);
207 if (!rc)
208 {
209 *pMutexSem = (RTSEMMUTEX)(void *)hmtx;
210 return VINF_SUCCESS;
211 }
212
213 return RTErrConvertFromOS2(rc);
214}
215
216
217RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX MutexSem)
218{
219 /*
220 * Close semaphore handle.
221 */
222 int rc = DosCloseMutexSem(SEM2HND(MutexSem));
223 if (!rc)
224 return VINF_SUCCESS;
225 AssertMsgFailed(("Destroy MutexSem %p failed, rc=%d\n", MutexSem, rc));
226 return RTErrConvertFromOS2(rc);
227}
228
229
230RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX MutexSem, unsigned cMillies)
231{
232 /*
233 * Lock mutex semaphore.
234 */
235 int rc = DosRequestMutexSem(SEM2HND(MutexSem), cMillies == RT_INDEFINITE_WAIT ? SEM_INDEFINITE_WAIT : cMillies);
236 switch (rc)
237 {
238 case NO_ERROR: return VINF_SUCCESS;
239 case ERROR_SEM_TIMEOUT:
240 case ERROR_TIMEOUT: return VERR_TIMEOUT;
241 case ERROR_INTERRUPT: return VERR_INTERRUPTED;
242 case ERROR_SEM_OWNER_DIED: return VERR_SEM_OWNER_DIED;
243 default:
244 {
245 AssertMsgFailed(("Wait on MutexSem %p failed, rc=%d\n", MutexSem, rc));
246 return RTErrConvertFromOS2(rc);
247 }
248 }
249}
250
251RTDECL(int) RTSemMutexRelease(RTSEMMUTEX MutexSem)
252{
253 /*
254 * Unlock mutex semaphore.
255 */
256 int rc = DosReleaseMutexSem(SEM2HND(MutexSem));
257 if (!rc)
258 return VINF_SUCCESS;
259 AssertMsgFailed(("Release MutexSem %p failed, rc=%d\n", MutexSem, rc));
260 return RTErrConvertFromOS2(rc);
261}
262
263
264
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