class PooledThread

Wrapper around a thread that is used within ThreadPool.

Public

Constructors

PooledThread

PooledThread(const String &name)

Methods

~PooledThread

virtual ~PooledThread() = default

Initialize

void Initialize()

Initializes the pooled thread.

Must be called right after construction.

GetThread

Thread &GetThread() const

Returns the underlying thread.

Start

void Start(std::function<void ()> workerMethod)

Starts executing the given worker method.

Destroy

void Destroy()

Attempts to join the currently running thread and destroys it.

Caller must ensure that any worker method currently running properly returns, otherwise this will block indefinitely.

IsIdle

bool IsIdle()

Returns true if the thread is idle and new worker method can be scheduled on it.

IdleTime

time_t IdleTime()

Returns how long has the thread been idle.

Value is undefined if thread is not idle.

SetName

void SetName(const String &name)

Sets a name of the thread.

BlockUntilComplete

void BlockUntilComplete()

Blocks the current thread until this thread completes.

Returns immediately if the thread is idle.

OnThreadStarted

virtual void OnThreadStarted(const String &name) = 0

Called when the thread is first created.

OnThreadEnded

virtual void OnThreadEnded(const String &name) = 0

Called when the thread is being shut down.

Protected

Methods

Run

void Run()

Primary worker method that is ran when the thread is first initialized.

RunFunctionHelper

void RunFunctionHelper(const std::function<void ()> &function) const

Fields

mWorkerMethod

std::function<void ()> mWorkerMethod

mName

String mName

mIsThreadIdle

bool mIsThreadIdle

mIsThreadStarted

bool mIsThreadStarted

mIsThreadReady

bool mIsThreadReady

mIdleTime

time_t mIdleTime

mThread

Thread * mThread

mMutex

Mutex mMutex

mThreadStartedSignal

ConditionVariable mThreadStartedSignal

mThreadReadySignal

ConditionVariable mThreadReadySignal

mWorkerFinishedSignal

ConditionVariable mWorkerFinishedSignal