event/MaskMonitor: migrate from DeferredMonitor to DeferEvent

This commit is contained in:
Max Kellermann 2017-11-10 21:09:54 +01:00
parent 1ccd2a7b11
commit 42ad753e39
2 changed files with 17 additions and 9 deletions

View File

@ -24,11 +24,11 @@ void
MaskMonitor::OrMask(unsigned new_mask) MaskMonitor::OrMask(unsigned new_mask)
{ {
if (pending_mask.fetch_or(new_mask) == 0) if (pending_mask.fetch_or(new_mask) == 0)
DeferredMonitor::Schedule(); defer.Schedule();
} }
void void
MaskMonitor::RunDeferred() MaskMonitor::RunDeferred() noexcept
{ {
const unsigned mask = pending_mask.exchange(0); const unsigned mask = pending_mask.exchange(0);
if (mask != 0) if (mask != 0)

View File

@ -21,7 +21,7 @@
#define MPD_EVENT_MASK_MONITOR_HXX #define MPD_EVENT_MASK_MONITOR_HXX
#include "check.h" #include "check.h"
#include "DeferredMonitor.hxx" #include "DeferEvent.hxx"
#include "util/BindMethod.hxx" #include "util/BindMethod.hxx"
#include <atomic> #include <atomic>
@ -32,7 +32,9 @@
* *
* This class is thread-safe. * This class is thread-safe.
*/ */
class MaskMonitor final : DeferredMonitor { class MaskMonitor final {
DeferEvent defer;
typedef BoundMethod<void(unsigned)> Callback; typedef BoundMethod<void(unsigned)> Callback;
const Callback callback; const Callback callback;
@ -40,16 +42,22 @@ class MaskMonitor final : DeferredMonitor {
public: public:
MaskMonitor(EventLoop &_loop, Callback _callback) MaskMonitor(EventLoop &_loop, Callback _callback)
:DeferredMonitor(_loop), callback(_callback), pending_mask(0) {} :defer(_loop, BIND_THIS_METHOD(RunDeferred)),
callback(_callback), pending_mask(0) {}
using DeferredMonitor::GetEventLoop; EventLoop &GetEventLoop() {
using DeferredMonitor::Cancel; return defer.GetEventLoop();
}
void Cancel() {
defer.Cancel();
}
void OrMask(unsigned new_mask); void OrMask(unsigned new_mask);
protected: protected:
/* virtual methode from class DeferredMonitor */ /* DeferEvent callback */
void RunDeferred() override; void RunDeferred() noexcept;
}; };
#endif #endif