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