blob: 5def6b7397aa674e35044e2ca329d04e9108a020 [file] [log] [blame]
Sebastian Jansson7a603392019-03-20 15:50:351/*
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);
Sebastian Jansson9debe5a2019-03-22 14:42:3825 ScopedYieldPolicy(const ScopedYieldPolicy&) = delete;
26 ScopedYieldPolicy& operator=(const ScopedYieldPolicy&) = delete;
Sebastian Jansson7a603392019-03-20 15:50:3527 ~ScopedYieldPolicy();
28 // Will yield as specified by the currently active thread-local yield policy
29 // (which by default is a no-op).
30 static void YieldExecution();
31
32 private:
33 YieldInterface* const previous_;
34};
35
36} // namespace rtc
37
38#endif // RTC_BASE_SYNCHRONIZATION_YIELD_POLICY_H_