summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/Semaphore.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/OSSupport/Semaphore.cpp76
1 files changed, 46 insertions, 30 deletions
diff --git a/src/OSSupport/Semaphore.cpp b/src/OSSupport/Semaphore.cpp
index 468de6858..c1fc7d9c7 100644
--- a/src/OSSupport/Semaphore.cpp
+++ b/src/OSSupport/Semaphore.cpp
@@ -5,9 +5,9 @@
-cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /* = 0 */ )
+cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /* = 0 */)
#ifndef _WIN32
- : m_bNamed( false )
+ : m_bNamed( false)
#endif
{
#ifndef _WIN32
@@ -20,15 +20,15 @@ cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /*
m_bNamed = true;
AString Name;
- Printf(Name, "cSemaphore%p", this );
+ Printf(Name, "cSemaphore%p", this);
m_Handle = sem_open(Name.c_str(), O_CREAT, 777, a_InitialCount);
- if( m_Handle == SEM_FAILED )
+ if (m_Handle == SEM_FAILED)
{
- LOG("ERROR: Could not create Semaphore. (%i)", errno );
+ LOG("ERROR: Could not create Semaphore. (%i)", errno);
}
else
{
- if( sem_unlink(Name.c_str()) != 0 )
+ if (sem_unlink(Name.c_str()) != 0)
{
LOG("ERROR: Could not unlink cSemaphore. (%i)", errno);
}
@@ -36,56 +36,72 @@ cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /*
}
#else
m_Handle = CreateSemaphore(
- NULL, // security attribute
- a_InitialCount, // initial count
- a_MaxCount, // maximum count
- 0 // name (optional)
+ NULL, // security attribute
+ a_InitialCount, // initial count
+ a_MaxCount, // maximum count
+ 0 // name (optional)
);
#endif
}
+
+
+
+
cSemaphore::~cSemaphore()
{
#ifdef _WIN32
- CloseHandle( m_Handle );
+ 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;
- }
+ 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);
- }
+ 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 )
+ if (sem_post( (sem_t*)m_Handle) != 0)
{
- LOG("ERROR: Could not signal cSemaphore. (%i)", errno);
+ LOG("ERROR: Could not signal cSemaphore. (%i)", errno);
}
#else
- ReleaseSemaphore( m_Handle, 1, NULL );
+ ReleaseSemaphore( m_Handle, 1, NULL);
#endif
}
+
+
+
+