2015-11-23 04:35:40 +08:00
|
|
|
#pragma once
|
|
|
|
|
2016-07-31 04:20:21 +08:00
|
|
|
// TODO: remove from here and from the project
|
2015-11-23 04:35:40 +08:00
|
|
|
#include <atomic>
|
2016-07-31 04:20:21 +08:00
|
|
|
#include <iostream>
|
2015-11-23 04:35:40 +08:00
|
|
|
|
|
|
|
#include "threading/sync/lockable.hpp"
|
2016-06-17 02:07:49 +08:00
|
|
|
#include "utils/crtp.hpp"
|
2015-11-23 04:35:40 +08:00
|
|
|
|
2016-06-17 02:07:49 +08:00
|
|
|
template <class Derived, class lock_t = SpinLock>
|
2016-07-31 20:56:13 +08:00
|
|
|
class LazyGC : public Crtp<Derived>, public Lockable<lock_t>
|
|
|
|
{
|
2016-08-02 20:23:39 +08:00
|
|
|
public:
|
|
|
|
// add_ref method should be called by a thread
|
|
|
|
// when the thread has to do something over
|
|
|
|
// object which has to be lazy cleaned when
|
|
|
|
// the thread finish it job
|
|
|
|
void add_ref()
|
|
|
|
{
|
|
|
|
auto lock = this->acquire_unique();
|
|
|
|
++count;
|
|
|
|
}
|
2015-11-23 04:35:40 +08:00
|
|
|
|
2016-08-02 20:23:39 +08:00
|
|
|
protected:
|
|
|
|
size_t count{0};
|
2015-11-23 04:35:40 +08:00
|
|
|
};
|