Updated the Amiga OS port of SDL (thanks Gabriele)

This commit is contained in:
Sam Lantinga
2001-05-10 20:13:29 +00:00
parent 1f68c45edb
commit dc74cc4c2e
26 changed files with 1381 additions and 913 deletions

View File

@@ -25,7 +25,7 @@ static char rcsid =
"@(#) $Id$";
#endif
/* An native implementation of semaphores on AmigaOS */
/* An implementation of semaphores using mutexes and condition variables */
#include "SDL_error.h"
#include "SDL_thread.h"
@@ -35,9 +35,13 @@ static char rcsid =
struct SDL_semaphore
{
struct SignalSemaphore Sem;
Uint32 count;
Uint32 waiters_count;
SDL_mutex *count_lock;
SDL_cond *count_nonzero;
};
#undef D(x)
#undef D
#define D(x)
@@ -46,20 +50,18 @@ SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
SDL_sem *sem;
sem = (SDL_sem *)malloc(sizeof(*sem));
if ( ! sem ) {
SDL_OutOfMemory();
return(0);
}
memset(sem, 0, sizeof(*sem));
D(bug("Creating semaphore %lx...\n",sem));
memset(sem,0,sizeof(*sem));
InitSemaphore(&sem->Sem);
#if 1 // Allow multiple obtainings of the semaphore
while ( initial_value-- ) {
ReleaseSemaphore(&sem->Sem);
}
#endif
return(sem);
}
@@ -75,8 +77,6 @@ void SDL_DestroySemaphore(SDL_sem *sem)
int SDL_SemTryWait(SDL_sem *sem)
{
int retval;
if ( ! sem ) {
SDL_SetError("Passed a NULL semaphore");
return -1;
@@ -84,17 +84,17 @@ int SDL_SemTryWait(SDL_sem *sem)
D(bug("TryWait semaphore...%lx\n",sem));
retval = SDL_MUTEX_TIMEDOUT;
if ( AttemptSemaphore(&sem->Sem) ) {
retval = 0;
}
return retval;
ObtainSemaphore(&sem->Sem);
// ReleaseSemaphore(&sem->Sem);
return 1;
}
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
{
int retval;
if ( ! sem ) {
SDL_SetError("Passed a NULL semaphore");
return -1;
@@ -102,16 +102,22 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
D(bug("WaitTimeout (%ld) semaphore...%lx\n",timeout,sem));
#if 1 // We need to keep trying the semaphore until the timeout expires
retval = SDL_MUTEX_TIMEDOUT;
then = SDL_GetTicks();
do {
if ( AttemptSemaphore(&sem->Sem) ) {
retval = 0;
}
now = SDL_GetTicks();
} while ( (retval == SDL_MUTEX_TIMEDOUT) && ((now-then) < timeout) );
#else
/* A timeout of 0 is an easy case */
if ( timeout == 0 ) {
return SDL_SemTryWait(sem);
}
/*
SDL_LockMutex(sem->count_lock);
++sem->waiters_count;
retval = 0;
while ( (sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT) ) {
retval = SDL_CondWaitTimeout(sem->count_nonzero,
sem->count_lock, timeout);
}
--sem->waiters_count;
--sem->count;
SDL_UnlockMutex(sem->count_lock);
*/
if(!(retval=AttemptSemaphore(&sem->Sem)))
{
SDL_Delay(timeout);
@@ -123,22 +129,15 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
// ReleaseSemaphore(&sem->Sem);
retval=1;
}
#endif
return retval;
}
int SDL_SemWait(SDL_sem *sem)
{
if ( ! sem ) {
SDL_SetError("Passed a NULL semaphore");
return -1;
}
#if 1 // This should be an infinite wait - FIXME, what is the return value?
ObtainSemaphore(&sem->Sem);
return 0;
#else
return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
#endif
return 0;
// return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
}
Uint32 SDL_SemValue(SDL_sem *sem)
@@ -148,6 +147,7 @@ Uint32 SDL_SemValue(SDL_sem *sem)
value = 0;
if ( sem ) {
value = sem->Sem.ss_NestCount;
// SDL_UnlockMutex(sem->count_lock);
}
return value;
}
@@ -161,6 +161,14 @@ int SDL_SemPost(SDL_sem *sem)
D(bug("SemPost semaphore...%lx\n",sem));
ReleaseSemaphore(&sem->Sem);
#if 0
SDL_LockMutex(sem->count_lock);
if ( sem->waiters_count > 0 ) {
SDL_CondSignal(sem->count_nonzero);
}
++sem->count;
SDL_UnlockMutex(sem->count_lock);
#endif
return 0;
}

View File

@@ -25,7 +25,7 @@ static char rcsid =
"@(#) $Id$";
#endif
/* AmigaOS thread management routines for SDL */
/* BeOS thread management routines for SDL */
#include "SDL_error.h"
#include "SDL_mutex.h"
@@ -40,6 +40,8 @@ typedef struct {
struct Task *wait;
} thread_args;
#ifndef MORPHOS
#if defined(__SASC) && !defined(__PPC__)
__saveds __asm Uint32 RunThread(register __a0 char *args )
#elif defined(__PPC__)
@@ -60,6 +62,34 @@ Uint32 RunThread(char *args __asm("a0") )
return(0);
}
#else
#include <emul/emulinterface.h>
Uint32 RunTheThread(void)
{
thread_args *data=(thread_args *)atol(REG_A0);
struct Task *Father;
D(bug("Received data: %lx\n",data));
Father=data->wait;
SDL_RunThread(data);
Signal(Father,SIGBREAKF_CTRL_F);
return(0);
}
struct EmulLibEntry RunThread=
{
TRAP_LIB,
0,
RunTheThread
};
#endif
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
{
/* Create the thread and go! */
@@ -98,6 +128,7 @@ Uint32 SDL_ThreadID(void)
void SDL_SYS_WaitThread(SDL_Thread *thread)
{
SetSignal(0L,SIGBREAKF_CTRL_F|SIGBREAKF_CTRL_C);
Wait(SIGBREAKF_CTRL_F|SIGBREAKF_CTRL_C);
}

View File

@@ -265,6 +265,18 @@ void SDL_WaitThread(SDL_Thread *thread, int *status)
}
}
Uint32 SDL_GetThreadID(SDL_Thread *thread)
{
Uint32 id;
if ( thread ) {
id = thread->threadid;
} else {
id = SDL_ThreadID();
}
return(id);
}
void SDL_KillThread(SDL_Thread *thread)
{
if ( thread ) {