Crashpad
Classes | Public Member Functions | Static Public Attributes | Friends | List of all members
crashpad::WorkerThread Class Reference

A WorkerThread executes its Delegate's DoWork method repeatedly on a dedicated thread at a set time interval. More...

#include "util/thread/worker_thread.h"

Classes

class  Delegate
 An interface for doing work on a WorkerThread. More...
 

Public Member Functions

 WorkerThread (double work_interval, Delegate *delegate)
 Creates a new WorkerThread that is not yet running. More...
 
void Start (double initial_work_delay)
 Starts the worker thread. More...
 
void Stop ()
 Stops the worker thread from running. More...
 
void DoWorkNow ()
 Interrupts a work_interval to execute the work function immediately. This invokes Delegate::DoWork() on the thread, without waiting for the current work_interval to expire. After the delegate is invoked, the WorkerThread will start waiting for a new work_interval.
 
bool is_running () const
 

Static Public Attributes

static constexpr double kIndefiniteWait = Semaphore::kIndefiniteWait
 A delay or interval argument that causes an indefinite wait.
 

Friends

class internal::WorkerThreadImpl
 

Detailed Description

A WorkerThread executes its Delegate's DoWork method repeatedly on a dedicated thread at a set time interval.

Constructor & Destructor Documentation

◆ WorkerThread()

crashpad::WorkerThread::WorkerThread ( double  work_interval,
WorkerThread::Delegate delegate 
)

Creates a new WorkerThread that is not yet running.

Parameters
[in]work_intervalThe time interval in seconds at which the delegate runs. The interval counts from the completion of Delegate::DoWork() to the next invocation. This can be kIndefiniteWait if work should only be done when DoWorkNow() is called.
[in]delegateThe work delegate to invoke every interval.

Member Function Documentation

◆ is_running()

bool crashpad::WorkerThread::is_running ( ) const
inline
Returns
true if the thread is running, false if it is not.

◆ Start()

void crashpad::WorkerThread::Start ( double  initial_work_delay)

Starts the worker thread.

This may not be called if the thread is_running().

Parameters
[in]initial_work_delayThe amount of time in seconds to wait before invoking the delegate for the first time. Pass 0 for no delay. This can be kIndefiniteWait if work should not be done until DoWorkNow() is called.

◆ Stop()

void crashpad::WorkerThread::Stop ( )

Stops the worker thread from running.

This may only be called if the thread is_running().

If the work function is currently executing, this will not interrupt it. This method stops any future work from occurring. This method is safe to call from any thread with the exception of the worker thread itself, as this joins the thread.


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