Markus Handell | f70fbc8 | 2020-06-04 00:41:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "rtc_base/synchronization/yield.h" |
| 12 | |
| 13 | #if defined(WEBRTC_WIN) |
| 14 | #include <windows.h> |
| 15 | #else |
| 16 | #include <sched.h> |
| 17 | #include <time.h> |
| 18 | #endif |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | void YieldCurrentThread() { |
| 23 | // TODO(bugs.webrtc.org/11634): use dedicated OS functionality instead of |
| 24 | // sleep for yielding. |
| 25 | #if defined(WEBRTC_WIN) |
| 26 | ::Sleep(0); |
| 27 | #elif defined(WEBRTC_MAC) && defined(RTC_USE_NATIVE_MUTEX_ON_MAC) && \ |
| 28 | !RTC_USE_NATIVE_MUTEX_ON_MAC |
| 29 | sched_yield(); |
| 30 | #else |
| 31 | static const struct timespec ts_null = {0}; |
| 32 | nanosleep(&ts_null, nullptr); |
| 33 | #endif |
| 34 | } |
| 35 | |
| 36 | } // namespace webrtc |