Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Friends | List of all members
net_instaweb::Worker Class Referenceabstract

#include "worker.h"

Inheritance diagram for net_instaweb::Worker:
net_instaweb::QueuedWorker net_instaweb::SlowWorker

Public Member Functions

void Start ()
 Tries to start the work thread (if it hasn't been started already).
 
bool IsBusy ()
 
void ShutDown ()
 
void set_queue_size_stat (Waveform *x)
 

Protected Member Functions

 Worker (StringPiece thread_name, ThreadSystem *runtime)
 
bool QueueIfPermitted (Function *closure)
 
virtual bool IsPermitted (Function *closure)=0
 
int NumJobs ()
 

Friends

class WorkThread
 

Detailed Description

This class is a base for various mechanisms of running things in background.

If you just want to run something in background, you want to use a subclass of this, such as a SlowWorker or QueuedWorker instance.

Subclasses should implement bool PermitQueue() and provide an appropriate wrapper around QueueIfPermitted().

Member Function Documentation

bool net_instaweb::Worker::IsBusy ( )

Returns true if there was a job running or any jobs queued at the time this function was called.

virtual bool net_instaweb::Worker::IsPermitted ( Function closure)
protectedpure virtual

Subclasses should implement this method to implement the policy on whether to run given tasks or not.

int net_instaweb::Worker::NumJobs ( )
protected

Returns the number of jobs, including any running and queued jobs. The lock semantics here are as follows:

  • QueueIfPermitted calls IsPermitted with lock held.
  • NumJobs assumes lock to be held. => It's safe to call NumJobs from within IsPermitted if desired.
bool net_instaweb::Worker::QueueIfPermitted ( Function closure)
protected

If IsPermitted() returns true, queues up the given closure to be run, takes ownership of closure, and returns true. (Also wakes up the work thread to actually run it if it's idle)

Otherwise it merely returns false, and doesn't do anything else.

void net_instaweb::Worker::set_queue_size_stat ( Waveform x)
inline

Sets up a timed-variable statistic indicating the current queue depth.

This must be called prior to starting the thread.

void net_instaweb::Worker::ShutDown ( )

Finishes the currently running jobs, and deletes any queued jobs. No further jobs will be accepted after this call either; they will just be canceled. It is safe to call this method multiple times.


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