1 #ifndef _QUEUE_SPOT_HOLDER
2 #define _QUEUE_SPOT_HOLDER 1
4 // A RAII class to hold a shared resource, in our case an (unordered!) spot in a queue,
5 // for as long as a frame is under computation.
9 virtual ~QueueInterface() {}
10 virtual void take_queue_spot() = 0;
11 virtual void release_queue_spot() = 0;
14 class QueueSpotHolder {
16 QueueSpotHolder() : queue(nullptr) {}
18 explicit QueueSpotHolder(QueueInterface *queue) : queue(queue) {
19 queue->take_queue_spot();
22 QueueSpotHolder(QueueSpotHolder &&other) : queue(other.queue) {
23 other.queue = nullptr;
26 QueueSpotHolder &operator=(QueueSpotHolder &&other) {
28 other.queue = nullptr;
33 if (queue != nullptr) {
34 queue->release_queue_spot();
39 QueueSpotHolder(QueueSpotHolder &) = delete;
40 QueueSpotHolder &operator=(QueueSpotHolder &) = delete;
43 QueueInterface *queue;
46 #endif // !defined(_QUEUE_SPOT_HOLDER)