2016-06-17 02:07:49 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "threading/sync/lockable.hpp"
|
|
|
|
#include "threading/sync/spinlock.hpp"
|
|
|
|
|
|
|
|
template <class T, class lock_t = SpinLock>
|
|
|
|
class FreeList : Lockable<lock_t>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void swap(std::vector<T *> &dst) { std::swap(data, dst); }
|
|
|
|
|
|
|
|
void add(T *element)
|
|
|
|
{
|
|
|
|
auto lock = this->acquire_unique();
|
|
|
|
data.emplace_back(element);
|
|
|
|
}
|
|
|
|
|
2016-07-02 05:05:03 +08:00
|
|
|
size_t size() const
|
|
|
|
{
|
|
|
|
return data.size();
|
|
|
|
}
|
|
|
|
|
2016-06-17 02:07:49 +08:00
|
|
|
private:
|
|
|
|
std::vector<T *> data;
|
|
|
|
};
|