Crashpad

Classes | Public Member Functions | 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

## 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_interval | The time interval in seconds at which the delegate runs. The interval counts from the completion of Delegate::DoWork() to the next invocation.
  [in] | delegate | The 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_delay | The amount of time in seconds to wait before invoking the delegate for the first time. Pass `0` for no delay.

## ◆ 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:

- util/thread/worker_thread.h
- util/thread/worker_thread.cc