aboutsummaryrefslogtreecommitdiff
path: root/music_sampler/lock.py
diff options
context:
space:
mode:
Diffstat (limited to 'music_sampler/lock.py')
-rw-r--r--music_sampler/lock.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/music_sampler/lock.py b/music_sampler/lock.py
new file mode 100644
index 0000000..9beafcd
--- /dev/null
+++ b/music_sampler/lock.py
@@ -0,0 +1,23 @@
1import threading
2
3from . import debug_print
4
5class Lock:
6 def __init__(self, lock_type):
7 self.type = lock_type
8 self.lock = threading.RLock()
9
10 def __enter__(self, *args, **kwargs):
11 self.acquire(*args, **kwargs)
12
13 def __exit__(self, type, value, traceback, *args, **kwargs):
14 self.release(*args, **kwargs)
15
16 def acquire(self, *args, **kwargs):
17 #debug_print("acquiring lock for {}".format(self.type))
18 self.lock.acquire(*args, **kwargs)
19
20 def release(self, *args, **kwargs):
21 #debug_print("releasing lock for {}".format(self.type))
22 self.lock.release(*args, **kwargs)
23