Skip to content

Commit

Permalink
MorphOS: adapt threads
Browse files Browse the repository at this point in the history
  • Loading branch information
BeWorld2018 committed Jan 15, 2024
1 parent 01dc2dd commit 17f6882
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 237 deletions.
65 changes: 23 additions & 42 deletions src/thread/morphos/SDL_sysmutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
#include "SDL_internal.h"

/* An implementation of mutexes using semaphores */
// An implementation of mutexes using semaphores

#include "SDL_systhread_c.h"
#include <proto/exec.h>
Expand All @@ -30,74 +30,55 @@ struct SDL_Mutex
struct SignalSemaphore sem;
};

/* Create a mutex */
SDL_Mutex *
SDL_CreateMutex(void)
SDL_Mutex *SDL_CreateMutex(void)
{
SDL_Mutex *mutex;
SDL_Mutex *mutex = (SDL_Mutex *)SDL_calloc(1, sizeof(*mutex));

/* Allocate mutex memory */
mutex = (SDL_Mutex *) SDL_malloc(sizeof(*mutex));
if (mutex) {
/* Create the mutex semaphore, with initial value 1 */
memset(&mutex->sem, 0, sizeof(mutex->sem));
SDL_memset(&mutex->sem, 0, sizeof(mutex->sem));
InitSemaphore(&mutex->sem);
} else {
SDL_OutOfMemory();
}
return mutex;
}

/* Free the mutex */
void
SDL_DestroyMutex(SDL_Mutex * mutex)
void SDL_DestroyMutex(SDL_Mutex *mutex)
{
if (mutex)
SDL_free(mutex);
}

/* Lock the mutex */
int
SDL_LockMutex(SDL_Mutex * mutex) SDL_NO_THREAD_SAFETY_ANALYSIS /* clang doesn't know about NULL mutexes */
void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
{
#if SDL_THREADS_DISABLED
return 0;
#else
if (mutex == NULL) {
return 0;
#ifndef SDL_THREADS_DISABLED
if (mutex != NULL) {
ObtainSemaphore(&mutex->sem);
}

ObtainSemaphore(&mutex->sem);
return 0;
#endif /* SDL_THREADS_DISABLED */
}

/* try Lock the mutex */
int SDL_TryLockMutex(SDL_Mutex *mutex)
{
#if SDL_THREADS_DISABLED
return 0;
#else
if (mutex == NULL) {
return 0;
}
int retval = 0;
#ifndef SDL_THREADS_DISABLED
if (mutex) {

return AttemptSemaphore(&mutex->sem) ? 0 : SDL_MUTEX_TIMEDOUT;
#endif /* SDL_THREADS_DISABLED */
retval = AttemptSemaphore(&mutex->sem) ? 0 : SDL_MUTEX_TIMEDOUT;
}
#endif // SDL_THREADS_DISABLED
return retval;
}

/* Unlock the mutex */
int
SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS
void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
{
#if SDL_THREADS_DISABLED
return 0;
#else
if (mutex == NULL) {
return 0;
}
#ifndef SDL_THREADS_DISABLED
if (mutex != NULL) {
ReleaseSemaphore(&mutex->sem);

ReleaseSemaphore(&mutex->sem);
return 0;
#endif /* SDL_THREADS_DISABLED */
}
#endif // SDL_THREADS_DISABLED
}

169 changes: 0 additions & 169 deletions src/thread/morphos/SDL_sysrwlock.c

This file was deleted.

26 changes: 0 additions & 26 deletions src/thread/morphos/SDL_sysrwlock_c.h

This file was deleted.

0 comments on commit 17f6882

Please sign in to comment.