blob: ec504b9257e74b478718d010c7ea0b142f7b1695 [file] [edit]
// Copyright 2026 The Pigweed Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
#pragma once
#include "pw_async2/internal/lock.h"
#include "pw_chrono/system_clock.h"
#include "pw_sync/lock_annotations.h"
#include "pw_thread/sleep.h"
namespace pw::async2::internal {
inline void YieldToAnyThread() PW_LOCKS_EXCLUDED(internal::lock()) {
// Sleep to yield the CPU in case work must be completed in a lower priority
// priority thread to make progress. Depending on the RTOS, yield may not
// allow lower priority threads to be scheduled.
// TODO: b/456506369 - Switch to pw::this_thread::yield when it is updated.
this_thread::sleep_for(chrono::SystemClock::duration(1));
}
} // namespace pw::async2::internal