Commit feb78b96 authored by phcoder's avatar phcoder
Browse files

Use slock on platforms that lack std::mutex

parent e9904510
#include "slock_wrapper.h"
#ifndef USE_SLOCK_WRAPPER
#elif defined(PS2) || defined(WIIU) // Single-threaded
slock_wrap::slock_wrap() {
}
slock_wrap::~slock_wrap() {
}
void slock_wrap::lock() {
}
void slock_wrap::unlock() {
}
bool slock_wrap::try_lock() {
return true;
}
#else
extern "C" {
slock_t *slock_new(void);
void slock_free(slock_t *lock);
void slock_lock(slock_t *lock);
void slock_unlock(slock_t *lock);
void slock_free(slock_t *lock);
bool slock_try_lock(slock_t *lock);
}
slock_wrap::slock_wrap() {
slck = slock_new();
}
slock_wrap::~slock_wrap() {
slock_free(slck);
}
void slock_wrap::lock() {
slock_lock(slck);
}
void slock_wrap::unlock() {
slock_unlock(slck);
}
bool slock_wrap::try_lock() {
return slock_try_lock(slck);
}
#endif
#pragma once
#if defined(_3DS) || defined(__PSP__) || defined(PS2) || defined(WIIU)
#define USE_SLOCK_WRAPPER 1
#endif
#ifdef USE_SLOCK_WRAPPER
typedef struct slock slock_t;
class slock_wrap
{
public:
slock_wrap();
~slock_wrap();
void lock();
void unlock();
bool try_lock();
private:
slock_t *slck;
};
#endif
......@@ -5,7 +5,12 @@
#include <array>
#include <vector>
#ifdef __LIBRETRO__
#include "slock_wrapper.h"
#endif
#ifndef USE_SLOCK_WRAPPER
#include <mutex>
#endif
#if SOUND_ENABLED
......@@ -200,7 +205,11 @@ namespace retro8
std::array<SoundState, CHANNEL_COUNT> channels;
MusicState mstate;
#ifdef USE_SLOCK_WRAPPER
slock_wrap queueMutex;
#else
std::mutex queueMutex;
#endif
std::vector<Command> queue;
bool _soundEnabled, _musicEnabled;
......
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