diff src/thread/win32/SDL_syssem.c @ 36:13ee9f4834ea

Windows CE patches contributed by Rainer Loritz
author Sam Lantinga <slouken@lokigames.com>
date Wed, 23 May 2001 23:35:10 +0000
parents 74212992fb08
children e8157fcb3114
line wrap: on
line diff
--- a/src/thread/win32/SDL_syssem.c	Wed May 23 00:36:17 2001 +0000
+++ b/src/thread/win32/SDL_syssem.c	Wed May 23 23:35:10 2001 +0000
@@ -33,56 +33,17 @@
 
 #include "SDL_error.h"
 #include "SDL_thread.h"
-
 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
-
-/* No semaphores on Windows CE earlier than 3.0, hmm... */
-
-/* Create a semaphore */
-SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
-{
-	SDL_SetError("Semaphores not supported on WinCE");
-	return(NULL);
-}
-
-/* Free the semaphore */
-void SDL_DestroySemaphore(SDL_sem *sem)
-{
-	return;
-}
-
-int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
-{
-	SDL_SetError("Semaphores not supported on WinCE");
-	return(-1);
-}
+#include "win_ce_semaphore.h"
+#endif
 
-int SDL_SemTryWait(SDL_sem *sem)
-{
-	return SDL_SemWaitTimeout(sem, 0);
-}
-
-int SDL_SemWait(SDL_sem *sem)
-{
-	return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
-}
-
-/* Returns the current count of the semaphore */
-Uint32 SDL_SemValue(SDL_sem *sem)
-{
-	return(0);
-}
-
-int SDL_SemPost(SDL_sem *sem)
-{
-	SDL_SetError("Semaphores not supported on WinCE");
-	return(-1);
-}
-
-#else
 
 struct SDL_semaphore {
+#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
+	SYNCHHANDLE id;
+#else
 	HANDLE id;
+#endif
 	Uint32 volatile count;
 };
 
@@ -96,7 +57,11 @@
 	sem = (SDL_sem *)malloc(sizeof(*sem));
 	if ( sem ) {
 		/* Create the semaphore, with max value 32K */
+#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
+		sem->id = CreateSemaphoreCE(NULL, initial_value, 32*1024, NULL);
+#else
 		sem->id = CreateSemaphore(NULL, initial_value, 32*1024, NULL);
+#endif
 		sem->count = initial_value;
 		if ( ! sem->id ) {
 			SDL_SetError("Couldn't create semaphore");
@@ -114,7 +79,11 @@
 {
 	if ( sem ) {
 		if ( sem->id ) {
+#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
+			CloseSynchHandle(sem->id);
+#else
 			CloseHandle(sem->id);
+#endif
 			sem->id = 0;
 		}
 		free(sem);
@@ -136,7 +105,11 @@
 	} else {
 		dwMilliseconds = (DWORD)timeout;
 	}
+#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
+	switch (WaitForSemaphoreCE(sem->id, dwMilliseconds)) {
+#else
 	switch (WaitForSingleObject(sem->id, dwMilliseconds)) {
+#endif
 	    case WAIT_OBJECT_0:
 		--sem->count;
 		retval = 0;
@@ -184,12 +157,14 @@
 	 * is waiting for this semaphore.
 	 */
 	++sem->count;
+#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
+	if ( ReleaseSemaphoreCE(sem->id, 1, NULL) == FALSE ) {
+#else
 	if ( ReleaseSemaphore(sem->id, 1, NULL) == FALSE ) {
+#endif
 		--sem->count;	/* restore */
 		SDL_SetError("ReleaseSemaphore() failed");
 		return -1;
 	}
 	return 0;
 }
-
-#endif /* _WIN32_WCE */
\ No newline at end of file