2 * Copyright (c) 2013-2014 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef _QOS_PRIVATE_H
25 #define _QOS_PRIVATE_H
27 #include <pthread/qos.h>
28 #include <pthread/priority_private.h>
29 #include <sys/qos.h> /* qos_class_t */
30 #include <sys/qos_private.h>
32 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
33 // allow __DARWIN_C_LEVEL to turn off the use of mach_port_t
34 #include <mach/port.h>
37 // redeffed here to avoid leaving __QOS_ENUM defined in the public header
38 #define __QOS_ENUM(name, type, ...) enum { __VA_ARGS__ }; typedef type name##_t
39 #define __QOS_AVAILABLE_10_10
40 #define __QOS_AVAILABLE_10_11
41 #define __QOS_AVAILABLE_10_12
43 #if defined(__has_feature) && defined(__has_extension)
44 #if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums)
46 #define __QOS_ENUM(name, type, ...) typedef enum : type { __VA_ARGS__ } name##_t
48 #if __has_feature(enumerator_attributes)
49 #undef __QOS_AVAILABLE_10_10
50 #define __QOS_AVAILABLE_10_10 __API_AVAILABLE(macos(10.10), ios(8.0))
51 #undef __QOS_AVAILABLE_10_11
52 #define __QOS_AVAILABLE_10_11 __API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0), watchos(2.0))
53 #undef __QOS_AVAILABLE_10_12
54 #define __QOS_AVAILABLE_10_12 __API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
58 __QOS_ENUM(_pthread_set_flags
, unsigned int,
59 _PTHREAD_SET_SELF_QOS_FLAG __QOS_AVAILABLE_10_10
= 0x1,
60 _PTHREAD_SET_SELF_VOUCHER_FLAG __QOS_AVAILABLE_10_10
= 0x2,
61 _PTHREAD_SET_SELF_FIXEDPRIORITY_FLAG __QOS_AVAILABLE_10_11
= 0x4,
62 _PTHREAD_SET_SELF_TIMESHARE_FLAG __QOS_AVAILABLE_10_11
= 0x8,
63 _PTHREAD_SET_SELF_WQ_KEVENT_UNBIND __QOS_AVAILABLE_10_12
= 0x10,
67 #undef __QOS_AVAILABLE_10_10
68 #undef __QOS_AVAILABLE_10_11
69 #undef __QOS_AVAILABLE_10_12
76 * @function pthread_set_qos_class_np
79 * Sets the requested QOS class and relative priority of the current thread.
82 * The QOS class and relative priority represent an overall combination of
83 * system quality of service attributes on a thread.
85 * Subsequent calls to interfaces such as pthread_setschedparam() that are
86 * incompatible or in conflict with the QOS class system will unset the QOS
87 * class requested with this interface and pthread_get_qos_class_np() will
88 * return QOS_CLASS_UNSPECIFIED thereafter. A thread so modified is permanently
89 * opted-out of the QOS class system and calls to this function to request a QOS
90 * class for such a thread will fail and return EPERM.
93 * The current thread as returned by pthread_self().
94 * EINVAL will be returned if any other thread is provided.
98 * - QOS_CLASS_USER_INTERACTIVE
99 * - QOS_CLASS_USER_INITIATED
100 * - QOS_CLASS_DEFAULT
101 * - QOS_CLASS_UTILITY
102 * - QOS_CLASS_BACKGROUND
103 * - QOS_CLASS_MAINTENANCE
104 * EINVAL will be returned if any other value is provided.
106 * @param __relative_priority
107 * A relative priority within the QOS class. This value is a negative offset
108 * from the maximum supported scheduler priority for the given class.
109 * EINVAL will be returned if the value is greater than zero or less than
110 * QOS_MIN_RELATIVE_PRIORITY.
113 * Zero if successful, othwerise an errno value.
115 __API_DEPRECATED_WITH_REPLACEMENT("pthread_set_qos_class_self_np", macos(10.10, 10.10), ios(8.0, 8.0))
117 pthread_set_qos_class_np(pthread_t __pthread
,
118 qos_class_t __qos_class
,
119 int __relative_priority
);
121 /* Private interfaces for libdispatch to encode/decode specific values of pthread_priority_t. */
123 // Encode a class+priority pair into a pthread_priority_t,
124 __API_AVAILABLE(macos(10.10), ios(8.0))
126 _pthread_qos_class_encode(qos_class_t qos_class
, int relative_priority
, unsigned long flags
);
128 // Decode a pthread_priority_t into a class+priority pair.
129 __API_AVAILABLE(macos(10.10), ios(8.0))
131 _pthread_qos_class_decode(pthread_priority_t priority
, int *relative_priority
, unsigned long *flags
);
133 // Encode a legacy workqueue API priority into a pthread_priority_t. This API
134 // is deprecated and can be removed when the simulator no longer uses it.
135 __API_DEPRECATED("no longer used", macos(10.10, 10.13), ios(8.0, 11.0))
137 _pthread_qos_class_encode_workqueue(int queue_priority
, unsigned long flags
);
139 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
141 // Set QoS or voucher, or both, on pthread_self()
142 __API_AVAILABLE(macos(10.10), ios(8.0))
144 _pthread_set_properties_self(_pthread_set_flags_t flags
, pthread_priority_t priority
, mach_port_t voucher
);
146 // Set self to fixed priority without disturbing QoS or priority
147 __API_AVAILABLE(macos(10.10), ios(8.0))
149 pthread_set_fixedpriority_self(void);
151 // Inverse of pthread_set_fixedpriority_self()
152 __API_AVAILABLE(macos(10.10), ios(8.0))
154 pthread_set_timeshare_self(void);
157 * @const PTHREAD_MAX_PARALLELISM_PHYSICAL
158 * Flag that can be used with pthread_qos_max_parallelism() and
159 * pthread_time_constraint_max_parallelism() to ask for a count of physical
160 * compute units available for parallelism (default is logical).
162 #define PTHREAD_MAX_PARALLELISM_PHYSICAL 0x1
165 * @function pthread_qos_max_parallelism
168 * Returns the number of compute units available for parallel computation at
169 * a specified QoS class.
172 * The specified QoS class.
175 * 0 or PTHREAD_MAX_PARALLELISM_PHYSICAL.
178 * The number of compute units available for parallel computation for the
179 * specified QoS, or -1 on failure (with errno set accordingly).
181 __API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
183 pthread_qos_max_parallelism(qos_class_t qos
, unsigned long flags
);
186 * @function pthread_time_constraint_max_parallelism()
189 * Returns the number of compute units available for parallel computation on
193 * 0 or PTHREAD_MAX_PARALLELISM_PHYSICAL.
196 * The number of compute units available for parallel computation on realtime
197 * threads, or -1 on failure (with errno set accordingly).
199 __API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
201 pthread_time_constraint_max_parallelism(unsigned long flags
);
203 #endif // __DARWIN_C_LEVEL >= __DARWIN_C_FULL
209 #endif //_QOS_PRIVATE_H