~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/counted_lock.py

  • Committer: Martin Pool
  • Date: 2008-06-11 03:56:46 UTC
  • mfrom: (3452.1.1 bzr.dev.mlm)
  • mto: This revision was merged to the branch mainline in revision 3493.
  • Revision ID: mbp@sourcefrog.net-20080611035646-gcfmu3tzavlvxj3z
\#212289 avoid assuming Windows diff tools can understand symlinks

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Counted lock class"""
18
18
 
27
27
 
28
28
    This can be used with any object that provides a basic Lock interface,
29
29
    including LockDirs and OS file locks.
30
 
 
31
 
    :ivar _token: While a write lock is held, this is the token 
32
 
        for it.
33
30
    """
34
31
 
35
32
    def __init__(self, real_lock):
68
65
 
69
66
        If the lock was originally acquired in read mode this will fail.
70
67
 
71
 
        :param token: If given and the lock is already held, 
72
 
            then validate that we already hold the real
73
 
            lock with this token.
74
 
 
75
 
        :returns: The token from the underlying lock.
 
68
        :param token: If non-None, reacquire the lock using this token.
76
69
        """
77
70
        if self._lock_count == 0:
78
 
            self._token = self._real_lock.lock_write(token=token)
 
71
            return_token = self._real_lock.lock_write(token)
79
72
            self._lock_mode = 'w'
80
73
            self._lock_count += 1
81
 
            return self._token
 
74
            return return_token
82
75
        elif self._lock_mode != 'w':
83
76
            raise errors.ReadOnlyError(self)
84
77
        else:
85
78
            self._real_lock.validate_token(token)
86
79
            self._lock_count += 1
87
 
            return self._token
 
80
            return token
88
81
 
89
82
    def unlock(self):
90
83
        if self._lock_count == 0: