cec: and now proper predicates
[deb_libcec.git] / src / lib / platform / sockets / socket.h
index 58a3e3a751efbcad16462fc173a73917703e074f..369fbe4c9f78101ba6cef915e1bff37e4737f8e2 100644 (file)
@@ -105,7 +105,7 @@ namespace PLATFORM
   public:
     CProtectedSocket(_Socket *socket) :
       m_socket(socket),
-      m_iUseCount(0) {}
+      m_bIsIdle(true) {}
 
     virtual ~CProtectedSocket(void)
     {
@@ -151,13 +151,13 @@ namespace PLATFORM
     virtual bool IsBusy(void)
     {
       CLockObject lock(m_mutex);
-      return m_socket && m_iUseCount > 0;
+      return m_socket && !m_bIsIdle;
     }
 
-    virtual int GetUseCount(void)
+    virtual bool IsIdle(void)
     {
       CLockObject lock(m_mutex);
-      return m_iUseCount;
+      return m_socket && m_bIsIdle;
     }
 
     virtual ssize_t Write(void* data, size_t len)
@@ -208,27 +208,21 @@ namespace PLATFORM
     bool WaitReady(void)
     {
       CLockObject lock(m_mutex);
-      if (m_iUseCount > 0)
-        m_condition.Wait(m_mutex);
-
-      if (m_iUseCount > 0)
-        return false;
-
-      ++m_iUseCount;
+      m_condition.Wait(m_mutex, m_bIsIdle);
+      m_bIsIdle = false;
       return true;
     }
 
     void MarkReady(void)
     {
       CLockObject lock(m_mutex);
-      if (m_iUseCount > 0)
-        --m_iUseCount;
+      m_bIsIdle = true;
       m_condition.Signal();
     }
 
-    _Socket   *m_socket;
-    CMutex     m_mutex;
-    CCondition m_condition;
-    int        m_iUseCount;
+    _Socket *          m_socket;
+    CMutex             m_mutex;
+    CCondition<bool &> m_condition;
+    bool               m_bIsIdle;
   };
 };