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

#include "scheduler_sequence.h"

Inheritance diagram for net_instaweb::Scheduler::Sequence:

Public Member Functions

 Sequence (Scheduler *scheduler)
void Add (Function *function) override LOCKS_EXCLUDED(scheduler_-> mutex())
bool RunTasksUntil (int64 timeout_ms, bool *done) EXCLUSIVE_LOCKS_REQUIRED(scheduler_-> mutex())
void ForwardToSequence (net_instaweb::Sequence *forwarding_sequence) EXCLUSIVE_LOCKS_REQUIRED(scheduler_-> mutex())

Detailed Description

Implements a sequence which is run directly from RunTasksUntil, rather than running in a background thread.

Constructor & Destructor Documentation

net_instaweb::Scheduler::Sequence::Sequence ( Scheduler scheduler)

The scheduler is used for doing timed-waits so that any pending scheduler alarms fire before the wait-period ends.

Member Function Documentation

void net_instaweb::Scheduler::Sequence::Add ( Function function) -> mutex())

Adds 'function' to a sequence. Note that this can occur at any time the sequence is live – you can add functions to a sequence that has already started processing. The caller is expected to ensure Function will be cleaned up after Run or Cancel.

'function' can be called any time after Add(), and may in fact be called before Add() returns. It's OK for the function to call Add again.

If the sequence is destructed after Add, but before the function has been run, function->Cancel() will be called when the Sequence is destroyed.

Implements net_instaweb::Sequence.

void net_instaweb::Scheduler::Sequence::ForwardToSequence ( net_instaweb::Sequence forwarding_sequence) -> mutex())

Atomically forwards all activity to an alternative Sequence. Any pending functions in the work_queue_ are transferred into the sequence, and new functions passed to Add are added to forwarding_sequence rather than being placed into the WorkQueue.

This is intended to be called once, after request-thread activity is done, to handle any pending background tasks.

Note: both the scheduler lock (which must be held when calling this method) and the forwarding_sequence's mutex must be held concurrently during the implementation of Schedule::Add. We don't want to let go of scheduler_->mutex() during this operation because then it would no longer be atomic. Thus forwarding_sequence must not have the same mutex as scheduler_.

bool net_instaweb::Scheduler::Sequence::RunTasksUntil ( int64  timeout_ms,
bool *  done 
) -> mutex())

Runs functions for this sequence directly, until *done is true or the timeout expires. Returns 'false' if the timeout expired prior to 'done' getting set to true. 'done' must be protected by scheduler_->mutex(), and is expected to be set by one of the sequence tasks.

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