diff --git a/pw_thread/BUILD.bazel b/pw_thread/BUILD.bazel index 5ec3252f49..25dcde09b7 100644 --- a/pw_thread/BUILD.bazel +++ b/pw_thread/BUILD.bazel @@ -94,7 +94,7 @@ pw_facade( ], backend = ":sleep_backend", implementation_deps = [ - ":id", + ":thread", ], includes = ["public"], deps = [ @@ -214,7 +214,7 @@ pw_facade( ], backend = ":yield_backend", implementation_deps = [ - ":id", + ":thread", ], includes = ["public"], deps = [ @@ -271,7 +271,6 @@ cc_library( "thread_facade_test.cc", ], deps = [ - ":id", ":non_portable_test_thread_options", ":thread", "//pw_chrono:system_clock", @@ -310,7 +309,7 @@ pw_cc_test( "id_facade_test.cc", ], deps = [ - ":id", + ":thread", "//pw_unit_test", ], ) @@ -331,8 +330,8 @@ pw_cc_test( "sleep_facade_test_c.c", ], deps = [ - ":id", ":sleep", + ":thread", "//pw_chrono:system_clock", "//pw_preprocessor", "//pw_unit_test", @@ -377,7 +376,7 @@ pw_cc_test( "yield_facade_test_c.c", ], deps = [ - ":id", + ":thread", ":yield", "//pw_preprocessor", "//pw_unit_test", diff --git a/pw_thread/BUILD.gn b/pw_thread/BUILD.gn index d495b8cfec..ad951a1de3 100644 --- a/pw_thread/BUILD.gn +++ b/pw_thread/BUILD.gn @@ -186,7 +186,7 @@ pw_test("test_thread_context_facade_test") { pw_test("id_facade_test") { enable_if = pw_thread_ID_BACKEND != "" sources = [ "id_facade_test.cc" ] - deps = [ ":id" ] + deps = [ ":thread" ] } pw_test("thread_snapshot_service_test") { @@ -213,8 +213,8 @@ pw_test("sleep_facade_test") { "sleep_facade_test_c.c", ] deps = [ - ":id", ":sleep", + ":thread", "$dir_pw_chrono:system_clock", ] } @@ -233,7 +233,6 @@ pw_source_set("thread_facade_test") { testonly = pw_unit_test_TESTONLY sources = [ "thread_facade_test.cc" ] deps = [ - ":id", ":non_portable_test_thread_options", ":sleep", ":thread", @@ -263,7 +262,7 @@ pw_test("yield_facade_test") { "yield_facade_test_c.c", ] deps = [ - ":id", + ":thread", ":yield", ] } diff --git a/pw_thread/CMakeLists.txt b/pw_thread/CMakeLists.txt index 1693edee4a..dc789cd82f 100644 --- a/pw_thread/CMakeLists.txt +++ b/pw_thread/CMakeLists.txt @@ -26,6 +26,7 @@ pw_add_library(pw_thread.config INTERFACE ${pw_thread_CONFIG} ) +# pw_thread.id is deprecated; depend on pw_thread.thread instead. pw_add_facade(pw_thread.id INTERFACE BACKEND pw_thread.id_BACKEND @@ -183,7 +184,7 @@ if(NOT "${pw_thread.id_BACKEND}" STREQUAL "") SOURCES id_facade_test.cc PRIVATE_DEPS - pw_thread.id + pw_thread.thread GROUPS modules pw_thread @@ -198,8 +199,8 @@ if((NOT "${pw_thread.id_BACKEND}" STREQUAL "") AND sleep_facade_test_c.c PRIVATE_DEPS pw_chrono.system_clock - pw_thread.id pw_thread.sleep + pw_thread.thread GROUPS modules pw_thread @@ -223,7 +224,6 @@ pw_add_library(pw_thread.thread_facade_test STATIC SOURCES thread_facade_test.cc PRIVATE_DEPS - pw_thread.id pw_thread.sleep pw_thread.non_portable_test_thread_options pw_thread.thread @@ -238,7 +238,7 @@ if((NOT "${pw_thread.id_BACKEND}" STREQUAL "") AND yield_facade_test.cc yield_facade_test_c.c PRIVATE_DEPS - pw_thread.id + pw_thread.thread pw_thread.yield GROUPS modules diff --git a/pw_thread/backend.cmake b/pw_thread/backend.cmake index fa894e9fb5..86f8a89c3d 100644 --- a/pw_thread/backend.cmake +++ b/pw_thread/backend.cmake @@ -15,7 +15,7 @@ include_guard(GLOBAL) include($ENV{PW_ROOT}/pw_build/pigweed.cmake) -# Backend for the pw_thread module's pw::thread::Id. +# Backend for the pw_thread module's pw::Thread::id. pw_add_backend_variable(pw_thread.id_BACKEND) # Backend for the pw_thread module's pw::thread::sleep_{for,until}. diff --git a/pw_thread/backend.gni b/pw_thread/backend.gni index 38f795ac55..3986e28107 100644 --- a/pw_thread/backend.gni +++ b/pw_thread/backend.gni @@ -13,7 +13,7 @@ # the License. declare_args() { - # Backend for the pw_thread module's pw::thread::Id. + # Backend for the pw_thread module's pw::Thread::id. pw_thread_ID_BACKEND = "" # Backend for the pw_thread module's pw::thread::sleep_{for,until}. diff --git a/pw_thread/docs.rst b/pw_thread/docs.rst index 616d1624d4..0069a39439 100644 --- a/pw_thread/docs.rst +++ b/pw_thread/docs.rst @@ -103,8 +103,8 @@ C --------------------- Thread Identification --------------------- -The class ``pw::thread::Id`` is a lightweight, trivially copyable class that -serves as a unique identifier of Thread objects. +The class :cpp:type:`pw::Thread::id` is a lightweight, trivially copyable class +that serves as a unique identifier of Thread objects. Instances of this class may also hold the special distinct value that does not represent any thread. Once a thread has finished, the value of its @@ -113,20 +113,19 @@ Thread::id may be reused by another thread. This class is designed for use as key in associative containers, both ordered and unordered. -Although the current API is similar to C++11 STL -`std::thread::id `_, it is -missing the required hashing and streaming operators and may diverge further in -the future. +Although the current API is similar to C++11 STL `std::thread::id +`_, it is missing the +required hashing and streaming operators and may diverge further in the future. -A thread's identification (``pw::thread::Id``) can be acquired only in C++ in -one of two ways: +A thread's identification (:cpp:type:`pw::Thread::id`) can be acquired only in +C++ in one of two ways: -1) Using the ``pw::thread::Thread`` handle's ``pw::thread::Id get_id() const`` +1) Using the :cpp:type:`pw::Thread` handle's ``pw::Thread::id get_id() const`` method. 2) While executing the thread using - ``pw::thread::Id pw::this_thread::get_id() noexcept``. + ``pw::Thread::id pw::this_thread::get_id() noexcept``. -.. cpp:function:: pw::thread::Id pw::this_thread::get_id() noexcept +.. cpp:function:: pw::Thread::id pw::this_thread::get_id() noexcept This is thread safe, not IRQ safe. It is implementation defined whether this is safe before the scheduler has started. @@ -136,13 +135,12 @@ Example ======= .. code-block:: cpp - #include "pw_thread/id.h" + #include "pw_thread/thread.h" void FunctionInvokedByThread() { - const pw::thread::Id my_id = pw::this_thread::get_id(); + const pw::Thread::id my_id = pw::this_thread::get_id(); } - .. _module-pw_thread-thread-creation: --------------- diff --git a/pw_thread/id_facade_test.cc b/pw_thread/id_facade_test.cc index ccf8509f86..4618d733f7 100644 --- a/pw_thread/id_facade_test.cc +++ b/pw_thread/id_facade_test.cc @@ -12,7 +12,7 @@ // License for the specific language governing permissions and limitations under // the License. -#include "pw_thread/id.h" +#include "pw_thread/thread.h" #include "pw_unit_test/framework.h" namespace pw::this_thread { @@ -22,7 +22,7 @@ TEST(Id, GetId) { // We expect unit tests to run in a thread context. // Unfortunately beyond this we need the ability to create and destroy threads // to test more Id functionality. - EXPECT_NE(get_id(), thread::Id()); + EXPECT_NE(get_id(), Thread::id()); } } // namespace diff --git a/pw_thread/public/pw_thread/id.h b/pw_thread/public/pw_thread/id.h index 6204af08fe..799836ff58 100644 --- a/pw_thread/public/pw_thread/id.h +++ b/pw_thread/public/pw_thread/id.h @@ -15,9 +15,11 @@ #include "pw_thread_backend/id_native.h" +// This header is deprecated. Include pw_thread/thread.h instead. + namespace pw::thread { -// Legacy alias. Use pw::Thread::id instead. +// Legacy alias. Use pw::Thread::id in pw_thread/thread.h instead. using Id = backend::NativeId; } // namespace pw::thread @@ -26,7 +28,7 @@ namespace pw::this_thread { // This is thread safe, not IRQ safe. It is implementation defined whether this // is safe before the scheduler has started. -thread::Id get_id() noexcept; +thread::backend::NativeId get_id() noexcept; } // namespace pw::this_thread diff --git a/pw_thread/public/pw_thread/thread.h b/pw_thread/public/pw_thread/thread.h index b46dfab3b9..231ae40507 100644 --- a/pw_thread/public/pw_thread/thread.h +++ b/pw_thread/public/pw_thread/thread.h @@ -13,7 +13,7 @@ // the License. #pragma once -#include +#include #include "pw_function/function.h" #include "pw_thread/id.h" diff --git a/pw_thread/sleep_facade_test.cc b/pw_thread/sleep_facade_test.cc index 23063ad2e8..232595de2f 100644 --- a/pw_thread/sleep_facade_test.cc +++ b/pw_thread/sleep_facade_test.cc @@ -15,8 +15,8 @@ #include #include "pw_chrono/system_clock.h" -#include "pw_thread/id.h" #include "pw_thread/sleep.h" +#include "pw_thread/thread.h" #include "pw_unit_test/framework.h" using pw::chrono::SystemClock; @@ -47,7 +47,7 @@ constexpr pw_chrono_SystemClock_Duration kRoundedArbitraryLongDurationInC = TEST(Sleep, SleepForPositiveDuration) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); SystemClock::time_point before = SystemClock::now(); sleep_for(kRoundedArbitraryShortDuration); @@ -57,7 +57,7 @@ TEST(Sleep, SleepForPositiveDuration) { TEST(Sleep, SleepForZeroLengthDuration) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); // Ensure it doesn't sleep when a zero length duration is used. SystemClock::time_point before = SystemClock::now(); @@ -68,7 +68,7 @@ TEST(Sleep, SleepForZeroLengthDuration) { TEST(Sleep, SleepForNegativeDuration) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); // Ensure it doesn't sleep when a negative duration is used. SystemClock::time_point before = SystemClock::now(); @@ -79,7 +79,7 @@ TEST(Sleep, SleepForNegativeDuration) { TEST(Sleep, SleepUntilFutureWakeupTime) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); SystemClock::time_point deadline = SystemClock::now() + kRoundedArbitraryShortDuration; @@ -89,7 +89,7 @@ TEST(Sleep, SleepUntilFutureWakeupTime) { TEST(Sleep, SleepUntilCurrentWakeupTime) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); // Ensure it doesn't sleep when now is used. SystemClock::time_point deadline = @@ -100,7 +100,7 @@ TEST(Sleep, SleepUntilCurrentWakeupTime) { TEST(Sleep, SleepUntilPastWakeupTime) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); // Ensure it doesn't sleep when a timestamp in the past is used. SystemClock::time_point deadline = @@ -111,7 +111,7 @@ TEST(Sleep, SleepUntilPastWakeupTime) { TEST(Sleep, SleepForPositiveDurationInC) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); pw_chrono_SystemClock_TimePoint before = pw_chrono_SystemClock_Now(); pw_this_thread_SleepFor(kRoundedArbitraryShortDurationInC); @@ -122,7 +122,7 @@ TEST(Sleep, SleepForPositiveDurationInC) { TEST(Sleep, SleepForZeroLengthDurationInC) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); // Ensure it doesn't sleep when a zero length duration is used. pw_chrono_SystemClock_TimePoint before = pw_chrono_SystemClock_Now(); @@ -134,7 +134,7 @@ TEST(Sleep, SleepForZeroLengthDurationInC) { TEST(Sleep, SleepForNegativeDurationInC) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); // Ensure it doesn't sleep when a negative duration is used. pw_chrono_SystemClock_TimePoint before = pw_chrono_SystemClock_Now(); @@ -147,7 +147,7 @@ TEST(Sleep, SleepForNegativeDurationInC) { TEST(Sleep, SleepUntilFutureWakeupTimeInC) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); pw_chrono_SystemClock_TimePoint deadline; deadline.duration_since_epoch.ticks = @@ -160,7 +160,7 @@ TEST(Sleep, SleepUntilFutureWakeupTimeInC) { TEST(Sleep, SleepUntilCurrentWakeupTimeInC) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); // Ensure it doesn't sleep when now is used. pw_chrono_SystemClock_TimePoint deadline; @@ -174,7 +174,7 @@ TEST(Sleep, SleepUntilCurrentWakeupTimeInC) { TEST(Sleep, SleepUntilPastWakeupTimeInC) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); // Ensure it doesn't sleep when a timestamp in the past is used. pw_chrono_SystemClock_TimePoint deadline; diff --git a/pw_thread/test_thread_context_facade_test.cc b/pw_thread/test_thread_context_facade_test.cc index 2632a4212d..47e7d9c133 100644 --- a/pw_thread/test_thread_context_facade_test.cc +++ b/pw_thread/test_thread_context_facade_test.cc @@ -35,19 +35,19 @@ TEST(Thread, TestThreadContext) { thread_1 = Thread(context_1.options(), [&thread_ran_sem_1] { thread_ran_sem_1.release(); }); - EXPECT_NE(thread_0.get_id(), Id()); + EXPECT_NE(thread_0.get_id(), Thread::id()); EXPECT_TRUE(thread_0.joinable()); - EXPECT_NE(thread_1.get_id(), Id()); + EXPECT_NE(thread_1.get_id(), Thread::id()); EXPECT_TRUE(thread_1.joinable()); thread_0.detach(); thread_1.detach(); - EXPECT_EQ(thread_0.get_id(), Id()); + EXPECT_EQ(thread_0.get_id(), Thread::id()); EXPECT_FALSE(thread_0.joinable()); - EXPECT_EQ(thread_1.get_id(), Id()); + EXPECT_EQ(thread_1.get_id(), Thread::id()); EXPECT_FALSE(thread_1.joinable()); thread_ran_sem_0.acquire(); diff --git a/pw_thread/thread_facade_test.cc b/pw_thread/thread_facade_test.cc index 54f32d2369..1d0ad26b56 100644 --- a/pw_thread/thread_facade_test.cc +++ b/pw_thread/thread_facade_test.cc @@ -13,7 +13,6 @@ // the License. #include "pw_sync/binary_semaphore.h" -#include "pw_thread/id.h" #include "pw_thread/non_portable_test_thread_options.h" #include "pw_thread/thread.h" #include "pw_unit_test/framework.h" @@ -21,30 +20,29 @@ namespace { using ::pw::sync::BinarySemaphore; -using ::pw::thread::Id; -using ::pw::thread::Thread; using ::pw::thread::ThreadCore; using ::pw::thread::test::TestOptionsThread0; using ::pw::thread::test::TestOptionsThread1; using ::pw::thread::test::WaitUntilDetachedThreadsCleanedUp; TEST(Thread, DefaultIds) { - Thread not_executing_thread; - EXPECT_EQ(not_executing_thread.get_id(), Id()); + pw::Thread not_executing_thread; + EXPECT_EQ(not_executing_thread.get_id(), pw::Thread::id()); } #if PW_THREAD_JOINING_ENABLED TEST(Thread, DefaultConstructedThreadIsNotJoinable) { - Thread thread; + pw::Thread thread; EXPECT_FALSE(thread.joinable()); } TEST(Thread, JoinWaitsForLambdaCompletion) { BinarySemaphore thread_ran; - Thread thread(TestOptionsThread0(), [&thread_ran] { thread_ran.release(); }); + pw::Thread thread(TestOptionsThread0(), + [&thread_ran] { thread_ran.release(); }); EXPECT_TRUE(thread.joinable()); thread.join(); - EXPECT_EQ(thread.get_id(), Id()); + EXPECT_EQ(thread.get_id(), pw::Thread::id()); EXPECT_TRUE(thread_ran.try_acquire()); } @@ -56,14 +54,14 @@ TEST(Thread, DetachAllowsThreadToRunAfterExitingScope) { BinarySemaphore thread_finished; } semaphores; { - Thread thread(TestOptionsThread0(), [&semaphores] { + pw::Thread thread(TestOptionsThread0(), [&semaphores] { semaphores.thread_blocker.acquire(); semaphores.thread_finished.release(); }); - EXPECT_NE(thread.get_id(), Id()); + EXPECT_NE(thread.get_id(), pw::Thread::id()); EXPECT_TRUE(thread.joinable()); thread.detach(); - EXPECT_EQ(thread.get_id(), Id()); + EXPECT_EQ(thread.get_id(), pw::Thread::id()); EXPECT_FALSE(thread.joinable()); } EXPECT_FALSE(semaphores.thread_finished.try_acquire()); @@ -74,29 +72,29 @@ TEST(Thread, DetachAllowsThreadToRunAfterExitingScope) { } TEST(Thread, SwapWithoutExecution) { - Thread thread_0; - Thread thread_1; + pw::Thread thread_0; + pw::Thread thread_1; // Make sure we can swap threads which are not associated with any execution. thread_0.swap(thread_1); } TEST(Thread, SwapWithOneExecuting) { - Thread thread_0; - EXPECT_EQ(thread_0.get_id(), Id()); + pw::Thread thread_0; + EXPECT_EQ(thread_0.get_id(), pw::Thread::id()); BinarySemaphore thread_ran_sem; - Thread thread_1(TestOptionsThread1(), - [&thread_ran_sem] { thread_ran_sem.release(); }); + pw::Thread thread_1(TestOptionsThread1(), + [&thread_ran_sem] { thread_ran_sem.release(); }); - EXPECT_NE(thread_1.get_id(), Id()); + EXPECT_NE(thread_1.get_id(), pw::Thread::id()); thread_0.swap(thread_1); - EXPECT_NE(thread_0.get_id(), Id()); - EXPECT_EQ(thread_1.get_id(), Id()); + EXPECT_NE(thread_0.get_id(), pw::Thread::id()); + EXPECT_EQ(thread_1.get_id(), pw::Thread::id()); thread_0.detach(); - EXPECT_EQ(thread_0.get_id(), Id()); + EXPECT_EQ(thread_0.get_id(), pw::Thread::id()); thread_ran_sem.acquire(); WaitUntilDetachedThreadsCleanedUp(); @@ -104,15 +102,15 @@ TEST(Thread, SwapWithOneExecuting) { TEST(Thread, SwapWithTwoExecuting) { BinarySemaphore thread_a_ran_sem; - Thread thread_0(TestOptionsThread0(), - [&thread_a_ran_sem] { thread_a_ran_sem.release(); }); + pw::Thread thread_0(TestOptionsThread0(), + [&thread_a_ran_sem] { thread_a_ran_sem.release(); }); BinarySemaphore thread_b_ran_sem; - Thread thread_1(TestOptionsThread1(), - [&thread_b_ran_sem] { thread_b_ran_sem.release(); }); - const Id thread_a_id = thread_0.get_id(); - EXPECT_NE(thread_a_id, Id()); - const Id thread_b_id = thread_1.get_id(); - EXPECT_NE(thread_b_id, Id()); + pw::Thread thread_1(TestOptionsThread1(), + [&thread_b_ran_sem] { thread_b_ran_sem.release(); }); + const pw::Thread::id thread_a_id = thread_0.get_id(); + EXPECT_NE(thread_a_id, pw::Thread::id()); + const pw::Thread::id thread_b_id = thread_1.get_id(); + EXPECT_NE(thread_b_id, pw::Thread::id()); EXPECT_NE(thread_a_id, thread_b_id); thread_0.swap(thread_1); @@ -120,9 +118,9 @@ TEST(Thread, SwapWithTwoExecuting) { EXPECT_EQ(thread_0.get_id(), thread_b_id); thread_0.detach(); - EXPECT_EQ(thread_0.get_id(), Id()); + EXPECT_EQ(thread_0.get_id(), pw::Thread::id()); thread_1.detach(); - EXPECT_EQ(thread_1.get_id(), Id()); + EXPECT_EQ(thread_1.get_id(), pw::Thread::id()); thread_a_ran_sem.acquire(); thread_b_ran_sem.acquire(); @@ -130,22 +128,22 @@ TEST(Thread, SwapWithTwoExecuting) { } TEST(Thread, MoveOperator) { - Thread thread_0; - EXPECT_EQ(thread_0.get_id(), Id()); + pw::Thread thread_0; + EXPECT_EQ(thread_0.get_id(), pw::Thread::id()); BinarySemaphore thread_ran_sem; - Thread thread_1(TestOptionsThread1(), - [&thread_ran_sem] { thread_ran_sem.release(); }); - EXPECT_NE(thread_1.get_id(), Id()); + pw::Thread thread_1(TestOptionsThread1(), + [&thread_ran_sem] { thread_ran_sem.release(); }); + EXPECT_NE(thread_1.get_id(), pw::Thread::id()); thread_0 = std::move(thread_1); - EXPECT_NE(thread_0.get_id(), Id()); + EXPECT_NE(thread_0.get_id(), pw::Thread::id()); #ifndef __clang_analyzer__ - EXPECT_EQ(thread_1.get_id(), Id()); + EXPECT_EQ(thread_1.get_id(), pw::Thread::id()); #endif // ignore use-after-move thread_0.detach(); - EXPECT_EQ(thread_0.get_id(), Id()); + EXPECT_EQ(thread_0.get_id(), pw::Thread::id()); thread_ran_sem.acquire(); WaitUntilDetachedThreadsCleanedUp(); @@ -163,11 +161,11 @@ class SemaphoreReleaser : public ThreadCore { TEST(Thread, ThreadCore) { SemaphoreReleaser semaphore_releaser; - Thread thread(TestOptionsThread0(), semaphore_releaser); - EXPECT_NE(thread.get_id(), Id()); + pw::Thread thread(TestOptionsThread0(), semaphore_releaser); + EXPECT_NE(thread.get_id(), pw::Thread::id()); EXPECT_TRUE(thread.joinable()); thread.detach(); - EXPECT_EQ(thread.get_id(), Id()); + EXPECT_EQ(thread.get_id(), pw::Thread::id()); EXPECT_FALSE(thread.joinable()); semaphore_releaser.semaphore().acquire(); diff --git a/pw_thread/yield_facade_test.cc b/pw_thread/yield_facade_test.cc index 5506cb1868..09d0abf7e4 100644 --- a/pw_thread/yield_facade_test.cc +++ b/pw_thread/yield_facade_test.cc @@ -12,7 +12,7 @@ // License for the specific language governing permissions and limitations under // the License. -#include "pw_thread/id.h" +#include "pw_thread/thread.h" #include "pw_thread/yield.h" #include "pw_unit_test/framework.h" @@ -28,7 +28,7 @@ void pw_this_thread_CallYield(); TEST(Yield, CompilesAndRuns) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); // Unfortunately we have not thought of a useful way to test yield without // knowing the backend implementation as things like round robin scheduling @@ -39,7 +39,7 @@ TEST(Yield, CompilesAndRuns) { TEST(Yield, CompilesAndRunsInC) { // Ensure we are in a thread context, meaning we are permitted to sleep. - ASSERT_NE(get_id(), thread::Id()); + ASSERT_NE(get_id(), Thread::id()); // Unfortunately we have not thought of a useful way to test yield without // knowing the backend implementation as things like round robin scheduling diff --git a/pw_thread_embos/BUILD.gn b/pw_thread_embos/BUILD.gn index b41d3a1cf1..98377b2316 100644 --- a/pw_thread_embos/BUILD.gn +++ b/pw_thread_embos/BUILD.gn @@ -48,7 +48,7 @@ pw_source_set("config") { ] } -# This target provides the backend for pw::thread::Id. +# This target provides the backend for pw::Thread::id. pw_source_set("id") { public_configs = [ ":public_include_path", @@ -100,8 +100,8 @@ if (pw_chrono_SYSTEM_CLOCK_BACKEND != "" && pw_thread_SLEEP_BACKEND != "") { "$dir_pw_assert", "$dir_pw_chrono_embos:system_clock", "$dir_pw_third_party/embos", - "$dir_pw_thread:id", "$dir_pw_thread:sleep.facade", + "$dir_pw_thread:thread", ] } } @@ -158,7 +158,7 @@ pw_source_set("yield") { public_deps = [ "$dir_pw_assert", "$dir_pw_third_party/embos", - "$dir_pw_thread:id", + "$dir_pw_thread:thread", ] deps = [ "$dir_pw_thread:yield.facade" ] } diff --git a/pw_thread_embos/public/pw_thread_embos/thread_inline.h b/pw_thread_embos/public/pw_thread_embos/thread_inline.h index ed8cc4f8f1..4575654c1d 100644 --- a/pw_thread_embos/public/pw_thread_embos/thread_inline.h +++ b/pw_thread_embos/public/pw_thread_embos/thread_inline.h @@ -16,7 +16,7 @@ #include #include "pw_assert/assert.h" -#include "pw_thread/id.h" +#include "pw_thread/thread.h" #include "pw_thread_embos/context.h" namespace pw::thread { @@ -31,11 +31,11 @@ inline Thread& Thread::operator=(Thread&& other) { inline Thread::~Thread() { PW_DASSERT(native_type_ == nullptr); } -inline Id Thread::get_id() const { +inline Thread::id Thread::get_id() const { if (native_type_ == nullptr) { - return Id(nullptr); + return Thread::id(nullptr); } - return Id(&native_type_->tcb()); + return Thread::id(&native_type_->tcb()); } inline void Thread::swap(Thread& other) { diff --git a/pw_thread_embos/public/pw_thread_embos/yield_inline.h b/pw_thread_embos/public/pw_thread_embos/yield_inline.h index 8acf5e043e..7c5cd542cd 100644 --- a/pw_thread_embos/public/pw_thread_embos/yield_inline.h +++ b/pw_thread_embos/public/pw_thread_embos/yield_inline.h @@ -15,13 +15,13 @@ #include "RTOS.h" #include "pw_assert/assert.h" -#include "pw_thread/id.h" +#include "pw_thread/thread.h" namespace pw::this_thread { inline void yield() noexcept { // Ensure this is being called by a thread. - PW_DASSERT(get_id() != thread::Id()); + PW_DASSERT(get_id() != Thread::id()); OS_Yield(); } diff --git a/pw_thread_embos/sleep.cc b/pw_thread_embos/sleep.cc index 5ba9894e44..cccded8694 100644 --- a/pw_thread_embos/sleep.cc +++ b/pw_thread_embos/sleep.cc @@ -20,7 +20,7 @@ #include "pw_assert/check.h" #include "pw_chrono/system_clock.h" #include "pw_chrono_embos/system_clock_constants.h" -#include "pw_thread/id.h" +#include "pw_thread/thread.h" using pw::chrono::SystemClock; @@ -28,7 +28,7 @@ namespace pw::this_thread { void sleep_for(chrono::SystemClock::duration sleep_duration) { // Ensure we are invoking this from a thread. - PW_DCHECK(get_id() != thread::Id()); + PW_DCHECK(get_id() != Thread::id()); // Yield for negative and zero length durations. if (sleep_duration <= SystemClock::duration::zero()) { diff --git a/pw_thread_embos/thread.cc b/pw_thread_embos/thread.cc index 9d80091c3d..dfb5334085 100644 --- a/pw_thread_embos/thread.cc +++ b/pw_thread_embos/thread.cc @@ -14,7 +14,6 @@ #include "pw_thread/thread.h" #include "pw_assert/check.h" -#include "pw_thread/id.h" #include "pw_thread_embos/config.h" #include "pw_thread_embos/context.h" #include "pw_thread_embos/options.h" diff --git a/pw_thread_freertos/BUILD.bazel b/pw_thread_freertos/BUILD.bazel index 77fe050f7e..783e8c3096 100644 --- a/pw_thread_freertos/BUILD.bazel +++ b/pw_thread_freertos/BUILD.bazel @@ -60,8 +60,8 @@ cc_library( deps = [ "//pw_assert", "//pw_chrono:system_clock", - "//pw_thread:id", "//pw_thread:sleep.facade", + "//pw_thread:thread", "@freertos", ], ) @@ -166,7 +166,7 @@ cc_library( "yield_public_overrides", ], deps = [ - "//pw_thread:id", + "//pw_thread:thread", "//pw_thread:yield.facade", "@freertos", ], diff --git a/pw_thread_freertos/BUILD.gn b/pw_thread_freertos/BUILD.gn index 682486c695..3458872e5f 100644 --- a/pw_thread_freertos/BUILD.gn +++ b/pw_thread_freertos/BUILD.gn @@ -51,7 +51,7 @@ config("id_public_overrides") { visibility = [ ":*" ] } -# This target provides the backend for pw::thread::Id & pw::this_thread::get_id. +# This target provides the backend for pw::Thread::id & pw::this_thread::get_id. pw_source_set("id") { public_configs = [ ":public_include_path", @@ -104,8 +104,8 @@ pw_source_set("sleep") { "$dir_pw_assert", "$dir_pw_chrono_freertos:system_clock", "$dir_pw_third_party/freertos", - "$dir_pw_thread:id", "$dir_pw_thread:sleep.facade", + "$dir_pw_thread:thread", ] } @@ -123,10 +123,10 @@ pw_source_set("thread") { ] public_deps = [ ":config", + ":id", "$dir_pw_assert", "$dir_pw_string", "$dir_pw_third_party/freertos", - "$dir_pw_thread:id", "$dir_pw_thread:thread.facade", dir_pw_function, dir_pw_span, @@ -182,7 +182,7 @@ pw_source_set("yield") { public_deps = [ "$dir_pw_assert", "$dir_pw_third_party/freertos", - "$dir_pw_thread:id", + "$dir_pw_thread:thread", ] deps = [ "$dir_pw_thread:yield.facade" ] } diff --git a/pw_thread_freertos/CMakeLists.txt b/pw_thread_freertos/CMakeLists.txt index 3552094a9b..865f61aab7 100644 --- a/pw_thread_freertos/CMakeLists.txt +++ b/pw_thread_freertos/CMakeLists.txt @@ -27,7 +27,7 @@ pw_add_library(pw_thread_freertos.config INTERFACE ${pw_thread_freertos_CONFIG} ) -# This target provides the backend for pw::thread::Id & pw::this_thread::get_id. +# This target provides the backend for pw::Thread::id & pw::this_thread::get_id. pw_add_library(pw_thread_freertos.id INTERFACE HEADERS public/pw_thread_freertos/id_inline.h @@ -41,7 +41,7 @@ pw_add_library(pw_thread_freertos.id INTERFACE pw_assert pw_interrupt.context pw_third_party.freertos - pw_thread.id.facade + pw_thread.thread.facade ) # This target provides the backend for pw::this_thread::sleep_{for,until}. @@ -61,7 +61,7 @@ pw_add_library(pw_thread_freertos.sleep STATIC pw_assert pw_chrono_freertos.system_clock pw_third_party.freertos - pw_thread.id + pw_thread.thread ) # This target provides the backend for pw::Thread and the headers needed for @@ -83,7 +83,6 @@ pw_add_library(pw_thread_freertos.thread STATIC pw_span pw_string pw_third_party.freertos - pw_thread.id pw_thread.thread.facade pw_thread_freertos.config SOURCES @@ -101,7 +100,7 @@ pw_add_library(pw_thread_freertos.yield INTERFACE PUBLIC_DEPS pw_assert pw_third_party.freertos - pw_thread.id + pw_thread.thread pw_thread.yield.facade ) diff --git a/pw_thread_freertos/public/pw_thread_freertos/thread_inline.h b/pw_thread_freertos/public/pw_thread_freertos/thread_inline.h index 67b19aaa47..d073905fb1 100644 --- a/pw_thread_freertos/public/pw_thread_freertos/thread_inline.h +++ b/pw_thread_freertos/public/pw_thread_freertos/thread_inline.h @@ -17,7 +17,6 @@ #include "FreeRTOS.h" #include "pw_assert/assert.h" -#include "pw_thread/id.h" #include "pw_thread/thread.h" #include "pw_thread_freertos/config.h" #include "pw_thread_freertos/options.h" @@ -35,11 +34,11 @@ inline Thread& Thread::operator=(Thread&& other) { inline Thread::~Thread() { PW_DASSERT(native_type_ == nullptr); } -inline Id Thread::get_id() const { +inline Thread::id Thread::get_id() const { if (native_type_ == nullptr) { - return Id(nullptr); + return Thread::id(nullptr); } - return Id(native_type_->task_handle()); + return Thread::id(native_type_->task_handle()); } inline void Thread::swap(Thread& other) { diff --git a/pw_thread_freertos/public/pw_thread_freertos/yield_inline.h b/pw_thread_freertos/public/pw_thread_freertos/yield_inline.h index cd0ddc273f..fc2ca20332 100644 --- a/pw_thread_freertos/public/pw_thread_freertos/yield_inline.h +++ b/pw_thread_freertos/public/pw_thread_freertos/yield_inline.h @@ -17,7 +17,7 @@ #include "FreeRTOS.h" #include "pw_assert/assert.h" -#include "pw_thread/id.h" +#include "pw_thread/thread.h" #include "pw_thread/yield.h" #include "task.h" @@ -25,7 +25,7 @@ namespace pw::this_thread { inline void yield() noexcept { // Ensure this is being called by a thread. - PW_DASSERT(get_id() != thread::Id()); + PW_DASSERT(get_id() != Thread::id()); taskYIELD(); } diff --git a/pw_thread_freertos/sleep.cc b/pw_thread_freertos/sleep.cc index 1efa3dffd8..752c49f032 100644 --- a/pw_thread_freertos/sleep.cc +++ b/pw_thread_freertos/sleep.cc @@ -20,7 +20,7 @@ #include "pw_assert/check.h" #include "pw_chrono/system_clock.h" #include "pw_chrono_freertos/system_clock_constants.h" -#include "pw_thread/id.h" +#include "pw_thread/thread.h" #include "task.h" using pw::chrono::SystemClock; @@ -29,7 +29,7 @@ namespace pw::this_thread { void sleep_for(SystemClock::duration sleep_duration) { // Ensure this is being called by a thread. - PW_DCHECK(get_id() != thread::Id()); + PW_DCHECK(get_id() != Thread::id()); // Yield for negative and zero length durations. if (sleep_duration <= SystemClock::duration::zero()) { diff --git a/pw_thread_freertos/thread.cc b/pw_thread_freertos/thread.cc index 0eb22979d3..c01c50aec7 100644 --- a/pw_thread_freertos/thread.cc +++ b/pw_thread_freertos/thread.cc @@ -16,7 +16,6 @@ #include "FreeRTOS.h" #include "pw_assert/check.h" #include "pw_preprocessor/compiler.h" -#include "pw_thread/id.h" #include "pw_thread_freertos/config.h" #include "pw_thread_freertos/context.h" #include "pw_thread_freertos/options.h" diff --git a/pw_thread_stl/BUILD.gn b/pw_thread_stl/BUILD.gn index d866221f45..a607ff5ff2 100644 --- a/pw_thread_stl/BUILD.gn +++ b/pw_thread_stl/BUILD.gn @@ -31,7 +31,7 @@ config("id_public_overrides") { visibility = [ ":*" ] } -# This target provides the backend for pw::thread::Id & pw::this_thread::get_id. +# This target provides the backend for pw::Thread::id & pw::this_thread::get_id. pw_source_set("id") { public_configs = [ ":public_include_path", diff --git a/pw_thread_stl/CMakeLists.txt b/pw_thread_stl/CMakeLists.txt index 243dba316e..3d48f3875e 100644 --- a/pw_thread_stl/CMakeLists.txt +++ b/pw_thread_stl/CMakeLists.txt @@ -14,7 +14,7 @@ include($ENV{PW_ROOT}/pw_build/pigweed.cmake) -# This target provides the backend for pw::thread::Id & pw::this_thread::get_id. +# This target provides the backend for pw::Thread::id & pw::this_thread::get_id. pw_add_library(pw_thread_stl.id INTERFACE HEADERS public/pw_thread_stl/id_inline.h @@ -25,7 +25,7 @@ pw_add_library(pw_thread_stl.id INTERFACE public id_public_overrides PUBLIC_DEPS - pw_thread.id.facade + pw_thread.thread.facade ) # This target provides the backend for pw::Thread with joining capability. diff --git a/pw_thread_stl/public/pw_thread_stl/thread_inline.h b/pw_thread_stl/public/pw_thread_stl/thread_inline.h index 10bab06824..596c8cc1ae 100644 --- a/pw_thread_stl/public/pw_thread_stl/thread_inline.h +++ b/pw_thread_stl/public/pw_thread_stl/thread_inline.h @@ -46,7 +46,7 @@ inline Thread& Thread::operator=(Thread&& other) { inline Thread::~Thread() = default; -inline Id Thread::get_id() const { return native_type_.get_id(); } +inline Thread::id Thread::get_id() const { return native_type_.get_id(); } inline void Thread::join() { native_type_.join(); } diff --git a/pw_thread_threadx/BUILD.gn b/pw_thread_threadx/BUILD.gn index 48584c4508..1cf7e2c832 100644 --- a/pw_thread_threadx/BUILD.gn +++ b/pw_thread_threadx/BUILD.gn @@ -53,7 +53,7 @@ config("id_public_overrides") { visibility = [ ":*" ] } -# This target provides the backend for pw::thread::Id. +# This target provides the backend for pw::Thread::id. pw_source_set("id") { public_configs = [ ":public_include_path", @@ -65,12 +65,12 @@ pw_source_set("id") { "$dir_pw_third_party/threadx", ] public = [ + "$dir_pw_thread:thread.facade", "id_public_overrides/pw_thread_backend/id_inline.h", "id_public_overrides/pw_thread_backend/id_native.h", "public/pw_thread_threadx/id_inline.h", "public/pw_thread_threadx/id_native.h", ] - deps = [ "$dir_pw_thread:id.facade" ] } if (pw_chrono_SYSTEM_CLOCK_BACKEND != "" && pw_thread_SLEEP_BACKEND != "") { @@ -104,7 +104,7 @@ if (pw_chrono_SYSTEM_CLOCK_BACKEND != "" && pw_thread_SLEEP_BACKEND != "") { "$dir_pw_assert", "$dir_pw_chrono_threadx:system_clock", "$dir_pw_third_party/threadx", - "$dir_pw_thread:id", + "$dir_pw_thread:thread", ] } } @@ -126,7 +126,6 @@ pw_source_set("thread") { "$dir_pw_assert", "$dir_pw_string", "$dir_pw_third_party/threadx", - "$dir_pw_thread:id", "$dir_pw_thread:thread.facade", dir_pw_function, dir_pw_span, @@ -161,7 +160,7 @@ pw_source_set("yield") { public_deps = [ "$dir_pw_assert", "$dir_pw_third_party/threadx", - "$dir_pw_thread:id", + "$dir_pw_thread:thread", ] deps = [ "$dir_pw_thread:yield.facade" ] } diff --git a/pw_thread_threadx/public/pw_thread_threadx/thread_inline.h b/pw_thread_threadx/public/pw_thread_threadx/thread_inline.h index 33ab70f27b..f0dac238cc 100644 --- a/pw_thread_threadx/public/pw_thread_threadx/thread_inline.h +++ b/pw_thread_threadx/public/pw_thread_threadx/thread_inline.h @@ -16,7 +16,7 @@ #include #include "pw_assert/assert.h" -#include "pw_thread/id.h" +#include "pw_thread/thread.h" #include "pw_thread_threadx/config.h" #include "pw_thread_threadx/options.h" @@ -32,11 +32,11 @@ inline Thread& Thread::operator=(Thread&& other) { inline Thread::~Thread() { PW_DASSERT(native_type_ == nullptr); } -inline Id Thread::get_id() const { +inline Thread::id Thread::get_id() const { if (native_type_ == nullptr) { - return Id(nullptr); + return Thread::id(nullptr); } - return Id(&native_type_->tcb()); + return Thread::id(&native_type_->tcb()); } inline void Thread::swap(Thread& other) { diff --git a/pw_thread_threadx/public/pw_thread_threadx/yield_inline.h b/pw_thread_threadx/public/pw_thread_threadx/yield_inline.h index a3002a0a94..138c1865cb 100644 --- a/pw_thread_threadx/public/pw_thread_threadx/yield_inline.h +++ b/pw_thread_threadx/public/pw_thread_threadx/yield_inline.h @@ -14,14 +14,14 @@ #pragma once #include "pw_assert/assert.h" -#include "pw_thread/id.h" +#include "pw_thread/thread.h" #include "tx_api.h" namespace pw::this_thread { inline void yield() { // Ensure this is being called by a thread. - PW_DASSERT(get_id() != thread::Id()); + PW_DASSERT(get_id() != Thread::id()); tx_thread_relinquish(); } diff --git a/pw_thread_threadx/sleep.cc b/pw_thread_threadx/sleep.cc index 5bfb0ca7bc..b1f73d430e 100644 --- a/pw_thread_threadx/sleep.cc +++ b/pw_thread_threadx/sleep.cc @@ -19,7 +19,7 @@ #include "pw_assert/check.h" #include "pw_chrono/system_clock.h" #include "pw_chrono_threadx/system_clock_constants.h" -#include "pw_thread/id.h" +#include "pw_thread/thread.h" #include "tx_api.h" using pw::chrono::SystemClock; @@ -28,7 +28,7 @@ namespace pw::this_thread { void sleep_for(chrono::SystemClock::duration sleep_duration) { // Ensure this is being called by a thread. - PW_DCHECK(get_id() != thread::Id()); + PW_DCHECK(get_id() != Thread::id()); // Yield for negative and zero length durations. if (sleep_duration <= chrono::SystemClock::duration::zero()) { diff --git a/pw_thread_threadx/thread.cc b/pw_thread_threadx/thread.cc index d03e463602..ea322c692b 100644 --- a/pw_thread_threadx/thread.cc +++ b/pw_thread_threadx/thread.cc @@ -15,7 +15,6 @@ #include "pw_assert/check.h" #include "pw_preprocessor/compiler.h" -#include "pw_thread/id.h" #include "pw_thread_threadx/config.h" #include "pw_thread_threadx/context.h" #include "pw_thread_threadx/options.h" diff --git a/pw_thread_zephyr/CMakeLists.txt b/pw_thread_zephyr/CMakeLists.txt index cf63581006..900299d91a 100644 --- a/pw_thread_zephyr/CMakeLists.txt +++ b/pw_thread_zephyr/CMakeLists.txt @@ -24,7 +24,7 @@ pw_add_library(pw_thread_zephyr.config INTERFACE "${pw_thread_zephyr_CONFIG}" ) -# This target provides the backend for pw::thread::Id & pw::this_thread::get_id. +# This target provides the backend for pw::Thread::id & pw::this_thread::get_id. pw_add_library(pw_thread_zephyr.id INTERFACE HEADERS public/pw_thread_zephyr/id_inline.h @@ -37,7 +37,7 @@ pw_add_library(pw_thread_zephyr.id INTERFACE PUBLIC_DEPS pw_assert pw_interrupt.context - pw_thread.id.facade + pw_thread.thread.facade ) pw_add_library(pw_thread_zephyr.sleep STATIC @@ -75,7 +75,6 @@ pw_add_library(pw_thread_zephyr.thread STATIC pw_function pw_span pw_string - pw_thread.id pw_thread.thread.facade pw_thread_zephyr.config SOURCES diff --git a/pw_thread_zephyr/public/pw_thread_zephyr/thread_inline.h b/pw_thread_zephyr/public/pw_thread_zephyr/thread_inline.h index 672067e566..9425519d7d 100644 --- a/pw_thread_zephyr/public/pw_thread_zephyr/thread_inline.h +++ b/pw_thread_zephyr/public/pw_thread_zephyr/thread_inline.h @@ -16,7 +16,6 @@ #include #include "pw_assert/assert.h" -#include "pw_thread/id.h" #include "pw_thread/thread.h" namespace pw::thread { @@ -31,11 +30,11 @@ inline Thread& Thread::operator=(Thread&& other) { inline Thread::~Thread() { PW_DASSERT(native_type_ == nullptr); } -inline Id Thread::get_id() const { +inline Thread::id Thread::get_id() const { if (native_type_ == nullptr) { - return Id(nullptr); + return Thread::id(nullptr); } - return Id(native_type_->task_handle()); + return Thread::id(native_type_->task_handle()); } inline void Thread::swap(Thread& other) { diff --git a/pw_thread_zephyr/thread.cc b/pw_thread_zephyr/thread.cc index 1c3a97825f..42b2c97f97 100644 --- a/pw_thread_zephyr/thread.cc +++ b/pw_thread_zephyr/thread.cc @@ -18,7 +18,6 @@ #include "pw_assert/check.h" #include "pw_preprocessor/compiler.h" -#include "pw_thread/id.h" #include "pw_thread_zephyr/config.h" #include "pw_thread_zephyr/context.h" #include "pw_thread_zephyr/options.h"