Resource Tuner
Loading...
Searching...
No Matches
OrderedQueue.h
1// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2// SPDX-License-Identifier: BSD-3-Clause-Clear
3
4#ifndef ORDERED_QUEUE_H
5#define ORDERED_QUEUE_H
6
7#include <iostream>
8#include <queue>
9#include <vector>
10#include <mutex>
11#include <condition_variable>
12
13#include "Message.h"
14#include "MemoryPool.h"
15#include "Utils.h"
16
23protected:
24 int32_t mElementCount;
25 std::mutex mOrderedQueueMutex;
26 std::condition_variable mOrderedQueueCondition;
27 int8_t lockStatus;
28
29 struct QueueOrdering {
30 int8_t operator() (Message* &a, Message* &b) {
31 return a->getPriority() > b->getPriority();
32 }
33 };
34
39 std::priority_queue<Message*, std::vector<Message*>, QueueOrdering> mOrderedQueue;
40
41public:
44
53 int8_t addAndWakeup(Message* req);
54
60 virtual void orderedQueueConsumerHook() = 0;
61
71
76 void wait();
77
85
86 void forcefulAwake();
87};
88
89#endif
Base-Type for Request and Signal classes.
Definition Message.h:12
This class represents a mutex-protected multiple producer, single consumer priority queue.
Message * pop()
Used by the consumer end to poll a request from the OrderedQueue.
void wait()
Used by the Consumer end to wait for Requests.
virtual void orderedQueueConsumerHook()=0
Provides a mechanism, to hook or plug-in the Consumer Code.
int8_t addAndWakeup(Message *req)
Used by the producers to add a new request to the OrderedQueue.
std::priority_queue< Message *, std::vector< Message * >, QueueOrdering > mOrderedQueue
Core OrderedQueue Data Structure, to store the Requests pushed by the Publisher threads....
int8_t hasPendingTasks()
Used by the consumer to check if there are any pending requests in the OrderedQueue.