Automatic periodic status dump from controller.
This commit is contained in:
parent
ae65eb5105
commit
31785f7f6e
3 changed files with 52 additions and 52 deletions
|
@ -30,6 +30,7 @@
|
|||
#include <queue>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <chrono>
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
|
@ -58,10 +59,6 @@ public:
|
|||
c.notify_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value Value to set to next queue item if return value is true
|
||||
* @return False if stop() has been called, true otherwise
|
||||
*/
|
||||
inline bool get(T &value)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m);
|
||||
|
@ -75,6 +72,29 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
enum TimedWaitResult
|
||||
{
|
||||
OK,
|
||||
TIMED_OUT,
|
||||
STOP
|
||||
};
|
||||
|
||||
inline TimedWaitResult get(T &value,const unsigned long ms)
|
||||
{
|
||||
const std::chrono::milliseconds ms2{ms};
|
||||
std::unique_lock<std::mutex> lock(m);
|
||||
if (!r) return STOP;
|
||||
while (q.empty()) {
|
||||
if (c.wait_for(lock,ms2) == std::cv_status::timeout)
|
||||
return ((r) ? TIMED_OUT : STOP);
|
||||
else if (!r)
|
||||
return STOP;
|
||||
}
|
||||
value = q.front();
|
||||
q.pop();
|
||||
return OK;
|
||||
}
|
||||
|
||||
private:
|
||||
volatile bool r;
|
||||
std::queue<T> q;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue