Page Speed Optimization Libraries
1.13.35.1
|
#include "function.h"
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 () |
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.
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.
|
inlineprotectedvirtual |
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::MemberFunction4< C, T1, T2, T3, T4 >, net_instaweb::MemberFunction3< C, T1, T2, T3 >, net_instaweb::SchedulerBlockingFunction, net_instaweb::MemberFunction2< C, T1, T2 >, net_instaweb::MemberFunction1< C, T1 >, net_instaweb::MemberFunction0< C >, net_instaweb::QueuedWorkerPool::Sequence::AddFunction, net_instaweb::CentralControllerCallback< TransactionContext >, net_instaweb::CentralControllerCallback< ExpensiveOperationContext >, net_instaweb::CentralControllerCallback< ScheduleRewriteContext >, net_instaweb::WorkerTestBase::CountFunction, and net_instaweb::NotifyFunction.
|
inline |
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.
|
protectedpure virtual |
Callers must override this to define the action to take when a closure is run. If this is called, Cancel() should not be called. This is a convention that's expected of callers of Function objects, but is not enforced by the Function implementation.
Implemented in net_instaweb::RewriteDriverFactory::Deleter< T >, net_instaweb::MemberFunction4< C, T1, T2, T3, T4 >, net_instaweb::MemberFunction3< C, T1, T2, T3 >, net_instaweb::SchedulerBlockingFunction, net_instaweb::MemberFunction2< C, T1, T2 >, net_instaweb::MemberFunction1< C, T1 >, net_instaweb::MemberFunction0< C >, net_instaweb::DeleteNotifyFunction, net_instaweb::WorkerTestBase::WaitRunFunction, net_instaweb::WorkerTestBase::NotifyRunFunction, net_instaweb::QueuedWorkerPool::Sequence::AddFunction, net_instaweb::CentralControllerCallback< TransactionContext >, net_instaweb::CentralControllerCallback< ExpensiveOperationContext >, net_instaweb::CentralControllerCallback< ScheduleRewriteContext >, net_instaweb::WorkerTestBase::CountFunction, and net_instaweb::NotifyFunction.
|
inline |
|
inline |
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.