mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-01-29 19:25:50 +00:00
7c219fd731
git-subtree-dir: SpiffWorkflow git-subtree-split: 63db3e45947ec66b8d0efc2c74064004f8ff482c
31 lines
593 B
Python
31 lines
593 B
Python
from builtins import object
|
|
|
|
try:
|
|
# python 2
|
|
from mutex import mutex
|
|
|
|
except ImportError:
|
|
# python 3
|
|
from threading import Lock
|
|
|
|
class mutex(object):
|
|
|
|
def __init__(self):
|
|
self.lock = Lock()
|
|
|
|
def lock(self):
|
|
raise NotImplementedError
|
|
|
|
def test(self):
|
|
has = self.lock.acquire(blocking=False)
|
|
if has:
|
|
self.lock.release()
|
|
|
|
return has
|
|
|
|
def testandset(self):
|
|
return self.lock.acquire(blocking=False)
|
|
|
|
def unlock(self):
|
|
self.lock.release()
|