--- /dev/null
+#include "i2-base.h"
+
+using namespace icinga;
+
+condvar::condvar(void)
+{
+#ifdef _WIN32
+ InitializeConditionVariable(&m_CondVar);
+#else /* _WIN32 */
+
+#endif /* _WIN32 */
+}
+
+condvar::~condvar(void)
+{
+#ifdef _WIN32
+ /* nothing to do here */
+#else /* _WIN32 */
+
+#endif /* _WIN32 */
+}
+
+void condvar::wait(mutex *mtx)
+{
+#ifdef _WIN32
+ SleepConditionVariableCS(&m_CondVar, mtx->get(), INFINITE);
+#else /* _WIN32 */
+ pthread_cond_wait(&m_CondVar, mtx->get());
+#endif /* _WIN32 */
+}
+
+void condvar::signal(void)
+{
+#ifdef _WIN32
+ WakeConditionVariable(&m_CondVar);
+#else /* _WIN32 */
+ pthread_cond_signal(&m_CondVar);
+#endif /* _WIN32 */
+}
+
+void condvar::broadcast(void)
+{
+#ifdef _WIN32
+ WakeAllConditionVariable(&m_CondVar);
+#else /* _WIN32 */
+ pthread_cond_broadcast(&m_CondVar);
+#endif /* _WIN32 */
+}
+
+
+#ifdef _WIN32
+CONDITION_VARIABLE *condvar::get(void)
+#else /* _WIN32 */
+pthread_cond_t *condvar::get(void)
+#endif /* _WIN32 */
+{
+ return &m_CondVar;
+}
--- /dev/null
+#ifndef I2_CONDVAR_H
+#define I2_CONDVAR_H
+
+namespace icinga
+{
+
+class condvar
+{
+private:
+#ifdef _WIN32
+ CONDITION_VARIABLE m_CondVar;
+#else /* _WIN32 */
+ pthread_cond_t m_CondVar;
+#endif /* _WIN32 */
+
+public:
+ condvar(void);
+ ~condvar(void);
+
+ void wait(mutex *mtx);
+ void signal(void);
+ void broadcast(void);
+
+#ifdef _WIN32
+ CONDITION_VARIABLE *get(void);
+#else /* _WIN32 */
+ pthread_cond_t *get(void);
+#endif /* _WIN32 */
+};
+
+}
+
+#endif /* I2_CONDVAR_H */
\ No newline at end of file
# include "unix.h"
#endif
+#include "mutex.h"
+#include "condvar.h"
#include "object.h"
#include "memory.h"
#include "delegate.h"
--- /dev/null
+#include "i2-base.h"
+
+using namespace icinga;
+
+mutex::mutex(void)
+{
+#ifdef _WIN32
+ InitializeCriticalSection(&m_Mutex);
+#else /* _WIN32 */
+ pthread_mutex_init(&m_Mutex);
+#endif /* _WIN32 */
+}
+
+mutex::~mutex(void)
+{
+#ifdef _WIN32
+ DeleteCriticalSection(&m_Mutex);
+#else /* _WIN32 */
+ pthread_mutex_init(&m_Mutex);
+#endif /* _WIN32 */
+}
+
+bool mutex::tryenter(void)
+{
+#ifdef _WIN32
+ return (TryEnterCriticalSection(&m_Mutex) == TRUE);
+#else /* _WIN32 */
+ return pthread_mutex_tryenter(&m_Mutex);
+#endif /* _WIN32 */
+}
+
+void mutex::enter(void)
+{
+#ifdef _WIN32
+ EnterCriticalSection(&m_Mutex);
+#else /* _WIN32 */
+ pthread_mutex_enter(&m_Mutex);
+#endif /* _WIN32 */
+}
+
+void mutex::exit(void)
+{
+#ifdef _WIN32
+ LeaveCriticalSection(&m_Mutex);
+#else /* _WIN32 */
+ pthread_mutex_exit(&m_Mutex);
+#endif /* _WIN32 */
+}
+
+#ifdef _WIN32
+CRITICAL_SECTION *mutex::get(void)
+#else /* _WIN32 */
+pthread_mutex_t *mutex::get(void)
+#endif /* _WIN32 */
+{
+ return &m_Mutex;
+}
--- /dev/null
+#ifndef I2_MUTEX_H
+#define I2_MUTEX_H
+
+namespace icinga
+{
+
+class mutex
+{
+private:
+#ifdef _WIN32
+ CRITICAL_SECTION m_Mutex;
+#else /* _WIN32 */
+ pthread_mutex_t m_Mutex;
+#endif /* _WIN32 */
+
+public:
+ mutex(void);
+ ~mutex(void);
+
+ bool tryenter(void);
+ void enter(void);
+ void exit(void);
+
+#ifdef _WIN32
+ CRITICAL_SECTION *get(void);
+#else /* _WIN32 */
+ pthread_mutex_t *get(void);
+#endif /* _WIN32 */
+};
+
+}
+
+#endif /* I2_MUTEX_H */