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