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/base:tracing_internal", 145 "//absl/debugging:stacktrace", 146 "//absl/debugging:symbolize", 147 "//absl/time", 148 ] + select({ 149 "//conditions:default": [], 150 }), 151) 152 153cc_test( 154 name = "barrier_test", 155 size = "small", 156 srcs = ["barrier_test.cc"], 157 copts = ABSL_TEST_COPTS, 158 linkopts = ABSL_DEFAULT_LINKOPTS, 159 tags = [ 160 "no_test_wasm", # b/122473323 161 ], 162 deps = [ 163 ":synchronization", 164 "//absl/time", 165 "@com_google_googletest//:gtest", 166 "@com_google_googletest//:gtest_main", 167 ], 168) 169 170cc_test( 171 name = "blocking_counter_test", 172 size = "small", 173 srcs = ["blocking_counter_test.cc"], 174 copts = ABSL_TEST_COPTS, 175 linkopts = ABSL_DEFAULT_LINKOPTS, 176 tags = [ 177 "no_test_wasm", # b/122473323 178 ], 179 deps = [ 180 ":synchronization", 181 "//absl/base:config", 182 "//absl/base:core_headers", 183 "//absl/base:tracing_internal", 184 "//absl/time", 185 "@com_google_googletest//:gtest", 186 "@com_google_googletest//:gtest_main", 187 ], 188) 189 190cc_binary( 191 name = "blocking_counter_benchmark", 192 testonly = True, 193 srcs = ["blocking_counter_benchmark.cc"], 194 copts = ABSL_TEST_COPTS, 195 linkopts = ABSL_DEFAULT_LINKOPTS, 196 tags = ["benchmark"], 197 deps = [ 198 ":synchronization", 199 ":thread_pool", 200 "//absl/base:no_destructor", 201 "@com_github_google_benchmark//:benchmark_main", 202 ], 203) 204 205cc_test( 206 name = "graphcycles_test", 207 size = "medium", 208 srcs = ["internal/graphcycles_test.cc"], 209 copts = ABSL_TEST_COPTS, 210 linkopts = ABSL_DEFAULT_LINKOPTS, 211 deps = [ 212 ":graphcycles_internal", 213 "//absl/base:core_headers", 214 "//absl/log", 215 "//absl/log:check", 216 "@com_google_googletest//:gtest", 217 "@com_google_googletest//:gtest_main", 218 ], 219) 220 221cc_test( 222 name = "graphcycles_benchmark", 223 srcs = ["internal/graphcycles_benchmark.cc"], 224 copts = ABSL_TEST_COPTS, 225 linkopts = ABSL_DEFAULT_LINKOPTS, 226 tags = [ 227 "benchmark", 228 ], 229 deps = [ 230 ":graphcycles_internal", 231 "//absl/base:raw_logging_internal", 232 "@com_github_google_benchmark//:benchmark_main", 233 "@com_google_googletest//:gtest", 234 ], 235) 236 237cc_library( 238 name = "thread_pool", 239 testonly = True, 240 hdrs = ["internal/thread_pool.h"], 241 linkopts = ABSL_DEFAULT_LINKOPTS, 242 visibility = [ 243 "//absl:__subpackages__", 244 ], 245 deps = [ 246 ":synchronization", 247 "//absl/base:core_headers", 248 "//absl/functional:any_invocable", 249 ], 250) 251 252cc_test( 253 name = "mutex_test", 254 size = "large", 255 srcs = ["mutex_test.cc"], 256 copts = ABSL_TEST_COPTS, 257 flaky = 1, 258 linkopts = ABSL_DEFAULT_LINKOPTS, 259 shard_count = 25, 260 deps = [ 261 ":synchronization", 262 ":thread_pool", 263 "//absl/base", 264 "//absl/base:config", 265 "//absl/base:core_headers", 266 "//absl/log", 267 "//absl/log:check", 268 "//absl/memory", 269 "//absl/time", 270 "@com_google_googletest//:gtest", 271 "@com_google_googletest//:gtest_main", 272 ], 273) 274 275cc_test( 276 name = "mutex_method_pointer_test", 277 srcs = ["mutex_method_pointer_test.cc"], 278 copts = ABSL_TEST_COPTS, 279 linkopts = ABSL_DEFAULT_LINKOPTS, 280 deps = [ 281 ":synchronization", 282 "//absl/base:config", 283 "@com_google_googletest//:gtest", 284 "@com_google_googletest//:gtest_main", 285 ], 286) 287 288cc_library( 289 name = "mutex_benchmark_common", 290 testonly = True, 291 srcs = ["mutex_benchmark.cc"], 292 copts = ABSL_TEST_COPTS, 293 linkopts = ABSL_DEFAULT_LINKOPTS, 294 visibility = [ 295 ], 296 deps = [ 297 ":synchronization", 298 ":thread_pool", 299 "//absl/base", 300 "//absl/base:config", 301 "//absl/base:no_destructor", 302 "@com_github_google_benchmark//:benchmark_main", 303 ], 304 alwayslink = 1, 305) 306 307cc_binary( 308 name = "mutex_benchmark", 309 testonly = True, 310 copts = ABSL_DEFAULT_COPTS, 311 linkopts = ABSL_DEFAULT_LINKOPTS, 312 deps = [ 313 ":mutex_benchmark_common", 314 ], 315) 316 317cc_test( 318 name = "notification_test", 319 size = "small", 320 srcs = ["notification_test.cc"], 321 copts = ABSL_TEST_COPTS, 322 flaky = 1, 323 linkopts = ABSL_DEFAULT_LINKOPTS, 324 tags = ["no_test_lexan"], 325 deps = [ 326 ":synchronization", 327 "//absl/base:config", 328 "//absl/base:core_headers", 329 "//absl/base:tracing_internal", 330 "//absl/time", 331 "@com_google_googletest//:gtest", 332 "@com_google_googletest//:gtest_main", 333 ], 334) 335 336cc_library( 337 name = "per_thread_sem_test_common", 338 testonly = True, 339 srcs = ["internal/per_thread_sem_test.cc"], 340 copts = ABSL_TEST_COPTS, 341 linkopts = ABSL_DEFAULT_LINKOPTS, 342 visibility = [ 343 ], 344 deps = [ 345 ":synchronization", 346 "//absl/base", 347 "//absl/base:config", 348 "//absl/strings", 349 "//absl/time", 350 "@com_google_googletest//:gtest", 351 ], 352 alwayslink = 1, 353) 354 355cc_test( 356 name = "per_thread_sem_test", 357 size = "large", 358 copts = ABSL_TEST_COPTS, 359 linkopts = ABSL_DEFAULT_LINKOPTS, 360 tags = [ 361 "no_test_wasm", 362 ], 363 deps = [ 364 ":per_thread_sem_test_common", 365 ":synchronization", 366 "//absl/strings", 367 "//absl/time", 368 "@com_google_googletest//:gtest_main", 369 ], 370) 371 372cc_test( 373 name = "waiter_test", 374 srcs = ["internal/waiter_test.cc"], 375 copts = ABSL_TEST_COPTS, 376 flaky = 1, 377 linkopts = ABSL_DEFAULT_LINKOPTS, 378 deps = [ 379 ":kernel_timeout_internal", 380 ":synchronization", 381 ":thread_pool", 382 "//absl/base:config", 383 "//absl/random", 384 "//absl/time", 385 "@com_google_googletest//:gtest", 386 "@com_google_googletest//:gtest_main", 387 ], 388) 389 390cc_test( 391 name = "lifetime_test", 392 srcs = [ 393 "lifetime_test.cc", 394 ], 395 copts = ABSL_TEST_COPTS, 396 linkopts = ABSL_DEFAULT_LINKOPTS, 397 tags = [ 398 "no_test_ios_x86_64", 399 "no_test_wasm", 400 ], 401 deps = [ 402 ":synchronization", 403 "//absl/base:core_headers", 404 "//absl/log:check", 405 ], 406) 407