Fix a race condition in the enb csv metrics where set_handle was called while the metrics thread is running causing a race in the enb member variable.

Fix it by setting it during object construction.
master
faluco 3 years ago committed by Andre Puschmann
parent f3b427cbd7
commit 8d33d93c77

@ -32,11 +32,10 @@ namespace srsenb {
class metrics_csv : public srsran::metrics_listener<enb_metrics_t> class metrics_csv : public srsran::metrics_listener<enb_metrics_t>
{ {
public: public:
metrics_csv(std::string filename); metrics_csv(std::string filename, enb_metrics_interface* enb_);
~metrics_csv(); ~metrics_csv();
void set_metrics(const enb_metrics_t& m, const uint32_t period_usec); void set_metrics(const enb_metrics_t& m, const uint32_t period_usec);
void set_handle(enb_metrics_interface* enb_);
void stop(); void stop();
private: private:

@ -632,10 +632,9 @@ int main(int argc, char* argv[])
metricshub.add_listener(&metrics_screen); metricshub.add_listener(&metrics_screen);
metrics_screen.set_handle(enb.get()); metrics_screen.set_handle(enb.get());
srsenb::metrics_csv metrics_file(args.general.metrics_csv_filename); srsenb::metrics_csv metrics_file(args.general.metrics_csv_filename, enb.get());
if (args.general.metrics_csv_enable) { if (args.general.metrics_csv_enable) {
metricshub.add_listener(&metrics_file); metricshub.add_listener(&metrics_file);
metrics_file.set_handle(enb.get());
} }
srsenb::metrics_json json_metrics(json_channel, enb.get()); srsenb::metrics_json json_metrics(json_channel, enb.get());

@ -27,7 +27,8 @@ using namespace std;
namespace srsenb { namespace srsenb {
metrics_csv::metrics_csv(std::string filename) : n_reports(0), metrics_report_period(1.0), enb(NULL) metrics_csv::metrics_csv(std::string filename, enb_metrics_interface* enb_) :
n_reports(0), metrics_report_period(1.0), enb(enb_)
{ {
file.open(filename.c_str(), std::ios_base::out); file.open(filename.c_str(), std::ios_base::out);
} }
@ -37,11 +38,6 @@ metrics_csv::~metrics_csv()
stop(); stop();
} }
void metrics_csv::set_handle(enb_metrics_interface* enb_)
{
enb = enb_;
}
void metrics_csv::stop() void metrics_csv::stop()
{ {
if (file.is_open()) { if (file.is_open()) {

@ -201,8 +201,7 @@ int main(int argc, char** argv)
metrics_screen.set_handle(&enb); metrics_screen.set_handle(&enb);
// the CSV file writer // the CSV file writer
metrics_csv metrics_file(csv_file_name); metrics_csv metrics_file(csv_file_name, &enb);
metrics_file.set_handle(&enb);
// create metrics hub and register metrics for stdout // create metrics hub and register metrics for stdout
srsran::metrics_hub<enb_metrics_t> metricshub; srsran::metrics_hub<enb_metrics_t> metricshub;

Loading…
Cancel
Save