memgraph/data_structures/sllist.hpp

38 lines
610 B
C++
Raw Normal View History

#pragma once
2015-06-22 20:31:26 +08:00
#include <list>
#include "sync/spinlock.hpp"
#include "sync/lockable.hpp"
template <class T>
class SpinLockedList : Lockable<SpinLock>
2015-06-22 20:31:26 +08:00
{
public:
void push_front(T item)
{
auto guard = this->acquire();
head = new Node(item, head);
}
bool remove(const T&)
{
// HM!
}
private:
struct Node : Lockable<SpinLock>
{
Node(T item, Node* next) : item(item), next(next) {}
T item;
Node* next;
};
Node* head;
// TODO add removed items to a list for garbage collection
// std::list<Node*> removed;
2015-06-22 20:31:26 +08:00
};