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 hdrs = ["internal/kernel_timeout.h"], 57 copts = ABSL_DEFAULT_COPTS, 58 linkopts = ABSL_DEFAULT_LINKOPTS, 59 visibility = [ 60 "//absl/synchronization:__pkg__", 61 ], 62 deps = [ 63 "//absl/base:core_headers", 64 "//absl/base:raw_logging_internal", 65 "//absl/time", 66 ], 67) 68 69cc_library( 70 name = "synchronization", 71 srcs = [ 72 "barrier.cc", 73 "blocking_counter.cc", 74 "internal/create_thread_identity.cc", 75 "internal/per_thread_sem.cc", 76 "internal/waiter.cc", 77 "mutex.cc", 78 "notification.cc", 79 ], 80 hdrs = [ 81 "barrier.h", 82 "blocking_counter.h", 83 "internal/create_thread_identity.h", 84 "internal/futex.h", 85 "internal/per_thread_sem.h", 86 "internal/waiter.h", 87 "mutex.h", 88 "notification.h", 89 ], 90 copts = ABSL_DEFAULT_COPTS, 91 linkopts = select({ 92 "//absl:msvc_compiler": [], 93 "//absl:clang-cl_compiler": [], 94 "//absl:wasm": [], 95 "//conditions:default": ["-pthread"], 96 }) + ABSL_DEFAULT_LINKOPTS, 97 deps = [ 98 ":graphcycles_internal", 99 ":kernel_timeout_internal", 100 "//absl/base:atomic_hook", 101 "//absl/base", 102 "//absl/base:base_internal", 103 "//absl/base:config", 104 "//absl/base:core_headers", 105 "//absl/base:dynamic_annotations", 106 "//absl/base:malloc_internal", 107 "//absl/base:raw_logging_internal", 108 "//absl/debugging:stacktrace", 109 "//absl/debugging:symbolize", 110 "//absl/time", 111 ] + select({ 112 "//conditions:default": [], 113 }), 114) 115 116cc_test( 117 name = "barrier_test", 118 size = "small", 119 srcs = ["barrier_test.cc"], 120 copts = ABSL_TEST_COPTS, 121 linkopts = ABSL_DEFAULT_LINKOPTS, 122 tags = [ 123 "no_test_wasm", 124 ], 125 deps = [ 126 ":synchronization", 127 "//absl/time", 128 "@com_google_googletest//:gtest_main", 129 ], 130) 131 132cc_test( 133 name = "blocking_counter_test", 134 size = "small", 135 srcs = ["blocking_counter_test.cc"], 136 copts = ABSL_TEST_COPTS, 137 linkopts = ABSL_DEFAULT_LINKOPTS, 138 tags = [ 139 "no_test_wasm", 140 ], 141 deps = [ 142 ":synchronization", 143 "//absl/time", 144 "@com_google_googletest//:gtest_main", 145 ], 146) 147 148cc_binary( 149 name = "blocking_counter_benchmark", 150 testonly = 1, 151 srcs = ["blocking_counter_benchmark.cc"], 152 copts = ABSL_TEST_COPTS, 153 linkopts = ABSL_DEFAULT_LINKOPTS, 154 tags = ["benchmark"], 155 visibility = ["//visibility:private"], 156 deps = [ 157 ":synchronization", 158 ":thread_pool", 159 "@com_github_google_benchmark//:benchmark_main", 160 ], 161) 162 163cc_test( 164 name = "graphcycles_test", 165 size = "medium", 166 srcs = ["internal/graphcycles_test.cc"], 167 copts = ABSL_TEST_COPTS, 168 linkopts = ABSL_DEFAULT_LINKOPTS, 169 deps = [ 170 ":graphcycles_internal", 171 "//absl/base:core_headers", 172 "//absl/base:raw_logging_internal", 173 "@com_google_googletest//:gtest_main", 174 ], 175) 176 177cc_test( 178 name = "graphcycles_benchmark", 179 srcs = ["internal/graphcycles_benchmark.cc"], 180 copts = ABSL_TEST_COPTS, 181 linkopts = ABSL_DEFAULT_LINKOPTS, 182 tags = [ 183 "benchmark", 184 ], 185 deps = [ 186 ":graphcycles_internal", 187 "//absl/base:raw_logging_internal", 188 "@com_github_google_benchmark//:benchmark_main", 189 ], 190) 191 192cc_library( 193 name = "thread_pool", 194 testonly = 1, 195 hdrs = ["internal/thread_pool.h"], 196 linkopts = ABSL_DEFAULT_LINKOPTS, 197 visibility = [ 198 "//absl:__subpackages__", 199 ], 200 deps = [ 201 ":synchronization", 202 "//absl/base:core_headers", 203 "//absl/functional:any_invocable", 204 ], 205) 206 207cc_test( 208 name = "mutex_test", 209 size = "large", 210 srcs = ["mutex_test.cc"], 211 copts = ABSL_TEST_COPTS, 212 linkopts = ABSL_DEFAULT_LINKOPTS, 213 shard_count = 25, 214 deps = [ 215 ":synchronization", 216 ":thread_pool", 217 "//absl/base", 218 "//absl/base:config", 219 "//absl/base:core_headers", 220 "//absl/base:raw_logging_internal", 221 "//absl/memory", 222 "//absl/time", 223 "@com_google_googletest//:gtest_main", 224 ], 225) 226 227cc_test( 228 name = "mutex_method_pointer_test", 229 srcs = ["mutex_method_pointer_test.cc"], 230 copts = ABSL_TEST_COPTS, 231 linkopts = ABSL_DEFAULT_LINKOPTS, 232 deps = [ 233 ":synchronization", 234 "//absl/base:config", 235 "@com_google_googletest//:gtest_main", 236 ], 237) 238 239cc_library( 240 name = "mutex_benchmark_common", 241 testonly = 1, 242 srcs = ["mutex_benchmark.cc"], 243 copts = ABSL_TEST_COPTS, 244 linkopts = ABSL_DEFAULT_LINKOPTS, 245 visibility = [ 246 "//absl/synchronization:__pkg__", 247 ], 248 deps = [ 249 ":synchronization", 250 ":thread_pool", 251 "//absl/base", 252 "//absl/base:config", 253 "@com_github_google_benchmark//:benchmark_main", 254 ], 255 alwayslink = 1, 256) 257 258cc_binary( 259 name = "mutex_benchmark", 260 testonly = 1, 261 copts = ABSL_DEFAULT_COPTS, 262 linkopts = ABSL_DEFAULT_LINKOPTS, 263 visibility = ["//visibility:private"], 264 deps = [ 265 ":mutex_benchmark_common", 266 ], 267) 268 269cc_test( 270 name = "notification_test", 271 size = "small", 272 srcs = ["notification_test.cc"], 273 copts = ABSL_TEST_COPTS, 274 linkopts = ABSL_DEFAULT_LINKOPTS, 275 tags = ["no_test_lexan"], 276 deps = [ 277 ":synchronization", 278 "//absl/time", 279 "@com_google_googletest//:gtest_main", 280 ], 281) 282 283cc_library( 284 name = "per_thread_sem_test_common", 285 testonly = 1, 286 srcs = ["internal/per_thread_sem_test.cc"], 287 copts = ABSL_TEST_COPTS, 288 linkopts = ABSL_DEFAULT_LINKOPTS, 289 deps = [ 290 ":synchronization", 291 "//absl/base", 292 "//absl/base:config", 293 "//absl/strings", 294 "//absl/time", 295 "@com_google_googletest//:gtest", 296 ], 297 alwayslink = 1, 298) 299 300cc_test( 301 name = "per_thread_sem_test", 302 size = "large", 303 copts = ABSL_TEST_COPTS, 304 linkopts = ABSL_DEFAULT_LINKOPTS, 305 tags = [ 306 "no_test_wasm", 307 ], 308 deps = [ 309 ":per_thread_sem_test_common", 310 ":synchronization", 311 "//absl/strings", 312 "//absl/time", 313 "@com_google_googletest//:gtest_main", 314 ], 315) 316 317cc_test( 318 name = "lifetime_test", 319 srcs = [ 320 "lifetime_test.cc", 321 ], 322 copts = ABSL_TEST_COPTS, 323 linkopts = ABSL_DEFAULT_LINKOPTS, 324 tags = [ 325 "no_test_ios_x86_64", 326 "no_test_wasm", 327 ], 328 deps = [ 329 ":synchronization", 330 "//absl/base:core_headers", 331 "//absl/base:raw_logging_internal", 332 ], 333) 334