memgraph/data_structures/slstack.hpp
2015-09-13 11:34:17 +02:00

37 lines
569 B
C++

#ifndef MEMGRAPH_DATA_STRUCTURES_SPINLOCK_STACK_HPP
#define MEMGRAPH_DATA_STRUCTURES_SPINLOCK_STACK_HPP
#include <stack>
#include "threading/sync/spinlock.hpp"
#include "threading/sync/lockable.hpp"
template <class T>
class SpinLockStack : Lockable<SpinLock>
{
public:
T pop()
{
auto guard = acquire();
T elem = stack.top();
stack.pop();
return elem;
}
void push(const T& elem)
{
auto guard = acquire();
stack.push(elem);
}
private:
SpinLock lock;
std::stack<T> stack;
};
#endif