• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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 "pw_chrono/system_clock.h"
18 #include "pw_thread/sleep.h"
19 #include "pw_thread/test_threads.h"
20 #include "pw_thread_freertos/context.h"
21 #include "pw_thread_freertos/options.h"
22 
23 namespace pw::thread::test {
24 namespace {
25 freertos::StaticContextWithStack thread_0_context;
26 freertos::StaticContextWithStack thread_1_context;
27 }  // namespace
28 
TestOptionsThread0()29 const Options& TestOptionsThread0() {
30   static constexpr freertos::Options thread_0_options =
31       freertos::Options()
32           .set_name("pw::TestThread0")
33           .set_static_context(thread_0_context);
34   return thread_0_options;
35 }
36 
TestOptionsThread1()37 const Options& TestOptionsThread1() {
38   static constexpr freertos::Options thread_1_options =
39       freertos::Options()
40           .set_name("pw::TestThread1")
41           .set_static_context(thread_1_context);
42   return thread_1_options;
43 }
44 
WaitUntilDetachedThreadsCleanedUp()45 void WaitUntilDetachedThreadsCleanedUp() {
46   // One may be tempted to use the context's task_handle to wait until it's a
47   // nullptr. However, there's still a race condition that the task has not
48   // finished the execution of vTaskDelete. In addition during this time the
49   // the task_handle has been cleared meaning we cannot call vTaskDelete.
50   this_thread::sleep_for(
51       chrono::SystemClock::for_at_least(std::chrono::milliseconds(50)));
52 }
53 
54 }  // namespace pw::thread::test
55