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

Delta Between Two Patch Sets: src/shared/EventWithSetter.cpp

Issue 6567422169448448: Issue 119 - Switch to injecting CSS for element hiding (Closed)
Left Patch Set: rebase Created Oct. 28, 2015, 11:46 a.m.
Right Patch Set: rename OnQuit Created Sept. 30, 2016, 3:25 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/shared/EventWithSetter.h ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 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 #include <cassert>
18 #include "EventWithSetter.h"
19
20 Event::Event()
21 : m_handle(CreateEvent(/*eventAttributes*/nullptr, /*manualReset*/TRUE,
22 /*initState*/FALSE, /*name*/nullptr))
23 {
24 assert(!!*this && "Handle should be successfully created");
25 }
26
27 Event::~Event()
28 {
29 if (!!*this) {
30 CloseHandle(m_handle);
31 }
32 }
33
34 void Event::Set()
35 {
36 SetEvent(m_handle);
37 }
38
39 void Event::Reset()
40 {
41 ResetEvent(m_handle);
42 }
43
44 bool Event::Wait(int32_t timeoutMsec /*= InfiniteTimeout*/)
45 {
46 return WaitForSingleObject(m_handle, timeoutMsec) == WAIT_OBJECT_0;
47 }
48
49 EventWithSetter::Setter::Setter(const DataPtr& data)
50 : m_data(data)
51 {
52 }
53
54 EventWithSetter::Setter::~Setter()
55 {
56 if (!m_data->isSetCalled)
57 m_data->event.Set();
58 }
59
60 void EventWithSetter::Setter::Set()
61 {
62 m_data->isSetCalled = true;
63 m_data->event.Set();
64 }
65
66 EventWithSetter::EventWithSetter()
67 : m_data(std::make_shared<Data>())
68 {
69 }
70
71 std::shared_ptr<EventWithSetter::Setter> EventWithSetter::CreateSetter()
72 {
73 std::shared_ptr<Setter> retValue = m_data->eventSetter.lock();
74 assert(!m_data->isSetterCreated && !retValue && "Setter is already created how ever it's supposed to be created only once");
75 if (!retValue)
76 {
77 retValue = std::make_shared<Setter>(m_data);
78 }
79 m_data->isSetterCreated = true;
80 return retValue;
81 }
82
83 bool EventWithSetter::Wait(int32_t timeoutMsec /*= Event::InfiniteTimeout*/)
84 {
85 assert(m_data->isSetterCreated && "Wrong class usage. The setter should be cre ated before calling Wait.");
86 return m_data->isSetterCreated && m_data->event.Wait(timeoutMsec) && m_data->i sSetCalled;
87 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld