Minecraft Community Edition 0.1.0
Loading...
Searching...
No Matches
mce::ThreadManager Class Reference

Classes

struct  ThreadInfo
 Metadata stored per managed thread. More...

Public Member Functions

 ThreadManager (QEventBus &qBus)
 Construct a ThreadManager bound to a QEventBus.
 ~ThreadManager ()
 Destructor cleans up managed threads and subscriptions.
template<typename F>
ThreadcreateThread (const eastl::string &name, F func)
 Create (and store) a Thread from a generic callable.
template<typename C>
ThreadcreateThread (const eastl::string &name, void(C::*func)(), C *object)
 Create (and store) a Thread for a member function on an object.
void launch (Thread *th)
 Launch a previously created Thread instance.
void launch (const eastl::string &name)
 Convenience: launches the thread with the given name.
void waitAll ()
 Block until all managed threads have finished executing.
void cleanupFinished ()
 Remove and cleanup finished threads from internal storage.
void printStats ()
 Print statistics (e.g. runtime durations) for managed threads.
size_t activeCount () const
 Count of currently active (non-finished) threads.

Constructor & Destructor Documentation

◆ ThreadManager()

mce::ThreadManager::ThreadManager ( QEventBus & qBus)
explicit

Construct a ThreadManager bound to a QEventBus.

Parameters
qBusReference to the application's QEventBus used to post thread events.

The ThreadManager subscribes to thread lifecycle events on qBus to maintain accurate bookkeeping.

Member Function Documentation

◆ activeCount()

size_t mce::ThreadManager::activeCount ( ) const

Count of currently active (non-finished) threads.

Returns
Number of active threads being tracked.

◆ cleanupFinished()

void mce::ThreadManager::cleanupFinished ( )

Remove and cleanup finished threads from internal storage.

This method may be used regularly to free resources held for threads that have already completed.

◆ createThread() [1/2]

template<typename F>
Thread * mce::ThreadManager::createThread ( const eastl::string & name,
F func )
inline

Create (and store) a Thread from a generic callable.

Template Parameters
FCallable type (lambda, functor or function pointer).
Parameters
nameHuman readable name for the thread.
funcCallable to execute when the thread runs.
Returns
Pointer to the created Thread (owned by ThreadManager).

The returned Thread pointer is non-owning; ThreadManager retains ownership in its internal storage (threadStorage). The thread is created but not launched — call launch() to start it.

◆ createThread() [2/2]

template<typename C>
Thread * mce::ThreadManager::createThread ( const eastl::string & name,
void(C::* func )(),
C * object )
inline

Create (and store) a Thread for a member function on an object.

Template Parameters
CClass type of the target object.
Parameters
nameHuman readable name for the thread.
funcPointer to the member function to call.
objectPointer to the object instance on which to call the member function.
Returns
Pointer to the created Thread (owned by ThreadManager).

Creates a Thread adapter that will call (object->*func)() when executed.

◆ launch() [1/2]

void mce::ThreadManager::launch ( const eastl::string & name)

Convenience: launches the thread with the given name.

Parameters
nameName of the thread to launch.

Finds the Thread associated with name and launches it. If multiple threads share the same name behavior depends on underlying container order.

◆ launch() [2/2]

void mce::ThreadManager::launch ( Thread * th)

Launch a previously created Thread instance.

Parameters
thPointer to the Thread returned from createThread().

This will call Thread::launch() on the provided Thread pointer.

◆ printStats()

void mce::ThreadManager::printStats ( )

Print statistics (e.g. runtime durations) for managed threads.

Implementations should format and output info about active/finished threads using the project's logging facilities.

◆ waitAll()

void mce::ThreadManager::waitAll ( )

Block until all managed threads have finished executing.

Joins/waits any active threads tracked by this manager.


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