repositories
/
deb_libcec.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
sync LibCecSharp
[deb_libcec.git]
/
src
/
lib
/
platform
/
util
/
buffer.h
diff --git
a/src/lib/platform/util/buffer.h
b/src/lib/platform/util/buffer.h
index 8777661df1c4e6942f937905126b868c2d2cce1f..4b57a29c7d340e180f04f29222eaae9d140f7802 100644
(file)
--- a/
src/lib/platform/util/buffer.h
+++ b/
src/lib/platform/util/buffer.h
@@
-31,7
+31,7
@@
* http://www.pulse-eight.net/
*/
* http://www.pulse-eight.net/
*/
-#include "
..
/threads/mutex.h"
+#include "
lib/platform
/threads/mutex.h"
#include <queue>
namespace PLATFORM
#include <queue>
namespace PLATFORM
@@
-41,7
+41,8
@@
namespace PLATFORM
{
public:
SyncedBuffer(size_t iMaxSize = 100) :
{
public:
SyncedBuffer(size_t iMaxSize = 100) :
- m_maxSize(iMaxSize) {}
+ m_maxSize(iMaxSize),
+ m_bHasMessages(false) {}
virtual ~SyncedBuffer(void)
{
virtual ~SyncedBuffer(void)
{
@@
-53,6
+54,7
@@
namespace PLATFORM
CLockObject lock(m_mutex);
while (!m_buffer.empty())
m_buffer.pop();
CLockObject lock(m_mutex);
while (!m_buffer.empty())
m_buffer.pop();
+ m_condition.Broadcast();
}
size_t Size(void)
}
size_t Size(void)
@@
-74,17
+76,29
@@
namespace PLATFORM
return false;
m_buffer.push(entry);
return false;
m_buffer.push(entry);
+ m_bHasMessages = true;
+ m_condition.Signal();
return true;
}
return true;
}
- bool Pop(_BType &entry)
+ bool Pop(_BType &entry
, uint32_t iTimeoutMs = 0
)
{
bool bReturn(false);
CLockObject lock(m_mutex);
{
bool bReturn(false);
CLockObject lock(m_mutex);
+
+ // wait for a signal if the buffer is empty
+ if (m_buffer.empty() && iTimeoutMs > 0)
+ {
+ if (!m_condition.Wait(m_mutex, m_bHasMessages, iTimeoutMs))
+ return bReturn;
+ }
+
+ // pop the first item
if (!m_buffer.empty())
{
entry = m_buffer.front();
m_buffer.pop();
if (!m_buffer.empty())
{
entry = m_buffer.front();
m_buffer.pop();
+ m_bHasMessages = !m_buffer.empty();
bReturn = true;
}
return bReturn;
bReturn = true;
}
return bReturn;
@@
-106,5
+120,7
@@
namespace PLATFORM
size_t m_maxSize;
std::queue<_BType> m_buffer;
CMutex m_mutex;
size_t m_maxSize;
std::queue<_BType> m_buffer;
CMutex m_mutex;
+ CCondition<bool> m_condition;
+ bool m_bHasMessages;
};
};
};
};