diff --git a/gloop/thread/BUILD b/gloop/thread/BUILD index faaae547c..52c9bf00f 100644 --- a/gloop/thread/BUILD +++ b/gloop/thread/BUILD @@ -46,15 +46,12 @@ POSIX_PORT_DEPS = [ POSIX_PORT_SOURCES = [ "add_after_helper.cc", - "cpu_subcontainer.h", # Stubbed out, private. "executor.cc", "logger.h", "pcqueue.h", # private. - "port/cpu_subcontainer.cc", "python_stack_size.h", "timedcall.cc", "thread.cc", - "thread_options.cc", "threadpool.cc", "watchdog.h", # private. "watchdog.cc", @@ -67,7 +64,6 @@ POSIX_PORT_HEADERS = [ "ordered-producer-consumer-queue.h", "thread.h", "threadpool.h", - "thread_options.h", "timedcall.h", "wait_queue_thread.h", ] @@ -239,6 +235,33 @@ cc_library( ], ) +cc_library( + name = "thread_options", + srcs = ["thread_options.cc"], + hdrs = ["thread_options.h"], + deps = [ + "//gloop:enforce_gloop_support", + "@abseil-cpp//absl/flags:flag", + ], +) + +cc_library( + name = "cpu_subcontainer_stub", + srcs = ["cpu_subcontainer_stub.cc"], + hdrs = ["cpu_subcontainer.h"], + visibility = ["//visibility:private"], + deps = ["//gloop:enforce_gloop_support"], +) + +cc_library( + name = "cpu_subcontainer", + hdrs = ["cpu_subcontainer.h"], + deps = [ + ":cpu_subcontainer_stub", + "//gloop:enforce_gloop_support", + ], +) + cc_library( name = "thread", srcs = select({ @@ -246,19 +269,20 @@ cc_library( "add_after_helper.cc", "executor.cc", "logger.cc", - "port/cpu_subcontainer.cc", "stack_reclaimer.cc", "stack_reclaimer.h", "thread.cc", - "thread_options.cc", "threadpool.cc", "timedcall.cc", "watchdog.cc", ], }), - hdrs = ["threadlocal.h"] + select({ + hdrs = [ + "cpu_subcontainer.h", + "thread_options.h", + "threadlocal.h", + ] + select({ "//conditions:default": POSIX_PORT_HEADERS + [ - "cpu_subcontainer.h", "logger.h", "pcqueue.h", "watchdog.h", @@ -269,12 +293,14 @@ cc_library( }), deps = [ ":config", + ":cpu_subcontainer", ":exit_timeout_seconds", ":os_semaphore", ":prioritized_wait_queue", ":python_stack_size", ":sync_queue", ":thread-internal", + ":thread_options", ":threadlocal", ":wait_queue", ":wait_state", diff --git a/gloop/thread/config.h b/gloop/thread/config.h index c2575ecbe..52fb64de4 100644 --- a/gloop/thread/config.h +++ b/gloop/thread/config.h @@ -38,7 +38,6 @@ #include #endif -#define THREAD_HAVE_CPU_SUBCONTAINERS 0 #define THREAD_HAVE_THREAD_CONTROL 1 // THREAD_HAVE_THREAD_CLASS: diff --git a/gloop/thread/port/cpu_subcontainer.cc b/gloop/thread/cpu_subcontainer_stub.cc similarity index 90% rename from gloop/thread/port/cpu_subcontainer.cc rename to gloop/thread/cpu_subcontainer_stub.cc index b14a79f52..6e6e25ec7 100644 --- a/gloop/thread/port/cpu_subcontainer.cc +++ b/gloop/thread/cpu_subcontainer_stub.cc @@ -20,13 +20,9 @@ // Stub implementation for unsupported platforms. -#include "gloop/thread/cpu_subcontainer.h" - -#include "gloop/thread/config.h" +#include -#if THREAD_HAVE_CPU_SUBCONTAINERS -#error Feature macros and BUILD file are out of sync. -#endif +#include "gloop/thread/cpu_subcontainer.h" thread::CpuSubContainer::CpuSubContainer(const std::string& path) : path_(path) {} diff --git a/gloop/thread/thread.cc b/gloop/thread/thread.cc index 717573000..07bfc7609 100644 --- a/gloop/thread/thread.cc +++ b/gloop/thread/thread.cc @@ -656,7 +656,7 @@ void Thread::Start(absl::SourceLocation loc) { #if !defined(__Fuchsia__) pthread_attr_setschedpolicy(&attr, SCHED_FIFO); #endif - if (options_.sched_priority() < 0) { + if (options_.get_sched_priority() < 0) { sched_param.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1; } else { #if !defined(__Fuchsia__) && !defined(__ANDROID__) @@ -674,7 +674,7 @@ void Thread::Start(absl::SourceLocation loc) { // is set. pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); #endif - sched_param.sched_priority = options_.sched_priority(); + sched_param.sched_priority = options_.get_sched_priority(); } pthread_attr_setschedparam(&attr, &sched_param); break; diff --git a/gloop/thread/thread_manager.cc b/gloop/thread/thread_manager.cc index 9f7d75cc7..e0cf995e1 100644 --- a/gloop/thread/thread_manager.cc +++ b/gloop/thread/thread_manager.cc @@ -1277,7 +1277,7 @@ static bool TMCanUseDefaultExecutor(const Options& options) { if (options.stack_size() > base.stack_size()) return false; if (options.guard_size() > base.guard_size()) return false; if (options.scheduling_policy() != base.scheduling_policy()) return false; - if (options.sched_priority() != base.sched_priority()) return false; + if (options.get_sched_priority() != base.get_sched_priority()) return false; if (options.nice_priority_level() != base.nice_priority_level()) return false; if (options.io_class() != base.io_class()) return false; if (options.io_priority_level() != base.io_priority_level()) return false; diff --git a/gloop/thread/thread_options.h b/gloop/thread/thread_options.h index 1a5baba33..bcf017f16 100644 --- a/gloop/thread/thread_options.h +++ b/gloop/thread/thread_options.h @@ -148,7 +148,10 @@ class Options { return *this; } - int sched_priority() const { return sched_priority_; } + /** Return the scheduling priority. This is named differently because some + * targets define a macro named `sched_priority` in global scope. + */ + int get_sched_priority() const { return sched_priority_; } // // CAUTION: The following methods are not for general use