mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-24 10:07:48 +00:00
85d1965abd
SUMMARY dosep.py starts lots and lots of dotest instances. This option helps you find if two (or more) dotest instances are using the same directory at the same time. Enable it to cause test failures and stderr messages if dotest instances try to run in the same directory simultaneously. It is disabled by default because it litters the test directories with ".dirlock" files TEST PLAN Set lldbtest.debug_confirm_directory_exclusivity = True run ./dosep.py Differential Revision: http://reviews.llvm.org/D9868 llvm-svn: 237935
28 lines
617 B
Python
28 lines
617 B
Python
"""
|
|
Interprocess mutex based on file locks
|
|
"""
|
|
|
|
import fcntl
|
|
import os
|
|
|
|
class Lock:
|
|
|
|
def __init__(self, filename):
|
|
self.filename = filename
|
|
# This will create it if it does not exist already
|
|
unbuffered = 0
|
|
self.handle = open(filename, 'a+', unbuffered)
|
|
|
|
def acquire(self):
|
|
fcntl.flock(self.handle, fcntl.LOCK_EX)
|
|
|
|
# will throw IOError if unavailable
|
|
def try_acquire(self):
|
|
fcntl.flock(self.handle, fcntl.LOCK_NB | fcntl.LOCK_EX)
|
|
|
|
def release(self):
|
|
fcntl.flock(self.handle, fcntl.LOCK_UN)
|
|
|
|
def __del__(self):
|
|
self.handle.close()
|