diff options
author | Cengiz Can <cengizc@gmail.com> | 2015-06-02 00:26:57 +0200 |
---|---|---|
committer | Cengiz Can <cengizc@gmail.com> | 2015-06-04 10:48:56 +0200 |
commit | c967698b2de6a0c588dbf0cebc493dbb03989333 (patch) | |
tree | 90ed066862c081299e02b173b9de99643e7e5732 /src/OSSupport/Semaphore.cpp | |
parent | Merge pull request #2202 from mc-server/CmakeCleanup (diff) | |
download | cuberite-c967698b2de6a0c588dbf0cebc493dbb03989333.tar cuberite-c967698b2de6a0c588dbf0cebc493dbb03989333.tar.gz cuberite-c967698b2de6a0c588dbf0cebc493dbb03989333.tar.bz2 cuberite-c967698b2de6a0c588dbf0cebc493dbb03989333.tar.lz cuberite-c967698b2de6a0c588dbf0cebc493dbb03989333.tar.xz cuberite-c967698b2de6a0c588dbf0cebc493dbb03989333.tar.zst cuberite-c967698b2de6a0c588dbf0cebc493dbb03989333.zip |
Diffstat (limited to 'src/OSSupport/Semaphore.cpp')
-rw-r--r-- | src/OSSupport/Semaphore.cpp | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/src/OSSupport/Semaphore.cpp b/src/OSSupport/Semaphore.cpp deleted file mode 100644 index 6a2d57901..000000000 --- a/src/OSSupport/Semaphore.cpp +++ /dev/null @@ -1,107 +0,0 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - - - - - -cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /* = 0 */) -#ifndef _WIN32 - : m_bNamed( false) -#endif -{ -#ifndef _WIN32 - (void)a_MaxCount; - m_Handle = new sem_t; - if (sem_init( (sem_t*)m_Handle, 0, 0)) - { - LOG("WARNING cSemaphore: Could not create unnamed semaphore, fallback to named."); - delete (sem_t*)m_Handle; // named semaphores return their own address - m_bNamed = true; - - AString Name; - Printf(Name, "cSemaphore%p", this); - m_Handle = sem_open(Name.c_str(), O_CREAT, 777, a_InitialCount); - if (m_Handle == SEM_FAILED) - { - LOG("ERROR: Could not create Semaphore. (%i)", errno); - } - else - { - if (sem_unlink(Name.c_str()) != 0) - { - LOG("ERROR: Could not unlink cSemaphore. (%i)", errno); - } - } - } -#else - m_Handle = CreateSemaphore( - nullptr, // security attribute - a_InitialCount, // initial count - a_MaxCount, // maximum count - 0 // name (optional) - ); -#endif -} - - - - - -cSemaphore::~cSemaphore() -{ -#ifdef _WIN32 - CloseHandle( m_Handle); -#else - if (m_bNamed) - { - if (sem_close( (sem_t*)m_Handle) != 0) - { - LOG("ERROR: Could not close cSemaphore. (%i)", errno); - } - } - else - { - sem_destroy( (sem_t*)m_Handle); - delete (sem_t*)m_Handle; - } - m_Handle = 0; - -#endif -} - - - - - -void cSemaphore::Wait() -{ -#ifndef _WIN32 - if (sem_wait( (sem_t*)m_Handle) != 0) - { - LOG("ERROR: Could not wait for cSemaphore. (%i)", errno); - } -#else - WaitForSingleObject( m_Handle, INFINITE); -#endif -} - - - - - -void cSemaphore::Signal() -{ -#ifndef _WIN32 - if (sem_post( (sem_t*)m_Handle) != 0) - { - LOG("ERROR: Could not signal cSemaphore. (%i)", errno); - } -#else - ReleaseSemaphore( m_Handle, 1, nullptr); -#endif -} - - - - |