Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/DefaultTimer.h

Issue 29402565: Issue 5082 - fix possible race condition in DefaultTimer (Closed)
Patch Set: Created April 4, 2017, 10:50 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/DefaultTimer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #ifndef ADBLOCK_PLUS_DEFAULT_TIMER_H 18 #ifndef ADBLOCK_PLUS_DEFAULT_TIMER_H
19 #define ADBLOCK_PLUS_DEFAULT_TIMER_H 19 #define ADBLOCK_PLUS_DEFAULT_TIMER_H
20 20
21 #include <AdblockPlus/ITimer.h> 21 #include <AdblockPlus/ITimer.h>
22 #include <mutex> 22 #include <mutex>
23 #include <condition_variable> 23 #include <condition_variable>
24 #include <queue> 24 #include <queue>
25 #include <atomic>
26 #include <thread> 25 #include <thread>
27 26
28 namespace AdblockPlus 27 namespace AdblockPlus
29 { 28 {
30 class DefaultTimer : public ITimer 29 class DefaultTimer : public ITimer
31 { 30 {
32 struct TimerUnit 31 struct TimerUnit
33 { 32 {
34 std::chrono::steady_clock::time_point fireAt; 33 std::chrono::steady_clock::time_point fireAt;
35 TimerCallback callback; 34 TimerCallback callback;
(...skipping 10 matching lines...) Expand all
46 public: 45 public:
47 DefaultTimer(); 46 DefaultTimer();
48 ~DefaultTimer(); 47 ~DefaultTimer();
49 void SetTimer(const std::chrono::milliseconds& timeout, const TimerCallback& timerCallback) override; 48 void SetTimer(const std::chrono::milliseconds& timeout, const TimerCallback& timerCallback) override;
50 private: 49 private:
51 void ThreadFunc(); 50 void ThreadFunc();
52 private: 51 private:
53 std::mutex mutex; 52 std::mutex mutex;
54 std::condition_variable conditionVariable; 53 std::condition_variable conditionVariable;
55 TimerUnits timers; 54 TimerUnits timers;
56 std::atomic<bool> shouldThreadStop; 55 bool shouldThreadStop;
57 std::thread m_thread; 56 std::thread m_thread;
58 }; 57 };
59 } 58 }
60 59
61 #endif 60 #endif
OLDNEW
« no previous file with comments | « no previous file | src/DefaultTimer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld