Skip to content

Commit

Permalink
Move threading primitives into internal/thread
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 583664971
Change-Id: Ia457e09bb150056f50ca50ed6b1c9d3f0276f31c
  • Loading branch information
laramiel authored and copybara-github committed Nov 18, 2023
1 parent 2b1dec0 commit ed1e9f4
Show file tree
Hide file tree
Showing 44 changed files with 283 additions and 166 deletions.
100 changes: 3 additions & 97 deletions tensorstore/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ tensorstore_cc_library(
"concurrency_resource_provider.h",
],
deps = [
":thread_pool",
":type_traits",
"//tensorstore:context",
"//tensorstore/internal/cache_key",
"//tensorstore/internal/json_binding",
"//tensorstore/internal/json_binding:bindable",
"//tensorstore/internal/thread:thread_pool",
"//tensorstore/util:executor",
"//tensorstore/util:result",
"@com_github_nlohmann_json//:nlohmann_json",
Expand All @@ -166,7 +166,7 @@ tensorstore_cc_library(
hdrs = ["concurrent_testutil.h"],
deps = [
":multi_barrier",
":thread",
"//tensorstore/internal/thread",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",
],
Expand Down Expand Up @@ -1742,68 +1742,6 @@ tensorstore_cc_library(
],
)

tensorstore_cc_library(
name = "thread",
srcs = ["thread.cc"],
hdrs = ["thread.h"],
deps = [
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/log:absl_check",
],
)

tensorstore_cc_test(
name = "thread_test",
srcs = ["thread_test.cc"],
deps = [
":thread",
"@com_google_googletest//:gtest_main",
],
)

tensorstore_cc_library(
name = "thread_pool",
srcs = ["thread_pool.cc"],
hdrs = ["thread_pool.h"],
deps = [
":attributes",
":intrusive_ptr",
":mutex",
":no_destructor",
":thread",
"//tensorstore/internal/metrics",
"//tensorstore/internal/tracing",
"//tensorstore/util:executor",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
],
)

tensorstore_cc_test(
name = "thread_pool_test",
size = "small",
deps = [
":thread_pool",
":thread_pool_test_lib",
],
)

tensorstore_cc_library(
name = "thread_pool_test_lib",
testonly = True,
srcs = ["thread_pool_test.cc"],
deps = [
"//tensorstore/util:executor",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest_main",
],
)

tensorstore_cc_library(
name = "type_traits",
hdrs = ["type_traits.h"],
Expand Down Expand Up @@ -1931,38 +1869,6 @@ tensorstore_cc_library(
],
)

tensorstore_cc_library(
name = "schedule_at",
srcs = ["schedule_at.cc"],
hdrs = ["schedule_at.h"],
deps = [
":intrusive_red_black_tree",
":no_destructor",
":tagged_ptr",
":thread",
"//tensorstore/internal/metrics",
"//tensorstore/internal/tracing",
"//tensorstore/util:stop_token",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
],
)

tensorstore_cc_test(
name = "schedule_at_test",
size = "small",
srcs = ["schedule_at_test.cc"],
deps = [
":schedule_at",
"//tensorstore/util:executor",
"//tensorstore/util:stop_token",
"@com_google_absl//absl/synchronization",
"@com_google_googletest//:gtest_main",
],
)

tensorstore_cc_library(
name = "multi_barrier",
srcs = ["multi_barrier.cc"],
Expand All @@ -1978,7 +1884,7 @@ tensorstore_cc_test(
srcs = ["multi_barrier_test.cc"],
deps = [
":multi_barrier",
":thread",
"//tensorstore/internal/thread",
"@com_google_googletest//:gtest_main",
],
)
Expand Down
6 changes: 3 additions & 3 deletions tensorstore/internal/cache/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//bazel:tensorstore.bzl", "tensorstore_cc_binary", "tensorstore_cc_library", "tensorstore_cc_test")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("//bazel:tensorstore.bzl", "tensorstore_cc_binary", "tensorstore_cc_library", "tensorstore_cc_test")

package(default_visibility = ["//tensorstore:internal_packages"])

Expand Down Expand Up @@ -360,7 +360,7 @@ tensorstore_cc_binary(
"//tensorstore/index_space:transformed_array",
"//tensorstore/internal:element_copy_function",
"//tensorstore/internal:intrusive_ptr",
"//tensorstore/internal:thread_pool",
"//tensorstore/internal/thread:thread_pool",
"//tensorstore/kvstore:generation",
"//tensorstore/util:executor",
"//tensorstore/util:future",
Expand Down Expand Up @@ -405,7 +405,7 @@ tensorstore_cc_test(
"//tensorstore/internal:memory",
"//tensorstore/internal:meta",
"//tensorstore/internal:queue_testutil",
"//tensorstore/internal:thread_pool",
"//tensorstore/internal/thread:thread_pool",
"//tensorstore/kvstore:generation",
"//tensorstore/kvstore:mock_kvstore",
"//tensorstore/kvstore:test_util",
Expand Down
2 changes: 1 addition & 1 deletion tensorstore/internal/cache/chunk_cache_benchmark_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "tensorstore/internal/cache/chunk_cache.h"
#include "tensorstore/internal/element_copy_function.h"
#include "tensorstore/internal/intrusive_ptr.h"
#include "tensorstore/internal/thread_pool.h"
#include "tensorstore/internal/thread/thread_pool.h"
#include "tensorstore/kvstore/generation.h"
#include "tensorstore/progress.h"
#include "tensorstore/rank.h"
Expand Down
2 changes: 1 addition & 1 deletion tensorstore/internal/cache/chunk_cache_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#include "tensorstore/internal/memory.h"
#include "tensorstore/internal/meta.h"
#include "tensorstore/internal/queue_testutil.h"
#include "tensorstore/internal/thread_pool.h"
#include "tensorstore/internal/thread/thread_pool.h"
#include "tensorstore/kvstore/generation.h"
#include "tensorstore/kvstore/memory/memory_key_value_store.h"
#include "tensorstore/kvstore/mock_kvstore.h"
Expand Down
2 changes: 1 addition & 1 deletion tensorstore/internal/concurrency_resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "tensorstore/internal/json_binding/bindable.h"
#include "tensorstore/internal/json_binding/json_binding.h"
#include "tensorstore/internal/json_binding/std_optional.h"
#include "tensorstore/internal/thread_pool.h"
#include "tensorstore/internal/thread/thread_pool.h"
#include "tensorstore/internal/type_traits.h"
#include "tensorstore/util/executor.h"
#include "tensorstore/util/result.h"
Expand Down
2 changes: 1 addition & 1 deletion tensorstore/internal/concurrent_testutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <thread> // NOLINT

#include "tensorstore/internal/multi_barrier.h"
#include "tensorstore/internal/thread.h"
#include "tensorstore/internal/thread/thread.h"

namespace tensorstore {
namespace internal {
Expand Down
6 changes: 3 additions & 3 deletions tensorstore/internal/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ tensorstore_cc_library(
"//tensorstore/internal:cord_util",
"//tensorstore/internal:env",
"//tensorstore/internal:no_destructor",
"//tensorstore/internal:thread",
"//tensorstore/internal/log:verbose_flag",
"//tensorstore/internal/metrics",
"//tensorstore/internal/thread",
"//tensorstore/util:future",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/log:absl_log",
Expand Down Expand Up @@ -149,7 +149,7 @@ tensorstore_cc_test(
deps = [
":curl_transport",
":transport_test_utils",
"//tensorstore/internal:thread",
"//tensorstore/internal/thread",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/strings",
Expand All @@ -165,7 +165,7 @@ tensorstore_cc_test(
":curl_transport",
":http",
":transport_test_utils",
"//tensorstore/internal:thread",
"//tensorstore/internal/thread",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",
Expand Down
2 changes: 1 addition & 1 deletion tensorstore/internal/http/curl_transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#include "tensorstore/internal/metrics/gauge.h"
#include "tensorstore/internal/metrics/histogram.h"
#include "tensorstore/internal/no_destructor.h"
#include "tensorstore/internal/thread.h"
#include "tensorstore/internal/thread/thread.h"
#include "tensorstore/util/future.h"

namespace tensorstore {
Expand Down
2 changes: 1 addition & 1 deletion tensorstore/internal/http/curl_transport_http2_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "tensorstore/internal/http/curl_transport.h"
#include "tensorstore/internal/http/http_request.h"
#include "tensorstore/internal/http/transport_test_utils.h"
#include "tensorstore/internal/thread.h"
#include "tensorstore/internal/thread/thread.h"

using ::tensorstore::internal_http::HttpRequestBuilder;
using ::tensorstore::transport_test_utils::AcceptNonBlocking;
Expand Down
2 changes: 1 addition & 1 deletion tensorstore/internal/http/curl_transport_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "absl/log/absl_log.h"
#include "absl/strings/str_cat.h"
#include "tensorstore/internal/http/transport_test_utils.h"
#include "tensorstore/internal/thread.h"
#include "tensorstore/internal/thread/thread.h"

using ::tensorstore::internal_http::HttpRequestBuilder;
using ::tensorstore::transport_test_utils::AcceptNonBlocking;
Expand Down
2 changes: 1 addition & 1 deletion tensorstore/internal/multi_barrier_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <type_traits>

#include <gtest/gtest.h>
#include "tensorstore/internal/thread.h"
#include "tensorstore/internal/thread/thread.h"

namespace internal = tensorstore::internal;

Expand Down
101 changes: 101 additions & 0 deletions tensorstore/internal/thread/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
load("//bazel:tensorstore.bzl", "tensorstore_cc_library", "tensorstore_cc_test")

package(default_visibility = ["//tensorstore:internal_packages"])

licenses(["notice"])

tensorstore_cc_library(
name = "schedule_at",
srcs = ["schedule_at.cc"],
hdrs = ["schedule_at.h"],
deps = [
":thread",
"//tensorstore/internal:attributes",
"//tensorstore/internal:intrusive_red_black_tree",
"//tensorstore/internal:no_destructor",
"//tensorstore/internal:tagged_ptr",
"//tensorstore/internal/metrics",
"//tensorstore/internal/tracing",
"//tensorstore/util:stop_token",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
],
)

tensorstore_cc_test(
name = "schedule_at_test",
size = "small",
srcs = ["schedule_at_test.cc"],
deps = [
":schedule_at",
"//tensorstore/util:stop_token",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest_main",
],
)

tensorstore_cc_library(
name = "thread",
srcs = ["thread.cc"],
hdrs = ["thread.h"],
deps = [
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/log:absl_check",
],
)

tensorstore_cc_test(
name = "thread_test",
srcs = ["thread_test.cc"],
deps = [
":thread",
"@com_google_googletest//:gtest_main",
],
)

tensorstore_cc_library(
name = "thread_pool",
srcs = ["thread_pool.cc"],
hdrs = ["thread_pool.h"],
deps = [
":thread",
"//tensorstore/internal:attributes",
"//tensorstore/internal:intrusive_ptr",
"//tensorstore/internal:mutex",
"//tensorstore/internal:no_destructor",
"//tensorstore/internal/metrics",
"//tensorstore/util:executor",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
],
)

tensorstore_cc_library(
name = "thread_pool_test_cc",
testonly = 1,
textual_hdrs = ["thread_pool_test.inc"],
deps = [
"//tensorstore/util:executor",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest",
],
)

tensorstore_cc_test(
name = "thread_pool_test",
size = "small",
srcs = ["thread_pool_test.cc"],
deps = [
":thread_pool",
":thread_pool_test_cc",
"@com_google_googletest//:gtest_main",
],
)
Loading

0 comments on commit ed1e9f4

Please sign in to comment.