diff --git a/srsue/hdr/phy/sf_worker.h b/srsue/hdr/phy/sf_worker.h index ebfed6f8b..fedf85112 100644 --- a/srsue/hdr/phy/sf_worker.h +++ b/srsue/hdr/phy/sf_worker.h @@ -63,15 +63,16 @@ public: void set_crnti(uint16_t rnti); void enable_pregen_signals(bool enabled); - /* Methods for plotting */ + ///< Methods for plotting called from GUI thread int read_ce_abs(float* ce_abs, uint32_t tx_antenna, uint32_t rx_antenna); uint32_t get_cell_nof_ports() { - if (cell_initiated) { - return cell.nof_ports; - } else { - return 1; + // wait until cell is initialized + std::unique_lock lock(mutex); + while (!cell_initiated) { + cell_init_cond.wait(lock); } + return cell.nof_ports; } uint32_t get_rx_nof_antennas() { return phy->args->nof_rx_ant; } int read_pdsch_d(cf_t* pdsch_d); @@ -101,6 +102,7 @@ private: srslte_cell_t cell = {}; srslte_tdd_config_t tdd_config = {}; + std::condition_variable cell_init_cond; bool cell_initiated = false; cf_t* prach_ptr = nullptr; diff --git a/srsue/src/phy/sf_worker.cc b/srsue/src/phy/sf_worker.cc index cdbf6fc56..057a9ee8f 100644 --- a/srsue/src/phy/sf_worker.cc +++ b/srsue/src/phy/sf_worker.cc @@ -90,13 +90,12 @@ void sf_worker::reset() bool sf_worker::set_cell(uint32_t cc_idx, srslte_cell_t cell_) { - bool ret = false; std::lock_guard lock(mutex); if (cc_idx < cc_workers.size()) { if (!cc_workers[cc_idx]->set_cell(cell_)) { Error("Setting cell for cc=%d\n", cc_idx); - goto unlock; + return false; } } else { Error("Setting cell for cc=%d; Not enough CC workers (%zd);\n", cc_idx, cc_workers.size()); @@ -105,11 +104,10 @@ bool sf_worker::set_cell(uint32_t cc_idx, srslte_cell_t cell_) if (cc_idx == 0) { cell = cell_; cell_initiated = true; + cell_init_cond.notify_one(); } - ret = true; -unlock: - return ret; + return true; } cf_t* sf_worker::get_buffer(uint32_t carrier_idx, uint32_t antenna_idx) @@ -468,6 +466,9 @@ void* plot_thread_run(void* arg) plot_scatter_addToWindowGrid(&psync, (char*)"srsue", 1, row_count++); #endif /* SYNC_PLOT_LEN > 0 */ + uint32_t num_tx = worker->get_cell_nof_ports(); + uint32_t num_rx = worker->get_rx_nof_antennas(); + int n; int readed_pdsch_re = 0; while (!plot_quit) { @@ -477,8 +478,8 @@ void* plot_thread_run(void* arg) n = worker->read_pdsch_d(&tmp_plot2[readed_pdsch_re]); readed_pdsch_re += n; } else { - for (uint32_t tx = 0; tx < worker->get_cell_nof_ports(); tx++) { - for (uint32_t rx = 0; rx < worker->get_rx_nof_antennas(); rx++) { + for (uint32_t tx = 0; tx < num_tx; tx++) { + for (uint32_t rx = 0; rx < num_rx; rx++) { n = worker->read_ce_abs(tmp_plot, tx, rx); if (n > 0) { plot_real_setNewData(&pce[tx][rx], tmp_plot, n); @@ -502,7 +503,6 @@ void* plot_thread_run(void* arg) void init_plots(srsue::sf_worker* worker) { - if (sem_init(&plot_sem, 0, 0)) { perror("sem_init"); exit(-1); diff --git a/srsue/src/phy/sync.cc b/srsue/src/phy/sync.cc index aa540455d..e7bae06bd 100644 --- a/srsue/src/phy/sync.cc +++ b/srsue/src/phy/sync.cc @@ -374,8 +374,7 @@ bool sync::cell_is_camping() void sync::run_thread() { - sf_worker* worker = NULL; - sf_worker* last_worker = NULL; + sf_worker* worker = nullptr; cf_t* buffer[SRSLTE_MAX_RADIOS][SRSLTE_MAX_PORTS] = {NULL}; bool is_end_of_burst = false;