From 95cda2905c29e5af5002211e5672b20e8098cefe Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 21 May 2021 16:42:23 +0300 Subject: libcamera: thread: Document dispatchMessages() thread-safety requirements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Thread class is incorrectly documented as thread-safe, as the dispatchMessages() function isn't thread-safe. Fix the documentation by tagging individual functions as thread-safe as appropriate. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Umang Jain Reviewed-by: Hirokazu Honda Reviewed-by: Jacopo Mondi --- src/libcamera/thread.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libcamera/thread.cpp b/src/libcamera/thread.cpp index 198670de..285b8083 100644 --- a/src/libcamera/thread.cpp +++ b/src/libcamera/thread.cpp @@ -229,8 +229,6 @@ ThreadData *ThreadData::current() * called. The event loop dispatches events (messages, notifiers and timers) * sent to the objects living in the thread. This behaviour can be modified by * overriding the run() function. - * - * \context This class is \threadsafe. */ /** @@ -361,6 +359,8 @@ void Thread::finishThread() * * Calling exit() on a thread that reimplements the run() method and doesn't * call exec() will likely have no effect. + * + * \context This function is \threadsafe. */ void Thread::exit(int code) { @@ -383,6 +383,8 @@ void Thread::exit(int code) * utils::duration::max(), the wait never times out. If the thread is not * running the function returns immediately. * + * \context This function is \threadsafe. + * * \return True if the thread has finished, or false if the wait timed out */ bool Thread::wait(utils::duration duration) @@ -412,6 +414,8 @@ bool Thread::wait(utils::duration duration) * started. This method guarantees that it returns true after the start() * method returns, and false after the wait() method returns. * + * \context This function is \threadsafe. + * * \return True if the thread is running, false otherwise */ bool Thread::isRunning() @@ -427,6 +431,7 @@ bool Thread::isRunning() /** * \brief Retrieve the Thread instance for the current thread + * \context This function is \threadsafe. * \return The Thread instance for the current thread */ Thread *Thread::current() @@ -441,6 +446,8 @@ Thread *Thread::current() * The thread ID corresponds to the Linux thread ID (TID) as returned by the * gettid system call. * + * \context This function is \threadsafe. + * * \return The ID of the current thread */ pid_t Thread::currentId() @@ -455,6 +462,8 @@ 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() @@ -544,6 +553,10 @@ void Thread::removeMessages(Object *receiver) * This function immediately dispatches all the messages previously posted for * this thread with postMessage() that match the message \a type. If the \a type * is Message::Type::None, all messages are dispatched. + * + * Messages shall only be dispatched from the current thread, typically within + * the thread from the run() function. Calling this function outside of the + * thread results in undefined behaviour. */ void Thread::dispatchMessages(Message::Type type) { -- cgit v1.2.1