diff options
Diffstat (limited to 'core/os/thread_safe.h')
-rw-r--r-- | core/os/thread_safe.h | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/core/os/thread_safe.h b/core/os/thread_safe.h index c9a832b41b..a60773e8ed 100644 --- a/core/os/thread_safe.h +++ b/core/os/thread_safe.h @@ -29,41 +29,42 @@ #ifndef THREAD_SAFE_H #define THREAD_SAFE_H - #include "os/mutex.h" class ThreadSafe { Mutex *mutex; -public: - inline void lock() const { if (mutex) mutex->lock(); } - inline void unlock() const { if (mutex) mutex->unlock(); } +public: + inline void lock() const { + if (mutex) mutex->lock(); + } + inline void unlock() const { + if (mutex) mutex->unlock(); + } ThreadSafe(); ~ThreadSafe(); - }; - class ThreadSafeMethod { const ThreadSafe *_ts; + public: ThreadSafeMethod(const ThreadSafe *p_ts) { - _ts=p_ts; + _ts = p_ts; _ts->lock(); } ~ThreadSafeMethod() { _ts->unlock(); } }; - #ifndef NO_THREADS #define _THREAD_SAFE_CLASS_ ThreadSafe __thread__safe__; -#define _THREAD_SAFE_METHOD_ ThreadSafeMethod __thread_safe_method__(&__thread__safe__); +#define _THREAD_SAFE_METHOD_ ThreadSafeMethod __thread_safe_method__(&__thread__safe__); #define _THREAD_SAFE_LOCK_ __thread__safe__.lock(); #define _THREAD_SAFE_UNLOCK_ __thread__safe__.unlock(); @@ -76,7 +77,4 @@ public: #endif - - - #endif |