Clean-up pyocf c-python shared objects instance tracking
Signed-off-by: Jan Musial <jan.musial@intel.com>
This commit is contained in:
parent
4c9d4fe24e
commit
441e3c20d7
@ -59,7 +59,7 @@ class Data:
|
|||||||
DATA_POISON = 0xA5
|
DATA_POISON = 0xA5
|
||||||
PAGE_SIZE = 4096
|
PAGE_SIZE = 4096
|
||||||
|
|
||||||
_instances_ = {}
|
_instances_ = weakref.WeakValueDictionary()
|
||||||
_ocf_instances_ = []
|
_ocf_instances_ = []
|
||||||
|
|
||||||
def __init__(self, byte_count: int):
|
def __init__(self, byte_count: int):
|
||||||
@ -69,12 +69,12 @@ class Data:
|
|||||||
self.handle = cast(byref(self.buffer), c_void_p)
|
self.handle = cast(byref(self.buffer), c_void_p)
|
||||||
|
|
||||||
memset(self.handle, self.DATA_POISON, self.size)
|
memset(self.handle, self.DATA_POISON, self.size)
|
||||||
type(self)._instances_[self.handle.value] = weakref.ref(self)
|
type(self)._instances_[self.handle.value] = self
|
||||||
self._as_parameter_ = self.handle
|
self._as_parameter_ = self.handle
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls, ref):
|
def get_instance(cls, ref):
|
||||||
return cls._instances_[ref]()
|
return cls._instances_[ref]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_ops(cls):
|
def get_ops(cls):
|
||||||
|
@ -69,7 +69,7 @@ class LoggerPriv(Structure):
|
|||||||
|
|
||||||
|
|
||||||
class Logger(Structure):
|
class Logger(Structure):
|
||||||
_instances_ = {}
|
_instances_ = weakref.WeakValueDictionary()
|
||||||
|
|
||||||
_fields_ = [("logger", c_void_p)]
|
_fields_ = [("logger", c_void_p)]
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ class Logger(Structure):
|
|||||||
)
|
)
|
||||||
self.priv = LoggerPriv(_log=self._log)
|
self.priv = LoggerPriv(_log=self._log)
|
||||||
self._as_parameter_ = cast(pointer(self.priv), c_void_p).value
|
self._as_parameter_ = cast(pointer(self.priv), c_void_p).value
|
||||||
self._instances_[self._as_parameter_] = weakref.ref(self)
|
self._instances_[self._as_parameter_] = self
|
||||||
|
|
||||||
def get_ops(self):
|
def get_ops(self):
|
||||||
return self.ops
|
return self.ops
|
||||||
@ -92,7 +92,7 @@ class Logger(Structure):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls, ctx: int):
|
def get_instance(cls, ctx: int):
|
||||||
priv = OcfLib.getInstance().ocf_logger_get_priv(ctx)
|
priv = OcfLib.getInstance().ocf_logger_get_priv(ctx)
|
||||||
return cls._instances_[priv]()
|
return cls._instances_[priv]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@LoggerOps.LOG
|
@LoggerOps.LOG
|
||||||
|
@ -38,7 +38,7 @@ def io_queue_run(*, queue: Queue, kick: Condition, stop: Event):
|
|||||||
|
|
||||||
|
|
||||||
class Queue:
|
class Queue:
|
||||||
_instances_ = {}
|
_instances_ = weakref.WeakValueDictionary()
|
||||||
|
|
||||||
def __init__(self, cache, name):
|
def __init__(self, cache, name):
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ class Queue:
|
|||||||
if status:
|
if status:
|
||||||
raise OcfError("Couldn't create queue object", status)
|
raise OcfError("Couldn't create queue object", status)
|
||||||
|
|
||||||
Queue._instances_[self.handle.value] = weakref.ref(self)
|
Queue._instances_[self.handle.value] = self
|
||||||
self._as_parameter_ = self.handle
|
self._as_parameter_ = self.handle
|
||||||
|
|
||||||
self.stop_event = Event()
|
self.stop_event = Event()
|
||||||
@ -70,7 +70,7 @@ class Queue:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls, ref):
|
def get_instance(cls, ref):
|
||||||
return cls._instances_[ref]()
|
return cls._instances_[ref]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@QueueOps.KICK_SYNC
|
@QueueOps.KICK_SYNC
|
||||||
|
@ -78,8 +78,8 @@ class Volume(Structure):
|
|||||||
VOLUME_POISON = 0x13
|
VOLUME_POISON = 0x13
|
||||||
|
|
||||||
_fields_ = [("_storage", c_void_p)]
|
_fields_ = [("_storage", c_void_p)]
|
||||||
_instances_ = {}
|
_instances_ = weakref.WeakValueDictionary()
|
||||||
_uuid_ = {}
|
_uuid_ = weakref.WeakValueDictionary()
|
||||||
|
|
||||||
props = None
|
props = None
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ class Volume(Structure):
|
|||||||
else:
|
else:
|
||||||
self.uuid = str(id(self))
|
self.uuid = str(id(self))
|
||||||
|
|
||||||
type(self)._uuid_[self.uuid] = weakref.ref(self)
|
type(self)._uuid_[self.uuid] = self
|
||||||
|
|
||||||
self.data = create_string_buffer(int(self.size))
|
self.data = create_string_buffer(int(self.size))
|
||||||
memset(self.data, self.VOLUME_POISON, self.size)
|
memset(self.data, self.VOLUME_POISON, self.size)
|
||||||
@ -138,7 +138,7 @@ class Volume(Structure):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls, ref):
|
def get_instance(cls, ref):
|
||||||
instance = cls._instances_[ref]()
|
instance = cls._instances_[ref]
|
||||||
if instance is None:
|
if instance is None:
|
||||||
print("tried to access {} but it's gone".format(ref))
|
print("tried to access {} but it's gone".format(ref))
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ class Volume(Structure):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_by_uuid(cls, uuid):
|
def get_by_uuid(cls, uuid):
|
||||||
return cls._uuid_[uuid]()
|
return cls._uuid_[uuid]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@VolumeOps.SUBMIT_IO
|
@VolumeOps.SUBMIT_IO
|
||||||
@ -205,7 +205,7 @@ class Volume(Structure):
|
|||||||
if volume.opened:
|
if volume.opened:
|
||||||
return -OcfErrorCode.OCF_ERR_NOT_OPEN_EXC
|
return -OcfErrorCode.OCF_ERR_NOT_OPEN_EXC
|
||||||
|
|
||||||
Volume._instances_[ref] = weakref.ref(volume)
|
Volume._instances_[ref] = volume
|
||||||
|
|
||||||
return volume.open()
|
return volume.open()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user