annotate src/thread/os2/SDL_syssem.c @ 1433:bb6839704ed6

SDL_windows.h is no longer necessary
author Sam Lantinga <slouken@libsdl.org>
date Sat, 25 Feb 2006 22:18:25 +0000
parents d910939febfa
children 782fd950bd46 c121d94672cb a1b03ba2fcd0
rev   line source
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
6 modify it under the terms of the GNU Lesser General Public
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
13 Lesser General Public License for more details.
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 Sam Lantinga
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 slouken@libsdl.org
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
22 #include "SDL_config.h"
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 /* Semaphore functions using the OS/2 API */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 #define INCL_DOS
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 #define INCL_DOSERRORS
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 #define INCL_DOSSEMAPHORES
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29 #include <os2.h>
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 #include "SDL_thread.h"
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 #include "SDL_timer.h"
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 struct SDL_semaphore {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 HMTX id;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 HEV changed;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 Uint32 value;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 };
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 /* Create a semaphore */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 DECLSPEC SDL_sem * SDLCALL SDL_CreateSemaphore(Uint32 initial_value)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 SDL_sem *sem;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 ULONG ulrc;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 /* Allocate sem memory */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
49 sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 if ( sem ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 /* Create the mutex semaphore */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 ulrc = DosCreateMutexSem(NULL,&(sem->id),0,TRUE);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 if ( ulrc ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 SDL_SetError("Couldn't create semaphore");
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
55 SDL_free(sem);
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 sem = NULL;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 } else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 DosCreateEventSem(NULL, &(sem->changed), 0, FALSE);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 sem->value = initial_value;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 } else {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 SDL_OutOfMemory();
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 return(sem);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
68
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 /* Free the semaphore */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 if ( sem ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 if ( sem->id ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 DosCloseEventSem(sem->changed);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 DosCloseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 sem->id = 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
78 SDL_free(sem);
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84 ULONG ulrc;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 if ( ! sem ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 SDL_SetError("Passed a NULL sem");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 if ( timeout == SDL_MUTEX_MAXWAIT ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 while (1) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 ulrc = DosRequestMutexSem(sem->id, SEM_INDEFINITE_WAIT);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 if (ulrc) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 /* if error waiting mutex */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 SDL_SetError("DosRequestMutexSem() failed");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 } else if (sem->value) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 sem->value--;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 } else {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 ULONG ulPostCount;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 DosResetEventSem(sem->changed, &ulPostCount);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 /* continue waiting until somebody posts the semaphore */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 DosWaitEventSem(sem->changed, SEM_INDEFINITE_WAIT);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 } else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 if ( timeout == 0 )
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 ulrc = DosRequestMutexSem(sem->id, SEM_INDEFINITE_WAIT);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 if (ulrc==NO_ERROR)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 if (sem->value)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 sem->value--;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 } else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 return SDL_MUTEX_TIMEDOUT;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 } else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 SDL_SetError("DosRequestMutexSem() failed");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 } else {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 ulrc = DosRequestMutexSem(sem->id, SEM_INDEFINITE_WAIT);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 if (ulrc) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 /* if error waiting mutex */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 SDL_SetError("DosRequestMutexSem() failed");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 } else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 if (sem->value) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 sem->value--;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 } else {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 ULONG ulPostCount;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 DosResetEventSem(sem->changed, &ulPostCount);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 /* continue waiting until somebody posts the semaphore */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 ulrc = DosWaitEventSem(sem->changed, timeout);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 if (ulrc==NO_ERROR)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 return SDL_MUTEX_TIMEDOUT;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 /* never reached */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 return SDL_SemWaitTimeout(sem, 0);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 /* Returns the current count of the semaphore */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem *sem)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 if ( ! sem ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 SDL_SetError("Passed a NULL sem");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 return sem->value;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 if ( ! sem ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 SDL_SetError("Passed a NULL sem");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 if ( DosRequestMutexSem(sem->id,SEM_INDEFINITE_WAIT) ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 SDL_SetError("DosRequestMutexSem() failed");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 sem->value++;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 DosPostEventSem(sem->changed);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 }