21 #include "../../SDL_internal.h"
28 #include "../../core/os2/SDL_os2.h"
30 #define INCL_DOSSEMAPHORES
31 #define INCL_DOSERRORS
46 SDL_sem *pSDLSem =
SDL_malloc(
sizeof(SDL_sem));
48 if (pSDLSem ==
NULL) {
53 ulRC = DosCreateEventSem(
NULL, &pSDLSem->hEv, DCE_AUTORESET,
FALSE);
54 if (ulRC != NO_ERROR) {
55 debug_os2(
"DosCreateEventSem(), rc = %u", ulRC);
60 ulRC = DosCreateMutexSem(
NULL, &pSDLSem->hMtx, 0,
FALSE);
61 if (ulRC != NO_ERROR) {
62 debug_os2(
"DosCreateMutexSem(), rc = %u", ulRC);
63 DosCloseEventSem(pSDLSem->hEv);
68 pSDLSem->cPost = initial_value;
78 DosCloseMutexSem(
sem->hMtx);
79 DosCloseEventSem(
sem->hEv);
87 ULONG ulStartTime, ulCurTime;
94 if (
timeout != SEM_INDEFINITE_WAIT)
95 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &ulStartTime,
sizeof(ULONG));
98 ulRC = DosRequestMutexSem(
sem->hMtx, SEM_INDEFINITE_WAIT);
100 return SDL_SetError(
"DosRequestMutexSem() failed, rc = %u", ulRC);
106 DosReleaseMutexSem(
sem->hMtx);
111 if (
timeout == SEM_INDEFINITE_WAIT)
112 ulTimeout = SEM_INDEFINITE_WAIT;
114 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &ulCurTime,
sizeof(ULONG));
115 ulTimeout = ulCurTime - ulStartTime;
118 ulTimeout =
timeout - ulTimeout;
121 ulRC = DosWaitEventSem(
sem->hEv, ulTimeout);
122 if (ulRC == ERROR_TIMEOUT)
125 if (ulRC != NO_ERROR)
126 return SDL_SetError(
"DosWaitEventSem() failed, rc = %u", ulRC);
154 ulRC = DosRequestMutexSem(
sem->hMtx, SEM_INDEFINITE_WAIT);
155 if (ulRC != NO_ERROR)
156 return SDL_SetError(
"DosRequestMutexSem() failed, rc = %u", ulRC);
159 DosReleaseMutexSem(
sem->hMtx);
172 ulRC = DosRequestMutexSem(
sem->hMtx, SEM_INDEFINITE_WAIT);
173 if (ulRC != NO_ERROR)
174 return SDL_SetError(
"DosRequestMutexSem() failed, rc = %u", ulRC);
178 ulRC = DosPostEventSem(
sem->hEv);
179 if (ulRC != NO_ERROR && ulRC != ERROR_ALREADY_POSTED) {
180 debug_os2(
"DosPostEventSem() failed, rc = %u", ulRC);
183 DosReleaseMutexSem(
sem->hMtx);
#define SDL_OutOfMemory()
#define SDL_MUTEX_TIMEDOUT
#define SDL_MUTEX_MAXWAIT
GLbitfield GLuint64 timeout
int SDL_SemWait(SDL_sem *sem)
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
void SDL_DestroySemaphore(SDL_sem *sem)
int SDL_SemPost(SDL_sem *sem)
Uint32 SDL_SemValue(SDL_sem *sem)
int SDL_SemTryWait(SDL_sem *sem)
SDL_sem * SDL_CreateSemaphore(Uint32 initial_value)