OLD | NEW |
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 |
(...skipping 25 matching lines...) Expand all Loading... |
36 } | 36 } |
37 conditionVariable.notify_one(); | 37 conditionVariable.notify_one(); |
38 if (m_thread.joinable()) | 38 if (m_thread.joinable()) |
39 m_thread.join(); | 39 m_thread.join(); |
40 } | 40 } |
41 | 41 |
42 void DefaultTimer::SetTimer(const std::chrono::milliseconds& timeout, const Time
rCallback& timerCallback) | 42 void DefaultTimer::SetTimer(const std::chrono::milliseconds& timeout, const Time
rCallback& timerCallback) |
43 { | 43 { |
44 if (!timerCallback) | 44 if (!timerCallback) |
45 return; | 45 return; |
46 std::lock_guard<std::mutex> lock(mutex); | 46 { |
47 TimerUnit timer = { std::chrono::steady_clock::now() + timeout, timerCallback
}; | 47 std::lock_guard<std::mutex> lock(mutex); |
48 timers.push(timer); | 48 TimerUnit timer = { std::chrono::steady_clock::now() + timeout, timerCallbac
k }; |
| 49 timers.push(timer); |
| 50 } |
49 conditionVariable.notify_one(); | 51 conditionVariable.notify_one(); |
50 } | 52 } |
51 | 53 |
52 void DefaultTimer::ThreadFunc() | 54 void DefaultTimer::ThreadFunc() |
53 { | 55 { |
54 while (true) | 56 while (true) |
55 { | 57 { |
56 std::unique_lock<std::mutex> lock(mutex); | 58 std::unique_lock<std::mutex> lock(mutex); |
57 if (timers.empty()) | 59 if (timers.empty()) |
58 { | 60 { |
(...skipping 20 matching lines...) Expand all Loading... |
79 catch (...) | 81 catch (...) |
80 { | 82 { |
81 // do nothing, but the thread will be alive. | 83 // do nothing, but the thread will be alive. |
82 } | 84 } |
83 lock.lock(); | 85 lock.lock(); |
84 } | 86 } |
85 if (shouldThreadStop) | 87 if (shouldThreadStop) |
86 return; | 88 return; |
87 } | 89 } |
88 } | 90 } |
OLD | NEW |