![]() |
ezEngine Release 26.3
|
Thread base class enabling cross-thread function call dispatching. More...
#include <ThreadWithDispatcher.h>

Public Types | |
| using | DispatchFunction = ezDelegate< void(), 128 > |
Public Types inherited from ezThread | |
| enum | ezThreadStatus { Created = 0 , Running , Finished } |
| Thread execution state. More... | |
Public Member Functions | |
| ezThreadWithDispatcher (const char *szName="ezThreadWithDispatcher", ezUInt32 uiStackSize=128 *1024) | |
| Initializes the runnable class. | |
| virtual | ~ezThreadWithDispatcher () |
| Destructor checks if the thread is deleted while still running, which is not allowed as this is a data hazard. | |
| void | Dispatch (DispatchFunction &&delegate) |
| Use this to enqueue a function call to the given delegate at some later point running in the given thread context. | |
Public Member Functions inherited from ezThread | |
| ezThread (ezStringView sName="ezThread", ezUInt32 uiStackSize=128 *1024) | |
| Creates a new thread with specified name and stack size. | |
| virtual | ~ezThread () |
| Destructor checks if the thread is deleted while still running, which is not allowed as this is a data hazard. | |
| ezThreadStatus | GetThreadStatus () const |
| Returns the thread status. | |
| bool | IsRunning () const |
| Helper function to determine if the thread is running. | |
| const char * | GetThreadName () const |
| Returns the thread name. | |
Public Member Functions inherited from ezOSThread | |
| ezOSThread (ezOSThreadEntryPoint threadEntryPoint, void *pUserData=nullptr, ezStringView sName="ezOSThread", ezUInt32 uiStackSize=128 *1024) | |
| Initializes the thread instance (e.g. thread creation etc.) | |
| virtual | ~ezOSThread () |
| Destructor. | |
| void | Start () |
| Starts the thread. | |
| void | Join () |
| Waits in the calling thread until the thread has finished execution (e.g. returned from the thread function) | |
| const ezThreadID & | GetThreadID () const |
| Returns the thread ID of the thread object, may be used in comparison operations with ezThreadUtils::GetCurrentThreadID() for example. | |
Protected Member Functions | |
| void | DispatchQueue () |
| Needs to be called by derived thread implementations to dispatch the function calls. | |
Private Member Functions | |
| virtual ezUInt32 | Run ()=0 |
| The run function can be used to implement a long running task in a thread in a platform independent way. | |
Additional Inherited Members | |
Static Public Member Functions inherited from ezThread | |
| static const ezThread * | GetCurrentThread () |
| Returns the current ezThread if the current platform thread is an ezThread. Returns nullptr otherwise. | |
Static Public Member Functions inherited from ezOSThread | |
| static ezInt32 | GetThreadCount () |
| Returns how many ezOSThreads are currently active. | |
Static Public Attributes inherited from ezThread | |
| static ezEvent< const ezThreadEvent &, ezMutex > | s_ThreadEvents |
| Global events for thread lifecycle monitoring. | |
Protected Attributes inherited from ezOSThread | |
| ezThreadHandle | m_hHandle |
| ezThreadID | m_ThreadID |
| ezOSThreadEntryPoint | m_EntryPoint |
| void * | m_pUserData |
| ezString | m_sName |
| ezUInt32 | m_uiStackSize |
Thread base class enabling cross-thread function call dispatching.
Extends ezThread to provide a message passing mechanism where other threads can schedule function calls to execute within this thread's context. Useful for thread-safe operations that must run on specific threads (e.g., UI updates, OpenGL calls).
Derived classes must call DispatchQueue() regularly in their Run() method to process queued function calls. The double-buffering design ensures minimal lock contention.
|
privatepure virtual |
The run function can be used to implement a long running task in a thread in a platform independent way.
Implements ezThread.