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