1 // Copyright 2020 The Pigweed Authors
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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
16 #include "pw_chrono/system_clock.h"
17 #include "pw_preprocessor/util.h"
21 namespace pw::this_thread {
23 // Blocks the execution of the current thread for at least the specified
24 // duration. This function may block for longer due to scheduling or resource
27 // A sleep duration of 0 will at minimum yield, meaning it will provide a hint
28 // to the implementation to reschedule the execution of threads, allowing other
31 // This can only be called from a thread, meaning the scheduler is running.
32 void sleep_for(chrono::SystemClock::duration for_at_least);
34 // Blocks the execution of the current thread until at least the specified
35 // deadline. This function may block for longer due to scheduling or resource
38 // A sleep deadline in the past up to the current time will at minimum yield
39 // meaning it will provide a hint to the implementation to reschedule the
40 // execution of threads, allowing other threads to run.
42 // This can only be called from a thread, meaning the scheduler is running.
43 void sleep_until(chrono::SystemClock::time_point until_at_least);
45 } // namespace pw::this_thread
47 // The backend can opt to include inlined implementations.
48 #if __has_include("pw_thread_backend/sleep_inline.h")
49 #include "pw_thread_backend/sleep_inline.h"
50 #endif // __has_include("pw_thread_backend/sleep_inline.h")
56 void pw_this_thread_SleepFor(pw_chrono_SystemClock_Duration for_at_least);
57 void pw_this_thread_SleepUntil(pw_chrono_SystemClock_TimePoint until_at_least);