extend thread class to set unique thread name in ctor

this will also extend all classes that use srslte::thread
to specify the name of the thread in the ctor as well
as to set the name of the worker threads in the thread pool
the thread name will be displayed in gdb.
master
Andre Puschmann 6 years ago
parent 0e95867f13
commit e47010130f

@ -63,7 +63,6 @@ private:
std::string filename;
pthread_cond_t not_empty;
pthread_mutex_t mutex;
pthread_t thread;
std::deque<str_ptr> buffer;
};

@ -54,8 +54,9 @@ template<typename metrics_t>
class metrics_hub : public periodic_thread
{
public:
metrics_hub() : m(nullptr), sleep_start(std::chrono::steady_clock::now()) {}
bool init(metrics_interface<metrics_t> *m_, float report_period_secs_=1.0) {
metrics_hub() : m(nullptr), sleep_start(std::chrono::steady_clock::now()), periodic_thread("METRICS_HUB") {}
bool init(metrics_interface<metrics_t>* m_, float report_period_secs_ = 1.0)
{
m = m_;
// Start with user-default priority
start_periodic(report_period_secs_*1e6, -2);

@ -39,7 +39,9 @@
void threads_print_self();
#ifdef __cplusplus
}
}
#include <string>
#ifndef SRSLTE_THREADS_H
#define SRSLTE_THREADS_H
@ -47,20 +49,22 @@
class thread
{
public:
thread() {
_thread = 0;
}
thread(const std::string& name_) : _thread(0), name(name_) {}
bool start(int prio = -1) {
return threads_new_rt_prio(&_thread, thread_function_entry, this, prio);
}
bool start_cpu(int prio, int cpu) {
return threads_new_rt_cpu(&_thread, thread_function_entry, this, cpu, prio);
}
bool start_cpu_mask(int prio, int mask){
bool start_cpu_mask(int prio, int mask)
{
return threads_new_rt_mask(&_thread, thread_function_entry, this, mask, prio);
}
void print_priority() {
threads_print_self();
}
void print_priority() { threads_print_self(); }
void set_name(const std::string& name_)
{
name = name_;
pthread_setname_np(pthread_self(), name.c_str());
}
void wait_thread_finish() {
pthread_join(_thread, NULL);
@ -68,16 +72,25 @@ public:
void thread_cancel() {
pthread_cancel(_thread);
}
protected:
virtual void run_thread() = 0;
private:
static void *thread_function_entry(void *_this) { ((thread*) _this)->run_thread(); return NULL; }
static void* thread_function_entry(void* _this)
{
pthread_setname_np(pthread_self(), ((thread*)_this)->name.c_str());
((thread*)_this)->run_thread();
return NULL;
}
pthread_t _thread;
std::string name;
};
class periodic_thread : public thread
{
public:
periodic_thread(const std::string name_) : thread(name_) {}
void start_periodic(int period_us_, int priority = -1) {
run_enable = true;
period_us = period_us_;
@ -157,4 +170,3 @@ private:
#endif // SRSLTE_THREADS_H
#endif // __cplusplus

@ -27,12 +27,11 @@ using namespace std;
namespace srslte{
logger_file::logger_file()
:logfile(NULL)
,is_running(false)
,cur_length(0)
,max_length(0)
{}
logger_file::logger_file() : logfile(NULL), is_running(false), cur_length(0), max_length(0), thread("LOGGER_FILE")
{
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&not_empty, NULL);
}
logger_file::~logger_file() {
if(is_running) {
@ -46,9 +45,9 @@ logger_file::~logger_file() {
if (logfile) {
fclose(logfile);
}
}
pthread_mutex_destroy(&mutex);
pthread_cond_destroy(&not_empty);
}
}
void logger_file::init(std::string file, int max_length_) {

@ -30,12 +30,13 @@
namespace srslte {
thread_pool::worker::worker() : my_id(0), running(false), my_parent(NULL) {}
thread_pool::worker::worker() : my_id(0), running(false), my_parent(NULL), thread("THREAD_POOL_WORKER") {}
void thread_pool::worker::setup(uint32_t id, thread_pool *parent, uint32_t prio, uint32_t mask)
{
my_id = id;
my_parent = parent;
if(mask == 255)
{
start(prio);
@ -49,6 +50,7 @@ void thread_pool::worker::setup(uint32_t id, thread_pool *parent, uint32_t prio,
void thread_pool::worker::run_thread()
{
set_name(std::string("WORKER") + std::to_string(my_id));
running = true;
while(running) {
wait_to_start();

@ -89,7 +89,7 @@ public:
class ul_writer : public thread
{
public:
ul_writer(rlc_am* rlc_) : rlc(rlc_), running(false) {}
ul_writer(rlc_am* rlc_) : rlc(rlc_), running(false), thread("UL_WRITER") {}
~ul_writer() { stop(); }
void stop()
{

@ -109,15 +109,20 @@ class mac_dummy
,public thread
{
public:
mac_dummy(rlc_interface_mac *rlc1_, rlc_interface_mac *rlc2_, stress_test_args_t args_, uint32_t lcid_, rlc_pcap* pcap_ = NULL)
:timers(8)
,run_enable(true)
,rlc1(rlc1_)
,rlc2(rlc2_)
,args(args_)
,pcap(pcap_)
,lcid(lcid_)
,log("MAC ")
mac_dummy(rlc_interface_mac* rlc1_,
rlc_interface_mac* rlc2_,
stress_test_args_t args_,
uint32_t lcid_,
rlc_pcap* pcap_ = NULL) :
timers(8),
run_enable(true),
rlc1(rlc1_),
rlc2(rlc2_),
args(args_),
pcap(pcap_),
lcid(lcid_),
log("MAC "),
thread("MAC_DUMMY")
{
log.set_level(static_cast<LOG_LEVEL_ENUM>(args.log_level));
log.set_hex_limit(LOG_HEX_LIMIT);
@ -209,14 +214,15 @@ class rlc_tester
,public thread
{
public:
rlc_tester(rlc_interface_pdcp *rlc_, std::string name_, stress_test_args_t args_, uint32_t lcid_)
:log("Testr")
,rlc(rlc_)
,run_enable(true)
,rx_pdus()
,name(name_)
,args(args_)
,lcid(lcid_)
rlc_tester(rlc_interface_pdcp* rlc_, std::string name_, stress_test_args_t args_, uint32_t lcid_) :
log("Testr"),
rlc(rlc_),
run_enable(true),
rx_pdus(),
name(name_),
args(args_),
lcid(lcid_),
thread("RLC_TESTER")
{
log.set_level(srslte::LOG_LEVEL_ERROR);
log.set_hex_limit(LOG_HEX_LIMIT);

@ -196,7 +196,7 @@ private:
/* Class to run upper-layer timers with normal priority */
class timer_thread : public thread {
public:
timer_thread(srslte::timers *t) : ttisync(10240),timers(t),running(false) {start();}
timer_thread(srslte::timers* t) : ttisync(10240), timers(t), running(false), thread("MAC_TIMER") { start(); }
void tti_clock();
void stop();
private:

@ -33,8 +33,16 @@ namespace srsenb {
class prach_worker : thread
{
public:
prach_worker() : initiated(false), prach_nof_det(0), max_prach_offset_us(0), buffer_pool(8),
running(false), nof_sf(0), sf_cnt(0) {
prach_worker() :
initiated(false),
prach_nof_det(0),
max_prach_offset_us(0),
buffer_pool(8),
running(false),
nof_sf(0),
sf_cnt(0),
thread("PRACH_WORKER")
{
log_h = NULL;
mac = NULL;
bzero(&prach, sizeof(srslte_prach_t));

@ -71,7 +71,7 @@ private:
// Class to create
class mch_thread : public thread {
public:
mch_thread() : initiated(false), running(false), run_enable(false), pool(NULL), lcid_counter(0) {}
mch_thread() : initiated(false), running(false), run_enable(false), pool(NULL), lcid_counter(0), thread("MCH") {}
bool init(std::string m1u_multiaddr_, std::string m1u_if_addr_, pdcp_interface_gtpu *pdcp_, srslte::log *gtpu_log_);
void stop();
private:

@ -106,8 +106,8 @@ class rrc : public rrc_interface_pdcp,
public thread
{
public:
rrc() : act_monitor(this), cnotifier(NULL), running(false), nof_si_messages(0) {
rrc() : act_monitor(this), cnotifier(NULL), running(false), nof_si_messages(0), thread("RRC")
{
users.clear();
pending_paging.clear();

@ -61,6 +61,8 @@ class s1ap
,public thread
{
public:
s1ap();
~s1ap();
bool init(s1ap_args_t args_, rrc_interface_s1ap *rrc_, srslte::log *s1ap_log_);
void stop();
void get_metrics(s1ap_metrics_t &m);

@ -901,7 +901,8 @@ void mac::timer_thread::tti_clock()
* DEMUX unit
*
*******************************************************/
mac::pdu_process::pdu_process(pdu_process_handler *h) : running(false) {
mac::pdu_process::pdu_process(pdu_process_handler* h) : running(false), thread("MAC_PDU_PROCESS")
{
handler = h;
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cvar, NULL);

@ -37,7 +37,8 @@ using namespace std;
namespace srsenb {
txrx::txrx() : tx_worker_cnt(0), nof_workers(0), tti(0) {
txrx::txrx() : tx_worker_cnt(0), nof_workers(0), tti(0), thread("TXRX")
{
running = false;
radio_h = NULL;
log_h = NULL;

@ -28,7 +28,7 @@
using namespace srslte;
namespace srsenb {
gtpu::gtpu():mchthread()
gtpu::gtpu() : mchthread(), thread("GTPU")
{
pdcp = NULL;
gtpu_log = NULL;

@ -865,7 +865,7 @@ void rrc::run_thread()
Activity monitor class
*******************************************************************************/
rrc::activity_monitor::activity_monitor(rrc* parent_)
rrc::activity_monitor::activity_monitor(rrc* parent_) : thread("RRC_ACTIVITY_MONITOR")
{
running = true;
parent = parent_;

@ -38,6 +38,17 @@ using srslte::uint32_to_uint8;
namespace srsenb{
s1ap::s1ap() :
thread("S1AP"),
rrc(nullptr),
s1ap_log(nullptr),
pool(nullptr),
mme_connected(false),
running(false),
next_eNB_UE_S1AP_ID(1),
next_ue_stream_id(1){};
s1ap::~s1ap(){};
bool s1ap::init(s1ap_args_t args_, rrc_interface_s1ap *rrc_, srslte::log *s1ap_log_)
{
rrc = rrc_;

@ -39,9 +39,7 @@ pthread_mutex_t mbms_gw_instance_mutex = PTHREAD_MUTEX_INITIALIZER;
const uint16_t MBMS_GW_BUFFER_SIZE = 2500;
mbms_gw::mbms_gw():
m_running(false),
m_sgi_mb_up(false)
mbms_gw::mbms_gw() : m_running(false), m_sgi_mb_up(false), thread("MBMS_GW")
{
return;
}

@ -31,7 +31,7 @@ namespace srsepc {
mme* mme::m_instance = NULL;
pthread_mutex_t mme_instance_mutex = PTHREAD_MUTEX_INITIALIZER;
mme::mme() : m_running(false)
mme::mme() : m_running(false), thread("MME")
{
m_pool = srslte::byte_buffer_pool::get_instance();
return;

@ -31,7 +31,7 @@ namespace srsepc {
spgw* spgw::m_instance = NULL;
pthread_mutex_t spgw_instance_mutex = PTHREAD_MUTEX_INITIALIZER;
spgw::spgw() : m_running(false)
spgw::spgw() : m_running(false), thread("SPGW")
{
m_gtpc = new spgw::gtpc;
m_gtpu = new spgw::gtpu;

@ -45,7 +45,7 @@
namespace srsue {
async_scell_recv::async_scell_recv() : thread()
async_scell_recv::async_scell_recv() : thread("ASYNC_SCELL_RECV")
{
initiated = false;
buffer_write_idx = 0;

@ -42,7 +42,7 @@ using namespace asn1::rrc;
namespace srsue {
phy::phy() : workers_pool(MAX_WORKERS), workers(0), common(MAX_WORKERS), scell_sync()
phy::phy() : workers_pool(MAX_WORKERS), workers(0), common(MAX_WORKERS), scell_sync(), thread("PHY")
{
tdd_config = {};
prach_cfg = {};

@ -42,7 +42,7 @@ double callback_set_rx_gain(void *h, double gain) {
return ((sync*)h)->set_rx_gain(gain);
}
sync::sync()
sync::sync() : thread("SYNC")
{
cellsearch_earfcn_index = 0;
current_sflen = 0;
@ -1665,7 +1665,7 @@ int sync::meas_stop(uint32_t earfcn, int pci)
return -1;
}
sync::intra_measure::intra_measure() : scell()
sync::intra_measure::intra_measure() : scell(), thread("SYNC_INTRA_MEASURE")
{
rrc = NULL;

@ -37,7 +37,7 @@ using namespace asn1::rrc;
namespace srsue {
mac::mac() : timers(64), pdu_process_thread(&demux_unit), mch_msg(10), running(false), pcap(nullptr)
mac::mac() : timers(64), pdu_process_thread(&demux_unit), mch_msg(10), running(false), pcap(nullptr), thread("MAC")
{
// Create PCell HARQ entities
auto ul = ul_harq_entity_ptr(new ul_harq_entity());
@ -646,7 +646,7 @@ uint32_t mac::timer_get_unique_id()
* DEMUX unit
*
*******************************************************/
mac::pdu_process::pdu_process(demux *demux_unit_)
mac::pdu_process::pdu_process(demux* demux_unit_) : thread("MAC_PDU_PROCESS")
{
demux_unit = demux_unit_;
pthread_mutex_init(&mutex, NULL);

@ -51,7 +51,8 @@ rrc::rrc() :
last_state(RRC_STATE_CONNECTED),
drb_up(false),
rlc_flush_timeout(2000),
rlc_flush_counter(0)
rlc_flush_counter(0),
thread("RRC")
{
n310_cnt = 0;
n311_cnt = 0;

@ -69,8 +69,7 @@ namespace srsue {
#define DRB1_LCID 3
gw::gw()
:if_up(false)
gw::gw() : if_up(false), thread("GW")
{
current_ip_addr = 0;
}

Loading…
Cancel
Save