diff --git a/srsenb/hdr/stack/mac/sched.h b/srsenb/hdr/stack/mac/sched.h index 9e4b40f17..3264b9e57 100644 --- a/srsenb/hdr/stack/mac/sched.h +++ b/srsenb/hdr/stack/mac/sched.h @@ -17,9 +17,9 @@ #include "sched_ue.h" #include "srslte/common/log.h" #include "srslte/interfaces/sched_interface.h" +#include #include #include -#include #include namespace srsenb { @@ -38,9 +38,8 @@ public: sched(); ~sched() override; - void init(rrc_interface_mac* rrc); + void init(rrc_interface_mac* rrc, const sched_args_t& sched_cfg); int cell_cfg(const std::vector& cell_cfg) override; - void set_sched_cfg(sched_args_t* sched_cfg); int reset() final; int ue_cfg(uint16_t rnti, const ue_cfg_t& ue_cfg) final; @@ -103,7 +102,7 @@ protected: srslte::tti_point last_tti; std::mutex sched_mutex; - bool configured = false; + std::atomic configured; }; } // namespace srsenb diff --git a/srsenb/src/stack/mac/mac.cc b/srsenb/src/stack/mac/mac.cc index 9eef56326..4bbaa1f71 100644 --- a/srsenb/src/stack/mac/mac.cc +++ b/srsenb/src/stack/mac/mac.cc @@ -58,10 +58,7 @@ bool mac::init(const mac_args_t& args_, stack_task_queue = task_sched.make_task_queue(); - scheduler.init(rrc); - - // Set default scheduler configuration - scheduler.set_sched_cfg(&args.sched); + scheduler.init(rrc, args.sched); // Init softbuffer for SI messages common_buffers.resize(cells.size()); diff --git a/srsenb/src/stack/mac/sched.cc b/srsenb/src/stack/mac/sched.cc index 25aa01517..e8f23ca27 100644 --- a/srsenb/src/stack/mac/sched.cc +++ b/srsenb/src/stack/mac/sched.cc @@ -37,9 +37,10 @@ sched::sched() {} sched::~sched() {} -void sched::init(rrc_interface_mac* rrc_) +void sched::init(rrc_interface_mac* rrc_, const sched_args_t& sched_cfg_) { - rrc = rrc_; + rrc = rrc_; + sched_cfg = sched_cfg_; // Initialize first carrier scheduler carrier_schedulers.emplace_back(new carrier_sched{rrc, &ue_db, 0, &sched_results}); @@ -50,7 +51,7 @@ void sched::init(rrc_interface_mac* rrc_) int sched::reset() { std::lock_guard lock(sched_mutex); - configured = false; + configured.store(false, std::memory_order_release); for (std::unique_ptr& c : carrier_schedulers) { c->reset(); } @@ -58,14 +59,7 @@ int sched::reset() return 0; } -void sched::set_sched_cfg(sched_interface::sched_args_t* sched_cfg_) -{ - std::lock_guard lock(sched_mutex); - if (sched_cfg_ != nullptr) { - sched_cfg = *sched_cfg_; - } -} - +/// Called by rrc::init int sched::cell_cfg(const std::vector& cell_cfg) { std::lock_guard lock(sched_mutex); @@ -89,8 +83,7 @@ int sched::cell_cfg(const std::vector& cell_cfg) carrier_schedulers[i]->carrier_cfg(sched_cell_params[i]); } - configured = true; - + configured.store(true, std::memory_order_release); return 0; } @@ -292,7 +285,7 @@ std::array sched::get_scell_activation_mask(uint16_t // Downlink Scheduler API int sched::dl_sched(uint32_t tti_tx_dl, uint32_t enb_cc_idx, sched_interface::dl_sched_res_t& sched_result) { - if (!configured) { + if (not configured.load(std::memory_order_acquire)) { return 0; } @@ -313,7 +306,7 @@ int sched::dl_sched(uint32_t tti_tx_dl, uint32_t enb_cc_idx, sched_interface::dl // Uplink Scheduler API int sched::ul_sched(uint32_t tti, uint32_t enb_cc_idx, srsenb::sched_interface::ul_sched_res_t& sched_result) { - if (!configured) { + if (not configured.load(std::memory_order_acquire)) { return 0; } diff --git a/srsenb/test/mac/sched_ca_test.cc b/srsenb/test/mac/sched_ca_test.cc index 0b6bbc9b9..65099afcf 100644 --- a/srsenb/test/mac/sched_ca_test.cc +++ b/srsenb/test/mac/sched_ca_test.cc @@ -115,7 +115,6 @@ int test_scell_activation(test_scell_activation_params params) sched_sim_event_generator generator; // Setup scheduler common_sched_tester tester; - tester.init(nullptr); tester.sim_cfg(sim_args); /* Simulation */ diff --git a/srsenb/test/mac/sched_test_common.cc b/srsenb/test/mac/sched_test_common.cc index 20918097f..30ab4c61e 100644 --- a/srsenb/test/mac/sched_test_common.cc +++ b/srsenb/test/mac/sched_test_common.cc @@ -125,7 +125,7 @@ int common_sched_tester::sim_cfg(sim_sched_args args) { sim_args0 = std::move(args); - sched::set_sched_cfg(&sim_args0.sched_args); + sched::init(nullptr, sim_args0.sched_args); sched_sim.reset(new sched_sim_random{this, sim_args0.cell_cfg}); sched_stats.reset(new sched_result_stats{sim_args0.cell_cfg}); diff --git a/srsenb/test/mac/sched_test_rand.cc b/srsenb/test/mac/sched_test_rand.cc index 488e8102b..8d9c5138b 100644 --- a/srsenb/test/mac/sched_test_rand.cc +++ b/srsenb/test/mac/sched_test_rand.cc @@ -242,7 +242,6 @@ void test_scheduler_rand(sched_sim_events sim) sched_tester tester; srsenb::sched my_sched; - tester.init(nullptr); tester.sim_cfg(std::move(sim.sim_args)); tester.test_next_ttis(sim.tti_events);