Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::StorageThreadDispatcherBase Class Referenceabstract

Abstract base class for dispatching tasks to the thread that owns DataStorage. More...

#include <mitkStorageThreadDispatcherBase.h>

Inheritance diagram for mitk::StorageThreadDispatcherBase:
Collaboration diagram for mitk::StorageThreadDispatcherBase:

Public Member Functions

 mitkClassMacroItkParent (StorageThreadDispatcherBase, itk::Object)
 
void Execute (std::function< void()> task)
 Execute a task on the storage-owning thread, blocking until completion. More...
 
virtual bool IsDispatchThread () const =0
 Check if the current thread is the dispatch target thread. More...
 
virtual void Post (std::function< void()> task)=0
 Post a task to run on the storage-owning thread, returning immediately. More...
 
template<typename R >
R ExecuteWithResult (std::function< R()> task)
 Convenience template for tasks that return a value. More...
 

Protected Member Functions

virtual void ExecuteDispatched (std::function< void()> task)=0
 Execute a task on the storage-owning thread, blocking until completion. More...
 
 StorageThreadDispatcherBase ()=default
 
 ~StorageThreadDispatcherBase () override=default
 

Detailed Description

Abstract base class for dispatching tasks to the thread that owns DataStorage.

Implementations provide thread-marshaling to ensure DataStorage operations (which trigger synchronous observer events) execute on the correct thread. (e.g. the Qt implementation dispatches to the GUI main thread.)

In headless/test scenarios, no dispatcher is needed - tasks execute directly.

Definition at line 32 of file mitkStorageThreadDispatcherBase.h.

Constructor & Destructor Documentation

◆ StorageThreadDispatcherBase()

mitk::StorageThreadDispatcherBase::StorageThreadDispatcherBase ( )
protecteddefault

◆ ~StorageThreadDispatcherBase()

mitk::StorageThreadDispatcherBase::~StorageThreadDispatcherBase ( )
overrideprotecteddefault

Member Function Documentation

◆ Execute()

void mitk::StorageThreadDispatcherBase::Execute ( std::function< void()>  task)
inline

Execute a task on the storage-owning thread, blocking until completion.

Checks thread affinity automatically to avoid deadlocks (e.g., Qt::BlockingQueuedConnection deadlocks if called from the target thread). If on the dispatch thread, executes the task directly.

Precondition
task must not be empty.

Definition at line 46 of file mitkStorageThreadDispatcherBase.h.

◆ ExecuteDispatched()

virtual void mitk::StorageThreadDispatcherBase::ExecuteDispatched ( std::function< void()>  task)
protectedpure virtual

Execute a task on the storage-owning thread, blocking until completion.

Must be implemented in derived classes.

Parameters
[in]taskthe task to execute on the dispatch thread.
Precondition
task must not be empty.

◆ ExecuteWithResult()

template<typename R >
R mitk::StorageThreadDispatcherBase::ExecuteWithResult ( std::function< R()>  task)
inline

Convenience template for tasks that return a value.

Blocks until the task completes and returns the result.

Returns
The result of the executed task.

Definition at line 93 of file mitkStorageThreadDispatcherBase.h.

◆ IsDispatchThread()

virtual bool mitk::StorageThreadDispatcherBase::IsDispatchThread ( ) const
pure virtual

Check if the current thread is the dispatch target thread.

Callers can check this before Execute(), but Execute() does it automatically to avoid deadlocks (e.g., Qt::BlockingQueuedConnection deadlocks if called from the target thread).

Returns
True if the current thread is the dispatch target thread.

◆ mitkClassMacroItkParent()

mitk::StorageThreadDispatcherBase::mitkClassMacroItkParent ( StorageThreadDispatcherBase  ,
itk::Object   
)

◆ Post()

virtual void mitk::StorageThreadDispatcherBase::Post ( std::function< void()>  task)
pure virtual

Post a task to run on the storage-owning thread, returning immediately.

Unlike Execute(), Post() never runs the task inline: it always defers to a later turn of the dispatch thread's event loop, even when called from the dispatch thread itself. Callers rely on that deferral – e.g. to escape a context (such as the platform loader lock held during library/plugin load) in which running the task synchronously would deadlock.

The task's result, if any, is discarded (fire-and-forget). Ordering relative to other posted tasks follows the dispatch thread's own queue semantics.

Precondition
task must not be empty.

The documentation for this class was generated from the following file: