]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/ocf/tests/functional/pyocf/types/queue.py
2 # Copyright(c) 2019 Intel Corporation
3 # SPDX-License-Identifier: BSD-3-Clause-Clear
6 from ctypes
import c_void_p
, CFUNCTYPE
, Structure
, byref
7 from threading
import Thread
, Condition
, Event
10 from ..ocf
import OcfLib
11 from .shared
import OcfError
14 class QueueOps(Structure
):
15 KICK
= CFUNCTYPE(None, c_void_p
)
16 KICK_SYNC
= CFUNCTYPE(None, c_void_p
)
17 STOP
= CFUNCTYPE(None, c_void_p
)
19 _fields_
= [("kick", KICK
), ("kick_sync", KICK_SYNC
), ("stop", STOP
)]
26 def io_queue_run(*, queue
: Queue
, kick
: Condition
, stop
: Event
):
28 return stop
.is_set() or OcfLib
.getInstance().ocf_queue_pending_io(queue
)
32 kick
.wait_for(wait_predicate
)
34 OcfLib
.getInstance().ocf_queue_run(queue
)
36 if stop
.is_set() and not OcfLib
.getInstance().ocf_queue_pending_io(queue
):
43 def __init__(self
, cache
, name
, mngt_queue
: bool = False):
45 self
.ops
= QueueOps(kick
=type(self
)._kick
, stop
=type(self
)._stop
)
47 self
.handle
= c_void_p()
48 status
= OcfLib
.getInstance().ocf_queue_create(
49 cache
.cache_handle
, byref(self
.handle
), byref(self
.ops
)
52 raise OcfError("Couldn't create queue object", status
)
54 Queue
._instances
_[self
.handle
.value
] = weakref
.ref(self
)
55 self
._as
_parameter
_ = self
.handle
57 self
.stop_event
= Event()
58 self
.kick_condition
= Condition()
65 "kick": self
.kick_condition
,
66 "stop": self
.stop_event
,
70 self
.mngt_queue
= mngt_queue
73 def get_instance(cls
, ref
):
74 return cls
._instances
_[ref
]()
79 Queue
.get_instance(ref
).kick_sync()
84 Queue
.get_instance(ref
).kick()
89 Queue
.get_instance(ref
).stop()
92 OcfLib
.getInstance().ocf_queue_run(self
.handle
)
95 with self
.kick_condition
:
96 self
.kick_condition
.notify_all()
99 with self
.kick_condition
:
100 self
.stop_event
.set()
101 self
.kick_condition
.notify_all()
105 OcfLib
.getInstance().ocf_queue_put(self
)