From 012a44bd13ab41d056e7d3884a39027b6cea62b5 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 30 Jul 2019 22:12:11 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E6=88=90=E5=91=98=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/modules/asura-utils/threading/semaphore.cpp | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'source/modules/asura-utils/threading/semaphore.cpp') diff --git a/source/modules/asura-utils/threading/semaphore.cpp b/source/modules/asura-utils/threading/semaphore.cpp index aa5d9dd..7e5ccf5 100644 --- a/source/modules/asura-utils/threading/semaphore.cpp +++ b/source/modules/asura-utils/threading/semaphore.cpp @@ -10,42 +10,42 @@ namespace AsuraEngine { #define try_create_semaphore(impl) \ - if (!mImpl) \ + if (!m_Impl) \ { \ try \ { \ - mImpl = new impl(init_count); \ + m_Impl = new impl(init_count); \ } \ catch (Exception& e) \ { \ - mImpl = nullptr; \ + m_Impl = nullptr; \ } \ } Semaphore::Semaphore(unsigned int init_count) - : mImpl(nullptr) + : m_Impl(nullptr) { #ifdef ASURA_THREAD_WIN32 try_create_semaphore(SemaphoreWin32); #endif - //ASSERT(mImpl); + //ASSERT(m_Impl); } Semaphore::~Semaphore() { - if (mImpl) delete mImpl; + if (m_Impl) delete m_Impl; } void Semaphore::Signal() { - ASSERT(mImpl); - mImpl->Signal(); + ASSERT(m_Impl); + m_Impl->Signal(); } bool Semaphore::Wait(int timeout /*= ASURA_MUTEX_MAXWAIT*/) { - ASSERT(mImpl); - return mImpl->Wait(timeout); + ASSERT(m_Impl); + return m_Impl->Wait(timeout); } #if ASURA_THREAD_WIN32 @@ -54,8 +54,8 @@ namespace AsuraEngine : SemaphoreImpl(init_value) { // UINT_MAX get error. - mSem = CreateSemaphore(NULL, init_value, INT_MAX, NULL); - if (!mSem) + m_Sem = CreateSemaphore(NULL, init_value, INT_MAX, NULL); + if (!m_Sem) { int errorCode = GetLastError(); throw Exception("Cant use win32 semaphore. Error code: %d.", errorCode); @@ -64,23 +64,23 @@ namespace AsuraEngine SemaphoreWin32::~SemaphoreWin32() { - CloseHandle(mSem); + CloseHandle(m_Sem); } void SemaphoreWin32::Signal() { - InterlockedIncrement(&mCount); - if (ReleaseSemaphore(mSem, 1, NULL) == FALSE) - InterlockedDecrement(&mCount); + InterlockedIncrement(&m_Count); + if (ReleaseSemaphore(m_Sem, 1, NULL) == FALSE) + InterlockedDecrement(&m_Count); } bool SemaphoreWin32::Wait(int timeout) { int result; - result = WaitForSingleObject(mSem, timeout); + result = WaitForSingleObject(m_Sem, timeout); if (result == WAIT_OBJECT_0) { - InterlockedDecrement(&mCount); + InterlockedDecrement(&m_Count); return true; } else if(result == WAIT_TIMEOUT) -- cgit v1.1-26-g67d0