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