db/update/InotifyQueue: migrate from TimeoutMonitor to TimerEvent

This commit is contained in:
Max Kellermann 2017-08-29 16:38:50 +02:00
parent 91d4b5cfed
commit dc531b64ae
2 changed files with 10 additions and 8 deletions

View File

@ -33,7 +33,7 @@ static constexpr std::chrono::steady_clock::duration INOTIFY_UPDATE_DELAY =
std::chrono::seconds(5); std::chrono::seconds(5);
void void
InotifyQueue::OnTimeout() InotifyQueue::OnDelay()
{ {
unsigned id; unsigned id;
@ -43,7 +43,7 @@ InotifyQueue::OnTimeout()
id = update.Enqueue(uri_utf8, false); id = update.Enqueue(uri_utf8, false);
if (id == 0) { if (id == 0) {
/* retry later */ /* retry later */
Schedule(INOTIFY_UPDATE_DELAY); delay_event.Schedule(INOTIFY_UPDATE_DELAY);
return; return;
} }
@ -69,7 +69,7 @@ path_in(const char *path, const char *possible_parent) noexcept
void void
InotifyQueue::Enqueue(const char *uri_utf8) InotifyQueue::Enqueue(const char *uri_utf8)
{ {
Schedule(INOTIFY_UPDATE_DELAY); delay_event.Schedule(INOTIFY_UPDATE_DELAY);
for (auto i = queue.begin(), end = queue.end(); i != end;) { for (auto i = queue.begin(), end = queue.end(); i != end;) {
const char *current_uri = i->c_str(); const char *current_uri = i->c_str();

View File

@ -20,27 +20,29 @@
#ifndef MPD_INOTIFY_QUEUE_HXX #ifndef MPD_INOTIFY_QUEUE_HXX
#define MPD_INOTIFY_QUEUE_HXX #define MPD_INOTIFY_QUEUE_HXX
#include "event/TimeoutMonitor.hxx" #include "event/TimerEvent.hxx"
#include "Compiler.h"
#include <list> #include <list>
#include <string> #include <string>
class UpdateService; class UpdateService;
class InotifyQueue final : private TimeoutMonitor { class InotifyQueue final {
UpdateService &update; UpdateService &update;
std::list<std::string> queue; std::list<std::string> queue;
TimerEvent delay_event;
public: public:
InotifyQueue(EventLoop &_loop, UpdateService &_update) InotifyQueue(EventLoop &_loop, UpdateService &_update)
:TimeoutMonitor(_loop), update(_update) {} :update(_update),
delay_event(_loop, BIND_THIS_METHOD(OnDelay)) {}
void Enqueue(const char *uri_utf8); void Enqueue(const char *uri_utf8);
private: private:
virtual void OnTimeout() override; void OnDelay();
}; };
#endif #endif