1 // Copyright 2024 The Abseil Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef ABSL_BASE_INTERNAL_TRACING_H_
16 #define ABSL_BASE_INTERNAL_TRACING_H_
17
18 #include "absl/base/config.h"
19
20 namespace absl {
21 ABSL_NAMESPACE_BEGIN
22 namespace base_internal {
23
24 // Well known Abseil object types that have causality.
25 enum class ObjectKind { kUnknown, kBlockingCounter, kNotification };
26
27 // `TraceWait` and `TraceContinue` record the start and end of a potentially
28 // blocking wait operation on `object`. `object` typically represents a higher
29 // level synchronization object such as `absl::Notification`.
30 void TraceWait(const void* object, ObjectKind kind);
31 void TraceContinue(const void* object, ObjectKind kind);
32
33 // `TraceSignal` records a signal on `object`.
34 void TraceSignal(const void* object, ObjectKind kind);
35
36 // `TraceObserved` records the non-blocking observation of a signaled object.
37 void TraceObserved(const void* object, ObjectKind kind);
38
39 // ---------------------------------------------------------------------------
40 // Weak implementation detail:
41 //
42 // We define the weak API as extern "C": in some build configurations we pass
43 // `--detect-odr-violations` to the gold linker. This causes it to flag weak
44 // symbol overrides as ODR violations. Because ODR only applies to C++ and not
45 // C, `--detect-odr-violations` ignores symbols not mangled with C++ names.
46 // By changing our extension points to be extern "C", we dodge this check.
47 // ---------------------------------------------------------------------------
48 extern "C" {
49
50 void ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceWait)(const void* object,
51 ObjectKind kind);
52 void ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceContinue)(const void* object,
53 ObjectKind kind);
54 void ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceSignal)(const void* object,
55 ObjectKind kind);
56 void ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceObserved)(const void* object,
57 ObjectKind kind);
58
59 } // extern "C"
60
TraceWait(const void * object,ObjectKind kind)61 inline void TraceWait(const void* object, ObjectKind kind) {
62 ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceWait)(object, kind);
63 }
64
TraceContinue(const void * object,ObjectKind kind)65 inline void TraceContinue(const void* object, ObjectKind kind) {
66 ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceContinue)(object, kind);
67 }
68
TraceSignal(const void * object,ObjectKind kind)69 inline void TraceSignal(const void* object, ObjectKind kind) {
70 ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceSignal)(object, kind);
71 }
72
TraceObserved(const void * object,ObjectKind kind)73 inline void TraceObserved(const void* object, ObjectKind kind) {
74 ABSL_INTERNAL_C_SYMBOL(AbslInternalTraceObserved)(object, kind);
75 }
76
77 } // namespace base_internal
78 ABSL_NAMESPACE_END
79 } // namespace absl
80
81 #endif // ABSL_BASE_INTERNAL_TRACING_H_
82