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_test( 140 name = "graphcycles_test", 141 size = "medium", 142 srcs = ["internal/graphcycles_test.cc"], 143 copts = ABSL_TEST_COPTS, 144 linkopts = ABSL_DEFAULT_LINKOPTS, 145 deps = [ 146 ":graphcycles_internal", 147 "//absl/base:core_headers", 148 "//absl/base:raw_logging_internal", 149 "@com_google_googletest//:gtest_main", 150 ], 151) 152 153cc_test( 154 name = "graphcycles_benchmark", 155 srcs = ["internal/graphcycles_benchmark.cc"], 156 copts = ABSL_TEST_COPTS, 157 linkopts = ABSL_DEFAULT_LINKOPTS, 158 tags = [ 159 "benchmark", 160 ], 161 deps = [ 162 ":graphcycles_internal", 163 "//absl/base:raw_logging_internal", 164 "@com_github_google_benchmark//:benchmark_main", 165 ], 166) 167 168cc_library( 169 name = "thread_pool", 170 testonly = 1, 171 hdrs = ["internal/thread_pool.h"], 172 linkopts = ABSL_DEFAULT_LINKOPTS, 173 visibility = [ 174 "//absl:__subpackages__", 175 ], 176 deps = [ 177 ":synchronization", 178 "//absl/base:core_headers", 179 ], 180) 181 182cc_test( 183 name = "mutex_test", 184 size = "large", 185 srcs = ["mutex_test.cc"], 186 copts = ABSL_TEST_COPTS, 187 linkopts = ABSL_DEFAULT_LINKOPTS, 188 shard_count = 25, 189 deps = [ 190 ":synchronization", 191 ":thread_pool", 192 "//absl/base", 193 "//absl/base:config", 194 "//absl/base:core_headers", 195 "//absl/base:raw_logging_internal", 196 "//absl/memory", 197 "//absl/time", 198 "@com_google_googletest//:gtest_main", 199 ], 200) 201 202cc_library( 203 name = "mutex_benchmark_common", 204 testonly = 1, 205 srcs = ["mutex_benchmark.cc"], 206 copts = ABSL_TEST_COPTS, 207 linkopts = ABSL_DEFAULT_LINKOPTS, 208 visibility = [ 209 "//absl/synchronization:__pkg__", 210 ], 211 deps = [ 212 ":synchronization", 213 ":thread_pool", 214 "//absl/base", 215 "//absl/base:config", 216 "@com_github_google_benchmark//:benchmark_main", 217 ], 218 alwayslink = 1, 219) 220 221cc_binary( 222 name = "mutex_benchmark", 223 testonly = 1, 224 copts = ABSL_DEFAULT_COPTS, 225 linkopts = ABSL_DEFAULT_LINKOPTS, 226 visibility = ["//visibility:private"], 227 deps = [ 228 ":mutex_benchmark_common", 229 ], 230) 231 232cc_test( 233 name = "notification_test", 234 size = "small", 235 srcs = ["notification_test.cc"], 236 copts = ABSL_TEST_COPTS, 237 linkopts = ABSL_DEFAULT_LINKOPTS, 238 deps = [ 239 ":synchronization", 240 "//absl/time", 241 "@com_google_googletest//:gtest_main", 242 ], 243) 244 245cc_library( 246 name = "per_thread_sem_test_common", 247 testonly = 1, 248 srcs = ["internal/per_thread_sem_test.cc"], 249 copts = ABSL_TEST_COPTS, 250 linkopts = ABSL_DEFAULT_LINKOPTS, 251 deps = [ 252 ":synchronization", 253 "//absl/base", 254 "//absl/base:config", 255 "//absl/strings", 256 "//absl/time", 257 "@com_google_googletest//:gtest", 258 ], 259 alwayslink = 1, 260) 261 262cc_test( 263 name = "per_thread_sem_test", 264 size = "medium", 265 copts = ABSL_TEST_COPTS, 266 linkopts = ABSL_DEFAULT_LINKOPTS, 267 deps = [ 268 ":per_thread_sem_test_common", 269 ":synchronization", 270 "//absl/strings", 271 "//absl/time", 272 "@com_google_googletest//:gtest_main", 273 ], 274) 275 276cc_test( 277 name = "lifetime_test", 278 srcs = [ 279 "lifetime_test.cc", 280 ], 281 copts = ABSL_TEST_COPTS, 282 linkopts = ABSL_DEFAULT_LINKOPTS, 283 tags = ["no_test_ios_x86_64"], 284 deps = [ 285 ":synchronization", 286 "//absl/base:core_headers", 287 "//absl/base:raw_logging_internal", 288 ], 289) 290