Revision 42a999d1 lib/locking.py
b/lib/locking.py | ||
---|---|---|
29 | 29 |
from ganeti import utils |
30 | 30 |
|
31 | 31 |
|
32 |
def ssynchronized(lock, shared=0): |
|
33 |
"""Shared Synchronization decorator. |
|
34 |
|
|
35 |
Calls the function holding the given lock, either in exclusive or shared |
|
36 |
mode. It requires the passed lock to be a SharedLock (or support its |
|
37 |
semantics). |
|
38 |
|
|
39 |
""" |
|
40 |
def wrap(fn): |
|
41 |
def sync_function(*args, **kwargs): |
|
42 |
lock.acquire(shared=shared) |
|
43 |
try: |
|
44 |
return fn(*args, **kwargs) |
|
45 |
finally: |
|
46 |
lock.release() |
|
47 |
return sync_function |
|
48 |
return wrap |
|
49 |
|
|
50 |
|
|
32 | 51 |
class SharedLock: |
33 | 52 |
"""Implements a shared lock. |
34 | 53 |
|
Also available in: Unified diff