blob: 56159159c2a1c872f4273930ed6cc9f07252909f [file] [log] [blame]
Sebastian Jansson7a603392019-03-20 16:50:35 +01001/*
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
14namespace rtc {
15namespace {
16ABSL_CONST_INIT thread_local YieldInterface* current_yield_policy = nullptr;
17}
18
19ScopedYieldPolicy::ScopedYieldPolicy(YieldInterface* policy)
20 : previous_(current_yield_policy) {
21 current_yield_policy = policy;
22}
23
24ScopedYieldPolicy::~ScopedYieldPolicy() {
25 current_yield_policy = previous_;
26}
27
28void ScopedYieldPolicy::YieldExecution() {
29 if (current_yield_policy)
30 current_yield_policy->YieldExecution();
31}
32} // namespace rtc