Commit edac43bc authored by Richard Gobeille's avatar Richard Gobeille

engine: FORCE_INLINE mutex_lock() and mutex_unlock(), make mutex_try() actually work

parent 4716881b
......@@ -25,10 +25,39 @@ typedef SDL_mutex * mutex_t;
extern int32_t mutex_init(mutex_t *mutex);
extern void mutex_destroy(mutex_t *mutex);
extern void mutex_lock(mutex_t *mutex);
extern void mutex_unlock(mutex_t *mutex);
extern void mutex_try(mutex_t *mutex);
static FORCE_INLINE void mutex_lock(mutex_t *mutex)
{
#if SDL_MAJOR_VERSION >= 2
SDL_AtomicLock(mutex);
#elif defined _WIN32
EnterCriticalSection(mutex);
#elif SDL_MAJOR_VERSION == 1
SDL_LockMutex(*mutex);
#endif
}
static FORCE_INLINE void mutex_unlock(mutex_t *mutex)
{
#if SDL_MAJOR_VERSION >= 2
SDL_AtomicUnlock(mutex);
#elif defined _WIN32
LeaveCriticalSection(mutex);
#elif SDL_MAJOR_VERSION == 1
SDL_UnlockMutex(*mutex);
#endif
}
static FORCE_INLINE bool mutex_try(mutex_t *mutex)
{
#if SDL_MAJOR_VERSION >= 2
return SDL_AtomicTryLock(mutex);
#elif defined _WIN32
return TryEnterCriticalSection(mutex);
#elif SDL_MAJOR_VERSION == 1
return SDL_TryLockMutex(*mutex);
#endif
}
#ifdef __cplusplus
}
......
......@@ -39,36 +39,3 @@ void mutex_destroy(mutex_t *mutex)
}
#endif
}
void mutex_lock(mutex_t *mutex)
{
#if SDL_MAJOR_VERSION >= 2
SDL_AtomicLock(mutex);
#elif defined _WIN32
EnterCriticalSection(mutex);
#elif SDL_MAJOR_VERSION == 1
SDL_LockMutex(*mutex);
#endif
}
void mutex_unlock(mutex_t *mutex)
{
#if SDL_MAJOR_VERSION >= 2
SDL_AtomicUnlock(mutex);
#elif defined _WIN32
LeaveCriticalSection(mutex);
#elif SDL_MAJOR_VERSION == 1
SDL_UnlockMutex(*mutex);
#endif
}
void mutex_try(mutex_t *mutex)
{
#if SDL_MAJOR_VERSION >= 2
SDL_AtomicTryLock(mutex);
#elif defined _WIN32
TryEnterCriticalSection(mutex);
#elif SDL_MAJOR_VERSION == 1
SDL_TryLockMutex(*mutex);
#endif
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment