# Copyright 2018 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//third_party/abseil-cpp/absl.gni")

absl_source_set("graphcycles_internal") {
  sources = [ "internal/graphcycles.cc" ]
  public = [ "internal/graphcycles.h" ]
  deps = [
    "//third_party/abseil-cpp/absl/base",
    "//third_party/abseil-cpp/absl/base:base_internal",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
    "//third_party/abseil-cpp/absl/base:malloc_internal",
    "//third_party/abseil-cpp/absl/base:raw_logging_internal",
  ]
  visibility = [ ":*" ]
}

absl_source_set("kernel_timeout_internal") {
  sources = [ "internal/kernel_timeout.cc" ]
  public = [ "internal/kernel_timeout.h" ]
  deps = [
    "//third_party/abseil-cpp/absl/base",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
    "//third_party/abseil-cpp/absl/base:raw_logging_internal",
    "//third_party/abseil-cpp/absl/time",
  ]
  visibility = [ ":*" ]
}

absl_test("kernel_timeout_internal_test") {
  sources = [ "internal/kernel_timeout_test.cc" ]
  deps = [
    ":kernel_timeout_internal",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/random",
    "//third_party/abseil-cpp/absl/time",
  ]
}

absl_source_set("synchronization") {
  sources = [
    "barrier.cc",
    "blocking_counter.cc",
    "internal/create_thread_identity.cc",
    "internal/futex_waiter.cc",
    "internal/per_thread_sem.cc",
    "internal/pthread_waiter.cc",
    "internal/sem_waiter.cc",
    "internal/stdcpp_waiter.cc",
    "internal/waiter_base.cc",
    "internal/win32_waiter.cc",
    "mutex.cc",
    "notification.cc",
  ]
  public = [
    "barrier.h",
    "blocking_counter.h",
    "internal/create_thread_identity.h",
    "internal/futex.h",
    "internal/futex_waiter.h",
    "internal/per_thread_sem.h",
    "internal/pthread_waiter.h",
    "internal/sem_waiter.h",
    "internal/stdcpp_waiter.h",
    "internal/waiter.h",
    "internal/waiter_base.h",
    "internal/win32_waiter.h",
    "mutex.h",
    "notification.h",
  ]
  deps = [
    ":graphcycles_internal",
    ":kernel_timeout_internal",
    "//third_party/abseil-cpp/absl/base",
    "//third_party/abseil-cpp/absl/base:atomic_hook",
    "//third_party/abseil-cpp/absl/base:base_internal",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
    "//third_party/abseil-cpp/absl/base:dynamic_annotations",
    "//third_party/abseil-cpp/absl/base:malloc_internal",
    "//third_party/abseil-cpp/absl/base:raw_logging_internal",
    "//third_party/abseil-cpp/absl/base:tracing_internal",
    "//third_party/abseil-cpp/absl/debugging:stacktrace",
    "//third_party/abseil-cpp/absl/debugging:symbolize",
    "//third_party/abseil-cpp/absl/time",
  ]
}

absl_test("barrier_test") {
  sources = [ "barrier_test.cc" ]
  deps = [
    ":synchronization",
    "//third_party/abseil-cpp/absl/time",
  ]
}

# Conflicts at link time with "tracing_strong_test" because also defines
# strong functions for AbslInternalTraceWait and alike
# absl_test("blocking_counter_test") {
#   sources = [ "blocking_counter_test.cc" ]
#   deps = [
#     ":synchronization",
#     "//third_party/abseil-cpp/absl/base:config",
#     "//third_party/abseil-cpp/absl/base:core_headers",
#     "//third_party/abseil-cpp/absl/base:tracing_internal",
#     "//third_party/abseil-cpp/absl/time",
#   ]
# }

absl_test("graphcycles_test") {
  sources = [ "internal/graphcycles_test.cc" ]
  deps = [
    ":graphcycles_internal",
    "//third_party/abseil-cpp/absl/base:core_headers",
    "//third_party/abseil-cpp/absl/log",
    "//third_party/abseil-cpp/absl/log:check",
  ]
}

absl_source_set("thread_pool") {
  testonly = true
  public = [ "internal/thread_pool.h" ]
  deps = [
    ":synchronization",
    "//third_party/abseil-cpp/absl/base:core_headers",
    "//third_party/abseil-cpp/absl/functional:any_invocable",
  ]
  visibility = [ "//third_party/abseil-cpp/absl/*" ]
}

absl_test("mutex_test") {
  sources = [ "mutex_test.cc" ]
  deps = [
    ":synchronization",
    ":thread_pool",
    "//third_party/abseil-cpp/absl/base",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
    "//third_party/abseil-cpp/absl/log",
    "//third_party/abseil-cpp/absl/log:check",
    "//third_party/abseil-cpp/absl/memory",
    "//third_party/abseil-cpp/absl/time",
  ]
}

# Doesn't compile.
# absl_test("mutex_method_pointer_test") {
#   sources = [ "mutex_method_pointer_test.cc" ]
#   deps = [
#     ":synchronization",
#     "//third_party/abseil-cpp/absl/base:config",
#   ]
# }

# Conflicts at link time with "tracing_strong_test" because also defines
# strong functions for AbslInternalTraceWait and alike
# absl_test("notification_test") {
#   sources = [ "notification_test.cc" ]
#   deps = [
#     ":synchronization",
#     "//third_party/abseil-cpp/absl/base:config",
#     "//third_party/abseil-cpp/absl/base:core_headers",
#     "//third_party/abseil-cpp/absl/base:tracing_internal",
#     "//third_party/abseil-cpp/absl/time",
#   ]
# }

absl_source_set("per_thread_sem_test_common") {
  testonly = true
  sources = [ "internal/per_thread_sem_test.cc" ]
  deps = [
    ":synchronization",
    "//third_party/abseil-cpp/absl/base",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/strings",
    "//third_party/abseil-cpp/absl/time",
    "//third_party/googletest:gtest",
  ]
  visibility = [ ":*" ]
}

absl_test("per_thread_sem_test") {
  deps = [
    ":per_thread_sem_test_common",
    ":synchronization",
    "//third_party/abseil-cpp/absl/strings",
    "//third_party/abseil-cpp/absl/time",
  ]
}

absl_test("waiter_test") {
  sources = [ "internal/waiter_test.cc" ]
  deps = [
    ":kernel_timeout_internal",
    ":synchronization",
    ":thread_pool",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/random",
    "//third_party/abseil-cpp/absl/time",
  ]
}
# Has it's own main function and thus can't be included into absl_tests target
# absl_test("lifetime_test") {
#   sources = [ "lifetime_test.cc" ]
#   deps = [
#     ":synchronization",
#     "//third_party/abseil-cpp/absl/base:core_headers",
#     "//third_party/abseil-cpp/absl/log:check",
#   ]
# }
