Remove enb singleton and make sure log is initialized.

master
Pedro Alvarez 5 years ago committed by Andre Puschmann
parent bd3598f774
commit bb9ff82490

@ -115,11 +115,11 @@ struct all_args_t {
class enb : public enb_metrics_interface class enb : public enb_metrics_interface
{ {
public: public:
static enb* get_instance(void); enb();
static void cleanup(void); virtual ~enb();
int init(const all_args_t& args_); int init(const all_args_t& args_, srslte::logger* logger_);
void stop(); void stop();
@ -135,14 +135,8 @@ public:
bool get_metrics(enb_metrics_t* m); bool get_metrics(enb_metrics_t* m);
private: private:
static enb* instance;
const static int ENB_POOL_SIZE = 1024 * 10; const static int ENB_POOL_SIZE = 1024 * 10;
enb();
virtual ~enb();
int parse_args(const all_args_t& args_); int parse_args(const all_args_t& args_);
// eNB components // eNB components

@ -28,39 +28,23 @@
namespace srsenb { namespace srsenb {
enb* enb::instance = nullptr;
pthread_mutex_t enb_instance_mutex = PTHREAD_MUTEX_INITIALIZER;
enb* enb::get_instance()
{
pthread_mutex_lock(&enb_instance_mutex);
if (nullptr == instance) {
instance = new enb();
}
pthread_mutex_unlock(&enb_instance_mutex);
return (instance);
}
void enb::cleanup()
{
pthread_mutex_lock(&enb_instance_mutex);
if (nullptr != instance) {
delete instance;
instance = nullptr;
}
srslte::byte_buffer_pool::cleanup(); // pool has to be cleaned after enb is deleted
pthread_mutex_unlock(&enb_instance_mutex);
}
enb::enb() : started(false), pool(srslte::byte_buffer_pool::get_instance(ENB_POOL_SIZE)) enb::enb() : started(false), pool(srslte::byte_buffer_pool::get_instance(ENB_POOL_SIZE))
{ {
// print build info // print build info
std::cout << std::endl << get_build_string() << std::endl; std::cout << std::endl << get_build_string() << std::endl;
} }
enb::~enb() {} enb::~enb()
{
// pool has to be cleaned after enb is deleted
stack.reset();
srslte::byte_buffer_pool::cleanup();
}
int enb::init(const all_args_t& args_) int enb::init(const all_args_t& args_, srslte::logger* logger_)
{ {
logger = logger_;
// Init UE log // Init UE log
log.init("ENB ", logger); log.init("ENB ", logger);
log.set_level(srslte::LOG_LEVEL_INFO); log.set_level(srslte::LOG_LEVEL_INFO);
@ -72,16 +56,6 @@ int enb::init(const all_args_t& args_)
return SRSLTE_ERROR; return SRSLTE_ERROR;
} }
// set logger
if (args.log.filename == "stdout") {
logger = &logger_stdout;
} else {
logger_file.init(args.log.filename, args.log.file_max_size);
logger_file.log_char("\n\n");
logger_file.log_char(get_build_string().c_str());
logger = &logger_file;
}
pool_log.init("POOL", logger); pool_log.init("POOL", logger);
pool_log.set_level(srslte::LOG_LEVEL_ERROR); pool_log.set_level(srslte::LOG_LEVEL_ERROR);
pool->set_log(&pool_log); pool->set_log(&pool_log);

@ -32,6 +32,7 @@
#include <boost/program_options/parsers.hpp> #include <boost/program_options/parsers.hpp>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <memory>
#include "srsenb/hdr/enb.h" #include "srsenb/hdr/enb.h"
#include "srsenb/hdr/metrics_csv.h" #include "srsenb/hdr/metrics_csv.h"
@ -429,31 +430,45 @@ int main(int argc, char* argv[])
srslte::metrics_hub<enb_metrics_t> metricshub; srslte::metrics_hub<enb_metrics_t> metricshub;
metrics_stdout metrics_screen; metrics_stdout metrics_screen;
enb* enb = enb::get_instance(); cout << "--- Software Radio Systems LTE eNodeB ---" << endl << endl;
srslte_debug_handle_crash(argc, argv); srslte_debug_handle_crash(argc, argv);
parse_args(&args, argc, argv);
cout << "--- Software Radio Systems LTE eNodeB ---" << endl << endl; srslte::logger_stdout logger_stdout;
srslte::logger_file logger_file;
parse_args(&args, argc, argv); // Set logger
if (enb->init(args)) { srslte::logger* logger = nullptr;
if (args.log.filename == "stdout") {
logger = &logger_stdout;
} else {
logger_file.init(args.log.filename, args.log.file_max_size);
logger = &logger_file;
}
srslte::logmap::set_default_logger(logger);
// Create eNB
unique_ptr<srsenb::enb> enb{new srsenb::enb};
if (enb->init(args, logger) != SRSLTE_SUCCESS) {
enb->stop(); enb->stop();
return SRSLTE_ERROR; return SRSLTE_ERROR;
} }
metricshub.init(enb, args.general.metrics_period_secs); // Set metrics
metricshub.init(enb.get(), args.general.metrics_period_secs);
metricshub.add_listener(&metrics_screen); metricshub.add_listener(&metrics_screen);
metrics_screen.set_handle(enb); 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);
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); metrics_file.set_handle(enb.get());
} }
// create input thread // create input thread
pthread_t input; pthread_t input;
pthread_create(&input, NULL, &input_loop, &metrics_screen); pthread_create(&input, nullptr, &input_loop, &metrics_screen);
bool signals_pregenerated = false; bool signals_pregenerated = false;
if (running) { if (running) {
@ -476,7 +491,6 @@ int main(int argc, char* argv[])
pthread_join(input, NULL); pthread_join(input, NULL);
metricshub.stop(); metricshub.stop();
enb->stop(); enb->stop();
enb->cleanup();
cout << "--- exiting ---" << endl; cout << "--- exiting ---" << endl;
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;

Loading…
Cancel
Save