diff --git a/src/modules/logger/log_writer.cpp b/src/modules/logger/log_writer.cpp index 3752706182..8a75dc9102 100644 --- a/src/modules/logger/log_writer.cpp +++ b/src/modules/logger/log_writer.cpp @@ -48,7 +48,7 @@ void LogWriter::stop_log() notify(); } -pthread_t LogWriter::thread_start() +int LogWriter::thread_start(pthread_t &thread) { pthread_attr_t thr_attr; pthread_attr_init(&thr_attr); @@ -60,15 +60,10 @@ pthread_t LogWriter::thread_start() pthread_attr_setstacksize(&thr_attr, 1024); - pthread_t thr; - - if (0 != pthread_create(&thr, &thr_attr, &LogWriter::run_helper, this)) { - PX4_WARN("error creating logwriter thread"); - } - + int ret = pthread_create(&thread, &thr_attr, &LogWriter::run_helper, this); pthread_attr_destroy(&thr_attr); - return thr; + return ret; } void LogWriter::thread_stop() diff --git a/src/modules/logger/log_writer.h b/src/modules/logger/log_writer.h index 2c1b19f083..e49ab4efe4 100644 --- a/src/modules/logger/log_writer.h +++ b/src/modules/logger/log_writer.h @@ -17,7 +17,12 @@ class LogWriter public: LogWriter(uint8_t *buffer, size_t buffer_size); - pthread_t thread_start(); + /** + * start the thread + * @param thread will be set to the created thread on success + * @return 0 on success, error number otherwise (@see pthread_create) + */ + int thread_start(pthread_t &thread); void thread_stop(); diff --git a/src/modules/logger/logger.cpp b/src/modules/logger/logger.cpp index f00c8d051f..60315321e5 100644 --- a/src/modules/logger/logger.cpp +++ b/src/modules/logger/logger.cpp @@ -402,7 +402,12 @@ void Logger::run() // add_topic("estimator_status"); add_topic("vehicle_status", 100); - _writer_thread = _writer.thread_start(); + int ret = _writer.thread_start(_writer_thread); + + if (ret) { + PX4_ERR("logger: failed to create writer thread (%i)", ret); + return; + } _task_should_exit = false; @@ -584,7 +589,7 @@ void Logger::run() _writer.notify(); // wait for thread to complete - int ret = pthread_join(_writer_thread, NULL); + ret = pthread_join(_writer_thread, NULL); if (ret) { PX4_WARN("join failed: %d", ret);