]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
bitbake/utils.py: Add option to lockfiles to return immediately rather than wait
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 27 May 2011 15:13:27 +0000 (16:13 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 27 May 2011 16:24:12 +0000 (17:24 +0100)
There are usecases where we don't want to block waiting for a lockfile
so enhance the lockfile handling functions to support this.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
lib/bb/utils.py

index ccafda19e3980d07b1b673282bfc0411b970e339..82e5dc427779420d26b1f90e0a897fa5b4e84608 100644 (file)
@@ -402,7 +402,7 @@ def fileslocked(files):
     for lock in locks:
         bb.utils.unlockfile(lock)
 
-def lockfile(name, shared=False):
+def lockfile(name, shared=False, retry=True):
     """
     Use the file fn as a lock file, return when the lock has been acquired.
     Returns a variable to pass to unlockfile().
@@ -418,6 +418,8 @@ def lockfile(name, shared=False):
     op = fcntl.LOCK_EX
     if shared:
         op = fcntl.LOCK_SH
+    if not retry:
+        op = op | fcntl.LOCK_NB
 
     while True:
         # If we leave the lockfiles lying around there is no problem
@@ -442,6 +444,8 @@ def lockfile(name, shared=False):
             lf.close()
         except Exception:
             continue
+        if not retry:
+            return None
 
 def unlockfile(lf):
     """