memgraph/data_structures/slstack.hpp

36 lines
550 B
C++
Raw Normal View History

2015-06-22 04:20:36 +08:00
#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"
2015-06-22 04:20:36 +08:00
template <class T>
class SpinLockStack : Lockable<SpinLock>
2015-06-22 04:20:36 +08:00
{
public:
T pop()
{
auto guard = acquire();
2015-06-22 04:20:36 +08:00
T elem = stack.top();
stack.pop();
return elem;
}
void push(const T& elem)
{
auto guard = acquire();
2015-06-22 04:20:36 +08:00
stack.push(elem);
}
private:
std::stack<T> stack;
};
#endif