Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
MoinMoin.util.lock.LazyReadLock Class Reference
Inheritance diagram for MoinMoin.util.lock.LazyReadLock:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.util.lock.LazyReadLock:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def acquire
def release
def exists
def isExpired
def expire
def isLocked

Public Attributes

 writeLock
 lockDir
 dir
 timeout

Static Public Attributes

string fileName = 'read_lock_'
 timerClass = Timer

Private Attributes

 _locked

Detailed Description

Lazy Read lock

See ReadLock, but we do an optimization here:
If (and ONLY if) the resource protected by this lock is updated in a POSIX
style "write new content to tmpfile, rename tmpfile -> origfile", then reading
from an open origfile handle will give either the old content (when opened
before the rename happens) or the new content (when opened after the rename
happened), but never cause any trouble. This means that we don't have to lock
at all in that case.

Of course this doesn't work for us on the win32 platform:
* using MoveFileEx requires opening the file with some FILE_SHARE_DELETE
  mode - we currently don't do that
* Win 95/98/ME do not have MoveFileEx
We currently solve by using the non-lazy locking code in ReadLock class.

Definition at line 308 of file lock.py.


Constructor & Destructor Documentation

def MoinMoin.util.lock.LazyReadLock.__init__ (   self,
  dir,
  timeout = None 
)
Init a read lock

@param dir: the lock directory. Every resource should have one
    lock directory, which may contain read or write locks.
@param timeout: while trying to acquire, the lock will expire
    other unreleased write locks older than timeout.

Reimplemented from MoinMoin.util.lock.ReadLock.

Definition at line 325 of file lock.py.

00325 
00326     def __init__(self, dir, timeout=None):
00327         if sys.platform == 'win32':
00328             ReadLock.__init__(self, dir, timeout)
00329         else: # POSIX
00330             self._locked = False


Member Function Documentation

def MoinMoin.util.lock.LazyReadLock.acquire (   self,
  timeout = None 
)
Try to acquire a 'read' lock

To prevent race conditions, acquire first an exclusive lock,
then acquire a read lock. Finally release the exclusive lock so
other can have read lock, too.

Reimplemented from MoinMoin.util.lock.ReadLock.

Definition at line 331 of file lock.py.

00331 
00332     def acquire(self, timeout=None):
00333         if sys.platform == 'win32':
00334             return ReadLock.acquire(self, timeout)
00335         else: # POSIX
00336             self._locked = True
00337             return True

Reimplemented from MoinMoin.util.lock.ExclusiveLock.

Definition at line 344 of file lock.py.

00344 
00345     def exists(self):
00346         if sys.platform == 'win32':
00347             return ReadLock.exists(self)
00348         else: # POSIX
00349             return True

Return True if the lock is expired or missing; False otherwise. 

Reimplemented from MoinMoin.util.lock.ExclusiveLock.

Definition at line 356 of file lock.py.

00356 
00357     def expire(self):
00358         if sys.platform == 'win32':
00359             return ReadLock.expire(self)
00360         else: # POSIX
00361             return True

Return True if too old or missing; False otherwise

TODO: Since stat returns times using whole seconds, this is
quite broken. Maybe use OS specific calls like Carbon.File on
Mac OS X?

Reimplemented from MoinMoin.util.lock.ExclusiveLock.

Definition at line 350 of file lock.py.

00350 
00351     def isExpired(self):
00352         if sys.platform == 'win32':
00353             return ReadLock.isExpired(self)
00354         else: # POSIX
00355             return True

def MoinMoin.util.lock.ExclusiveLock.isLocked (   self) [inherited]

Definition at line 134 of file lock.py.

00134 
00135     def isLocked(self):
00136         return self._locked

Release the lock 

Reimplemented from MoinMoin.util.lock.ExclusiveLock.

Definition at line 338 of file lock.py.

00338 
00339     def release(self):
00340         if sys.platform == 'win32':
00341             return ReadLock.release(self)
00342         else:  # POSIX
00343             self._locked = False


Member Data Documentation

Reimplemented from MoinMoin.util.lock.ReadLock.

Definition at line 329 of file lock.py.

Definition at line 89 of file lock.py.

string MoinMoin.util.lock.ReadLock.fileName = 'read_lock_' [static, inherited]

Reimplemented from MoinMoin.util.lock.ExclusiveLock.

Definition at line 274 of file lock.py.

Reimplemented from MoinMoin.util.lock.ExclusiveLock.

Definition at line 299 of file lock.py.

Definition at line 92 of file lock.py.

Definition at line 77 of file lock.py.

Definition at line 286 of file lock.py.


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