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