2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2017 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2013-2014 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
8 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
10 * Copyright (C) 2007, 2010 Craig Edwards <brain@inspircd.org>
11 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
13 * This file is part of InspIRCd. InspIRCd is free software: you can
14 * redistribute it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2.
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 void Timer::SetInterval(unsigned int newinterval)
31 ServerInstance->Timers.DelTimer(this);
33 SetTrigger(ServerInstance->Time() + newinterval);
34 ServerInstance->Timers.AddTimer(this);
37 Timer::Timer(unsigned int secs_from_now, bool repeating)
38 : trigger(ServerInstance->Time() + secs_from_now)
46 ServerInstance->Timers.DelTimer(this);
49 void TimerManager::TickTimers(time_t TIME)
51 for (TimerMap::iterator i = Timers.begin(); i != Timers.end(); )
54 if (t->GetTrigger() > TIME)
64 t->SetTrigger(TIME + t->GetInterval());
70 void TimerManager::DelTimer(Timer* t)
72 std::pair<TimerMap::iterator, TimerMap::iterator> itpair = Timers.equal_range(t->GetTrigger());
74 for (TimerMap::iterator i = itpair.first; i != itpair.second; ++i)
84 void TimerManager::AddTimer(Timer* t)
86 Timers.insert(std::make_pair(t->GetTrigger(), t));