• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 CHPP_PLATFORM_SYNC_H_
18 #define CHPP_PLATFORM_SYNC_H_
19 
20 #include <pthread.h>
21 #include <stdint.h>
22 
23 #include "chpp/mutex.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 struct ChppNotifier {
30   pthread_cond_t cond;     // Condition variable
31   struct ChppMutex mutex;  // Platform-specific mutex
32   uint32_t signal;         // The 32-bit signal value stored when calling
33                            // chppNotifierSignal().
34 };
35 
36 /**
37  * Platform implementation of chppNotifierInit()
38  */
39 void chppPlatformNotifierInit(struct ChppNotifier *notifier);
40 
41 /**
42  * Platform implementation of chppNotifierDeinit()
43  */
44 void chppPlatformNotifierDeinit(struct ChppNotifier *notifier);
45 
46 /**
47  * Platform implementation of chppNotifierGetSignal()
48  */
49 uint32_t chppPlatformNotifierGetSignal(struct ChppNotifier *notifier);
50 
51 /**
52  * Platform implementation of chppNotifierWait()
53  */
54 uint32_t chppPlatformNotifierWait(struct ChppNotifier *notifier);
55 
56 /**
57  * Platform implementation of chppNotifierTimedWait()
58  */
59 uint32_t chppPlatformNotifierTimedWait(struct ChppNotifier *notifier,
60                                        uint64_t timeoutNs);
61 
62 /**
63  * Platform implementation of chppNotifierSignal()
64  */
65 void chppPlatformNotifierSignal(struct ChppNotifier *notifier, uint32_t signal);
66 
chppNotifierInit(struct ChppNotifier * notifier)67 static inline void chppNotifierInit(struct ChppNotifier *notifier) {
68   chppPlatformNotifierInit(notifier);
69 }
70 
chppNotifierDeinit(struct ChppNotifier * notifier)71 static inline void chppNotifierDeinit(struct ChppNotifier *notifier) {
72   chppPlatformNotifierDeinit(notifier);
73 }
74 
chppNotifierGetSignal(struct ChppNotifier * notifier)75 static inline uint32_t chppNotifierGetSignal(struct ChppNotifier *notifier) {
76   return chppPlatformNotifierGetSignal(notifier);
77 }
78 
chppNotifierWait(struct ChppNotifier * notifier)79 static inline uint32_t chppNotifierWait(struct ChppNotifier *notifier) {
80   return chppPlatformNotifierWait(notifier);
81 }
82 
chppNotifierTimedWait(struct ChppNotifier * notifier,uint64_t timeoutNs)83 static inline uint32_t chppNotifierTimedWait(struct ChppNotifier *notifier,
84                                              uint64_t timeoutNs) {
85   return chppPlatformNotifierTimedWait(notifier, timeoutNs);
86 }
87 
chppNotifierSignal(struct ChppNotifier * notifier,uint32_t signal)88 static inline void chppNotifierSignal(struct ChppNotifier *notifier,
89                                       uint32_t signal) {
90   chppPlatformNotifierSignal(notifier, signal);
91 }
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif  // CHPP_PLATFORM_SYNC_H_
98