BUILD.bazel 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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(
  23. default_visibility = ["//visibility:private"],
  24. features = [
  25. "header_modules",
  26. "layering_check",
  27. "parse_headers",
  28. ],
  29. )
  30. licenses(["notice"])
  31. # Internal data structure for efficiently detecting mutex dependency cycles
  32. cc_library(
  33. name = "graphcycles_internal",
  34. srcs = [
  35. "internal/graphcycles.cc",
  36. ],
  37. hdrs = [
  38. "internal/graphcycles.h",
  39. ],
  40. copts = ABSL_DEFAULT_COPTS + select({
  41. "//conditions:default": [],
  42. }),
  43. linkopts = ABSL_DEFAULT_LINKOPTS,
  44. deps = [
  45. "//absl/base",
  46. "//absl/base:base_internal",
  47. "//absl/base:config",
  48. "//absl/base:core_headers",
  49. "//absl/base:malloc_internal",
  50. "//absl/base:raw_logging_internal",
  51. ],
  52. )
  53. cc_library(
  54. name = "kernel_timeout_internal",
  55. srcs = ["internal/kernel_timeout.cc"],
  56. hdrs = ["internal/kernel_timeout.h"],
  57. copts = ABSL_DEFAULT_COPTS,
  58. linkopts = ABSL_DEFAULT_LINKOPTS,
  59. visibility = [
  60. ],
  61. deps = [
  62. "//absl/base",
  63. "//absl/base:config",
  64. "//absl/base:core_headers",
  65. "//absl/base:raw_logging_internal",
  66. "//absl/time",
  67. ] + select({
  68. "//conditions:default": [],
  69. }),
  70. )
  71. cc_test(
  72. name = "kernel_timeout_internal_test",
  73. srcs = ["internal/kernel_timeout_test.cc"],
  74. copts = ABSL_TEST_COPTS,
  75. flaky = 1,
  76. linkopts = ABSL_DEFAULT_LINKOPTS,
  77. deps = [
  78. ":kernel_timeout_internal",
  79. "//absl/base:config",
  80. "//absl/random",
  81. "//absl/time",
  82. "@com_google_googletest//:gtest",
  83. "@com_google_googletest//:gtest_main",
  84. ],
  85. )
  86. cc_library(
  87. name = "synchronization",
  88. srcs = [
  89. "barrier.cc",
  90. "blocking_counter.cc",
  91. "internal/create_thread_identity.cc",
  92. "internal/futex_waiter.cc",
  93. "internal/per_thread_sem.cc",
  94. "internal/pthread_waiter.cc",
  95. "internal/sem_waiter.cc",
  96. "internal/stdcpp_waiter.cc",
  97. "internal/waiter_base.cc",
  98. "internal/win32_waiter.cc",
  99. "mutex.cc",
  100. "notification.cc",
  101. ],
  102. hdrs = [
  103. "barrier.h",
  104. "blocking_counter.h",
  105. "internal/create_thread_identity.h",
  106. "internal/futex.h",
  107. "internal/futex_waiter.h",
  108. "internal/per_thread_sem.h",
  109. "internal/pthread_waiter.h",
  110. "internal/sem_waiter.h",
  111. "internal/stdcpp_waiter.h",
  112. "internal/waiter.h",
  113. "internal/waiter_base.h",
  114. "internal/win32_waiter.h",
  115. "mutex.h",
  116. "notification.h",
  117. ],
  118. copts = ABSL_DEFAULT_COPTS,
  119. linkopts = select({
  120. "//absl:msvc_compiler": [],
  121. "//absl:clang-cl_compiler": [],
  122. "//absl:wasm": [],
  123. "//conditions:default": ["-pthread"],
  124. }) + ABSL_DEFAULT_LINKOPTS,
  125. visibility = ["//visibility:public"],
  126. deps = [
  127. ":graphcycles_internal",
  128. ":kernel_timeout_internal",
  129. "//absl/base",
  130. "//absl/base:atomic_hook",
  131. "//absl/base:base_internal",
  132. "//absl/base:config",
  133. "//absl/base:core_headers",
  134. "//absl/base:dynamic_annotations",
  135. "//absl/base:malloc_internal",
  136. "//absl/base:raw_logging_internal",
  137. "//absl/debugging:stacktrace",
  138. "//absl/debugging:symbolize",
  139. "//absl/time",
  140. ] + select({
  141. "//conditions:default": [],
  142. }),
  143. )
  144. cc_test(
  145. name = "barrier_test",
  146. size = "small",
  147. srcs = ["barrier_test.cc"],
  148. copts = ABSL_TEST_COPTS,
  149. linkopts = ABSL_DEFAULT_LINKOPTS,
  150. tags = [
  151. "no_test_wasm", # b/122473323
  152. ],
  153. deps = [
  154. ":synchronization",
  155. "//absl/time",
  156. "@com_google_googletest//:gtest",
  157. "@com_google_googletest//:gtest_main",
  158. ],
  159. )
  160. cc_test(
  161. name = "blocking_counter_test",
  162. size = "small",
  163. srcs = ["blocking_counter_test.cc"],
  164. copts = ABSL_TEST_COPTS,
  165. linkopts = ABSL_DEFAULT_LINKOPTS,
  166. tags = [
  167. "no_test_wasm", # b/122473323
  168. ],
  169. deps = [
  170. ":synchronization",
  171. "//absl/time",
  172. "@com_google_googletest//:gtest",
  173. "@com_google_googletest//:gtest_main",
  174. ],
  175. )
  176. cc_binary(
  177. name = "blocking_counter_benchmark",
  178. testonly = True,
  179. srcs = ["blocking_counter_benchmark.cc"],
  180. copts = ABSL_TEST_COPTS,
  181. linkopts = ABSL_DEFAULT_LINKOPTS,
  182. tags = ["benchmark"],
  183. deps = [
  184. ":synchronization",
  185. ":thread_pool",
  186. "//absl/base:no_destructor",
  187. "@com_github_google_benchmark//:benchmark_main",
  188. ],
  189. )
  190. cc_test(
  191. name = "graphcycles_test",
  192. size = "medium",
  193. srcs = ["internal/graphcycles_test.cc"],
  194. copts = ABSL_TEST_COPTS,
  195. linkopts = ABSL_DEFAULT_LINKOPTS,
  196. deps = [
  197. ":graphcycles_internal",
  198. "//absl/base:core_headers",
  199. "//absl/log",
  200. "//absl/log:check",
  201. "@com_google_googletest//:gtest",
  202. "@com_google_googletest//:gtest_main",
  203. ],
  204. )
  205. cc_test(
  206. name = "graphcycles_benchmark",
  207. srcs = ["internal/graphcycles_benchmark.cc"],
  208. copts = ABSL_TEST_COPTS,
  209. linkopts = ABSL_DEFAULT_LINKOPTS,
  210. tags = [
  211. "benchmark",
  212. ],
  213. deps = [
  214. ":graphcycles_internal",
  215. "//absl/base:raw_logging_internal",
  216. "@com_github_google_benchmark//:benchmark_main",
  217. "@com_google_googletest//:gtest",
  218. ],
  219. )
  220. cc_library(
  221. name = "thread_pool",
  222. testonly = True,
  223. hdrs = ["internal/thread_pool.h"],
  224. linkopts = ABSL_DEFAULT_LINKOPTS,
  225. visibility = [
  226. "//absl:__subpackages__",
  227. ],
  228. deps = [
  229. ":synchronization",
  230. "//absl/base:core_headers",
  231. "//absl/functional:any_invocable",
  232. ],
  233. )
  234. cc_test(
  235. name = "mutex_test",
  236. size = "large",
  237. srcs = ["mutex_test.cc"],
  238. copts = ABSL_TEST_COPTS,
  239. flaky = 1,
  240. linkopts = ABSL_DEFAULT_LINKOPTS,
  241. shard_count = 25,
  242. deps = [
  243. ":synchronization",
  244. ":thread_pool",
  245. "//absl/base",
  246. "//absl/base:config",
  247. "//absl/base:core_headers",
  248. "//absl/log",
  249. "//absl/log:check",
  250. "//absl/memory",
  251. "//absl/time",
  252. "@com_google_googletest//:gtest",
  253. "@com_google_googletest//:gtest_main",
  254. ],
  255. )
  256. cc_test(
  257. name = "mutex_method_pointer_test",
  258. srcs = ["mutex_method_pointer_test.cc"],
  259. copts = ABSL_TEST_COPTS,
  260. linkopts = ABSL_DEFAULT_LINKOPTS,
  261. deps = [
  262. ":synchronization",
  263. "//absl/base:config",
  264. "@com_google_googletest//:gtest",
  265. "@com_google_googletest//:gtest_main",
  266. ],
  267. )
  268. cc_library(
  269. name = "mutex_benchmark_common",
  270. testonly = True,
  271. srcs = ["mutex_benchmark.cc"],
  272. copts = ABSL_TEST_COPTS,
  273. linkopts = ABSL_DEFAULT_LINKOPTS,
  274. visibility = [
  275. ],
  276. deps = [
  277. ":synchronization",
  278. ":thread_pool",
  279. "//absl/base",
  280. "//absl/base:config",
  281. "//absl/base:no_destructor",
  282. "@com_github_google_benchmark//:benchmark_main",
  283. ],
  284. alwayslink = 1,
  285. )
  286. cc_binary(
  287. name = "mutex_benchmark",
  288. testonly = True,
  289. copts = ABSL_DEFAULT_COPTS,
  290. linkopts = ABSL_DEFAULT_LINKOPTS,
  291. deps = [
  292. ":mutex_benchmark_common",
  293. ],
  294. )
  295. cc_test(
  296. name = "notification_test",
  297. size = "small",
  298. srcs = ["notification_test.cc"],
  299. copts = ABSL_TEST_COPTS,
  300. flaky = 1,
  301. linkopts = ABSL_DEFAULT_LINKOPTS,
  302. tags = ["no_test_lexan"],
  303. deps = [
  304. ":synchronization",
  305. "//absl/time",
  306. "@com_google_googletest//:gtest",
  307. "@com_google_googletest//:gtest_main",
  308. ],
  309. )
  310. cc_library(
  311. name = "per_thread_sem_test_common",
  312. testonly = True,
  313. srcs = ["internal/per_thread_sem_test.cc"],
  314. copts = ABSL_TEST_COPTS,
  315. linkopts = ABSL_DEFAULT_LINKOPTS,
  316. visibility = [
  317. ],
  318. deps = [
  319. ":synchronization",
  320. "//absl/base",
  321. "//absl/base:config",
  322. "//absl/strings",
  323. "//absl/time",
  324. "@com_google_googletest//:gtest",
  325. ],
  326. alwayslink = 1,
  327. )
  328. cc_test(
  329. name = "per_thread_sem_test",
  330. size = "large",
  331. copts = ABSL_TEST_COPTS,
  332. linkopts = ABSL_DEFAULT_LINKOPTS,
  333. tags = [
  334. "no_test_wasm",
  335. ],
  336. deps = [
  337. ":per_thread_sem_test_common",
  338. ":synchronization",
  339. "//absl/strings",
  340. "//absl/time",
  341. "@com_google_googletest//:gtest_main",
  342. ],
  343. )
  344. cc_test(
  345. name = "waiter_test",
  346. srcs = ["internal/waiter_test.cc"],
  347. copts = ABSL_TEST_COPTS,
  348. flaky = 1,
  349. linkopts = ABSL_DEFAULT_LINKOPTS,
  350. deps = [
  351. ":kernel_timeout_internal",
  352. ":synchronization",
  353. ":thread_pool",
  354. "//absl/base:config",
  355. "//absl/random",
  356. "//absl/time",
  357. "@com_google_googletest//:gtest",
  358. "@com_google_googletest//:gtest_main",
  359. ],
  360. )
  361. cc_test(
  362. name = "lifetime_test",
  363. srcs = [
  364. "lifetime_test.cc",
  365. ],
  366. copts = ABSL_TEST_COPTS,
  367. linkopts = ABSL_DEFAULT_LINKOPTS,
  368. tags = [
  369. "no_test_ios_x86_64",
  370. "no_test_wasm",
  371. ],
  372. deps = [
  373. ":synchronization",
  374. "//absl/base:core_headers",
  375. "//absl/log:check",
  376. ],
  377. )