37c12c6233f76639feb59d908da34fdb554983fe
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / common / wait_handle.h
1 /*
2  * Copyright © 2012 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Guest <thomas.guest@canonical.com>
17  *              Daniel van Vugt <daniel.van.vugt@canonical.com>
18  */
19
20 #ifndef ANBOX_COMMON_WAIT_HANDLE_H_
21 #define ANBOX_COMMON_WAIT_HANDLE_H_
22
23 #include <chrono>
24 #include <condition_variable>
25 #include <mutex>
26
27 namespace anbox {
28 namespace common {
29 struct WaitHandle {
30  public:
31   WaitHandle();
32   ~WaitHandle();
33
34   void expect_result();
35   void result_received();
36   void wait_for_all();
37   void wait_for_one();
38   void wait_for_pending(std::chrono::milliseconds limit);
39
40   bool has_result();
41   bool is_pending();
42
43  private:
44   std::mutex guard;
45   std::condition_variable wait_condition;
46
47   int expecting;
48   int received;
49 };
50 }  // namespace common
51 }  // namespace anbox
52
53 #endif