Class sh::base::ThreadDispatcher

class sh::base::ThreadDispatcher : public QObject

Dispatcher for sync/async invocation of functions into the associated thread.

Public Functions

ThreadDispatcher(QObject *parent, QThread *thread)

Constructed only by the infrastructure and made available otherwise.

void invokeSync(std::function<void()>)

Synchronously executes a function in the dispatcher’s thread.

If it already runs in the current thread, it just executes the function. It returns when the function is completely executed.

void invokeAsync(std::function<void()>)

Asynchronously executes a function in the dispatcher’s thread.

It directly returns. The actual execution will take place in a later message loop iteration of that thread.

void invokeAsync(std::function<void()>std::shared_ptr<void> obj1, std::shared_ptr<void> obj2 = 0, std::shared_ptr<void> obj3 = 0, )

Like the other variant, but it can also conserve some shared pointers until after execution.

bool inThread()

Returns if the current thread is already equal to the dispatcher’s thread (so dispatching isn’t required).

Signals

void _invoked()

Private Functions

void _invokeAsync(std::function<void()>)

Private Members

QMutex callsmutex
QThread *_thread
QQueue<std::function<void()>> _queue

Private Slots

void slot_invoked()