mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-08 10:50:19 +08:00
logger: proper error handling if writer thread creation fails
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user