Skip to content

Commit

Permalink
pw_thread_stl: Stub thread_iteration backend
Browse files Browse the repository at this point in the history
Change-Id: If7d1782a6ab0a0c7bcb8264284a477da94630af7
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/108054
Reviewed-by: Armando Montanez <amontanez@google.com>
Commit-Queue: Medha Kini <medhakini@google.com>
  • Loading branch information
Medha Kini authored and CQ Bot Account committed Aug 26, 2022
1 parent 994fb89 commit d5524c8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
1 change: 1 addition & 0 deletions pw_system/stl_backends.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
8 changes: 5 additions & 3 deletions pw_thread/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand Down
12 changes: 12 additions & 0 deletions pw_thread_stl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
11 changes: 11 additions & 0 deletions pw_thread_stl/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
Expand Down
27 changes: 27 additions & 0 deletions pw_thread_stl/thread_iteration.cc
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d5524c8

Please sign in to comment.