mirror of https://github.com/sipwise/sems.git
parent
200ba57bbd
commit
12317f7116
@ -0,0 +1,41 @@
|
||||
#include "SdNotify.h"
|
||||
|
||||
#include <systemd/sd-daemon.h>
|
||||
|
||||
void
|
||||
SdNotifier::ready()
|
||||
{
|
||||
std::unique_lock<std::mutex> _l(_lock);
|
||||
while (waiters)
|
||||
_cond.wait(_l);
|
||||
sd_notify(0, "READY=1");
|
||||
}
|
||||
|
||||
void
|
||||
SdNotifier::stopping()
|
||||
{
|
||||
sd_notify(0, "STOPPING=1");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SdNotifier::status(const std::string &s)
|
||||
{
|
||||
sd_notifyf(0, "STATUS=%s\n", s.c_str());
|
||||
}
|
||||
|
||||
void
|
||||
SdNotifier::waiter()
|
||||
{
|
||||
std::lock_guard<std::mutex> _l(_lock);
|
||||
waiters++;
|
||||
}
|
||||
|
||||
void
|
||||
SdNotifier::running()
|
||||
{
|
||||
std::lock_guard<std::mutex> _l(_lock);
|
||||
waiters--;
|
||||
if (!waiters)
|
||||
_cond.notify_one();
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#ifndef _SdNotify_h_
|
||||
#define _SdNotify_h_
|
||||
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
class SdNotifier
|
||||
{
|
||||
public:
|
||||
void ready();
|
||||
void stopping();
|
||||
void status(const std::string &s);
|
||||
|
||||
void waiter(); // increases waiter count by one
|
||||
void running(); // decreases waiter count by one
|
||||
|
||||
private:
|
||||
std::mutex _lock;
|
||||
std::condition_variable _cond;
|
||||
unsigned int waiters = 0;
|
||||
};
|
||||
|
||||
#endif // _SdNotify_h_
|
||||
|
Loading…
Reference in new issue