diff options
Diffstat (limited to 'src/libcamera/base/thread.cpp')
-rw-r--r-- | src/libcamera/base/thread.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp index 6bda9d14..4ac72036 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -18,6 +18,7 @@ #include <libcamera/base/log.h> #include <libcamera/base/message.h> #include <libcamera/base/mutex.h> +#include <libcamera/base/object.h> /** * \page thread Thread Support @@ -151,7 +152,7 @@ private: friend class ThreadMain; Thread *thread_; - bool running_; + bool running_ LIBCAMERA_TSA_GUARDED_BY(mutex_); pid_t tid_; Mutex mutex_; @@ -370,6 +371,12 @@ void Thread::run() void Thread::finishThread() { + /* + * Objects may have been scheduled for deletion right before the thread + * exited. Ensure they get deleted now, before the thread stops. + */ + dispatchMessages(Message::Type::DeferredDelete); + data_->mutex_.lock(); data_->running_ = false; data_->mutex_.unlock(); @@ -422,11 +429,15 @@ bool Thread::wait(utils::duration duration) { MutexLocker locker(data_->mutex_); + auto isRunning = ([&]() LIBCAMERA_TSA_REQUIRES(data_->mutex_) { + return !data_->running_; + }); + if (duration == utils::duration::max()) - data_->cv_.wait(locker, [&]() { return !data_->running_; }); + data_->cv_.wait(locker, isRunning); else hasFinished = data_->cv_.wait_for(locker, duration, - [&]() { return !data_->running_; }); + isRunning); } if (thread_.joinable()) |