diff --git a/src/eventia/eventia.cpp b/src/eventia/eventia.cpp index e8d0356..80e62d9 100644 --- a/src/eventia/eventia.cpp +++ b/src/eventia/eventia.cpp @@ -19,7 +19,7 @@ namespace { } } //unnamed namespace -struct EvThreadPool::LocalData { +struct Eventia::LocalData { LocalData(); std::mutex ev_mutex; @@ -28,36 +28,36 @@ struct EvThreadPool::LocalData { Context context; }; -EvThreadPool::LocalData::LocalData() : +Eventia::LocalData::LocalData() : loop(ev::AUTO), context{ &loop, &ev_mutex, &async } { } -EvThreadPool::EvThreadPool() : +Eventia::Eventia() : m_local(std::make_unique()) { assert(nullptr == ev_userdata(m_local->loop)); m_local->async.set(m_local->loop); - m_local->async.set(this); + m_local->async.set(this); m_local->async.start(); ev_set_userdata(m_local->loop, &m_local->context); ev_set_loop_release_cb(m_local->loop, &eve::unlock_mutex_libev, &eve::lock_mutex_libev); } -EvThreadPool::~EvThreadPool() noexcept = default; +Eventia::~Eventia() noexcept = default; -std::function EvThreadPool::event_functor() { +std::function Eventia::event_functor() { return std::function([this]() { std::unique_lock lock(m_local->ev_mutex); m_local->loop.run(0); }); } -void EvThreadPool::do_nothing() { +void Eventia::do_nothing() { } -void EvThreadPool::lock_mutex_libev() noexcept { +void Eventia::lock_mutex_libev() noexcept { try { m_local->ev_mutex.lock(); } @@ -67,11 +67,11 @@ void EvThreadPool::lock_mutex_libev() noexcept { } } -void EvThreadPool::unlock_mutex_libev() noexcept { +void Eventia::unlock_mutex_libev() noexcept { m_local->ev_mutex.unlock(); } -const Context& EvThreadPool::context() { +const Context& Eventia::context() { return m_local->context; } diff --git a/src/eventia/eventia.hpp b/src/eventia/eventia.hpp index 665e62b..d63ed1b 100644 --- a/src/eventia/eventia.hpp +++ b/src/eventia/eventia.hpp @@ -7,11 +7,11 @@ namespace eve { class Context; -class EvThreadPool { +class Eventia { friend class EvTimerTask; public: - EvThreadPool(); - ~EvThreadPool() noexcept; + Eventia(); + ~Eventia() noexcept; std::function event_functor(); void do_nothing(); diff --git a/src/eventia/timer.cpp b/src/eventia/timer.cpp index 90eea3c..61854eb 100644 --- a/src/eventia/timer.cpp +++ b/src/eventia/timer.cpp @@ -7,37 +7,37 @@ namespace eve { -struct EvTimerTask::LocalData { +struct Timer::LocalData { explicit LocalData (const Context& ctx); ev::timer timer; Context context; }; -EvTimerTask::LocalData::LocalData (const Context& ctx) : +Timer::LocalData::LocalData (const Context& ctx) : context(ctx) { } -EvTimerTask::EvTimerTask (double delay, const Context& ctx) : +Timer::Timer (double delay, const Context& ctx) : m_local(std::make_unique(ctx)) { assert(m_local->context.ev_mutex); m_local->timer.set(*m_local->context.loop); - m_local->timer.set(this); + m_local->timer.set(this); this->set_timer(delay); } -EvTimerTask::~EvTimerTask() noexcept = default; +Timer::~Timer() noexcept = default; -void EvTimerTask::on_timer_ev() { - std::cout << "EvTimerTask::on_timer_ev()\n"; +void Timer::on_timer_ev() { + std::cout << "Timer::on_timer_ev()\n"; m_local->timer.stop(); this->on_timer(); } -void EvTimerTask::set_timer (double delay) { +void Timer::set_timer (double delay) { std::unique_lock lock(*m_local->context.ev_mutex); ev_now_update(*m_local->context.loop); m_local->timer.start(delay, 0.0); diff --git a/src/eventia/timer.hpp b/src/eventia/timer.hpp index d148deb..3fc2a03 100644 --- a/src/eventia/timer.hpp +++ b/src/eventia/timer.hpp @@ -6,13 +6,12 @@ namespace eve { class Context; -class EvTimerTask { +class Timer { public: - EvTimerTask (double delay, const Context& ctx); - virtual ~EvTimerTask() noexcept; + Timer (double delay, const Context& ctx); + virtual ~Timer() noexcept; virtual void on_timer() = 0; - //RunningPool::subpool_type& subflow(); protected: void set_timer (double delay); diff --git a/src/evloop.cpp b/src/evloop.cpp index 4bd211e..4a5de03 100644 --- a/src/evloop.cpp +++ b/src/evloop.cpp @@ -61,7 +61,7 @@ void join(threadpool_type& pool) { void test() { roar11::ThreadPool pool(std::max(2U, std::thread::hardware_concurrency()) - 1); - eve::EvThreadPool worker; + eve::Eventia worker; pool.submit(worker.event_functor()); std::cout << "Instantiating html timer\n"; diff --git a/src/html_fetch_task.hpp b/src/html_fetch_task.hpp index 338439d..3376f20 100644 --- a/src/html_fetch_task.hpp +++ b/src/html_fetch_task.hpp @@ -11,12 +11,12 @@ namespace duck { auto time_rand = std::bind(std::uniform_int_distribution(2, 8), std::mt19937(std::time(0))); - class HtmlFetchTimer : public eve::EvTimerTask { + class HtmlFetchTimer : public eve::Timer { public: HtmlFetchTimer (HtmlFetchTimer&&) = default; HtmlFetchTimer (const HtmlFetchTimer&) = delete; HtmlFetchTimer (const eve::Context& ctx, roar11::ThreadPool* pool, std::string&& url) : - EvTimerTask(3.0, ctx), + eve::Timer(3.0, ctx), m_url(std::move(url)), m_pool(pool) {