cec: refactored threading/locking - added windows native instead of pthread-win32...
[deb_libcec.git] / src / lib / platform / os.h
similarity index 52%
rename from src/lib/platform/threads.cpp
rename to src/lib/platform/os.h
index c9f6c16214f652fb0179e669014cd44885da34f6..fbe090342986ce0e7bc67fd5ad3099ce33994df6 100644 (file)
@@ -1,3 +1,4 @@
+#pragma once
 /*
  * This file is part of the libCEC(R) library.
  *
  *     http://www.pulse-eight.net/
  */
 
-#include "threads.h"
-#include "timeutils.h"
-#include "os-dependent.h"
-
-using namespace CEC;
-
-CLockObject::CLockObject(IMutex *mutex, bool bTryLock /* = false */) :
-  m_mutex(mutex)
-{
-  if (m_mutex)
-    m_bLocked = bTryLock ? m_mutex->TryLock() : m_mutex->Lock();
-}
-
-CLockObject::~CLockObject(void)
-{
-  Leave();
-  m_mutex = NULL;
-}
-
-void CLockObject::Leave(void)
-{
-  if (m_mutex && m_bLocked)
-  {
-    m_bLocked = false;
-    m_mutex->Unlock();
-  }
-}
-
-void CLockObject::Lock(void)
-{
-  if (m_mutex)
-    m_bLocked = m_mutex->Lock();
-}
+#if defined(_WIN32) || defined(_WIN64)
+#ifndef __WINDOWS__
+#define __WINDOWS__
+#endif
+#include "windows/os-types.h"
+#include "windows/os-threads.h"
+#else
+#include "posix/os-types.h"
+#include "posix/os-threads.h"
+#endif
 
-void ICondition::Sleep(uint32_t iTimeout)
-{
-  CCondition w;
-  CMutex m;
-  CLockObject lock(&m);
-  w.Wait(&m, iTimeout);
-}
-
-IThread::IThread(void) :
-    m_bStop(false),
-    m_bRunning(false)
-{
-  m_threadCondition = new CCondition();
-  m_threadMutex     = new CMutex();
-}
-
-IThread::~IThread(void)
-{
-  StopThread();
-  delete m_threadCondition;
-  delete m_threadMutex;
-}
-
-bool IThread::StopThread(bool bWaitForExit /* = true */)
-{
-  m_bStop = true;
-  m_threadCondition->Broadcast();
-  bWaitForExit = true;
-
-  return false;
-}
-
-bool IThread::Sleep(uint32_t iTimeout)
-{
-  CLockObject lock(m_threadMutex);
-  return m_bStop ? false : m_threadCondition->Wait(m_threadMutex, iTimeout);
-}
+#include "timeutils.h"
+#include "threads/threads.h"
+#include "buffer.h"
+#include "StdString.h"