X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Fcommon%2Fwait_handle.cpp;fp=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Fcommon%2Fwait_handle.cpp;h=01598164df5901377e9c24815475a299fb37d683;hb=e26c1ec581be598521517829adba8c8dd23a768f;hp=0000000000000000000000000000000000000000;hpb=6699c1aea74eeb0eb400e6299079f0c7576f716f;p=iec.git
diff --git a/src/type3_AndroidCloud/anbox-master/src/anbox/common/wait_handle.cpp b/src/type3_AndroidCloud/anbox-master/src/anbox/common/wait_handle.cpp
new file mode 100644
index 0000000..0159816
--- /dev/null
+++ b/src/type3_AndroidCloud/anbox-master/src/anbox/common/wait_handle.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright © 2012-2014 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ *
+ * Authored by: Kevin DuBois
+ * Daniel van Vugt
+ */
+
+#include "anbox/common/wait_handle.h"
+
+namespace anbox {
+namespace common {
+WaitHandle::WaitHandle()
+ : guard(), wait_condition(), expecting(0), received(0) {}
+
+WaitHandle::~WaitHandle() {}
+
+void WaitHandle::expect_result() {
+ std::lock_guard lock(guard);
+
+ expecting++;
+}
+
+void WaitHandle::result_received() {
+ std::lock_guard lock(guard);
+
+ received++;
+ wait_condition.notify_all();
+}
+
+void WaitHandle::wait_for_all() // wait for all results you expect
+{
+ std::unique_lock lock(guard);
+
+ wait_condition.wait(lock, [&] { return received == expecting; });
+
+ received = 0;
+ expecting = 0;
+}
+
+void WaitHandle::wait_for_pending(std::chrono::milliseconds limit) {
+ std::unique_lock lock(guard);
+
+ wait_condition.wait_for(lock, limit, [&] { return received == expecting; });
+}
+
+void WaitHandle::wait_for_one() // wait for any single result
+{
+ std::unique_lock lock(guard);
+
+ wait_condition.wait(lock, [&] { return received != 0; });
+
+ --received;
+ --expecting;
+}
+
+bool WaitHandle::has_result() {
+ std::lock_guard lock(guard);
+
+ return received > 0;
+}
+
+bool WaitHandle::is_pending() {
+ std::unique_lock lock(guard);
+ return expecting > 0 && received != expecting;
+}
+} // namespace common
+} // namespace anbox