mirror of
https://github.com/13hannes11/UU_la_parallel_programming_practical_assignments.git
synced 2024-09-04 00:50:58 +02:00
first working threaded implementation of adt_checking
This commit is contained in:
26
Assignment_3/lib/SimpleLockingStack.cpp
Normal file
26
Assignment_3/lib/SimpleLockingStack.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "SimpleLockingStack.h"
|
||||
#include "ADT_Stack.h"
|
||||
|
||||
SimpleLockingStack::SimpleLockingStack(ADTOperationQueue * queue) : Stack(queue) { }
|
||||
|
||||
void SimpleLockingStack::push(int element) {
|
||||
mut.lock();
|
||||
vec.push_back(element);
|
||||
op_queue->enqueue(create_operation(methodname::push, element));
|
||||
mut.unlock();
|
||||
}
|
||||
int SimpleLockingStack::pop() {
|
||||
mut.lock();
|
||||
int e = vec.back();
|
||||
vec.pop_back();
|
||||
op_queue->enqueue(create_operation(methodname::pop, e));
|
||||
mut.unlock();
|
||||
return e;
|
||||
}
|
||||
int SimpleLockingStack::size() {
|
||||
mut.lock();
|
||||
int s = vec.size();
|
||||
op_queue->enqueue(create_operation(methodname::size, s));
|
||||
mut.unlock();
|
||||
return s;
|
||||
}
|
||||
Reference in New Issue
Block a user