Properly handle SIGINT to quit.
This puts ThreadPool::join() back to being private. Eventia events now should inherit from Event, which will take care of setting up the required callbacks so that events will be notified about the main event loop stopping. Inheriting from Event is currently not enforced.
This commit is contained in:
parent
1b65162a18
commit
34040e5af1
12 changed files with 318 additions and 35 deletions
|
@ -18,6 +18,7 @@
|
|||
#include "evloop.hpp"
|
||||
#include "timer_oro_api.hpp"
|
||||
#include "eventia/eventia.hpp"
|
||||
#include "eventia/signal.hpp"
|
||||
#include "roar11/ThreadPool.hpp"
|
||||
#include "oro/api.hpp"
|
||||
#include <iostream>
|
||||
|
@ -36,10 +37,20 @@ namespace {
|
|||
// }
|
||||
//};
|
||||
|
||||
void join(roar11::ThreadPool& pool) {
|
||||
pool.join();
|
||||
std::cout << "all tasks completed\n";
|
||||
}
|
||||
class SignalInt : public eve::Signal {
|
||||
public:
|
||||
SignalInt (const eve::Context& ctx, eve::Eventia* even) :
|
||||
eve::Signal(SIGINT, ctx),
|
||||
m_eventia(even)
|
||||
{ }
|
||||
|
||||
virtual void on_signal() override {
|
||||
m_eventia->stop();
|
||||
}
|
||||
|
||||
private:
|
||||
eve::Eventia* m_eventia;
|
||||
};
|
||||
|
||||
} //unnamed namespace
|
||||
|
||||
|
@ -54,11 +65,14 @@ void test(oro::Api* api, oro::OriginsDB* db, std::size_t thread_count) {
|
|||
eve::Eventia worker;
|
||||
pool.submit(worker.event_functor());
|
||||
|
||||
auto timer_items = worker.make_timer<TimerItems>(0.5, &pool, api, db);
|
||||
auto timer_icons = worker.make_timer<TimerIcons>(1.0, &pool, api, db);
|
||||
auto timer_shops = worker.make_timer<TimerShops>(1.5, &pool, api, db);
|
||||
auto timer_creat = worker.make_timer<TimerCreators>(2.0, &pool, api, db);
|
||||
auto sig_int = worker.make_event<SignalInt>(&worker);
|
||||
|
||||
join(pool);
|
||||
auto timer_items = worker.make_event<TimerItems>(0.5, &pool, api, db);
|
||||
auto timer_icons = worker.make_event<TimerIcons>(1.0, &pool, api, db);
|
||||
auto timer_shops = worker.make_event<TimerShops>(1.5, &pool, api, db);
|
||||
auto timer_creat = worker.make_event<TimerCreators>(2.0, &pool, api, db);
|
||||
|
||||
worker.wait();
|
||||
std::cout << "all tasks completed\n";
|
||||
}
|
||||
} //namespace duck
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue