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

master
Andre Puschmann 4 years ago
parent d8b2cfcef8
commit c1ad867824

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

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

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

Loading…
Cancel
Save