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

Unified Diff: src/shared/EventWithSetter.cpp

Issue 6567422169448448: Issue 119 - Switch to injecting CSS for element hiding (Closed)
Patch Set: rename OnQuit Created Sept. 30, 2016, 3:25 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/shared/EventWithSetter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/shared/EventWithSetter.cpp
diff --git a/src/shared/EventWithSetter.cpp b/src/shared/EventWithSetter.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..117b99ed36d11c37423560737c5c7cfdd466abc4
--- /dev/null
+++ b/src/shared/EventWithSetter.cpp
@@ -0,0 +1,87 @@
+/*
+* This file is part of Adblock Plus <https://adblockplus.org/>,
+* Copyright (C) 2006-2016 Eyeo GmbH
+*
+* Adblock Plus is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 3 as
+* published by the Free Software Foundation.
+*
+* Adblock Plus is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+*/
+#include <cassert>
+#include "EventWithSetter.h"
+
+Event::Event()
+ : m_handle(CreateEvent(/*eventAttributes*/nullptr, /*manualReset*/TRUE,
+/*initState*/FALSE, /*name*/nullptr))
+{
+ assert(!!*this && "Handle should be successfully created");
+}
+
+Event::~Event()
+{
+ if (!!*this) {
+ CloseHandle(m_handle);
+ }
+}
+
+void Event::Set()
+{
+ SetEvent(m_handle);
+}
+
+void Event::Reset()
+{
+ ResetEvent(m_handle);
+}
+
+bool Event::Wait(int32_t timeoutMsec /*= InfiniteTimeout*/)
+{
+ return WaitForSingleObject(m_handle, timeoutMsec) == WAIT_OBJECT_0;
+}
+
+EventWithSetter::Setter::Setter(const DataPtr& data)
+ : m_data(data)
+{
+}
+
+EventWithSetter::Setter::~Setter()
+{
+ if (!m_data->isSetCalled)
+ m_data->event.Set();
+}
+
+void EventWithSetter::Setter::Set()
+{
+ m_data->isSetCalled = true;
+ m_data->event.Set();
+}
+
+EventWithSetter::EventWithSetter()
+ : m_data(std::make_shared<Data>())
+{
+}
+
+std::shared_ptr<EventWithSetter::Setter> EventWithSetter::CreateSetter()
+{
+ std::shared_ptr<Setter> retValue = m_data->eventSetter.lock();
+ assert(!m_data->isSetterCreated && !retValue && "Setter is already created however it's supposed to be created only once");
+ if (!retValue)
+ {
+ retValue = std::make_shared<Setter>(m_data);
+ }
+ m_data->isSetterCreated = true;
+ return retValue;
+}
+
+bool EventWithSetter::Wait(int32_t timeoutMsec /*= Event::InfiniteTimeout*/)
+{
+ assert(m_data->isSetterCreated && "Wrong class usage. The setter should be created before calling Wait.");
+ return m_data->isSetterCreated && m_data->event.Wait(timeoutMsec) && m_data->isSetCalled;
+}
« no previous file with comments | « src/shared/EventWithSetter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld