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

Side by Side Diff: src/Scheduler.cpp

Issue 29370876: Issue #4692, #3595 - Stop sleeping in the implementation of `SetTimeout`
Patch Set: Created Jan. 9, 2017, 1:22 p.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 | « src/Scheduler.h ('k') | src/Timeout.h » ('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-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
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 }
OLDNEW
« no previous file with comments | « src/Scheduler.h ('k') | src/Timeout.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld