Sebastian Jansson | 7a60339 | 2019-03-20 16:50:35 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | #include "rtc_base/synchronization/yield_policy.h" |
| 11 | |
| 12 | #include "absl/base/attributes.h" |
| 13 | |
| 14 | namespace rtc { |
| 15 | namespace { |
| 16 | ABSL_CONST_INIT thread_local YieldInterface* current_yield_policy = nullptr; |
| 17 | } |
| 18 | |
| 19 | ScopedYieldPolicy::ScopedYieldPolicy(YieldInterface* policy) |
| 20 | : previous_(current_yield_policy) { |
| 21 | current_yield_policy = policy; |
| 22 | } |
| 23 | |
| 24 | ScopedYieldPolicy::~ScopedYieldPolicy() { |
| 25 | current_yield_policy = previous_; |
| 26 | } |
| 27 | |
| 28 | void ScopedYieldPolicy::YieldExecution() { |
| 29 | if (current_yield_policy) |
| 30 | current_yield_policy->YieldExecution(); |
| 31 | } |
| 32 | } // namespace rtc |