aboutsummaryrefslogtreecommitdiff
path: root/chpp/include/chpp/notifier.h
blob: 2624b476244c8ff6086000b57d7405e046f13a76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Implementation Notes
 * Each platform must supply a platform-specific platform_notifier.h to provide
 * definitions and a platform-specific notifier.c to provide the implementation
 * for the definitions in this file.
 */

#ifndef CHPP_SYNC_H_
#define CHPP_SYNC_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Platform-specific condition variable struct defined in the platform's
 * platform_notifier.h that enables the funcions defined here.
 */
struct ChppNotifier;

/**
 * Initializes the platform-specific ChppNotifier.
 * Will be called before notifier is used anywhere else.
 *
 * @param notifier Points to the ChppNotifier being initialized.
 */
static void chppNotifierInit(struct ChppNotifier *notifier);

/**
 * Deinitializes the platform-specific ChppNotifier.
 *
 * @param notifier Points to the ChppNotifier being deinitialized.
 */
static void chppNotifierDeinit(struct ChppNotifier *notifier);

/**
 * Returns the signal value in chppNotifierSignal(), if any. Resets the signal
 * value afterwards.
 *
 * @param notifier Points to the ChppNotifier being used.
 *
 * @return The signal value indicated in chppNotifierSignal().
 */
static uint32_t chppNotifierGetSignal(struct ChppNotifier *notifier);

/**
 * Waits on a platform-specific notifier until it is signaled through
 * chppNotifierSignal(). Similar to chppNotifierTimedWait(), but without the
 * timeout.
 *
 * @param notifier Points to the ChppNotifier being used.
 *
 * @return The signal value indicated in chppNotifierSignal().
 */
static uint32_t chppNotifierWait(struct ChppNotifier *notifier);

/**
 * Waits on a platform-specific notifier until it is signaled through
 * chppNotifierSignal() or until the specified timeout.
 *
 * Note that while the timeout is specified as a uint64_t, in practice, CHPP
 * would only use values up to CHPP_TRANSPORT_TX_TIMEOUT_NS.
 *
 * @param notifier Points to the ChppNotifier being used.
 * @param timeoutNs Timeout in nanoseconds.
 *
 * @return The signal value indicated in chppNotifierSignal().
 */
static uint32_t chppNotifierTimedWait(struct ChppNotifier *notifier,
                                      uint64_t timeoutNs);

/**
 * Signals chppNotifierTimedWait() with the specified signal value.
 *
 * The signal values can be defined by the user of this class. Note that it is
 * expected for different signals to be bitwise exclusive, i.e. each bit in the
 * uint32_t should indicate a specific type of signal event. This allows for
 * multiple events to be handled simultaneously in chppNotifierTimedWait().
 *
 * @param notifier Points to the ChppNotifier being used.
 */
static void chppNotifierSignal(struct ChppNotifier *notifier, uint32_t signal);

#ifdef __cplusplus
}
#endif

#include "chpp/platform/platform_notifier.h"

#endif  // CHPP_SYNC_H_