Add class Timer.

This commit is contained in:
XMRig 2019-03-18 02:36:17 +07:00
parent bbf0d11a51
commit 9a6a5a94b5
13 changed files with 271 additions and 73 deletions

View file

@ -29,37 +29,31 @@
#include "base/kernel/interfaces/IWatcherListener.h"
#include "base/io/Watcher.h"
#include "base/tools/Handle.h"
#include "base/tools/Timer.h"
xmrig::Watcher::Watcher(const String &path, IWatcherListener *listener) :
m_listener(listener),
m_path(path)
{
m_timer = new Timer(this);
m_fsEvent = new uv_fs_event_t;
m_fsEvent->data = this;
uv_fs_event_init(uv_default_loop(), m_fsEvent);
m_timer = new uv_timer_t;
uv_timer_init(uv_default_loop(), m_timer);
m_fsEvent->data = m_timer->data = this;
start();
}
xmrig::Watcher::~Watcher()
{
Handle::close(m_timer);
delete m_timer;
Handle::close(m_fsEvent);
}
void xmrig::Watcher::onTimer(uv_timer_t *handle)
{
static_cast<Watcher *>(handle->data)->reload();
}
void xmrig::Watcher::onFsEvent(uv_fs_event_t *handle, const char *filename, int, int)
{
if (!filename) {
@ -72,8 +66,8 @@ void xmrig::Watcher::onFsEvent(uv_fs_event_t *handle, const char *filename, int,
void xmrig::Watcher::queueUpdate()
{
uv_timer_stop(m_timer);
uv_timer_start(m_timer, xmrig::Watcher::onTimer, kDelay, 0);
m_timer->stop();
m_timer->start(kDelay, 0);
}