Windows CE patches contributed by Rainer Loritz

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%4037
This commit is contained in:
Sam Lantinga 2001-05-23 23:35:10 +00:00
parent 09112109c3
commit a95fb10027
11 changed files with 413 additions and 63 deletions

View file

@ -33,56 +33,17 @@ static char rcsid =
#include "SDL_error.h"
#include "SDL_thread.h"
#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
#include "win_ce_semaphore.h"
#endif
/* 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);
}
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 @@ SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
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 @@ void SDL_DestroySemaphore(SDL_sem *sem)
{
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 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
} 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 @@ int SDL_SemPost(SDL_sem *sem)
* 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 */