1/*
2 * Copyright 2013-present Facebook, Inc.
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#pragma once
18
19#include <folly/Portability.h>
20
21namespace folly {
22
23enum class annotate_rwlock_level : long {
24 rdlock = 0,
25 wrlock = 1,
26};
27
28namespace detail {
29
30void annotate_rwlock_create_impl(
31 void const volatile* const addr,
32 char const* const f,
33 int const l);
34
35void annotate_rwlock_create_static_impl(
36 void const volatile* const addr,
37 char const* const f,
38 int const l);
39
40void annotate_rwlock_destroy_impl(
41 void const volatile* const addr,
42 char const* const f,
43 int const l);
44
45void annotate_rwlock_acquired_impl(
46 void const volatile* const addr,
47 annotate_rwlock_level const w,
48 char const* const f,
49 int const l);
50
51void annotate_rwlock_released_impl(
52 void const volatile* const addr,
53 annotate_rwlock_level const w,
54 char const* const f,
55 int const l);
56
57void annotate_benign_race_sized_impl(
58 const volatile void* addr,
59 long size,
60 const char* desc,
61 const char* f,
62 int l);
63
64} // namespace detail
65
66FOLLY_ALWAYS_INLINE static void annotate_rwlock_create(
67 void const volatile* const addr,
68 char const* const f,
69 int const l) {
70 if (kIsSanitizeThread) {
71 detail::annotate_rwlock_create_impl(addr, f, l);
72 }
73}
74
75FOLLY_ALWAYS_INLINE static void annotate_rwlock_create_static(
76 void const volatile* const addr,
77 char const* const f,
78 int const l) {
79 if (kIsSanitizeThread) {
80 detail::annotate_rwlock_create_static_impl(addr, f, l);
81 }
82}
83
84FOLLY_ALWAYS_INLINE static void annotate_rwlock_destroy(
85 void const volatile* const addr,
86 char const* const f,
87 int const l) {
88 if (kIsSanitizeThread) {
89 detail::annotate_rwlock_destroy_impl(addr, f, l);
90 }
91}
92
93FOLLY_ALWAYS_INLINE static void annotate_rwlock_acquired(
94 void const volatile* const addr,
95 annotate_rwlock_level const w,
96 char const* const f,
97 int const l) {
98 if (kIsSanitizeThread) {
99 detail::annotate_rwlock_acquired_impl(addr, w, f, l);
100 }
101}
102
103FOLLY_ALWAYS_INLINE static void annotate_rwlock_try_acquired(
104 void const volatile* const addr,
105 annotate_rwlock_level const w,
106 bool const result,
107 char const* const f,
108 int const l) {
109 if (result) {
110 annotate_rwlock_acquired(addr, w, f, l);
111 }
112}
113
114FOLLY_ALWAYS_INLINE static void annotate_rwlock_released(
115 void const volatile* const addr,
116 annotate_rwlock_level const w,
117 char const* const f,
118 int const l) {
119 if (kIsSanitizeThread) {
120 detail::annotate_rwlock_released_impl(addr, w, f, l);
121 }
122}
123
124FOLLY_ALWAYS_INLINE static void annotate_benign_race_sized(
125 void const volatile* const addr,
126 long const size,
127 char const* const desc,
128 char const* const f,
129 int const l) {
130 if (kIsSanitizeThread) {
131 detail::annotate_benign_race_sized_impl(addr, size, desc, f, l);
132 }
133}
134
135} // namespace folly
136