libcamera
v0.0.0+100-debian/0_git20200629+e7aa92a-8-9-g77f5237c-dirty (2021-05-05T16:20:29+01:00)
Supporting cameras in Linux since 2019
|
A thread of execution. More...
Public Member Functions | |
Thread () | |
Create a thread. | |
void | start () |
Start the thread. | |
void | exit (int code=0) |
Stop the thread's event loop. More... | |
bool | wait (utils::duration duration=utils::duration::max()) |
Wait for the thread to finish. More... | |
bool | isRunning () |
Check if the thread is running. More... | |
EventDispatcher * | eventDispatcher () |
Retrieve the event dispatcher. More... | |
void | dispatchMessages (Message::Type type=Message::Type::None) |
Dispatch posted messages for this thread. More... | |
Static Public Member Functions | |
static Thread * | current () |
Retrieve the Thread instance for the current thread. More... | |
static pid_t | currentId () |
Retrieve the ID of the current thread. More... | |
Public Attributes | |
Signal< Thread * > | finished |
Signal the end of thread execution. | |
Protected Member Functions | |
int | exec () |
Enter the event loop. More... | |
virtual void | run () |
Main method of the thread. More... | |
Friends | |
class | Object |
class | ThreadData |
class | ThreadMain |
A thread of execution.
The Thread class is a wrapper around std::thread that handles integration with the Object, Signal and EventDispatcher classes.
Thread instances by default run an event loop until the exit() method is 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.
|
static |
|
static |
Retrieve the ID of the current thread.
The thread ID corresponds to the Linux thread ID (TID) as returned by the gettid system call.
void libcamera::Thread::dispatchMessages | ( | Message::Type | type = Message::Type::None | ) |
Dispatch posted messages for this thread.
[in] | type | The message type |
This function immediately dispatches all the messages previously posted for this thread with postMessage() that match the message type. If the type is Message::Type::None, all messages are dispatched.
EventDispatcher * libcamera::Thread::eventDispatcher | ( | ) |
Retrieve the event dispatcher.
This function retrieves the internal event dispatcher for the thread. The returned event dispatcher is valid until the thread is destroyed.
|
protected |
Enter the event loop.
This method enters an event loop based on the event dispatcher instance for the thread, and blocks until the exit() method is called. It is meant to be called within the thread from the run() method and shall not be called outside of the thread.
void libcamera::Thread::exit | ( | int | code = 0 | ) |
bool libcamera::Thread::isRunning | ( | ) |
|
protectedvirtual |
Main method of the thread.
When the thread is started with start(), it calls this method in the context of the new thread. The run() method can be overridden to perform custom work, either custom initialization and cleanup before and after calling the Thread::exec() function, or a custom thread loop altogether. When this method returns the thread execution is stopped, and the finished signal is emitted.
Note that if this function is overridden and doesn't call Thread::exec(), no events will be dispatched to the objects living in the thread. These objects will not be able to use the EventNotifier, Timer or Message facilities. This includes functions that rely on message dispatching, such as Object::deleteLater().
The base implementation just calls exec().
Reimplemented in libcamera::ThreadMain.
bool libcamera::Thread::wait | ( | utils::duration | duration = utils::duration::max() | ) |
Wait for the thread to finish.
[in] | duration | Maximum wait duration |
This function waits until the thread finishes or the duration has elapsed, whichever happens first. If duration is equal to utils::duration::max(), the wait never times out. If the thread is not running the function returns immediately.