diff --git a/pw_system/stl_backends.gni b/pw_system/stl_backends.gni index de2f0c28e8..06d901ebd2 100644 --- a/pw_system/stl_backends.gni +++ b/pw_system/stl_backends.gni @@ -33,6 +33,7 @@ PW_SYSTEM_STL_BACKENDS = { pw_thread_ID_BACKEND = "$dir_pw_thread_stl:id" pw_thread_SLEEP_BACKEND = "$dir_pw_thread_stl:sleep" pw_thread_THREAD_BACKEND = "$dir_pw_thread_stl:thread" + pw_thread_THREAD_ITERATION_BACKEND = "$dir_pw_thread_stl:thread_iteration" pw_thread_YIELD_BACKEND = "$dir_pw_thread_stl:yield" pw_system_TARGET_HOOKS_BACKEND = "$dir_pw_system:stl_target_hooks" } diff --git a/pw_thread/BUILD.bazel b/pw_thread/BUILD.bazel index 51b9b2d2c3..a55d6c7091 100644 --- a/pw_thread/BUILD.bazel +++ b/pw_thread/BUILD.bazel @@ -71,15 +71,17 @@ pw_cc_facade( "public/pw_thread/thread_iteration.h", ], includes = ["public"], + deps = [ + ":thread_info", + "//pw_function", + "//pw_status", + ], ) pw_cc_library( name = "thread_iteration", deps = [ - ":thread_info", ":thread_iteration_facade", - "//pw_function", - "//pw_status", "@pigweed_config//:pw_thread_thread_backend", ], ) diff --git a/pw_thread_stl/BUILD.bazel b/pw_thread_stl/BUILD.bazel index 91837a0cfe..b9a98b1730 100644 --- a/pw_thread_stl/BUILD.bazel +++ b/pw_thread_stl/BUILD.bazel @@ -101,6 +101,18 @@ pw_cc_library( ], ) +# This target provides a stub backend for pw::this_thread::thread_iteration. +# Iterating over child threads isn't supported by STL, so this only exists +# for portability reasons. +pw_cc_library( + name = "thread_iteration", + srcs = ["thread_iteration.cc"], + deps = [ + "//pw_status", + "//pw_thread:thread_iteration_facade", + ], +) + pw_cc_library( name = "test_threads", srcs = [ diff --git a/pw_thread_stl/BUILD.gn b/pw_thread_stl/BUILD.gn index 0e4e6b663c..c4d693c46f 100644 --- a/pw_thread_stl/BUILD.gn +++ b/pw_thread_stl/BUILD.gn @@ -105,6 +105,17 @@ pw_source_set("yield") { deps = [ "$dir_pw_thread:yield.facade" ] } +# This target provides a stub backend for pw::this_thread::thread_iteration. +# Iterating over child threads isn't supported by STL, so this only exists +# for portability reasons. +pw_source_set("thread_iteration") { + deps = [ + "$dir_pw_thread:thread_iteration.facade", + dir_pw_status, + ] + sources = [ "thread_iteration.cc" ] +} + pw_test_group("tests") { tests = [ ":thread_backend_test" ] } diff --git a/pw_thread_stl/thread_iteration.cc b/pw_thread_stl/thread_iteration.cc new file mode 100644 index 0000000000..034a88f615 --- /dev/null +++ b/pw_thread_stl/thread_iteration.cc @@ -0,0 +1,27 @@ +// Copyright 2022 The Pigweed Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +#include "pw_thread/thread_iteration.h" + +#include "pw_status/status.h" + +namespace pw::thread { + +// Stub backend implementation for STL. Unable to provide real implementation +// for thread iteration on STL targets. +Status ForEachThread([[maybe_unused]] const pw::thread::ThreadCallback& cb) { + return Status::Unimplemented(); +} + +} // namespace pw::thread