Page Speed Optimization Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
net_instaweb::QueuedWorkerPool Class Reference

#include "queued_worker_pool.h"


class  Sequence

Public Types

typedef std::set< Sequence * > SequenceSet

Public Member Functions

 QueuedWorkerPool (int max_workers, StringPiece thread_name_base, ThreadSystem *thread_system)
SequenceNewSequence ()
 Returns NULL if shutting down. More...
void FreeSequence (Sequence *sequence)
void ShutDown ()
void InitiateShutDown ()
void WaitForShutDownComplete ()
void SetLoadSheddingThreshold (int x)
void set_queue_size_stat (Waveform *x)

Static Public Member Functions

static bool AreBusy (const SequenceSet &sequences)

Static Public Attributes

static const int kNoLoadShedding = -1


class Sequence

Detailed Description

Maintains a predefined number of worker threads, and dispatches any number of groups of sequential tasks to those threads.

Member Function Documentation

static bool net_instaweb::QueuedWorkerPool::AreBusy ( const SequenceSet &  sequences)

Returns true if any of the given sequences is busy. Note that multiple sequences are checked atomically; otherwise we could end up missing work. For example, consider if we had a sequence for main rewrite work, and an another one for expensive work. In this case, if we tried to check their busyness independently, the following could happen: 1) First portion of inexpensive work is done, so we queue up some on expensive work thread. 2) We check whether inexpensive work sequence is busy. It's not. 3) The expensive work runs, finishes, and queues up more inexpensive work. 4) We check whether expensive sequence is busy. It's not, so we would conclude we quiesced — while there was still work in the inexpensive queue.

void net_instaweb::QueuedWorkerPool::FreeSequence ( Sequence sequence)

Shuts down a sequence and frees it. This does not block waiting for the Sequence to finish.

void net_instaweb::QueuedWorkerPool::InitiateShutDown ( )

Starts the shutdown process, preventing further tasks from being queued. Does not wait for any active tasks to be completed. This must be followed by WaitForShutDownComplete. It is invalid to call InitiateShutDown() twice in a row.

Sequence* net_instaweb::QueuedWorkerPool::NewSequence ( )

Returns NULL if shutting down.

Sequence is owned by the pool, and will be automatically freed when the pool is finally freed (e.g. on server shutdown). But the sequence does not auto-destruct when complete; it must be explicitly freed using FreeSequence().

void net_instaweb::QueuedWorkerPool::set_queue_size_stat ( Waveform x)

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

This must be called prior to creating sequences.

void net_instaweb::QueuedWorkerPool::SetLoadSheddingThreshold ( int  x)

If x == kNoLoadShedding disables load-shedding. Otherwise, if more than x sequences are queued waiting to run, sequences will start getting dropped and canceled, with oldest sequences canceled first.

Precondition: x > 0 || x == kNoLoadShedding x = kNoLoadShedding (the default) disables the limit.

Should be called before starting any work.

void net_instaweb::QueuedWorkerPool::ShutDown ( )

Shuts down all Sequences and Worker threads, but does not delete the sequences. The sequences will be deleted when the pool is destructed.

Equivalent to "InitiateShutDown(); WaitForShutDownComplete();"

void net_instaweb::QueuedWorkerPool::WaitForShutDownComplete ( )

Blocks waiting for all outstanding tasks to be completed. Must be preceded by InitiateShutDown().

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