mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-23 14:41:43 +00:00
add Lock.got_exclusive_lock
This commit is contained in:
parent
976925c625
commit
26007c0162
2 changed files with 13 additions and 0 deletions
|
@ -299,6 +299,8 @@ def release(self):
|
||||||
self._roster.modify(SHARED, REMOVE)
|
self._roster.modify(SHARED, REMOVE)
|
||||||
|
|
||||||
def upgrade(self):
|
def upgrade(self):
|
||||||
|
# WARNING: if multiple read-lockers want to upgrade, it will deadlock because they
|
||||||
|
# all will wait until the other read locks go away - and that won't happen.
|
||||||
if not self.is_exclusive:
|
if not self.is_exclusive:
|
||||||
self.acquire(exclusive=True, remove=SHARED)
|
self.acquire(exclusive=True, remove=SHARED)
|
||||||
|
|
||||||
|
@ -306,6 +308,9 @@ def downgrade(self):
|
||||||
if self.is_exclusive:
|
if self.is_exclusive:
|
||||||
self.acquire(exclusive=False, remove=EXCLUSIVE)
|
self.acquire(exclusive=False, remove=EXCLUSIVE)
|
||||||
|
|
||||||
|
def got_exclusive_lock(self):
|
||||||
|
return self.is_exclusive and self._lock.is_locked() and self._lock.by_me()
|
||||||
|
|
||||||
def break_lock(self):
|
def break_lock(self):
|
||||||
self._roster.remove()
|
self._roster.remove()
|
||||||
self._lock.break_lock()
|
self._lock.break_lock()
|
||||||
|
|
|
@ -86,6 +86,14 @@ def test_downgrade(self, lockpath):
|
||||||
assert len(lock._roster.get(SHARED)) == 1
|
assert len(lock._roster.get(SHARED)) == 1
|
||||||
assert len(lock._roster.get(EXCLUSIVE)) == 0
|
assert len(lock._roster.get(EXCLUSIVE)) == 0
|
||||||
|
|
||||||
|
def test_got_exclusive_lock(self, lockpath):
|
||||||
|
lock = UpgradableLock(lockpath, exclusive=True, id=ID1)
|
||||||
|
assert not lock.got_exclusive_lock()
|
||||||
|
lock.acquire()
|
||||||
|
assert lock.got_exclusive_lock()
|
||||||
|
lock.release()
|
||||||
|
assert not lock.got_exclusive_lock()
|
||||||
|
|
||||||
def test_break(self, lockpath):
|
def test_break(self, lockpath):
|
||||||
lock = UpgradableLock(lockpath, exclusive=True, id=ID1).acquire()
|
lock = UpgradableLock(lockpath, exclusive=True, id=ID1).acquire()
|
||||||
lock.break_lock()
|
lock.break_lock()
|
||||||
|
|
Loading…
Reference in a new issue