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 ], 204) 205 206cc_test( 207 name = "mutex_test", 208 size = "large", 209 srcs = ["mutex_test.cc"], 210 copts = ABSL_TEST_COPTS, 211 linkopts = ABSL_DEFAULT_LINKOPTS, 212 shard_count = 25, 213 deps = [ 214 ":synchronization", 215 ":thread_pool", 216 "//absl/base", 217 "//absl/base:config", 218 "//absl/base:core_headers", 219 "//absl/base:raw_logging_internal", 220 "//absl/memory", 221 "//absl/time", 222 "@com_google_googletest//:gtest_main", 223 ], 224) 225 226cc_library( 227 name = "mutex_benchmark_common", 228 testonly = 1, 229 srcs = ["mutex_benchmark.cc"], 230 copts = ABSL_TEST_COPTS, 231 linkopts = ABSL_DEFAULT_LINKOPTS, 232 visibility = [ 233 "//absl/synchronization:__pkg__", 234 ], 235 deps = [ 236 ":synchronization", 237 ":thread_pool", 238 "//absl/base", 239 "//absl/base:config", 240 "@com_github_google_benchmark//:benchmark_main", 241 ], 242 alwayslink = 1, 243) 244 245cc_binary( 246 name = "mutex_benchmark", 247 testonly = 1, 248 copts = ABSL_DEFAULT_COPTS, 249 linkopts = ABSL_DEFAULT_LINKOPTS, 250 visibility = ["//visibility:private"], 251 deps = [ 252 ":mutex_benchmark_common", 253 ], 254) 255 256cc_test( 257 name = "notification_test", 258 size = "small", 259 srcs = ["notification_test.cc"], 260 copts = ABSL_TEST_COPTS, 261 linkopts = ABSL_DEFAULT_LINKOPTS, 262 tags = ["no_test_lexan"], 263 deps = [ 264 ":synchronization", 265 "//absl/time", 266 "@com_google_googletest//:gtest_main", 267 ], 268) 269 270cc_library( 271 name = "per_thread_sem_test_common", 272 testonly = 1, 273 srcs = ["internal/per_thread_sem_test.cc"], 274 copts = ABSL_TEST_COPTS, 275 linkopts = ABSL_DEFAULT_LINKOPTS, 276 deps = [ 277 ":synchronization", 278 "//absl/base", 279 "//absl/base:config", 280 "//absl/strings", 281 "//absl/time", 282 "@com_google_googletest//:gtest", 283 ], 284 alwayslink = 1, 285) 286 287cc_test( 288 name = "per_thread_sem_test", 289 size = "large", 290 copts = ABSL_TEST_COPTS, 291 linkopts = ABSL_DEFAULT_LINKOPTS, 292 tags = [ 293 "no_test_wasm", 294 ], 295 deps = [ 296 ":per_thread_sem_test_common", 297 ":synchronization", 298 "//absl/strings", 299 "//absl/time", 300 "@com_google_googletest//:gtest_main", 301 ], 302) 303 304cc_test( 305 name = "lifetime_test", 306 srcs = [ 307 "lifetime_test.cc", 308 ], 309 copts = ABSL_TEST_COPTS, 310 linkopts = ABSL_DEFAULT_LINKOPTS, 311 tags = [ 312 "no_test_ios_x86_64", 313 "no_test_wasm", 314 ], 315 deps = [ 316 ":synchronization", 317 "//absl/base:core_headers", 318 "//absl/base:raw_logging_internal", 319 ], 320) 321