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