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