]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/timer.cpp
Remove an extern, partly because it's unused, partly because it then gets shadowed...
[user/henk/code/inspircd.git] / src / timer.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include <vector>
18 #include <map>
19 #include "inspircd_config.h"
20 #include "inspircd.h"
21 #include "typedefs.h"
22 #include "helperfuncs.h"
23 #include "timer.h"
24
25 typedef std::vector<InspTimer*> timergroup;
26 typedef std::map<time_t, timergroup*> timerlist;
27
28 timerlist Timers;
29
30 void TickTimers(time_t TIME)
31 {
32         timerlist::iterator found = Timers.find(TIME);
33
34         if (found != Timers.end())
35         {
36                 timergroup* x = found->second;
37                 /*
38                  * There are pending timers to trigger
39                  */
40                 for (timergroup::iterator y = x->begin(); y != x->end(); y++)
41                 {
42                         InspTimer* n = *y;
43                         n->Tick(TIME);
44                         delete n;
45                 }
46
47                 Timers.erase(found);
48                 delete x;
49         }
50 }
51
52 /*
53  * Because some muppets may do odd things, and their ircd may lock up due
54  * to crappy 3rd party modules, or they may change their system time a bit,
55  * this accounts for shifts of up to 120 secs by looking behind for missed
56  * timers and executing them. This is only executed once every 5 secs.
57  * If you move your clock BACK, and your timers move further ahead as a result,
58  * then tough titty you'll just have to wait.
59  */
60 void TickMissedTimers(time_t TIME)
61 {
62         for (time_t n = TIME-1; n > TIME-120; n--)
63         {
64                 timerlist::iterator found = Timers.find(n);
65                 if (found != Timers.end())
66                 {
67                         timergroup* x = found->second;
68                         for (timergroup::iterator y = x->begin(); y != x->end(); y++)
69                         {
70                                 InspTimer* z = *y;
71                                 z->Tick(TIME);
72                                 delete z;
73                         }
74
75                         Timers.erase(found);
76                         delete x;
77                 }
78         }
79 }
80
81 void AddTimer(InspTimer* T)
82 {
83         timergroup* x = NULL;
84
85         timerlist::iterator found = Timers.find(T->GetTimer());
86         
87         if (found != Timers.end())
88         {
89                 x = found->second;
90         }
91         else
92         {
93                 x = new timergroup;
94                 Timers[T->GetTimer()] = x;
95         }
96
97         x->push_back(T);
98 }