blob: db95071b611349a1d4a852aa31908680c9a6ecb1 [file] [log] [blame]
Ewout van Bekkum6e5d43e2021-05-06 15:29:44 -07001// Copyright 2021 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15#include "pw_thread/test_threads.h"
16
17#include <chrono>
18
19#include "RTOS.h"
20#include "pw_assert/check.h"
21#include "pw_chrono/system_clock.h"
22#include "pw_log/log.h"
23#include "pw_thread/sleep.h"
24#include "pw_thread_embos/context.h"
25#include "pw_thread_embos/options.h"
26
27namespace pw::thread::test {
28namespace {
29
30std::array<embos::ContextWithStack<>, 2> thread_contexts;
31
32} // namespace
33
34const Options& TestOptionsThread0() {
35 static constexpr embos::Options thread_0_options =
36 embos::Options()
37 .set_name("pw::TestThread0")
38 .set_context(thread_contexts[0]);
39 return thread_0_options;
40}
41
42const Options& TestOptionsThread1() {
43 static constexpr embos::Options thread_1_options =
44 embos::Options()
45 .set_name("pw::TestThread1")
46 .set_context(thread_contexts[1]);
47 return thread_1_options;
48}
49
50void WaitUntilDetachedThreadsCleanedUp() {
51 // embOS does not permit us to invoke a callback after the TCB has been
52 // unregistered from the kernel, however it does provide an API to query this
53 // status.
54 for (auto& context : thread_contexts) {
55 while (OS_IsTask(&context.tcb())) {
56 this_thread::sleep_for(
57 chrono::SystemClock::for_at_least(std::chrono::milliseconds(1)));
58 }
59 }
60}
61
62} // namespace pw::thread::test