From 084623519e95f0ab0cf4bc328b5fa736d679c5bd Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 31 Jul 2019 21:35:12 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E5=90=8D=E7=A7=B0=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/modules/asura-utils/threading/semaphore.h | 86 ++++++++++++------------ 1 file changed, 42 insertions(+), 44 deletions(-) (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 index c75ae8a..ae7b10b 100644 --- a/source/modules/asura-utils/threading/semaphore.h +++ b/source/modules/asura-utils/threading/semaphore.h @@ -7,64 +7,62 @@ #include #endif -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) - class SemaphoreImpl; +class SemaphoreImpl; - /// - /// ÐźÅÁ¿ - /// - class Semaphore - { - public: +/// +/// ÐźÅÁ¿ +/// +class Semaphore +{ +public: - Semaphore(unsigned int init_count = 1); - ~Semaphore(); + Semaphore(unsigned int init_count = 1); + ~Semaphore(); - void Signal(); - bool Wait(int timeout = ASURA_MUTEX_MAXWAIT); + void Signal(); + bool Wait(int timeout = ASURA_MUTEX_MAXWAIT); - private: - SemaphoreImpl* m_Impl; - }; +private: + SemaphoreImpl* m_Impl; +}; - class SemaphoreImpl - { - public: - SemaphoreImpl(unsigned int init_value) - : m_Count(init_value) - { - }; - virtual ~SemaphoreImpl() {}; - virtual void Signal() = 0; - virtual bool Wait(int timeout) = 0; - inline int Current() { return m_Count; } - protected: - unsigned int m_Count; - }; +class SemaphoreImpl +{ +public: + SemaphoreImpl(unsigned int init_value) + : m_Count(init_value) + { + }; + virtual ~SemaphoreImpl() {}; + virtual void Signal() = 0; + virtual bool Wait(int timeout) = 0; + inline int Current() { return m_Count; } +protected: + unsigned int m_Count; +}; #define wait(sem, ...) sem.Wait(__VA_ARGS__) #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 m_Sem; - }; +class SemaphoreWin32 : public SemaphoreImpl +{ +public: + SemaphoreWin32(unsigned int init_value); + ~SemaphoreWin32(); + void Signal() override; + bool Wait(int timeout) override; +private: + HANDLE m_Sem; +}; #endif // ASURA_THREAD_WIN32 - } -} +namespace_end +namespace_end #endif \ No newline at end of file -- cgit v1.1-26-g67d0