| Index: src/DefaultTimer.h | 
| diff --git a/src/DefaultTimer.h b/src/DefaultTimer.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..91ec09cb967cbd75980930c5778fc6e158b30b5c | 
| --- /dev/null | 
| +++ b/src/DefaultTimer.h | 
| @@ -0,0 +1,61 @@ | 
| +/* | 
| +* This file is part of Adblock Plus <https://adblockplus.org/>, | 
| +* Copyright (C) 2006-2017 eyeo GmbH | 
| +* | 
| +* Adblock Plus is free software: you can redistribute it and/or modify | 
| +* it under the terms of the GNU General Public License version 3 as | 
| +* published by the Free Software Foundation. | 
| +* | 
| +* Adblock Plus is distributed in the hope that it will be useful, | 
| +* but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| +* GNU General Public License for more details. | 
| +* | 
| +* You should have received a copy of the GNU General Public License | 
| +* along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 
| +*/ | 
| + | 
| +#ifndef ADBLOCK_PLUS_DEFAULT_TIMER_H | 
| +#define ADBLOCK_PLUS_DEFAULT_TIMER_H | 
| + | 
| +#include <AdblockPlus/ITimer.h> | 
| +#include <mutex> | 
| +#include <condition_variable> | 
| +#include <queue> | 
| +#include <atomic> | 
| +#include <thread> | 
| + | 
| +namespace AdblockPlus | 
| +{ | 
| +  class DefaultTimer : public ITimer | 
| +  { | 
| +    struct TimerUnit { | 
| +      std::chrono::steady_clock::time_point fireAt; | 
| +      TimerCallback callback; | 
| +    }; | 
| +    struct TimerUnitComparator { | 
| +      typedef bool result_type; | 
| +      typedef TimerUnit first_argument_type; | 
| +      typedef TimerUnit second_argument_type; | 
| +      bool operator()(const first_argument_type& t1, const second_argument_type& t2) const { | 
| +        // pay attention 2 < 1 because we need the smallest time at the top. | 
| +        return t2.fireAt < t1.fireAt; | 
| +      } | 
| +    }; | 
| +    typedef std::priority_queue<TimerUnit, std::vector<TimerUnit>, TimerUnitComparator> TimerUnits; | 
| +  public: | 
| +    DefaultTimer(); | 
| +    ~DefaultTimer(); | 
| +    void SetTimer(const std::chrono::milliseconds& timeout, const TimerCallback& timerCallback) override; | 
| +  private: | 
| +    void ThreadFunc(); | 
| +  private: | 
| +    std::mutex mutex; | 
| +    std::condition_variable conditionVariable; | 
| +    TimerUnits timers; | 
| +    std::atomic<bool> shouldThreadStop; | 
| +    std::thread m_thread; | 
| +  }; | 
| +} | 
| + | 
| +#endif | 
|  |