Rename classes
This commit is contained in:
parent
7fb055cd40
commit
9df60f074b
6 changed files with 27 additions and 28 deletions
|
@ -19,7 +19,7 @@ namespace {
|
||||||
}
|
}
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
struct EvThreadPool::LocalData {
|
struct Eventia::LocalData {
|
||||||
LocalData();
|
LocalData();
|
||||||
|
|
||||||
std::mutex ev_mutex;
|
std::mutex ev_mutex;
|
||||||
|
@ -28,36 +28,36 @@ struct EvThreadPool::LocalData {
|
||||||
Context context;
|
Context context;
|
||||||
};
|
};
|
||||||
|
|
||||||
EvThreadPool::LocalData::LocalData() :
|
Eventia::LocalData::LocalData() :
|
||||||
loop(ev::AUTO),
|
loop(ev::AUTO),
|
||||||
context{ &loop, &ev_mutex, &async }
|
context{ &loop, &ev_mutex, &async }
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
EvThreadPool::EvThreadPool() :
|
Eventia::Eventia() :
|
||||||
m_local(std::make_unique<LocalData>())
|
m_local(std::make_unique<LocalData>())
|
||||||
{
|
{
|
||||||
assert(nullptr == ev_userdata(m_local->loop));
|
assert(nullptr == ev_userdata(m_local->loop));
|
||||||
m_local->async.set(m_local->loop);
|
m_local->async.set(m_local->loop);
|
||||||
m_local->async.set<EvThreadPool, &EvThreadPool::do_nothing>(this);
|
m_local->async.set<Eventia, &Eventia::do_nothing>(this);
|
||||||
m_local->async.start();
|
m_local->async.start();
|
||||||
ev_set_userdata(m_local->loop, &m_local->context);
|
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);
|
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<void()> EvThreadPool::event_functor() {
|
std::function<void()> Eventia::event_functor() {
|
||||||
return std::function<void()>([this]() {
|
return std::function<void()>([this]() {
|
||||||
std::unique_lock<std::mutex> lock(m_local->ev_mutex);
|
std::unique_lock<std::mutex> lock(m_local->ev_mutex);
|
||||||
m_local->loop.run(0);
|
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 {
|
try {
|
||||||
m_local->ev_mutex.lock();
|
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();
|
m_local->ev_mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Context& EvThreadPool::context() {
|
const Context& Eventia::context() {
|
||||||
return m_local->context;
|
return m_local->context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,11 @@ namespace eve {
|
||||||
|
|
||||||
class Context;
|
class Context;
|
||||||
|
|
||||||
class EvThreadPool {
|
class Eventia {
|
||||||
friend class EvTimerTask;
|
friend class EvTimerTask;
|
||||||
public:
|
public:
|
||||||
EvThreadPool();
|
Eventia();
|
||||||
~EvThreadPool() noexcept;
|
~Eventia() noexcept;
|
||||||
|
|
||||||
std::function<void()> event_functor();
|
std::function<void()> event_functor();
|
||||||
void do_nothing();
|
void do_nothing();
|
||||||
|
|
|
@ -7,37 +7,37 @@
|
||||||
|
|
||||||
namespace eve {
|
namespace eve {
|
||||||
|
|
||||||
struct EvTimerTask::LocalData {
|
struct Timer::LocalData {
|
||||||
explicit LocalData (const Context& ctx);
|
explicit LocalData (const Context& ctx);
|
||||||
|
|
||||||
ev::timer timer;
|
ev::timer timer;
|
||||||
Context context;
|
Context context;
|
||||||
};
|
};
|
||||||
|
|
||||||
EvTimerTask::LocalData::LocalData (const Context& ctx) :
|
Timer::LocalData::LocalData (const Context& ctx) :
|
||||||
context(ctx)
|
context(ctx)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
EvTimerTask::EvTimerTask (double delay, const Context& ctx) :
|
Timer::Timer (double delay, const Context& ctx) :
|
||||||
m_local(std::make_unique<LocalData>(ctx))
|
m_local(std::make_unique<LocalData>(ctx))
|
||||||
{
|
{
|
||||||
assert(m_local->context.ev_mutex);
|
assert(m_local->context.ev_mutex);
|
||||||
|
|
||||||
m_local->timer.set(*m_local->context.loop);
|
m_local->timer.set(*m_local->context.loop);
|
||||||
m_local->timer.set<EvTimerTask, &EvTimerTask::on_timer_ev>(this);
|
m_local->timer.set<Timer, &Timer::on_timer_ev>(this);
|
||||||
this->set_timer(delay);
|
this->set_timer(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
EvTimerTask::~EvTimerTask() noexcept = default;
|
Timer::~Timer() noexcept = default;
|
||||||
|
|
||||||
void EvTimerTask::on_timer_ev() {
|
void Timer::on_timer_ev() {
|
||||||
std::cout << "EvTimerTask::on_timer_ev()\n";
|
std::cout << "Timer::on_timer_ev()\n";
|
||||||
m_local->timer.stop();
|
m_local->timer.stop();
|
||||||
this->on_timer();
|
this->on_timer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvTimerTask::set_timer (double delay) {
|
void Timer::set_timer (double delay) {
|
||||||
std::unique_lock<std::mutex> lock(*m_local->context.ev_mutex);
|
std::unique_lock<std::mutex> lock(*m_local->context.ev_mutex);
|
||||||
ev_now_update(*m_local->context.loop);
|
ev_now_update(*m_local->context.loop);
|
||||||
m_local->timer.start(delay, 0.0);
|
m_local->timer.start(delay, 0.0);
|
||||||
|
|
|
@ -6,13 +6,12 @@ namespace eve {
|
||||||
|
|
||||||
class Context;
|
class Context;
|
||||||
|
|
||||||
class EvTimerTask {
|
class Timer {
|
||||||
public:
|
public:
|
||||||
EvTimerTask (double delay, const Context& ctx);
|
Timer (double delay, const Context& ctx);
|
||||||
virtual ~EvTimerTask() noexcept;
|
virtual ~Timer() noexcept;
|
||||||
|
|
||||||
virtual void on_timer() = 0;
|
virtual void on_timer() = 0;
|
||||||
//RunningPool::subpool_type& subflow();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void set_timer (double delay);
|
void set_timer (double delay);
|
||||||
|
|
|
@ -61,7 +61,7 @@ void join(threadpool_type& pool) {
|
||||||
|
|
||||||
void test() {
|
void test() {
|
||||||
roar11::ThreadPool pool(std::max(2U, std::thread::hardware_concurrency()) - 1);
|
roar11::ThreadPool pool(std::max(2U, std::thread::hardware_concurrency()) - 1);
|
||||||
eve::EvThreadPool worker;
|
eve::Eventia worker;
|
||||||
pool.submit(worker.event_functor());
|
pool.submit(worker.event_functor());
|
||||||
|
|
||||||
std::cout << "Instantiating html timer\n";
|
std::cout << "Instantiating html timer\n";
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
namespace duck {
|
namespace duck {
|
||||||
auto time_rand = std::bind(std::uniform_int_distribution<int>(2, 8), std::mt19937(std::time(0)));
|
auto time_rand = std::bind(std::uniform_int_distribution<int>(2, 8), std::mt19937(std::time(0)));
|
||||||
|
|
||||||
class HtmlFetchTimer : public eve::EvTimerTask {
|
class HtmlFetchTimer : public eve::Timer {
|
||||||
public:
|
public:
|
||||||
HtmlFetchTimer (HtmlFetchTimer&&) = default;
|
HtmlFetchTimer (HtmlFetchTimer&&) = default;
|
||||||
HtmlFetchTimer (const HtmlFetchTimer&) = delete;
|
HtmlFetchTimer (const HtmlFetchTimer&) = delete;
|
||||||
HtmlFetchTimer (const eve::Context& ctx, roar11::ThreadPool* pool, std::string&& url) :
|
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_url(std::move(url)),
|
||||||
m_pool(pool)
|
m_pool(pool)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue