epoll_helper: use std::atomic to protect exit called from different thread

This commit is contained in:
Andre Puschmann 2021-05-18 12:40:58 +02:00
parent d8b2cfcef8
commit c1ad867824
3 changed files with 8 additions and 6 deletions

View File

@ -17,6 +17,7 @@
#ifndef SRSRAN_EPOLL_HELPER_H
#define SRSRAN_EPOLL_HELPER_H
#include <atomic>
#include <functional>
#include <signal.h>
#include <sys/epoll.h>
@ -58,7 +59,7 @@ private:
class epoll_signal_handler : public epoll_handler
{
public:
epoll_signal_handler(bool* running_) : running(running_) {}
epoll_signal_handler(std::atomic<bool>& running_) : running(running_) {}
int handle_event(int fd, epoll_event e, int epoll_fd)
{
@ -72,7 +73,7 @@ public:
case SIGINT:
case SIGHUP:
case SIGQUIT:
*running = false;
running = false;
break;
default:
fprintf(stderr, "got signal %d\n", info.ssi_signo);
@ -82,7 +83,7 @@ public:
}
private:
bool* running = nullptr;
std::atomic<bool>& running;
};
///< Create periodic epoll timer every 1ms

View File

@ -25,6 +25,7 @@
#include "ttcn3_sys_interface.h"
#include "ttcn3_ue.h"
#include "ttcn3_ut_interface.h"
#include <atomic>
#include <functional>
class ttcn3_syssim : public syssim_interface_phy,
@ -223,8 +224,8 @@ private:
all_args_t args = {};
// Simulator vars
ttcn3_ue* ue = nullptr;
bool running = false;
ttcn3_ue* ue = nullptr;
std::atomic<bool> running = {false};
typedef enum { UE_SWITCH_ON = 0, UE_SWITCH_OFF, ENABLE_DATA, DISABLE_DATA } ss_events_t;
block_queue<ss_events_t> event_queue;

View File

@ -49,7 +49,7 @@ ttcn3_syssim::ttcn3_syssim(ttcn3_ue* ue_) :
mac_msg_dl(20, ss_mac_logger),
pdus(logger),
ue(ue_),
signal_handler(&running),
signal_handler(running),
timer_handler(create_tti_timer(), [&](uint64_t res) { new_tti_indication(res); })
{
if (ue->init(all_args_t{}, this, "INIT_TEST") != SRSRAN_SUCCESS) {