blob: 814693066648cd8d63a50f2bf16ac796bb053270 [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#ifndef RTC_BASE_SYNCHRONIZATION_YIELD_POLICY_H_
11#define RTC_BASE_SYNCHRONIZATION_YIELD_POLICY_H_
12
13namespace rtc {
14class YieldInterface {
15 public:
16 virtual ~YieldInterface() = default;
17 virtual void YieldExecution() = 0;
18};
19
20// Sets the current thread-local yield policy while it's in scope and reverts
21// to the previous policy when it leaves the scope.
22class ScopedYieldPolicy final {
23 public:
24 explicit ScopedYieldPolicy(YieldInterface* policy);
25 ~ScopedYieldPolicy();
26 // Will yield as specified by the currently active thread-local yield policy
27 // (which by default is a no-op).
28 static void YieldExecution();
29
30 private:
31 YieldInterface* const previous_;
32};
33
34} // namespace rtc
35
36#endif // RTC_BASE_SYNCHRONIZATION_YIELD_POLICY_H_