summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2015-10-27 00:35:06 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2015-10-27 00:35:06 -0700
commitaf7b96c14a555805a50f13a1fa1343650db184ab (patch)
tree4bb3b2390feb14698d8de8dbedf0d41803c6f3f7 /lib
parentead8ac58c6ecde1b8bd32e9f651483b57c7e3bd5 (diff)
downloadspack-af7b96c14a555805a50f13a1fa1343650db184ab.tar.gz
spack-af7b96c14a555805a50f13a1fa1343650db184ab.tar.bz2
spack-af7b96c14a555805a50f13a1fa1343650db184ab.tar.xz
spack-af7b96c14a555805a50f13a1fa1343650db184ab.zip
Lock acquires return True/False depending on whether they got POSIX lock.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/llnl/util/lock.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/spack/llnl/util/lock.py b/lib/spack/llnl/util/lock.py
index 6e49bf74e6..dcca37687e 100644
--- a/lib/spack/llnl/util/lock.py
+++ b/lib/spack/llnl/util/lock.py
@@ -95,10 +95,15 @@ class Lock(object):
order, but the POSIX lock is held until all local read and
write locks are released.
+ Returns True if it is the first acquire and actually acquires
+ the POSIX lock, False if it is a nested transaction.
+
"""
- if self._reads == 0 and self._writes == 0:
- self._lock(fcntl.LOCK_SH, timeout)
self._reads += 1
+ if self._reads == 1 and self._writes == 0:
+ self._lock(fcntl.LOCK_SH, timeout)
+ return True
+ return False
def acquire_write(self, timeout=_default_timeout):
@@ -107,10 +112,16 @@ class Lock(object):
Read and write locks can be acquired and released in arbitrary
order, but the POSIX lock is held until all local read and
write locks are released.
+
+ Returns True if it is the first acquire and actually acquires
+ the POSIX lock, False if it is a nested transaction.
+
"""
- if self._writes == 0:
- self._lock(fcntl.LOCK_EX, timeout)
self._writes += 1
+ if self._writes == 1:
+ self._lock(fcntl.LOCK_EX, timeout)
+ return True
+ return False
def release_read(self):