~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/counted_lock.py

  • Committer: Martin Pool
  • Date: 2009-03-24 04:49:51 UTC
  • mfrom: (3407.2.20 controlfiles)
  • mto: This revision was merged to the branch mainline in revision 4202.
  • Revision ID: mbp@sourcefrog.net-20090324044951-k5h6x6u0zz4721m5
bzrdir takes responsibility for file/directory unix modes

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):
62
65
            self._lock_count = 1
63
66
            self._lock_mode = 'r'
64
67
 
65
 
    def lock_write(self):
 
68
    def lock_write(self, token=None):
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
        :param token: If given and the lock is already held, 
 
74
            then validate that we already hold the real
 
75
            lock with this token.
 
76
 
 
77
        :returns: The token from the underlying lock.
69
78
        """
70
79
        if self._lock_count == 0:
71
 
            self._real_lock.lock_write()
 
80
            self._token = self._real_lock.lock_write(token=token)
72
81
            self._lock_mode = 'w'
73
82
        elif self._lock_mode != 'w':
74
83
            raise ReadOnlyError(self)
75
84
        self._lock_count += 1
 
85
        return self._token
76
86
 
77
87
    def unlock(self):
78
88
        if self._lock_count == 0: