2012-03-31 09:09:40 +02:00
|
|
|
#include "i2-base.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2012-04-16 08:36:50 +02:00
|
|
|
CondVar::CondVar(void)
|
2012-03-31 09:09:40 +02:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
InitializeConditionVariable(&m_CondVar);
|
|
|
|
#else /* _WIN32 */
|
|
|
|
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
}
|
|
|
|
|
2012-04-16 08:36:50 +02:00
|
|
|
CondVar::~CondVar(void)
|
2012-03-31 09:09:40 +02:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
/* nothing to do here */
|
|
|
|
#else /* _WIN32 */
|
|
|
|
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
}
|
|
|
|
|
2012-04-16 08:36:50 +02:00
|
|
|
void CondVar::Wait(Mutex& mtx)
|
2012-03-31 09:09:40 +02:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
2012-04-16 08:36:50 +02:00
|
|
|
SleepConditionVariableCS(&m_CondVar, mtx.Get(), INFINITE);
|
2012-03-31 09:09:40 +02:00
|
|
|
#else /* _WIN32 */
|
2012-04-16 08:36:50 +02:00
|
|
|
pthread_cond_wait(&m_CondVar, mtx.Get());
|
2012-03-31 09:09:40 +02:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
}
|
|
|
|
|
2012-04-16 08:36:50 +02:00
|
|
|
void CondVar::Signal(void)
|
2012-03-31 09:09:40 +02:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
WakeConditionVariable(&m_CondVar);
|
|
|
|
#else /* _WIN32 */
|
|
|
|
pthread_cond_signal(&m_CondVar);
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
}
|
|
|
|
|
2012-04-16 08:36:50 +02:00
|
|
|
void CondVar::Broadcast(void)
|
2012-03-31 09:09:40 +02:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
WakeAllConditionVariable(&m_CondVar);
|
|
|
|
#else /* _WIN32 */
|
|
|
|
pthread_cond_broadcast(&m_CondVar);
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2012-04-16 08:36:50 +02:00
|
|
|
CONDITION_VARIABLE *CondVar::Get(void)
|
2012-03-31 09:09:40 +02:00
|
|
|
#else /* _WIN32 */
|
2012-04-16 08:36:50 +02:00
|
|
|
pthread_cond_t *CondVar::Get(void)
|
2012-03-31 09:09:40 +02:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
{
|
|
|
|
return &m_CondVar;
|
|
|
|
}
|