From c302f5ae5f9e30a28e487e8a764d9cc31546bbea Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 29 Mar 2019 22:51:04 +0800 Subject: *rename --- source/modules/asura-utils/threading/semaphore.h | 70 ++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 source/modules/asura-utils/threading/semaphore.h (limited to 'source/modules/asura-utils/threading/semaphore.h') diff --git a/source/modules/asura-utils/threading/semaphore.h b/source/modules/asura-utils/threading/semaphore.h new file mode 100644 index 0000000..80773d8 --- /dev/null +++ b/source/modules/asura-utils/threading/semaphore.h @@ -0,0 +1,70 @@ +#ifndef __ASURA_SEMAPHORE_H__ +#define __ASURA_SEMAPHORE_H__ + +#include "../utils_config.h" + +#if ASURA_THREAD_WIN32 +#include +#endif + +namespace AsuraEngine +{ + namespace Threading + { + + class SemaphoreImpl; + + /// + /// ÐźÅÁ¿ + /// + class Semaphore + { + public: + + Semaphore(unsigned int init_count = 1); + ~Semaphore(); + + void Signal(); + void Wait(int timeout = 0); + + private: + SemaphoreImpl* mImpl; + }; + + class SemaphoreImpl + { + public: + SemaphoreImpl(unsigned int init_value) + : mCount(init_value) + { + }; + virtual ~SemaphoreImpl() {}; + virtual void Signal() = 0; + virtual bool Wait(int timeout) = 0; + inline int Current() { return mCount; } + protected: + unsigned int mCount; + }; + +#define wait(sem) sem.Wait(); +#define signal(sem) sem.Signal(); + +#if ASURA_THREAD_WIN32 + + class SemaphoreWin32 : public SemaphoreImpl + { + public: + SemaphoreWin32(unsigned int init_value); + ~SemaphoreWin32(); + void Signal() override; + bool Wait(int timeout) override; + private: + HANDLE mSem; + }; + +#endif // ASURA_THREAD_WIN32 + + } +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0