2016-08-30 07:45:07 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "database/db.hpp"
|
2016-09-08 20:25:52 +08:00
|
|
|
#include "threading/thread.hpp"
|
2016-08-30 07:45:07 +08:00
|
|
|
|
|
|
|
class Thread;
|
|
|
|
|
|
|
|
class Cleaning
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2016-09-08 20:25:52 +08:00
|
|
|
// How much sec is a cleaning_cycle in which cleaner will clean at most
|
2016-09-19 06:22:36 +08:00
|
|
|
// once. Starts cleaner thread.
|
2016-09-08 20:25:52 +08:00
|
|
|
Cleaning(ConcurrentMap<std::string, Db> &dbs, size_t cleaning_cycle);
|
2016-08-30 07:45:07 +08:00
|
|
|
|
2016-09-19 06:22:36 +08:00
|
|
|
// Destroys this object after this thread joins cleaning thread.
|
2016-08-30 07:45:07 +08:00
|
|
|
~Cleaning();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ConcurrentMap<std::string, Db> &dbms;
|
|
|
|
|
2016-09-08 20:25:52 +08:00
|
|
|
const size_t cleaning_cycle;
|
|
|
|
|
2016-08-30 07:45:07 +08:00
|
|
|
std::vector<std::unique_ptr<Thread>> cleaners;
|
|
|
|
|
2016-09-19 06:22:36 +08:00
|
|
|
// Should i continue cleaning.
|
2016-08-30 07:45:07 +08:00
|
|
|
std::atomic<bool> cleaning = {true};
|
|
|
|
};
|