Skip to content

Commit

Permalink
Do fixes for Gekko mutexes, implement 3DS mutexes
Browse files Browse the repository at this point in the history
These lines from RetroArch probably should be removed after this PR is in RetroArch's rcheevos copy.
https://github.com/libretro/RetroArch/blob/228426880babb529fae8f01598a6d34698ad3b18/griffin/griffin.c#L193-L195
  • Loading branch information
CasualPokePlayer committed Oct 16, 2024
1 parent 32917bd commit 4375d04
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
33 changes: 29 additions & 4 deletions src/rc_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,47 @@ void rc_mutex_unlock(rc_mutex_t* mutex)

void rc_mutex_init(rc_mutex_t* mutex)
{
LWP_MutexInit(mutex, NULL);
/* LWP_MutexInit has the handle passed by reference */
/* Other LWP_Mutex* calls have the handle passed by value */
LWP_MutexInit(&mutex->handle, 1);
}

void rc_mutex_destroy(rc_mutex_t* mutex)
{
LWP_MutexDestroy(mutex);
LWP_MutexDestroy(mutex->handle);
}

void rc_mutex_lock(rc_mutex_t* mutex)
{
LWP_MutexLock(mutex);
LWP_MutexLock(mutex->handle);
}

void rc_mutex_unlock(rc_mutex_t* mutex)
{
LWP_MutexUnlock(mutex);
LWP_MutexUnlock(mutex->handle);
}

#elif defined(_3DS)

void rc_mutex_init(rc_mutex_t* mutex)
{
RecursiveLock_Init(mutex);
}

void rc_mutex_destroy(rc_mutex_t* mutex)
{
/* Nothing to do here */
(void)mutex;
}

void rc_mutex_lock(rc_mutex_t* mutex)
{
RecursiveLock_Lock(mutex);
}

void rc_mutex_unlock(rc_mutex_t* mutex)
{
RecursiveLock_Unlock(mutex);
}

#else
Expand Down
10 changes: 9 additions & 1 deletion src/rc_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ RC_BEGIN_C_DECLS
#define rc_mutex_lock(mutex)
#define rc_mutex_unlock(mutex)
#else
#if defined(_WIN32)
#if defined(_WIN32)
typedef struct rc_mutex_t {
#if defined(WINVER) && WINVER >= 0x0600
/* Windows Vista and later can use a slim reader/writer (SRW) lock */
Expand All @@ -97,6 +97,14 @@ RC_BEGIN_C_DECLS
CRITICAL_SECTION critical_section;
#endif
} rc_mutex_t;
#elif defined(GEKKO)
#include <ogcsys.h>
typedef struct rc_mutex_t {
mutex_t handle;
} rc_mutex_t;
#elif defined(_3DS)
#include <3ds/synchronization.h>
typedef RecursiveLock rc_mutex_t;
#else
#include <pthread.h>
typedef pthread_mutex_t rc_mutex_t;
Expand Down

0 comments on commit 4375d04

Please sign in to comment.