BUILD.bazel 7.2 KB

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