It should be easier to write a wrapper class and make STL priority_queue
a member variable. But to make sure you set up the custom comparator for your queue, otherwise the STL data structure won't know how to order your objects. There are a couple of ways to do it. I'm just using one as example here.
If you want to add synchronization to your data structure, you can simple add internal locks and/or condition variables in your class to lock/unlock the member variable q
.
class TaskQueue {
public:
TaskQueue() {};
bool empty() {
return q.empty()
}
void push(Task* t) {
q.push(t);
}
void pop() {
if (q.empty()) {
// You may want to do something here like throw an exception or not
}
// if not empty
q.pop();
}
Task* top() {
if (q.empty()) {
// You may want to do something here like throw an exception or not
}
return q.top();
}
private:
class TaskPtrComparator {
public:
bool operator()(Task* t1, Task* t2) {
// Comparison code here
}
};
priority_queue<Task*, vector<Task*>, TaskPtrComparator> q;
};