Page Speed Optimization Libraries  1.2.24.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Protected Member Functions
net_instaweb::Function Class Reference

#include "function.h"

Inheritance diagram for net_instaweb::Function:
net_instaweb::DeleteNotifyFunction net_instaweb::MemberFunctionBase< C > 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

List of all members.

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

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

virtual void net_instaweb::Function::Cancel ( ) [inline, protected, virtual]

Informs a the Function that it is being shut down. If this is called, Run() should not be called. This should never be called while a function is running. See also set_quit_requested(), which can be called during Run(), so that Run() implementations can check quit_requested() at their convenience to stop the operation in progress.

Reimplemented in net_instaweb::MemberFunction3< C, T1, T2, T3 >, net_instaweb::MemberFunction2< C, T1, T2 >, net_instaweb::SchedulerBlockingFunction, net_instaweb::MemberFunction1< C, T1 >, net_instaweb::MemberFunction0< C >, net_instaweb::QueuedWorkerPool::Sequence::AddFunction, and net_instaweb::WorkerTestBase::CountFunction.

bool net_instaweb::Function::quit_requested ( ) const [inline]

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.

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 ( ) [protected, pure virtual]

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().

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:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines