1// Copyright 2017 The Abseil Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Core interfaces and definitions used by by low-level interfaces such as
16// SpinLock.
17
18#ifndef ABSL_BASE_INTERNAL_SCHEDULING_MODE_H_
19#define ABSL_BASE_INTERNAL_SCHEDULING_MODE_H_
20
21#include "absl/base/config.h"
22
23namespace absl {
24ABSL_NAMESPACE_BEGIN
25namespace base_internal {
26
27// Used to describe how a thread may be scheduled. Typically associated with
28// the declaration of a resource supporting synchronized access.
29//
30// SCHEDULE_COOPERATIVE_AND_KERNEL:
31// Specifies that when waiting, a cooperative thread (e.g. a Fiber) may
32// reschedule (using base::scheduling semantics); allowing other cooperative
33// threads to proceed.
34//
35// SCHEDULE_KERNEL_ONLY: (Also described as "non-cooperative")
36// Specifies that no cooperative scheduling semantics may be used, even if the
37// current thread is itself cooperatively scheduled. This means that
38// cooperative threads will NOT allow other cooperative threads to execute in
39// their place while waiting for a resource of this type. Host operating system
40// semantics (e.g. a futex) may still be used.
41//
42// When optional, clients should strongly prefer SCHEDULE_COOPERATIVE_AND_KERNEL
43// by default. SCHEDULE_KERNEL_ONLY should only be used for resources on which
44// base::scheduling (e.g. the implementation of a Scheduler) may depend.
45//
46// NOTE: Cooperative resources may not be nested below non-cooperative ones.
47// This means that it is invalid to to acquire a SCHEDULE_COOPERATIVE_AND_KERNEL
48// resource if a SCHEDULE_KERNEL_ONLY resource is already held.
49enum SchedulingMode {
50 SCHEDULE_KERNEL_ONLY = 0, // Allow scheduling only the host OS.
51 SCHEDULE_COOPERATIVE_AND_KERNEL, // Also allow cooperative scheduling.
52};
53
54} // namespace base_internal
55ABSL_NAMESPACE_END
56} // namespace absl
57
58#endif // ABSL_BASE_INTERNAL_SCHEDULING_MODE_H_
59