Back to index

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

List of all members.

Public Member Functions

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

Public Attributes

 writeLock
 lockDir
 dir
 timeout

Static Public Attributes

string fileName = 'read_lock_'
 timerClass = Timer

Private Attributes

 _locked

Detailed Description

Read lock

The purpose of this lock is to mark the resource as read only.
Multiple ReadLocks can be acquired for same resource, but no
WriteLock can be acquired until all ReadLocks are released.

Allows only one lock per instance.

Definition at line 265 of file lock.py.


Constructor & Destructor Documentation

def MoinMoin.util.lock.ReadLock.__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.ExclusiveLock.

Reimplemented in MoinMoin.util.lock.LazyReadLock.

Definition at line 276 of file lock.py.

00276 
00277     def __init__(self, dir, timeout=None):
00278         """ Init a read lock
00279 
00280         @param dir: the lock directory. Every resource should have one
00281             lock directory, which may contain read or write locks.
00282         @param timeout: while trying to acquire, the lock will expire
00283             other unreleased write locks older than timeout.
00284         """
00285         ExclusiveLock.__init__(self, dir, timeout)
00286         writeLockDir = os.path.join(self.dir, WriteLock.fileName)
00287         self.writeLock = ExclusiveLock(writeLockDir, timeout)


Member Function Documentation

def MoinMoin.util.lock.ReadLock.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.ExclusiveLock.

Reimplemented in MoinMoin.util.lock.LazyReadLock.

Definition at line 288 of file lock.py.

00288 
00289     def acquire(self, timeout=None):
00290         """ Try to acquire a 'read' lock
00291 
00292         To prevent race conditions, acquire first an exclusive lock,
00293         then acquire a read lock. Finally release the exclusive lock so
00294         other can have read lock, too.
00295         """
00296         if self._locked:
00297             raise RuntimeError("lock already locked")
00298         if self.writeLock.acquire(timeout):
00299             try:
00300                 self.lockDir = tempfile.mkdtemp('', self.fileName, self.dir)
00301                 self._locked = True
00302                 logging.debug('acquired read lock: %s' % self.lockDir)
00303                 return True
00304             finally:
00305                 self.writeLock.release()
00306         return False
00307 

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

Reimplemented in MoinMoin.util.lock.LazyWriteLock, and MoinMoin.util.lock.LazyReadLock.

Definition at line 137 of file lock.py.

00137 
00138     def exists(self):
00139         return os.path.exists(self.lockDir)

Here is the caller graph for this function:

def MoinMoin.util.lock.ExclusiveLock.expire (   self) [inherited]
Return True if the lock is expired or missing; False otherwise. 

Reimplemented in MoinMoin.util.lock.LazyWriteLock, and MoinMoin.util.lock.LazyReadLock.

Definition at line 158 of file lock.py.

00158 
00159     def expire(self):
00160         """ Return True if the lock is expired or missing; False otherwise. """
00161         if self.isExpired():
00162             self._removeLockDir()
00163             logging.debug("expired lock: %s" % self.lockDir)
00164             return True
00165         return False

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.util.lock.ExclusiveLock.isExpired (   self) [inherited]
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 in MoinMoin.util.lock.LazyWriteLock, and MoinMoin.util.lock.LazyReadLock.

Definition at line 140 of file lock.py.

00140 
00141     def isExpired(self):
00142         """ Return True if too old or missing; False otherwise
00143 
00144         TODO: Since stat returns times using whole seconds, this is
00145         quite broken. Maybe use OS specific calls like Carbon.File on
00146         Mac OS X?
00147         """
00148         if self.timeout is None:
00149             return not self.exists()
00150         try:
00151             lock_age = time.time() - filesys.stat(self.lockDir).st_mtime
00152             return lock_age > self.timeout
00153         except OSError, err:
00154             if err.errno == errno.ENOENT:
00155                 # No such lock file, therefore "expired"
00156                 return True
00157             raise

Here is the call graph for this function:

Here is the caller graph for this function:

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

def MoinMoin.util.lock.ExclusiveLock.release (   self) [inherited]
Release the lock 

Reimplemented in MoinMoin.util.lock.LazyWriteLock, and MoinMoin.util.lock.LazyReadLock.

Definition at line 126 of file lock.py.

00126 
00127     def release(self):
00128         """ Release the lock """
00129         if not self._locked:
00130             raise RuntimeError('lock already released: %s' % self.lockDir)
00131         self._removeLockDir()
00132         self._locked = False
00133         logging.debug('released lock: %s' % self.lockDir)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from MoinMoin.util.lock.ExclusiveLock.

Reimplemented in MoinMoin.util.lock.LazyReadLock.

Definition at line 300 of file lock.py.

Definition at line 89 of file lock.py.

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

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: