Fixed: Unnamed semaphores are deprecated under OS X

--HG--
branch : hotfix
This commit is contained in:
kervala 2015-02-14 17:52:15 +01:00
parent 5aa8a1d615
commit 1690f777a1
2 changed files with 29 additions and 3 deletions

View file

@ -28,7 +28,11 @@
# endif
#elif defined(NL_OS_UNIX)
# include <pthread.h> // PThread
# ifdef NL_OS_MAC
# include <dispatch/dispatch.h>
# else
# include <semaphore.h> // PThread POSIX semaphores
# endif
# include <unistd.h>
# define __forceinline
# ifdef NL_OS_MAC
@ -532,7 +536,9 @@ private:
#ifdef NL_OS_WINDOWS
TNelRtlCriticalSection _Cs;
#elif defined NL_OS_UNIX
#elif defined(NL_OS_MAC)
dispatch_semaphore_t _Sem;
#elif defined(NL_OS_UNIX)
sem_t _Sem;
#else
# error "No fair mutex implementation for this OS"

View file

@ -406,13 +406,21 @@ void CUnfairMutex::leave()
*/
CFairMutex::CFairMutex()
{
#ifdef NL_OS_MAC
_Sem = dispatch_semaphore_create(1);
#else
sem_init( const_cast<sem_t*>(&_Sem), 0, 1 );
#endif
}
CFairMutex::CFairMutex( const std::string &name )
{
#ifdef NL_OS_MAC
_Sem = dispatch_semaphore_create(1);
#else
sem_init( const_cast<sem_t*>(&_Sem), 0, 1 );
#endif
}
@ -421,7 +429,11 @@ CFairMutex::CFairMutex( const std::string &name )
*/
CFairMutex::~CFairMutex()
{
#ifdef NL_OS_MAC
dispatch_release(_Sem);
#else
sem_destroy( const_cast<sem_t*>(&_Sem) ); // needs that no thread is waiting on the semaphore
#endif
}
@ -430,7 +442,11 @@ CFairMutex::~CFairMutex()
*/
void CFairMutex::enter()
{
#ifdef NL_OS_MAC
dispatch_semaphore_wait(_Sem, DISPATCH_TIME_FOREVER);
#else
sem_wait( const_cast<sem_t*>(&_Sem) );
#endif
}
@ -439,7 +455,11 @@ void CFairMutex::enter()
*/
void CFairMutex::leave()
{
#ifdef NL_OS_MAC
dispatch_semaphore_signal(_Sem);
#else
sem_post( const_cast<sem_t*>(&_Sem) );
#endif
}