From a8bbe551ac08a385c79351d6a89093e0c702fb78 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 17 Feb 2020 22:12:02 +0100 Subject: [PATCH] move thread class into srslte namespace to avoid ambiguity between std::thread --- lib/include/srslte/common/netsource_handler.h | 2 +- lib/include/srslte/common/threads.h | 28 +++++++++++++++++-- lib/src/common/test/thread_test.cc | 2 +- srsenb/hdr/phy/prach_worker.h | 2 +- srsenb/hdr/phy/txrx.h | 2 +- srsenb/hdr/stack/enb_stack_lte.h | 2 +- srsepc/hdr/mbms-gw/mbms-gw.h | 2 +- srsepc/hdr/mme/mme.h | 2 +- srsepc/hdr/spgw/spgw.h | 2 +- srsue/hdr/phy/phy.h | 2 +- srsue/hdr/phy/scell/async_scell_recv.h | 2 +- srsue/hdr/phy/scell/intra_measure.h | 2 +- srsue/hdr/phy/sync.h | 2 +- srsue/hdr/stack/ue_stack_lte.h | 2 +- srsue/hdr/stack/upper/gw.h | 2 +- srsue/test/phy/ue_phy_test.cc | 2 +- 16 files changed, 40 insertions(+), 18 deletions(-) diff --git a/lib/include/srslte/common/netsource_handler.h b/lib/include/srslte/common/netsource_handler.h index ba6a383f4..4bf94b6f8 100644 --- a/lib/include/srslte/common/netsource_handler.h +++ b/lib/include/srslte/common/netsource_handler.h @@ -34,7 +34,7 @@ #include #include -class netsource_handler : public thread +class netsource_handler : public srslte::thread { public: netsource_handler(const std::string name_) : thread(name_) { rx_buf = unique_byte_array_t(new byte_array_t); } diff --git a/lib/include/srslte/common/threads.h b/lib/include/srslte/common/threads.h index d931814e5..bad3f2897 100644 --- a/lib/include/srslte/common/threads.h +++ b/lib/include/srslte/common/threads.h @@ -46,11 +46,16 @@ void threads_print_self(); #include +namespace srslte { +; + class thread { public: thread(const std::string& name_) : _thread(0), name(name_) {} + thread(const thread&) = delete; + thread(thread&& other) noexcept { _thread = other._thread; @@ -58,21 +63,30 @@ public: other._thread = 0; other.name = ""; } + thread& operator=(const thread&) = delete; + thread& operator=(thread&&) noexcept = delete; - 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(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) { return threads_new_rt_mask(&_thread, thread_function_entry, this, mask, prio); } + 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); } + void thread_cancel() { pthread_cancel(_thread); } static std::string get_name() @@ -96,6 +110,7 @@ private: ((thread*)_this)->run_thread(); return NULL; } + pthread_t _thread; std::string name; }; @@ -104,12 +119,14 @@ 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_; start(priority); } + void stop_thread() { run_enable = false; @@ -124,6 +141,7 @@ private: int timer_fd; int period_us; bool run_enable; + void run_thread() { if (make_periodic()) { @@ -136,6 +154,7 @@ private: } } } + int make_periodic() { int ret = -1; @@ -164,6 +183,7 @@ private: } return ret; } + void wait_period() { unsigned long long missed; @@ -184,6 +204,8 @@ private: } }; +} // namespace srslte + #endif // __cplusplus #endif // SRSLTE_THREADS_H diff --git a/lib/src/common/test/thread_test.cc b/lib/src/common/test/thread_test.cc index 60e588928..6964fe79b 100644 --- a/lib/src/common/test/thread_test.cc +++ b/lib/src/common/test/thread_test.cc @@ -22,7 +22,7 @@ #include #include -class thread_test : public thread +class thread_test : public srslte::thread { public: thread_test() : thread("Thread Test") {} diff --git a/srsenb/hdr/phy/prach_worker.h b/srsenb/hdr/phy/prach_worker.h index 506934ca9..bc5dfdc4c 100644 --- a/srsenb/hdr/phy/prach_worker.h +++ b/srsenb/hdr/phy/prach_worker.h @@ -30,7 +30,7 @@ namespace srsenb { -class prach_worker : thread +class prach_worker : srslte::thread { public: prach_worker(uint32_t cc_idx_) : buffer_pool(8), thread("PRACH_WORKER") { cc_idx = cc_idx_; } diff --git a/srsenb/hdr/phy/txrx.h b/srsenb/hdr/phy/txrx.h index 28a8eb106..62c305ffb 100644 --- a/srsenb/hdr/phy/txrx.h +++ b/srsenb/hdr/phy/txrx.h @@ -34,7 +34,7 @@ namespace srsenb { typedef _Complex float cf_t; -class txrx : public thread +class txrx : public srslte::thread { public: txrx(); diff --git a/srsenb/hdr/stack/enb_stack_lte.h b/srsenb/hdr/stack/enb_stack_lte.h index 9c4431480..606c40c31 100644 --- a/srsenb/hdr/stack/enb_stack_lte.h +++ b/srsenb/hdr/stack/enb_stack_lte.h @@ -48,7 +48,7 @@ class enb_stack_lte final : public enb_stack_base, public stack_interface_s1ap_lte, public stack_interface_gtpu_lte, public stack_interface_mac_lte, - public thread + public srslte::thread { public: enb_stack_lte(srslte::logger* logger_); diff --git a/srsepc/hdr/mbms-gw/mbms-gw.h b/srsepc/hdr/mbms-gw/mbms-gw.h index 6339e0e95..178e3a8e1 100644 --- a/srsepc/hdr/mbms-gw/mbms-gw.h +++ b/srsepc/hdr/mbms-gw/mbms-gw.h @@ -59,7 +59,7 @@ struct pseudo_hdr { uint16_t udp_len; }; -class mbms_gw : public thread +class mbms_gw : public srslte::thread { public: static mbms_gw* get_instance(void); diff --git a/srsepc/hdr/mme/mme.h b/srsepc/hdr/mme/mme.h index ef9fd6d00..a6704c2aa 100644 --- a/srsepc/hdr/mme/mme.h +++ b/srsepc/hdr/mme/mme.h @@ -50,7 +50,7 @@ typedef struct { enum nas_timer_type type; } mme_timer_t; -class mme : public thread, public mme_interface_nas +class mme : public srslte::thread, public mme_interface_nas { public: static mme* get_instance(void); diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index a44dcecc8..5dbab3364 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -62,7 +62,7 @@ typedef struct spgw_tunnel_ctx { std::queue paging_queue; } spgw_tunnel_ctx_t; -class spgw : public thread +class spgw : public srslte::thread { class gtpc; class gtpu; diff --git a/srsue/hdr/phy/phy.h b/srsue/hdr/phy/phy.h index 9ba218a22..b7e373ecd 100644 --- a/srsue/hdr/phy/phy.h +++ b/srsue/hdr/phy/phy.h @@ -40,7 +40,7 @@ namespace srsue { typedef _Complex float cf_t; -class phy : public ue_lte_phy_base, public thread +class phy : public ue_lte_phy_base, public srslte::thread { public: explicit phy(srslte::logger* logger_) : logger(logger_), workers_pool(MAX_WORKERS), common(), thread("PHY"){}; diff --git a/srsue/hdr/phy/scell/async_scell_recv.h b/srsue/hdr/phy/scell/async_scell_recv.h index 33d6e5cb5..8c8ca21a0 100644 --- a/srsue/hdr/phy/scell/async_scell_recv.h +++ b/srsue/hdr/phy/scell/async_scell_recv.h @@ -34,7 +34,7 @@ namespace scell { #define SF_BUFFER_MAX_SAMPLES (5 * SRSLTE_SF_LEN_MAX) -class async_scell_recv : private thread +class async_scell_recv : private srslte::thread { public: async_scell_recv(); diff --git a/srsue/hdr/phy/scell/intra_measure.h b/srsue/hdr/phy/scell/intra_measure.h index 8b101b7ec..78f13fa81 100644 --- a/srsue/hdr/phy/scell/intra_measure.h +++ b/srsue/hdr/phy/scell/intra_measure.h @@ -32,7 +32,7 @@ namespace srsue { namespace scell { // Class to perform intra-frequency measurements -class intra_measure : public thread +class intra_measure : public srslte::thread { /* * The intra-cell measurment has 5 different states: diff --git a/srsue/hdr/phy/sync.h b/srsue/hdr/phy/sync.h index 1128c51ad..a2d97a9be 100644 --- a/srsue/hdr/phy/sync.h +++ b/srsue/hdr/phy/sync.h @@ -45,7 +45,7 @@ namespace srsue { typedef _Complex float cf_t; -class sync : public thread, public chest_feedback_itf +class sync : public srslte::thread, public chest_feedback_itf { public: sync() : thread("SYNC"){}; diff --git a/srsue/hdr/stack/ue_stack_lte.h b/srsue/hdr/stack/ue_stack_lte.h index 1fb3b1e9c..4f293b6ab 100644 --- a/srsue/hdr/stack/ue_stack_lte.h +++ b/srsue/hdr/stack/ue_stack_lte.h @@ -56,7 +56,7 @@ class ue_stack_lte final : public ue_stack_base, public stack_interface_mac, public stack_interface_rrc, public task_handler_interface_lte, - public thread + public srslte::thread { public: ue_stack_lte(); diff --git a/srsue/hdr/stack/upper/gw.h b/srsue/hdr/stack/upper/gw.h index df2c3746b..fef831a38 100644 --- a/srsue/hdr/stack/upper/gw.h +++ b/srsue/hdr/stack/upper/gw.h @@ -46,7 +46,7 @@ struct gw_args_t { std::string tun_dev_netmask; }; -class gw : public gw_interface_stack, public thread +class gw : public gw_interface_stack, public srslte::thread { public: gw(); diff --git a/srsue/test/phy/ue_phy_test.cc b/srsue/test/phy/ue_phy_test.cc index 68aeba4a3..f868383dd 100644 --- a/srsue/test/phy/ue_phy_test.cc +++ b/srsue/test/phy/ue_phy_test.cc @@ -58,7 +58,7 @@ private: received_##NAME = true; \ } -class phy_test_bench : public thread +class phy_test_bench : public srslte::thread { private: // Dummy classes