Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
split a piece of src/mc/ModelChecker.cpp into src/mc/remote/EventLoop.cpp
[simgrid.git] / src / mc / remote / EventLoop.cpp
1 /* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "src/mc/remote/EventLoop.hpp"
7 #include <sys/wait.h>
8
9 simgrid::mc::EventLoop::~EventLoop()
10 {
11   if (socket_event_ != nullptr)
12     event_free(socket_event_);
13   if (signal_event_ != nullptr)
14     event_free(signal_event_);
15   if (base_ != nullptr)
16     event_base_free(base_);
17 }
18
19 void simgrid::mc::EventLoop::start(int socket, void (*handler)(int, short, void*))
20 {
21   base_ = event_base_new();
22
23   socket_event_ = event_new(base_, socket, EV_READ | EV_PERSIST, handler, this);
24   event_add(socket_event_, NULL);
25
26   signal_event_ = event_new(base_, SIGCHLD, EV_SIGNAL | EV_PERSIST, handler, this);
27   event_add(signal_event_, NULL);
28 }
29
30 void simgrid::mc::EventLoop::dispatch()
31 {
32   event_base_dispatch(base_);
33 }
34
35 void simgrid::mc::EventLoop::break_loop()
36 {
37   event_base_loopbreak(base_);
38 }