| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 #include "Scheduler.h" | 18 #include "Scheduler.h" |
| 19 #include <thread> | 19 #include <thread> |
| 20 using namespace AdblockPlus; | |
| 21 | |
| 22 namespace | |
| 23 { | |
| 24 void SingleUseThreadMain(std::function<void()> task) | |
| 25 { | |
| 26 task(); | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 void StartImmediatelyInSingleUseDetachedThread(std::function<void()> task) | |
| 31 { | |
| 32 if (!task) | |
| 33 { | |
| 34 return; | |
| 35 } | |
| 36 auto th = std::thread(SingleUseThreadMain, task); | |
| 37 th.detach(); | |
| 38 } | |
| 39 | 20 |
| 40 OperationRunner::OperationRunner() | 21 OperationRunner::OperationRunner() |
| 41 : isRunning(true) | 22 : isRunning(true) |
| 42 { | 23 { |
| 43 th = std::thread([this]() { ThreadMain(); }); | 24 th = std::thread([this]() { ThreadMain(); }); |
| 44 /* | 25 /* |
| 45 * Note that we don't need to wait for our thread to start running | 26 * Note that we don't need to wait for our thread to start running |
| 46 * before we consider the object fully constructed. | 27 * before we consider the object fully constructed. |
| 47 * Because of how the `wait()` statement in `ThreadMain` is written, | 28 * Because of how the `wait()` statement in `ThreadMain` is written, |
| 48 * any operation arriving before the thread begins will be | 29 * any operation arriving before the thread begins will be |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 th = std::move(std::thread(f)); | 89 th = std::move(std::thread(f)); |
| 109 } | 90 } |
| 110 | 91 |
| 111 void SingleUseWorker::Join() | 92 void SingleUseWorker::Join() |
| 112 { | 93 { |
| 113 if (th.joinable()) | 94 if (th.joinable()) |
| 114 { | 95 { |
| 115 th.join(); | 96 th.join(); |
| 116 } | 97 } |
| 117 } | 98 } |
| OLD | NEW |