~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/counted_lock.py

  • Committer: Martin Pool
  • Date: 2008-05-12 06:29:29 UTC
  • mto: (3468.3.1 controlfiles)
  • mto: This revision was merged to the branch mainline in revision 4202.
  • Revision ID: mbp@sourcefrog.net-20080512062929-2x3mz8j2a33i8agp
Add lock token support to CountedLock

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
            self._lock_count = 1
66
66
            self._lock_mode = 'r'
67
67
 
68
 
    def lock_write(self):
 
68
    def lock_write(self, token=None):
69
69
        """Acquire the lock in write mode.
70
70
 
71
71
        If the lock was originally acquired in read mode this will fail.
72
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
 
73
77
        :returns: The token from the underlying lock.
74
78
        """
75
79
        if self._lock_count == 0:
76
 
            self._token = self._real_lock.lock_write()
 
80
            self._token = self._real_lock.lock_write(token=token)
77
81
            self._lock_mode = 'w'
78
82
        elif self._lock_mode != 'w':
79
83
            raise ReadOnlyError(self)