]> git.ipfire.org Git - thirdparty/squid.git/blob - src/base/RunnersRegistry.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / base / RunnersRegistry.cc
1 /*
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #include "squid.h"
10 #include "base/RunnersRegistry.h"
11 #include <set>
12
13 /// a collection of unique runners, in no particular order
14 typedef std::set<RegisteredRunner*> Runners;
15 /// all known runners
16 static Runners *TheRunners = NULL;
17
18 /// safely returns registered runners, initializing structures as needed
19 static Runners &
20 GetRunners()
21 {
22 if (!TheRunners)
23 TheRunners = new Runners;
24 return *TheRunners;
25 }
26
27 int
28 RegisterRunner(RegisteredRunner *rr)
29 {
30 Runners &runners = GetRunners();
31 runners.insert(rr);
32 return runners.size();
33 }
34
35 int
36 DeregisterRunner(RegisteredRunner *rr)
37 {
38 Runners &runners = GetRunners();
39 runners.erase(rr);
40 return runners.size();
41 }
42
43 void
44 RunRegistered(const RegisteredRunner::Method &m)
45 {
46 Runners &runners = GetRunners();
47 typedef Runners::iterator RRI;
48 for (RRI i = runners.begin(); i != runners.end(); ++i)
49 ((*i)->*m)();
50
51 if (m == &RegisteredRunner::finishShutdown) {
52 delete TheRunners;
53 TheRunners = NULL;
54 }
55 }
56
57 bool
58 UseThisStatic(const void *)
59 {
60 return true;
61 }
62