first working threaded implementation of adt_checking

This commit is contained in:
2021-01-10 16:05:20 +01:00
parent d610ef690f
commit f2f171ff77
4 changed files with 76 additions and 11 deletions

View File

@@ -1 +1 @@
add_library(sets STATIC ADT_Stack.h ADT_Stack.cpp Node.h Node.cpp Stack.h Stack.cpp )
add_library(sets STATIC ADT_Stack.h ADT_Stack.cpp Node.h Node.cpp Stack.h Stack.cpp SimpleLockingStack.h SimpleLockingStack.cpp)

View 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;
}

View File

@@ -0,0 +1,16 @@
#include <vector>
#include <mutex>
#include "Stack.h"
class SimpleLockingStack:public Stack{
private:
std::vector<int> vec;
std::mutex mut;
public:
SimpleLockingStack(ADTOperationQueue * queue);
void push(int element);
int pop();
int size();
};