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

#include "function.h"

Inheritance diagram for net_instaweb::Function:
net_instaweb::CentralControllerCallback< ExpensiveOperationContext > net_instaweb::CentralControllerCallback< ScheduleRewriteContext > net_instaweb::CentralControllerCallback< TransactionContext > net_instaweb::DeleteNotifyFunction net_instaweb::MemberFunctionBase< C > net_instaweb::NotifyFunction net_instaweb::QueuedAlarm net_instaweb::QueuedWorkerPool::Sequence::AddFunction net_instaweb::RewriteDriverFactory::Deleter< T > net_instaweb::SchedulerBlockingFunction net_instaweb::WorkerTestBase::CountFunction net_instaweb::WorkerTestBase::NotifyRunFunction net_instaweb::WorkerTestBase::WaitRunFunction

Public Member Functions

void set_quit_requested_pointer (AtomicBool *x)
bool quit_requested () const
void CallRun ()
void CallCancel ()
void set_delete_after_callback (bool x)
void Reset ()

Protected Member Functions

virtual void Run ()=0
virtual void Cancel ()

Detailed Description

Encapsulates a task to be run in response to some event, such as a Timer callback, an fetch, or a cache lookup.

Users of interfaces requiring a Function* can either derive a new class from Function, or use one of the helper template-classes or MakeFunction variants below, which create delayed calls to class methods.

Note that Functions by default are self-deleting after call, but you can override that with set_delete_after_callback(false).

A Function will always have its Run method or its Cancel method called, never both. A Function should never be deleted without its Run/Cancel method being called (except if set_delete_after_callback(false)).

Note that classes calling Functions use the CallRun or CallCancel methods, rather than calling Run or Cancel directly. This allows the Function class to enforce policy on making run & cancel mutually exclusive and implement delete-after-run.

Member Function Documentation

void net_instaweb::Function::CallRun ( )

Implementors of Function interfaces should call via these helper methods to initiate Run and Cancel callbacks. This helps centralize deletion of callbacks after they are called.

virtual void net_instaweb::Function::Cancel ( )
bool net_instaweb::Function::quit_requested ( ) const

Allows an infrastructure (e.g. Worker or Alarm) to request that a running Function stop soon, as it is being shut down.

This can should only be called during the Run() method.

void net_instaweb::Function::Reset ( )

Clears the state of the function so that it can be called or cancelled again. This only makes sense to call if set_delete_after_callback(false) has been called.

virtual void net_instaweb::Function::Run ( )
protectedpure virtual
void net_instaweb::Function::set_delete_after_callback ( bool  x)

By default, Functions delete themselves after being called. Call this method to override. If the Function is going to be re-called, Reset() must be called on it first. Will not take effect if called within Run() or Cancel().

void net_instaweb::Function::set_quit_requested_pointer ( AtomicBool x)

Functions used as Worker tasks can help the system shut down cleanly by calling quit_requested() periodically. To support this, Worker calls set_quit_requested_pointer so the Function object can access the atomic bool.

Note that a strategy of allocating the AtomicBool inside the Function object exposes a shutdown race when the function completes and deletes itself.

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