File: cleaner.h

package info (click to toggle)
apt-cacher-ng 2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,032 kB
  • ctags: 1,705
  • sloc: cpp: 16,869; sh: 536; ansic: 404; perl: 377; makefile: 124
file content (59 lines) | stat: -rw-r--r-- 1,283 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * cleaner.h
 *
 *  Created on: 05.02.2011
 *      Author: ed
 */

#ifndef CLEANER_H_
#define CLEANER_H_

#include "lockable.h"
#include <ctime>
#include <limits>

namespace acng
{

/**
 * @brief Primitive task scheduler for internal helper functions
 *
 * It's based on few assumptions: a) called methods are static,
 * b) called method return the next time they want to be called
 * c) called method can be run at any time without side-effects
 * (they have to check the need of their internal work by themselves)
 *
 * The implementation comes from a trade-off. Data size is not big enough to justify use of priority_queue,
 * and it also makes not much sense since time points need to be adjusted for specific usecases without
 * need to invalidate previous entries sitting in the prio-queue.
 *
 */
class cleaner : public base_with_condition
{
public:
	cleaner();
	void Init();
	virtual ~cleaner();

	void WorkLoop();
	void Stop();

	enum eType : char
	{
		TYPE_EXFILEITEM, TYPE_ACFGHOOKS, /* TYPE_EXDNS,*/ TYPE_EXCONNS,
		ETYPE_MAX
	};
	void ScheduleFor(time_t when, eType what);
	void dump_status();

private:
	pthread_t m_thr;
	time_t stamps[cleaner::ETYPE_MAX];
	bool m_terminating = false;
};

extern cleaner g_victor; // ... down to the nap

}

#endif /* CLEANER_H_ */