event/DeferredMonitor: use EventLoop::AddIdle()
This commit is contained in:
parent
fdc7d13ad1
commit
977004c350
@ -33,6 +33,9 @@
|
|||||||
|
|
||||||
namespace GlobalEvents {
|
namespace GlobalEvents {
|
||||||
class Monitor final : public DeferredMonitor {
|
class Monitor final : public DeferredMonitor {
|
||||||
|
public:
|
||||||
|
Monitor(EventLoop &_loop):DeferredMonitor(_loop) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Run() override;
|
virtual void Run() override;
|
||||||
};
|
};
|
||||||
@ -67,9 +70,9 @@ GlobalEvents::Monitor::Run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalEvents::Initialize()
|
GlobalEvents::Initialize(EventLoop &loop)
|
||||||
{
|
{
|
||||||
monitor.Construct();
|
monitor.Construct(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class EventLoop;
|
||||||
|
|
||||||
namespace GlobalEvents {
|
namespace GlobalEvents {
|
||||||
enum Event {
|
enum Event {
|
||||||
/** database update was finished */
|
/** database update was finished */
|
||||||
@ -59,7 +61,7 @@ namespace GlobalEvents {
|
|||||||
|
|
||||||
typedef void (*Handler)();
|
typedef void (*Handler)();
|
||||||
|
|
||||||
void Initialize();
|
void Initialize(EventLoop &loop);
|
||||||
|
|
||||||
void Deinitialize();
|
void Deinitialize();
|
||||||
|
|
||||||
|
@ -438,7 +438,7 @@ int mpd_main(int argc, char *argv[])
|
|||||||
|
|
||||||
daemonize_set_user();
|
daemonize_set_user();
|
||||||
|
|
||||||
GlobalEvents::Initialize();
|
GlobalEvents::Initialize(*main_loop);
|
||||||
GlobalEvents::Register(GlobalEvents::IDLE, idle_event_emitted);
|
GlobalEvents::Register(GlobalEvents::IDLE, idle_event_emitted);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
GlobalEvents::Register(GlobalEvents::SHUTDOWN, shutdown_event_emitted);
|
GlobalEvents::Register(GlobalEvents::SHUTDOWN, shutdown_event_emitted);
|
||||||
|
@ -32,7 +32,7 @@ DeferredMonitor::Cancel()
|
|||||||
void
|
void
|
||||||
DeferredMonitor::Schedule()
|
DeferredMonitor::Schedule()
|
||||||
{
|
{
|
||||||
const unsigned id = g_idle_add(Callback, this);
|
const unsigned id = loop.AddIdle(Callback, this);
|
||||||
const auto old_id = source_id.exchange(id);
|
const auto old_id = source_id.exchange(id);
|
||||||
if (old_id != 0)
|
if (old_id != 0)
|
||||||
g_source_remove(old_id);
|
g_source_remove(old_id);
|
||||||
|
@ -26,15 +26,19 @@
|
|||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
|
class EventLoop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defer execution of an event into an #EventLoop.
|
* Defer execution of an event into an #EventLoop.
|
||||||
*/
|
*/
|
||||||
class DeferredMonitor {
|
class DeferredMonitor {
|
||||||
|
EventLoop &loop;
|
||||||
|
|
||||||
std::atomic<guint> source_id;
|
std::atomic<guint> source_id;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DeferredMonitor()
|
DeferredMonitor(EventLoop &_loop)
|
||||||
:source_id(0) {}
|
:loop(_loop), source_id(0) {}
|
||||||
|
|
||||||
~DeferredMonitor() {
|
~DeferredMonitor() {
|
||||||
Cancel();
|
Cancel();
|
||||||
|
Loading…
Reference in New Issue
Block a user