logger: proper error handling if writer thread creation fails

This commit is contained in:
Beat Küng
2016-05-02 14:44:45 +02:00
committed by Lorenz Meier
parent 72263eaa97
commit 84015e5c01
3 changed files with 16 additions and 11 deletions
+3 -8
View File
@@ -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()
+6 -1
View File
@@ -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();
+7 -2
View File
@@ -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);