diff --git a/project/include/system/Mutex.h b/project/include/system/Mutex.h new file mode 100644 index 000000000..94fb92e41 --- /dev/null +++ b/project/include/system/Mutex.h @@ -0,0 +1,31 @@ +#ifndef LIME_SYSTEM_MUTEX_H +#define LIME_SYSTEM_MUTEX_H + + +namespace lime { + + + class Mutex { + + + public: + + Mutex (); + ~Mutex (); + + bool Lock (); + bool TryLock (); + bool Unlock (); + + private: + + void* mutex; + + + }; + + +} + + +#endif \ No newline at end of file diff --git a/project/src/backend/sdl/SDLMutex.cpp b/project/src/backend/sdl/SDLMutex.cpp new file mode 100644 index 000000000..a67c6b64f --- /dev/null +++ b/project/src/backend/sdl/SDLMutex.cpp @@ -0,0 +1,65 @@ +#include +#include + + +namespace lime { + + + Mutex::Mutex () { + + mutex = SDL_CreateMutex (); + + } + + + Mutex::~Mutex () { + + if (mutex) { + + SDL_DestroyMutex ((SDL_mutex*)mutex); + + } + + } + + + bool Mutex::Lock () { + + if (mutex) { + + return SDL_LockMutex ((SDL_mutex*)mutex) == 0; + + } + + return false; + + } + + + bool Mutex::TryLock () { + + if (mutex) { + + return SDL_TryLockMutex ((SDL_mutex*)mutex) == 0; + + } + + return false; + + } + + + bool Mutex::Unlock () { + + if (mutex) { + + return SDL_UnlockMutex ((SDL_mutex*)mutex) == 0; + + } + + return false; + + } + + +} \ No newline at end of file