1 // 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 <chrono> 16 17 #include "RTOS.h" 18 #include "pw_assert/check.h" 19 #include "pw_chrono/system_clock.h" 20 #include "pw_log/log.h" 21 #include "pw_thread/non_portable_test_thread_options.h" 22 #include "pw_thread/sleep.h" 23 #include "pw_thread_embos/context.h" 24 #include "pw_thread_embos/options.h" 25 26 namespace pw::thread::test { 27 namespace { 28 29 std::array<embos::ContextWithStack<>, 2> thread_contexts; 30 31 } // namespace 32 TestOptionsThread0()33const Options& TestOptionsThread0() { 34 static constexpr embos::Options thread_0_options = 35 embos::Options() 36 .set_name("pw::TestThread0") 37 .set_context(thread_contexts[0]); 38 return thread_0_options; 39 } 40 TestOptionsThread1()41const Options& TestOptionsThread1() { 42 static constexpr embos::Options thread_1_options = 43 embos::Options() 44 .set_name("pw::TestThread1") 45 .set_context(thread_contexts[1]); 46 return thread_1_options; 47 } 48 WaitUntilDetachedThreadsCleanedUp()49void WaitUntilDetachedThreadsCleanedUp() { 50 // embOS does not permit us to invoke a callback after the TCB has been 51 // unregistered from the kernel, however it does provide an API to query this 52 // status. 53 for (auto& context : thread_contexts) { 54 while (OS_IsTask(&context.tcb())) { 55 this_thread::sleep_for( 56 chrono::SystemClock::for_at_least(std::chrono::milliseconds(1))); 57 } 58 } 59 } 60 61 } // namespace pw::thread::test 62