From 1bd66f54a6bc928f99e321630f43d200df4d3579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Fri, 15 Aug 2025 12:11:32 +0200 Subject: [PATCH] libcamera: base: thread: eventDispatcher(): Not thread safe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function is not actually thread safe contrary to its documentation. Since it is currently not used in an unsafe context, simply remove the mention of thread safety from the documentation. The variable must still remain atomic because it is accessed internally from different threads, e.g. `Thread::postMessage()`. Also add an assertion to enforce this. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/libcamera/base/thread.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp index d8fe0d69..ba3caf6f 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -512,12 +512,12 @@ pid_t Thread::currentId() * This function retrieves the internal event dispatcher for the thread. The * returned event dispatcher is valid until the thread is destroyed. * - * \context This function is \threadsafe. - * * \return Pointer to the event dispatcher */ EventDispatcher *Thread::eventDispatcher() { + ASSERT(data_ == ThreadData::current()); + if (!data_->dispatcher_.load(std::memory_order_relaxed)) data_->dispatcher_.store(new EventDispatcherPoll(), std::memory_order_release);