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