• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CHRE_PLATFORM_CONDITION_VARIABLE_H_
18 #define CHRE_PLATFORM_CONDITION_VARIABLE_H_
19 
20 #include "chre/platform/mutex.h"
21 #include "chre/target_platform/condition_variable_base.h"
22 #include "chre/util/non_copyable.h"
23 
24 namespace chre {
25 
26 /**
27  * Provides an implementation of a Condition Variable. The public API is
28  * similar to std::condition_variable. ConditionVariableBase is subclassed here
29  * to allow platforms to inject their own storage for their implementation.
30  */
31 class ConditionVariable : public ConditionVariableBase,
32                           public NonCopyable {
33  public:
34   /**
35    * Allows the platform to do any condition variable initialization at
36    * construction time.
37    */
38   ConditionVariable();
39 
40   /**
41    * Allows the platform to do any condition variable deinitialization at
42    * destruction time.
43    */
44   ~ConditionVariable();
45 
46   /**
47    * Unblock one thread that is waiting on this condition variable.
48    */
49   void notify_one();
50 
51   /**
52    * Causes the current thread to block until the condition variable is
53    * notified. The provided mutex will be unlocked and the thread will be
54    * blocked until the condition variable has notified. The mutex is relocked
55    * prior to this function returning.
56    *
57    * @param The currently locked mutex.
58    */
59   void wait(Mutex& mutex);
60 };
61 
62 }  // namespace chre
63 
64 #include "chre/target_platform/condition_variable_impl.h"
65 
66 #endif  // CHRE_PLATFORM_CONDITION_VARIABLE_H_
67