/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/counted_lock.py

  • Committer: Martin Pool
  • Date: 2008-05-12 06:16:05 UTC
  • mto: (3468.3.1 controlfiles)
  • mto: This revision was merged to the branch mainline in revision 4202.
  • Revision ID: mbp@sourcefrog.net-20080512061605-ceef1h4fspghl2k2
CountedLock should manage lock tokens

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
    This can be used with any object that provides a basic Lock interface,
35
35
    including LockDirs and OS file locks.
 
36
 
 
37
    :ivar _token: While a write lock is held, this is the token 
 
38
        for it.
36
39
    """
37
40
 
38
41
    def __init__(self, real_lock):
66
69
        """Acquire the lock in write mode.
67
70
 
68
71
        If the lock was originally acquired in read mode this will fail.
 
72
 
 
73
        :returns: The token from the underlying lock.
69
74
        """
70
75
        if self._lock_count == 0:
71
 
            self._real_lock.lock_write()
 
76
            self._token = self._real_lock.lock_write()
72
77
            self._lock_mode = 'w'
73
78
        elif self._lock_mode != 'w':
74
79
            raise ReadOnlyError(self)
75
80
        self._lock_count += 1
 
81
        return self._token
76
82
 
77
83
    def unlock(self):
78
84
        if self._lock_count == 0: