Commit 7996a135 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add a simple decorator for instance methods

This is just a simple, hardcoded decorator for object methods needing
synchronization on the _lock instance attribute.

Reviewed-by: ultrotter
parent c8549bfd
...@@ -28,6 +28,7 @@ from ganeti import constants ...@@ -28,6 +28,7 @@ from ganeti import constants
from ganeti import workerpool from ganeti import workerpool
from ganeti import errors from ganeti import errors
from ganeti import mcpu from ganeti import mcpu
from ganeti import utils
JOBQUEUE_THREADS = 5 JOBQUEUE_THREADS = 5
......
...@@ -1063,3 +1063,22 @@ def CheckVolumeGroupSize(vglist, vgname, minsize): ...@@ -1063,3 +1063,22 @@ def CheckVolumeGroupSize(vglist, vgname, minsize):
return ("volume group '%s' too small (%s MiB required, %d MiB found)" % return ("volume group '%s' too small (%s MiB required, %d MiB found)" %
(vgname, minsize, vgsize)) (vgname, minsize, vgsize))
return None return None
def LockedMethod(fn):
"""Synchronized object access decorator.
This decorator is intended to protect access to an object using the
object's own lock which is hardcoded to '_lock'.
"""
def wrapper(self, *args, **kwargs):
assert hasattr(self, '_lock')
lock = self._lock
lock.acquire()
try:
result = fn(self, *args, **kwargs)
finally:
lock.release()
return result
return wrapper
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment