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

Side by Side Diff: test/PausePoint.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 | « test/PausePoint.h ('k') | test/SchedulerTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 #include "PausePoint.h"
19 #include <thread>
20
21 PausePoint::PausePoint()
22 : state(Idle)
23 {}
24
25 void PausePoint::Pause()
26 {
27 UniqueLockType ul(m);
28 if (state == Waiting)
29 {
30 cv.notify_one();
31 }
32 state = Paused;
33 cv.wait(ul,
34 [this]() -> bool
35 {
36 return state != Paused;
37 });
38 }
39
40 void PausePoint::WaitUntilPaused()
41 {
42 UniqueLockType ul(m);
43 if (state == Paused)
44 {
45 return;
46 }
47 state = Waiting;
48 cv.wait(ul,
49 [this]() -> bool
50 {
51 return state == Paused;
52 });
53 }
54
55 void PausePoint::Resume()
56 {
57 UniqueLockType ul(m);
58 if (state != Paused)
59 {
60 throw std::runtime_error("May not call Resume() when the puppet is not block ed.");
61 }
62 state = Idle;
63 cv.notify_one();
64 }
65
66 void PausePoint::ResumeAndSleep(unsigned int ms)
67 {
68 Resume();
69 std::this_thread::sleep_for(std::chrono::milliseconds(ms));
70 }
OLDNEW
« no previous file with comments | « test/PausePoint.h ('k') | test/SchedulerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld