annotate src/thread/os2/SDL_syssem.c @ 1386:2b7e0180a72c

Pick the right default GL library on IRIX
author Sam Lantinga <slouken@libsdl.org>
date Mon, 20 Feb 2006 10:19:22 +0000
parents c71e05b4dc2e
children d910939febfa
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 */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 /* Semaphore functions using the OS/2 API */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
25 #define INCL_DOS
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 #define INCL_DOSERRORS
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27 #define INCL_DOSSEMAPHORES
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 #include <os2.h>
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 #include "SDL_thread.h"
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 #include "SDL_timer.h"
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32
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 struct SDL_semaphore {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 HMTX id;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 HEV changed;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 Uint32 value;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 };
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 /* Create a semaphore */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 DECLSPEC SDL_sem * SDLCALL SDL_CreateSemaphore(Uint32 initial_value)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 SDL_sem *sem;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 ULONG ulrc;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 /* Allocate sem memory */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
48 sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 if ( sem ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 /* Create the mutex semaphore */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 ulrc = DosCreateMutexSem(NULL,&(sem->id),0,TRUE);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 if ( ulrc ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 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
54 SDL_free(sem);
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 sem = NULL;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 } else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 DosCreateEventSem(NULL, &(sem->changed), 0, FALSE);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 sem->value = initial_value;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 } else {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 SDL_OutOfMemory();
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 return(sem);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 }
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 /* Free the semaphore */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
69 DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
70 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71 if ( sem ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72 if ( sem->id ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 DosCloseEventSem(sem->changed);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 DosCloseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 sem->id = 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
77 SDL_free(sem);
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 }
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 DECLSPEC int SDLCALL SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 ULONG ulrc;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 if ( ! sem ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 SDL_SetError("Passed a NULL sem");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 }
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 if ( timeout == SDL_MUTEX_MAXWAIT ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 while (1) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 ulrc = DosRequestMutexSem(sem->id, SEM_INDEFINITE_WAIT);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 if (ulrc) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 /* if error waiting mutex */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 SDL_SetError("DosRequestMutexSem() failed");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 } else if (sem->value) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 sem->value--;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101 } else {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102 ULONG ulPostCount;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 DosResetEventSem(sem->changed, &ulPostCount);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 /* continue waiting until somebody posts the semaphore */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 DosWaitEventSem(sem->changed, SEM_INDEFINITE_WAIT);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 }
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 } else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 if ( timeout == 0 )
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 ulrc = DosRequestMutexSem(sem->id, SEM_INDEFINITE_WAIT);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 if (ulrc==NO_ERROR)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 if (sem->value)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 sem->value--;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 } else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 return SDL_MUTEX_TIMEDOUT;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 } else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 SDL_SetError("DosRequestMutexSem() failed");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 } else {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 ulrc = DosRequestMutexSem(sem->id, SEM_INDEFINITE_WAIT);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 if (ulrc) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 /* if error waiting mutex */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 SDL_SetError("DosRequestMutexSem() failed");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 } else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 if (sem->value) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 sem->value--;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 } else {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 ULONG ulPostCount;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 DosResetEventSem(sem->changed, &ulPostCount);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 /* continue waiting until somebody posts the semaphore */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 ulrc = DosWaitEventSem(sem->changed, timeout);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 if (ulrc==NO_ERROR)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 return SDL_MUTEX_TIMEDOUT;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151 }
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 /* never reached */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 }
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 DECLSPEC int SDLCALL SDL_SemTryWait(SDL_sem *sem)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 return SDL_SemWaitTimeout(sem, 0);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 }
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 DECLSPEC int SDLCALL SDL_SemWait(SDL_sem *sem)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 }
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 /* Returns the current count of the semaphore */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 DECLSPEC Uint32 SDLCALL SDL_SemValue(SDL_sem *sem)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 if ( ! sem ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 SDL_SetError("Passed a NULL sem");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 return sem->value;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 }
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 DECLSPEC int SDLCALL SDL_SemPost(SDL_sem *sem)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 if ( ! sem ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 SDL_SetError("Passed a NULL sem");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 if ( DosRequestMutexSem(sem->id,SEM_INDEFINITE_WAIT) ) {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 SDL_SetError("DosRequestMutexSem() failed");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 sem->value++;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 DosPostEventSem(sem->changed);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 DosReleaseMutexSem(sem->id);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 }