Mercurial > public > mercurial-scm > hg
diff mercurial/lock.py @ 8108:a26d33749bd8
made repo locks recursive and deprecate refcounting based lock releasing
all locks should use the explicit lock.release
mercurial.lock.lock.__del__ handles unwrapping recursive locks
localrepo.lock/wlock are still using weakref in order to keep backward
compatibiltiy to releasing locks via garbage collection
by ensuring the release on __del__
author | Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de> |
---|---|
date | Wed, 22 Apr 2009 02:01:22 +0200 |
parents | 7197812e8d44 |
children | 87a1605979e4 |
line wrap: on
line diff
--- a/mercurial/lock.py Wed Apr 22 01:53:15 2009 +0200 +++ b/mercurial/lock.py Wed Apr 22 02:01:22 2009 +0200 @@ -27,6 +27,11 @@ self.lock() def __del__(self): + if self.held: + # ensure the lock will be removed + # even if recursive locking did occur + self.held = 1 + self.release() def lock(self): @@ -45,6 +50,9 @@ inst.locker) def trylock(self): + if self.held: + self.held += 1 + return if lock._host is None: lock._host = socket.gethostname() lockname = '%s:%s' % (lock._host, os.getpid()) @@ -97,7 +105,9 @@ return locker def release(self): - if self.held: + if self.held > 1: + self.held -= 1 + elif self.held is 1: self.held = 0 if self.releasefn: self.releasefn() @@ -105,3 +115,8 @@ os.unlink(self.f) except: pass +def release(*locks): + for lock in locks: + if lock is not None: + lock.release() +