xref: /aosp_15_r20/external/cronet/third_party/abseil-cpp/absl/synchronization/BUILD.bazel (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1#
2# Copyright 2017 The Abseil Authors.
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#      https://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
17load(
18    "//absl:copts/configure_copts.bzl",
19    "ABSL_DEFAULT_COPTS",
20    "ABSL_DEFAULT_LINKOPTS",
21    "ABSL_TEST_COPTS",
22)
23
24package(
25    default_visibility = ["//visibility:private"],
26    features = [
27        "header_modules",
28        "layering_check",
29        "parse_headers",
30    ],
31)
32
33licenses(["notice"])
34
35# Internal data structure for efficiently detecting mutex dependency cycles
36cc_library(
37    name = "graphcycles_internal",
38    srcs = [
39        "internal/graphcycles.cc",
40    ],
41    hdrs = [
42        "internal/graphcycles.h",
43    ],
44    copts = ABSL_DEFAULT_COPTS + select({
45        "//conditions:default": [],
46    }),
47    linkopts = ABSL_DEFAULT_LINKOPTS,
48    deps = [
49        "//absl/base",
50        "//absl/base:base_internal",
51        "//absl/base:config",
52        "//absl/base:core_headers",
53        "//absl/base:malloc_internal",
54        "//absl/base:raw_logging_internal",
55    ],
56)
57
58cc_library(
59    name = "kernel_timeout_internal",
60    srcs = ["internal/kernel_timeout.cc"],
61    hdrs = ["internal/kernel_timeout.h"],
62    copts = ABSL_DEFAULT_COPTS,
63    linkopts = ABSL_DEFAULT_LINKOPTS,
64    visibility = [
65    ],
66    deps = [
67        "//absl/base",
68        "//absl/base:config",
69        "//absl/base:core_headers",
70        "//absl/base:raw_logging_internal",
71        "//absl/time",
72    ] + select({
73        "//conditions:default": [],
74    }),
75)
76
77cc_test(
78    name = "kernel_timeout_internal_test",
79    srcs = ["internal/kernel_timeout_test.cc"],
80    copts = ABSL_TEST_COPTS,
81    flaky = 1,
82    linkopts = ABSL_DEFAULT_LINKOPTS,
83    deps = [
84        ":kernel_timeout_internal",
85        "//absl/base:config",
86        "//absl/random",
87        "//absl/time",
88        "@com_google_googletest//:gtest",
89        "@com_google_googletest//:gtest_main",
90    ],
91)
92
93cc_library(
94    name = "synchronization",
95    srcs = [
96        "barrier.cc",
97        "blocking_counter.cc",
98        "internal/create_thread_identity.cc",
99        "internal/futex_waiter.cc",
100        "internal/per_thread_sem.cc",
101        "internal/pthread_waiter.cc",
102        "internal/sem_waiter.cc",
103        "internal/stdcpp_waiter.cc",
104        "internal/waiter_base.cc",
105        "internal/win32_waiter.cc",
106        "mutex.cc",
107        "notification.cc",
108    ],
109    hdrs = [
110        "barrier.h",
111        "blocking_counter.h",
112        "internal/create_thread_identity.h",
113        "internal/futex.h",
114        "internal/futex_waiter.h",
115        "internal/per_thread_sem.h",
116        "internal/pthread_waiter.h",
117        "internal/sem_waiter.h",
118        "internal/stdcpp_waiter.h",
119        "internal/waiter.h",
120        "internal/waiter_base.h",
121        "internal/win32_waiter.h",
122        "mutex.h",
123        "notification.h",
124    ],
125    copts = ABSL_DEFAULT_COPTS,
126    linkopts = select({
127        "//absl:msvc_compiler": [],
128        "//absl:clang-cl_compiler": [],
129        "//absl:wasm": [],
130        "//conditions:default": ["-pthread"],
131    }) + ABSL_DEFAULT_LINKOPTS,
132    visibility = ["//visibility:public"],
133    deps = [
134        ":graphcycles_internal",
135        ":kernel_timeout_internal",
136        "//absl/base",
137        "//absl/base:atomic_hook",
138        "//absl/base:base_internal",
139        "//absl/base:config",
140        "//absl/base:core_headers",
141        "//absl/base:dynamic_annotations",
142        "//absl/base:malloc_internal",
143        "//absl/base:raw_logging_internal",
144        "//absl/debugging:stacktrace",
145        "//absl/debugging:symbolize",
146        "//absl/time",
147    ] + select({
148        "//conditions:default": [],
149    }),
150)
151
152cc_test(
153    name = "barrier_test",
154    size = "small",
155    srcs = ["barrier_test.cc"],
156    copts = ABSL_TEST_COPTS,
157    linkopts = ABSL_DEFAULT_LINKOPTS,
158    tags = [
159        "no_test_wasm",  # b/122473323
160    ],
161    deps = [
162        ":synchronization",
163        "//absl/time",
164        "@com_google_googletest//:gtest",
165        "@com_google_googletest//:gtest_main",
166    ],
167)
168
169cc_test(
170    name = "blocking_counter_test",
171    size = "small",
172    srcs = ["blocking_counter_test.cc"],
173    copts = ABSL_TEST_COPTS,
174    linkopts = ABSL_DEFAULT_LINKOPTS,
175    tags = [
176        "no_test_wasm",  # b/122473323
177    ],
178    deps = [
179        ":synchronization",
180        "//absl/time",
181        "@com_google_googletest//:gtest",
182        "@com_google_googletest//:gtest_main",
183    ],
184)
185
186cc_binary(
187    name = "blocking_counter_benchmark",
188    testonly = True,
189    srcs = ["blocking_counter_benchmark.cc"],
190    copts = ABSL_TEST_COPTS,
191    linkopts = ABSL_DEFAULT_LINKOPTS,
192    tags = ["benchmark"],
193    deps = [
194        ":synchronization",
195        ":thread_pool",
196        "//absl/base:no_destructor",
197        "@com_github_google_benchmark//:benchmark_main",
198    ],
199)
200
201cc_test(
202    name = "graphcycles_test",
203    size = "medium",
204    srcs = ["internal/graphcycles_test.cc"],
205    copts = ABSL_TEST_COPTS,
206    linkopts = ABSL_DEFAULT_LINKOPTS,
207    deps = [
208        ":graphcycles_internal",
209        "//absl/base:core_headers",
210        "//absl/log",
211        "//absl/log:check",
212        "@com_google_googletest//:gtest",
213        "@com_google_googletest//:gtest_main",
214    ],
215)
216
217cc_test(
218    name = "graphcycles_benchmark",
219    srcs = ["internal/graphcycles_benchmark.cc"],
220    copts = ABSL_TEST_COPTS,
221    linkopts = ABSL_DEFAULT_LINKOPTS,
222    tags = [
223        "benchmark",
224    ],
225    deps = [
226        ":graphcycles_internal",
227        "//absl/base:raw_logging_internal",
228        "@com_github_google_benchmark//:benchmark_main",
229        "@com_google_googletest//:gtest",
230    ],
231)
232
233cc_library(
234    name = "thread_pool",
235    testonly = True,
236    hdrs = ["internal/thread_pool.h"],
237    linkopts = ABSL_DEFAULT_LINKOPTS,
238    visibility = [
239        "//absl:__subpackages__",
240    ],
241    deps = [
242        ":synchronization",
243        "//absl/base:core_headers",
244        "//absl/functional:any_invocable",
245    ],
246)
247
248cc_test(
249    name = "mutex_test",
250    size = "large",
251    srcs = ["mutex_test.cc"],
252    copts = ABSL_TEST_COPTS,
253    flaky = 1,
254    linkopts = ABSL_DEFAULT_LINKOPTS,
255    shard_count = 25,
256    deps = [
257        ":synchronization",
258        ":thread_pool",
259        "//absl/base",
260        "//absl/base:config",
261        "//absl/base:core_headers",
262        "//absl/log",
263        "//absl/log:check",
264        "//absl/memory",
265        "//absl/time",
266        "@com_google_googletest//:gtest",
267        "@com_google_googletest//:gtest_main",
268    ],
269)
270
271cc_test(
272    name = "mutex_method_pointer_test",
273    srcs = ["mutex_method_pointer_test.cc"],
274    copts = ABSL_TEST_COPTS,
275    linkopts = ABSL_DEFAULT_LINKOPTS,
276    deps = [
277        ":synchronization",
278        "//absl/base:config",
279        "@com_google_googletest//:gtest",
280        "@com_google_googletest//:gtest_main",
281    ],
282)
283
284cc_library(
285    name = "mutex_benchmark_common",
286    testonly = True,
287    srcs = ["mutex_benchmark.cc"],
288    copts = ABSL_TEST_COPTS,
289    linkopts = ABSL_DEFAULT_LINKOPTS,
290    visibility = [
291    ],
292    deps = [
293        ":synchronization",
294        ":thread_pool",
295        "//absl/base",
296        "//absl/base:config",
297        "//absl/base:no_destructor",
298        "@com_github_google_benchmark//:benchmark_main",
299    ],
300    alwayslink = 1,
301)
302
303cc_binary(
304    name = "mutex_benchmark",
305    testonly = True,
306    copts = ABSL_DEFAULT_COPTS,
307    linkopts = ABSL_DEFAULT_LINKOPTS,
308    deps = [
309        ":mutex_benchmark_common",
310    ],
311)
312
313cc_test(
314    name = "notification_test",
315    size = "small",
316    srcs = ["notification_test.cc"],
317    copts = ABSL_TEST_COPTS,
318    flaky = 1,
319    linkopts = ABSL_DEFAULT_LINKOPTS,
320    tags = ["no_test_lexan"],
321    deps = [
322        ":synchronization",
323        "//absl/time",
324        "@com_google_googletest//:gtest",
325        "@com_google_googletest//:gtest_main",
326    ],
327)
328
329cc_library(
330    name = "per_thread_sem_test_common",
331    testonly = True,
332    srcs = ["internal/per_thread_sem_test.cc"],
333    copts = ABSL_TEST_COPTS,
334    linkopts = ABSL_DEFAULT_LINKOPTS,
335    visibility = [
336    ],
337    deps = [
338        ":synchronization",
339        "//absl/base",
340        "//absl/base:config",
341        "//absl/strings",
342        "//absl/time",
343        "@com_google_googletest//:gtest",
344    ],
345    alwayslink = 1,
346)
347
348cc_test(
349    name = "per_thread_sem_test",
350    size = "large",
351    copts = ABSL_TEST_COPTS,
352    linkopts = ABSL_DEFAULT_LINKOPTS,
353    tags = [
354        "no_test_wasm",
355    ],
356    deps = [
357        ":per_thread_sem_test_common",
358        ":synchronization",
359        "//absl/strings",
360        "//absl/time",
361        "@com_google_googletest//:gtest_main",
362    ],
363)
364
365cc_test(
366    name = "waiter_test",
367    srcs = ["internal/waiter_test.cc"],
368    copts = ABSL_TEST_COPTS,
369    flaky = 1,
370    linkopts = ABSL_DEFAULT_LINKOPTS,
371    deps = [
372        ":kernel_timeout_internal",
373        ":synchronization",
374        ":thread_pool",
375        "//absl/base:config",
376        "//absl/random",
377        "//absl/time",
378        "@com_google_googletest//:gtest",
379        "@com_google_googletest//:gtest_main",
380    ],
381)
382
383cc_test(
384    name = "lifetime_test",
385    srcs = [
386        "lifetime_test.cc",
387    ],
388    copts = ABSL_TEST_COPTS,
389    linkopts = ABSL_DEFAULT_LINKOPTS,
390    tags = [
391        "no_test_ios_x86_64",
392        "no_test_wasm",
393    ],
394    deps = [
395        ":synchronization",
396        "//absl/base:core_headers",
397        "//absl/log:check",
398    ],
399)
400