mirror of
https://github.com/13hannes11/UU_la_parallel_programming_practical_assignments.git
synced 2024-09-04 00:50:58 +02:00
add adt operation queue
This commit is contained in:
@@ -65,3 +65,22 @@ void ADTStack::do_ops(std::vector<operation> ops) {
|
||||
}
|
||||
}
|
||||
|
||||
void ADTOperationQueue::enqueue(operation op) {
|
||||
mutex.lock();
|
||||
queue.push(op);
|
||||
mutex.unlock();
|
||||
}
|
||||
operation ADTOperationQueue::dequeue() {
|
||||
mutex.lock();
|
||||
operation op = this->queue.front();
|
||||
queue.pop();
|
||||
mutex.unlock();
|
||||
return op;
|
||||
}
|
||||
size_t ADTOperationQueue::size() {
|
||||
this->mutex.lock();
|
||||
size_t s = queue.size();
|
||||
this->mutex.unlock();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
|
||||
enum methodname {push, pop, size, noop};
|
||||
typedef struct _operation{
|
||||
@@ -18,4 +20,14 @@ class ADTStack {
|
||||
void size(int output);
|
||||
void do_op(operation * op);
|
||||
void do_ops(std::vector<operation> ops);
|
||||
};
|
||||
|
||||
class ADTOperationQueue{
|
||||
private:
|
||||
std::queue<operation> queue;
|
||||
std::mutex mutex;
|
||||
public:
|
||||
void enqueue(operation op);
|
||||
operation dequeue();
|
||||
size_t size();
|
||||
};
|
||||
Reference in New Issue
Block a user