blob: fc1884dc452eee07e65951400752e648e464ac8c [file] [log] [blame]
Ewout van Bekkumae6c03a2021-01-19 14:53:19 -08001// 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
23namespace pw::thread::test {
24namespace {
25freertos::StaticContextWithStack thread_0_context;
26freertos::StaticContextWithStack thread_1_context;
27} // namespace
28
29const 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
37const 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
45void 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.
Ewout van Bekkum959b8832021-03-11 08:55:01 -080050 this_thread::sleep_for(
51 chrono::SystemClock::for_at_least(std::chrono::milliseconds(50)));
Ewout van Bekkumae6c03a2021-01-19 14:53:19 -080052}
53
54} // namespace pw::thread::test