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 wait_to_start();
void finished();
bool is_stopped() const;
};
thread_pool(uint32_t nof_workers);

@ -82,21 +82,22 @@ void thread_pool::init_worker(uint32_t id, worker* obj, uint32_t prio, uint32_t
void thread_pool::stop()
{
mutex_queue.lock();
/* Stop any thread waiting for available worker */
running = false;
/* Now stop all workers */
for (uint32_t i = 0; i < nof_workers; i++) {
if (workers[i]) {
debug_thread("stop(): stopping %d\n", i);
status[i] = STOP;
cvar_worker[i].notify_all();
cvar_queue.notify_all();
{
std::lock_guard<std::mutex> lock(mutex_queue);
/* Stop any thread waiting for available worker */
running = false;
/* Now stop all workers */
for (uint32_t i = 0; i < nof_workers; i++) {
if (workers[i]) {
debug_thread("stop(): stopping %d\n", i);
status[i] = STOP;
cvar_worker[i].notify_all();
cvar_queue.notify_all();
}
}
}
mutex_queue.unlock();
for (uint32_t i = 0; i < nof_workers; 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)
{
for (uint32_t i = 0; i < nof_workers; i++) {

@ -18,6 +18,7 @@
#include "srsran/common/threads.h"
#include "srsran/interfaces/enb_phy_interfaces.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.
#define ENABLE_PRACH_GUI 0
@ -88,10 +89,10 @@ private:
stack_interface_phy_lte* stack = nullptr;
float max_prach_offset_us = 0.0f;
bool initiated = false;
bool running = false;
uint32_t nof_sf = 0;
uint32_t sf_cnt = 0;
uint32_t nof_workers = 0;
std::atomic<bool> running;
uint32_t nof_sf = 0;
uint32_t sf_cnt = 0;
uint32_t nof_workers = 0;
void run_thread() final;
int run_tti(sf_buffer* b);

@ -20,6 +20,7 @@
#include "srsran/config.h"
#include "srsran/phy/channel/channel.h"
#include "srsran/radio/radio.h"
#include <atomic>
namespace srsenb {
@ -51,9 +52,9 @@ private:
// Main system TTI counter
uint32_t tti = 0;
uint32_t tx_worker_cnt = 0;
uint32_t nof_workers = 0;
bool running = false;
uint32_t tx_worker_cnt = 0;
uint32_t nof_workers = 0;
std::atomic<bool> running;
};
} // namespace srsenb

Loading…
Cancel
Save