Skip to content
Snippets Groups Projects
Commit 68f85842 authored by Benny Baumann's avatar Benny Baumann
Browse files

add: Allow to stop the event loop programmatically

parent cfbce152
No related branches found
No related tags found
1 merge request!1First unit tests
......@@ -31,7 +31,24 @@ struct stdin_waiter : std::enable_shared_from_this<stdin_waiter>
void rmrf::ev::loop() {
::ev::default_loop defloop;
auto w = std::make_shared<stdin_waiter>();
//auto w = std::make_shared<stdin_waiter>();
defloop.run(0);
}
void stop_default_loop_cb(EV_P_ ev_async* event, int) {
::ev::loop_ref defloop = ::ev::get_default_loop();
ev_async_stop(defloop, event);
defloop.break_loop();
}
void rmrf::ev::stop() {
::ev::loop_ref defloop = ::ev::get_default_loop();
// We need to use the C API directly as ev++ does not yet support asynchrounous events
ev_async stop_event;
ev_async_init(&stop_event, stop_default_loop_cb);
ev_async_start(defloop, &stop_event);
ev_async_send(defloop, &stop_event);
}
......@@ -12,5 +12,6 @@ bool init_libev();
bool init_watchdog();
void loop();
void stop();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment