forked from organicmaps/organicmaps
Cleaned up condition and mutex
This commit is contained in:
parent
697561fd87
commit
806b3c3aa8
2 changed files with 18 additions and 25 deletions
|
@ -13,19 +13,6 @@
|
|||
|
||||
namespace threads
|
||||
{
|
||||
#if !defined(OMIM_OS_WINDOWS_NATIVE) && !defined(OMIM_OS_BADA)
|
||||
// only for pthreads
|
||||
struct CondDeleter
|
||||
{
|
||||
void operator()(pthread_cond_t * var)
|
||||
{
|
||||
::pthread_cond_destroy(var);
|
||||
delete var;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/// Implements mutexed condition semantics
|
||||
class Condition
|
||||
{
|
||||
|
@ -36,7 +23,7 @@ namespace threads
|
|||
#if defined(OMIM_OS_WINDOWS_NATIVE)
|
||||
CONDITION_VARIABLE m_Condition;
|
||||
#else
|
||||
shared_ptr<pthread_cond_t> m_Condition;
|
||||
pthread_cond_t m_Condition;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -48,8 +35,15 @@ namespace threads
|
|||
#elif defined(OMIM_OS_WINDOWS_NATIVE)
|
||||
::InitializeConditionVariable(&m_Condition);
|
||||
#else
|
||||
m_Condition = shared_ptr<pthread_cond_t>(new pthread_cond_t(), CondDeleter());
|
||||
::pthread_cond_init(m_Condition.get(), 0);
|
||||
::pthread_cond_init(&m_Condition, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
~Condition()
|
||||
{
|
||||
#if !defined(OMIM_OS_WINDOWS_NATIVE) && !defined(OMIM_OS_BADA)
|
||||
// only for pthreads
|
||||
::pthread_cond_destroy(&m_Condition);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -60,7 +54,7 @@ namespace threads
|
|||
#elif defined(OMIM_OS_WINDOWS_NATIVE)
|
||||
::WakeConditionVariable(&m_Condition);
|
||||
#else
|
||||
::pthread_cond_signal(m_Condition.get());
|
||||
::pthread_cond_signal(&m_Condition);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -71,7 +65,7 @@ namespace threads
|
|||
#elif defined(OMIM_OS_WINDOWS_NATIVE)
|
||||
::SleepConditionVariableCS(&m_Condition, &m_Mutex.m_Mutex, INFINITE);
|
||||
#else
|
||||
::pthread_cond_wait(m_Condition.get(), &m_Mutex.m_Mutex);
|
||||
::pthread_cond_wait(&m_Condition, &m_Mutex.m_Mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,6 @@
|
|||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include "../std/shared_ptr.hpp"
|
||||
|
||||
|
||||
namespace threads
|
||||
{
|
||||
/// Mutex primitive, used only for synchronizing this process threads
|
||||
|
@ -54,6 +51,8 @@ namespace threads
|
|||
{
|
||||
#if defined(OMIM_OS_WINDOWS_NATIVE)
|
||||
::DeleteCriticalSection(&m_Mutex);
|
||||
#elif !defined(OMIM_OS_BADA)
|
||||
::pthread_mutex_destroy(&m_Mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -63,9 +62,9 @@ namespace threads
|
|||
m_Mutex.Acquire();
|
||||
#elif defined(OMIM_OS_WINDOWS_NATIVE)
|
||||
::EnterCriticalSection(&m_Mutex);
|
||||
#else
|
||||
#else
|
||||
::pthread_mutex_lock(&m_Mutex);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void Unlock()
|
||||
|
@ -74,9 +73,9 @@ namespace threads
|
|||
m_Mutex.Release();
|
||||
#elif defined(OMIM_OS_WINDOWS_NATIVE)
|
||||
::LeaveCriticalSection(&m_Mutex);
|
||||
#else
|
||||
#else
|
||||
::pthread_mutex_unlock(&m_Mutex);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue