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

#include "scheduler_based_abstract_lock.h"

Inheritance diagram for net_instaweb::SchedulerBasedAbstractLock:

Public Member Functions

virtual bool LockTimedWait (int64 wait_ms)
virtual void LockTimedWait (int64 wait_ms, Function *callback)
virtual bool LockTimedWaitStealOld (int64 wait_ms, int64 steal_ms)
virtual void LockTimedWaitStealOld (int64 wait_ms, int64 steal_ms, Function *callback)
- Public Member Functions inherited from net_instaweb::NamedLock
virtual ~NamedLock ()
 Destructors of extending classes must unlock the lock if held on destruct.
virtual void Unlock ()=0
virtual bool Held ()=0
virtual GoogleString name () const =0
 The name the lock was created with, for debugging/logging purposes.

Protected Member Functions

virtual bool TryLock ()=0
virtual bool TryLockStealOld (int64 steal_ms)=0
virtual Schedulerscheduler () const =0


class SharedMemLockManagerTestBase
class FileSystemLockManagerTest

Detailed Description

A SchedulerBasedAbstractLock implements a Lock by blocking using the scheduler, using exponential sleep time backoff and polling the lock on wakeup. The total time blocked on a long-held lock will be about 1.5 times the time between the initial call to the lock routine attempt and the time the lock is unlocked (ie we might wait for an extra amount of time equal to half the time we were forced to wait).

Note that the NamedLock API is strictly non-blocking, but this class adds blocking APIs which should only be used by blocking implementations and their tests.

Member Function Documentation

virtual void net_instaweb::SchedulerBasedAbstractLock::LockTimedWait ( int64  wait_ms,
Function callback 

Attempts to take a lock. callback->Run() is called if the lock was granted, and callback->Cancel() is called if the lock could not be obtained within wait_ms. Note that the callback may be called directly from this method, or from another thread.

The caller is responsible for making sure that callback does not block.

TODO(jmarantz): consider removing this method as it has no callers in production code, though it does have callers in tests.

Implements net_instaweb::NamedLock.

virtual void net_instaweb::SchedulerBasedAbstractLock::LockTimedWaitStealOld ( int64  wait_ms,
int64  steal_ms,
Function callback 

Attempts to take a lock, calling callback->Run() when it is granted. If the current lock holder has locked it for more than steal_ms, the lock is "stolen". If the lock cannot be obtained within wait_ms from when this method was called, the lock is denied, and callback->Cancel() is called.

Note that the callback may be called directly from this method, or from another thread.

The caller is responsible for making sure that callback does not block.

Note that even if wait_ms > steal_ms, callback->Cancel() may be called if there are multiple concurrent attempts to take the lock.

Implements net_instaweb::NamedLock.

virtual bool net_instaweb::SchedulerBasedAbstractLock::TryLock ( )
protectedpure virtual

If lock is held, return false, otherwise lock and return true. Non-blocking. Note that implementations of this and other similar 'try' routines are permitted to return false conservatively. TryLock must eventually succeed if called repeatedly on an unheld lock, however.

virtual bool net_instaweb::SchedulerBasedAbstractLock::TryLockStealOld ( int64  steal_ms)
protectedpure virtual

TryLockStealOld immediately attempts to lock the lock, succeeding and returning true if the lock is unlocked or the lock can be stolen from the current holder. Otherwise return false. cf TryLock() for other caveats. Non-blocking.

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