use mutex or atomic in running flag to signal the interruption of a thread

master
Francisco 4 years ago committed by Francisco Paisana
parent 89628b691f
commit d02cc51e33

@ -58,6 +58,7 @@ public:
void run_thread(); void run_thread();
void wait_to_start(); void wait_to_start();
void finished(); void finished();
bool is_stopped() const;
}; };
thread_pool(uint32_t nof_workers); thread_pool(uint32_t nof_workers);

@ -82,7 +82,8 @@ void thread_pool::init_worker(uint32_t id, worker* obj, uint32_t prio, uint32_t
void thread_pool::stop() void thread_pool::stop()
{ {
mutex_queue.lock(); {
std::lock_guard<std::mutex> lock(mutex_queue);
/* Stop any thread waiting for available worker */ /* Stop any thread waiting for available worker */
running = false; running = false;
@ -96,7 +97,7 @@ void thread_pool::stop()
cvar_queue.notify_all(); cvar_queue.notify_all();
} }
} }
mutex_queue.unlock(); }
for (uint32_t i = 0; i < nof_workers; i++) { for (uint32_t i = 0; i < nof_workers; i++) {
debug_thread("stop(): waiting %d\n", i); debug_thread("stop(): waiting %d\n", i);
@ -136,6 +137,12 @@ void thread_pool::worker::finished()
} }
} }
bool thread_pool::worker::is_stopped() const
{
std::lock_guard<std::mutex> lock(my_parent->mutex_queue);
return my_parent->status[my_id] == STOP;
}
bool thread_pool::find_finished_worker(uint32_t tti, uint32_t* id) bool thread_pool::find_finished_worker(uint32_t tti, uint32_t* id)
{ {
for (uint32_t i = 0; i < nof_workers; i++) { for (uint32_t i = 0; i < nof_workers; i++) {

@ -18,6 +18,7 @@
#include "srsran/common/threads.h" #include "srsran/common/threads.h"
#include "srsran/interfaces/enb_phy_interfaces.h" #include "srsran/interfaces/enb_phy_interfaces.h"
#include "srsran/srslog/srslog.h" #include "srsran/srslog/srslog.h"
#include <atomic>
// Setting ENABLE_PRACH_GUI to non zero enables a GUI showing signal received in the PRACH window. // Setting ENABLE_PRACH_GUI to non zero enables a GUI showing signal received in the PRACH window.
#define ENABLE_PRACH_GUI 0 #define ENABLE_PRACH_GUI 0
@ -88,7 +89,7 @@ private:
stack_interface_phy_lte* stack = nullptr; stack_interface_phy_lte* stack = nullptr;
float max_prach_offset_us = 0.0f; float max_prach_offset_us = 0.0f;
bool initiated = false; bool initiated = false;
bool running = false; std::atomic<bool> running;
uint32_t nof_sf = 0; uint32_t nof_sf = 0;
uint32_t sf_cnt = 0; uint32_t sf_cnt = 0;
uint32_t nof_workers = 0; uint32_t nof_workers = 0;

@ -20,6 +20,7 @@
#include "srsran/config.h" #include "srsran/config.h"
#include "srsran/phy/channel/channel.h" #include "srsran/phy/channel/channel.h"
#include "srsran/radio/radio.h" #include "srsran/radio/radio.h"
#include <atomic>
namespace srsenb { namespace srsenb {
@ -53,7 +54,7 @@ private:
uint32_t tx_worker_cnt = 0; uint32_t tx_worker_cnt = 0;
uint32_t nof_workers = 0; uint32_t nof_workers = 0;
bool running = false; std::atomic<bool> running;
}; };
} // namespace srsenb } // namespace srsenb

Loading…
Cancel
Save