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 1c12e86dd05b6ec961f5521f1252ddec0712be58..4b57a29c7d340e180f04f29222eaae9d140f7802 100644
(file)
--- a/
src/lib/platform/util/buffer.h
+++ b/
src/lib/platform/util/buffer.h
@@
-2,7
+2,7
@@
/*
* This file is part of the libCEC(R) library.
*
/*
* This file is part of the libCEC(R) library.
*
- * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is Copyright (C) 2011
-2012
Pulse-Eight Limited. All rights reserved.
* libCEC(R) is an original work, containing original code.
*
* libCEC(R) is a trademark of Pulse-Eight Limited.
* libCEC(R) is an original work, containing original code.
*
* libCEC(R) is a trademark of Pulse-Eight Limited.
@@
-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
@@
-40,24
+40,34
@@
namespace PLATFORM
struct SyncedBuffer
{
public:
struct SyncedBuffer
{
public:
- SyncedBuffer(size_t iMaxSize = 100)
- {
- m_maxSize = iMaxSize;
- }
+ SyncedBuffer(size_t iMaxSize = 100) :
+ m_maxSize(iMaxSize),
+ m_bHasMessages(false) {}
virtual ~SyncedBuffer(void)
{
virtual ~SyncedBuffer(void)
{
- CLockObject lock(m_mutex, true);
Clear();
}
void Clear(void)
{
Clear();
}
void Clear(void)
{
+ CLockObject lock(m_mutex);
while (!m_buffer.empty())
m_buffer.pop();
while (!m_buffer.empty())
m_buffer.pop();
+ m_condition.Broadcast();
}
}
- size_t Size(void) const { return m_buffer.size(); }
+ size_t Size(void)
+ {
+ CLockObject lock(m_mutex);
+ return m_buffer.size();
+ }
+
+ bool IsEmpty(void)
+ {
+ CLockObject lock(m_mutex);
+ return m_buffer.empty();
+ }
bool Push(_BType entry)
{
bool Push(_BType entry)
{
@@
-66,17
+76,41
@@
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;
+ }
+
+ bool Peek(_BType &entry)
+ {
+ bool bReturn(false);
+ CLockObject lock(m_mutex);
+ if (!m_buffer.empty())
+ {
+ entry = m_buffer.front();
bReturn = true;
}
return bReturn;
bReturn = true;
}
return bReturn;
@@
-86,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;
};
};
};
};