| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 std::unique_lock<std::mutex> lock(mutex); | 56 std::unique_lock<std::mutex> lock(mutex); |
| 57 if (timers.empty()) | 57 if (timers.empty()) |
| 58 { | 58 { |
| 59 conditionVariable.wait(lock, [this]()->bool | 59 conditionVariable.wait(lock, [this]()->bool |
| 60 { | 60 { |
| 61 return shouldThreadStop || !timers.empty(); | 61 return shouldThreadStop || !timers.empty(); |
| 62 }); | 62 }); |
| 63 } | 63 } |
| 64 else | 64 else |
| 65 { | 65 { |
| 66 conditionVariable.wait_until(lock, timers.top().fireAt); | 66 auto fireAt = timers.top().fireAt; |
| 67 conditionVariable.wait_until(lock, fireAt); |
| 67 } | 68 } |
| 68 // execute all expired timers and remove them | 69 // execute all expired timers and remove them |
| 69 while (!shouldThreadStop && !timers.empty() && timers.top().fireAt <= std::c
hrono::steady_clock::now()) | 70 while (!shouldThreadStop && !timers.empty() && timers.top().fireAt <= std::c
hrono::steady_clock::now()) |
| 70 { | 71 { |
| 71 auto callback = timers.top().callback; | 72 auto callback = timers.top().callback; |
| 72 timers.pop(); | 73 timers.pop(); |
| 73 // allow to put new timers while this timer is being processed | 74 // allow to put new timers while this timer is being processed |
| 74 lock.unlock(); | 75 lock.unlock(); |
| 75 try | 76 try |
| 76 { | 77 { |
| 77 callback(); | 78 callback(); |
| 78 } | 79 } |
| 79 catch (...) | 80 catch (...) |
| 80 { | 81 { |
| 81 // do nothing, but the thread will be alive. | 82 // do nothing, but the thread will be alive. |
| 82 } | 83 } |
| 83 lock.lock(); | 84 lock.lock(); |
| 84 } | 85 } |
| 85 if (shouldThreadStop) | 86 if (shouldThreadStop) |
| 86 return; | 87 return; |
| 87 } | 88 } |
| 88 } | 89 } |
| OLD | NEW |