Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
wait_condition.h
Go to the documentation of this file.
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 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 General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 
19 #ifndef MIR_TEST_WAIT_CONDITION_H_
20 #define MIR_TEST_WAIT_CONDITION_H_
21 
22 #include <gmock/gmock.h>
23 
24 #include <chrono>
25 #include <mutex>
26 #include <condition_variable>
27 
28 namespace mir
29 {
30 namespace test
31 {
33 {
35 
36  void wait_for_at_most_seconds(int seconds)
37  {
38  std::unique_lock<std::mutex> ul(guard);
39  if (!woken) condition.wait_for(ul, std::chrono::seconds(seconds));
40  }
41 
43  {
44  std::unique_lock<std::mutex> ul(guard);
45  woken = true;
46  condition.notify_all();
47  }
48 
49  std::mutex guard;
50  std::condition_variable condition;
51  bool woken;
52 };
53 
54 ACTION_P(ReturnFalseAndWakeUp, wait_condition)
55 {
56  wait_condition->wake_up_everyone();
57  return false;
58 }
59 ACTION_P(WakeUp, wait_condition)
60 {
61  wait_condition->wake_up_everyone();
62 }
63 }
64 }
65 
66 #endif // MIR_TEST_WAIT_CONDITION_H_
std::mutex guard
Definition: wait_condition.h:49
std::condition_variable condition
Definition: wait_condition.h:50
bool woken
Definition: wait_condition.h:51
WaitCondition()
Definition: wait_condition.h:34
Definition: wait_condition.h:32
ACTION_P(ReturnFalseAndWakeUp, wait_condition)
Definition: wait_condition.h:54
return false
Definition: mock_egl.h:53
void wait_for_at_most_seconds(int seconds)
Definition: wait_condition.h:36
void wake_up_everyone()
Definition: wait_condition.h:42

Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Apr 11 21:14:53 UTC 2014