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 _PTHREAD_QOS_H
25 #define _PTHREAD_QOS_H
27 #include <sys/cdefs.h>
28 #include <Availability.h>
30 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
36 #if __has_feature(assume_nonnull)
37 _Pragma("clang assume_nonnull begin")
42 * @function pthread_attr_set_qos_class_np
45 * Sets the QOS class and relative priority of a pthread attribute structure
46 * which may be used to specify the requested QOS class of newly created
50 * The QOS class and relative priority represent an overall combination of
51 * system quality of service attributes on a thread.
53 * Subsequent calls to interfaces such as pthread_attr_setschedparam() that are
54 * incompatible or in conflict with the QOS class system will unset the QOS
55 * class requested with this interface and pthread_attr_get_qos_class_np() will
56 * return QOS_CLASS_UNSPECIFIED.
59 * The pthread attribute structure to modify.
63 * - QOS_CLASS_USER_INTERACTIVE
64 * - QOS_CLASS_USER_INITIATED
67 * - QOS_CLASS_BACKGROUND
68 * EINVAL will be returned if any other value is provided.
70 * @param __relative_priority
71 * A relative priority within the QOS class. This value is a negative offset
72 * from the maximum supported scheduler priority for the given class.
73 * EINVAL will be returned if the value is greater than zero or less than
74 * QOS_MIN_RELATIVE_PRIORITY.
77 * Zero if successful, otherwise an errno value.
79 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
)
81 pthread_attr_set_qos_class_np(pthread_attr_t
*__attr
,
82 qos_class_t __qos_class
, int __relative_priority
);
85 * @function pthread_attr_get_qos_class_np
88 * Gets the QOS class and relative priority of a pthread attribute structure.
91 * The pthread attribute structure to inspect.
94 * On output, a QOS class value:
95 * - QOS_CLASS_USER_INTERACTIVE
96 * - QOS_CLASS_USER_INITIATED
99 * - QOS_CLASS_BACKGROUND
100 * - QOS_CLASS_UNSPECIFIED
101 * This value may be NULL in which case no value is returned.
103 * @param __relative_priority
104 * On output, a relative priority offset within the QOS class.
105 * This value may be NULL in which case no value is returned.
108 * Zero if successful, otherwise an errno value.
110 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
)
112 pthread_attr_get_qos_class_np(pthread_attr_t
* __restrict __attr
,
113 qos_class_t
* _Nullable __restrict __qos_class
,
114 int * _Nullable __restrict __relative_priority
);
117 * @function pthread_set_qos_class_self_np
120 * Sets the requested QOS class and relative priority of the current thread.
123 * The QOS class and relative priority represent an overall combination of
124 * system quality of service attributes on a thread.
126 * Subsequent calls to interfaces such as pthread_setschedparam() that are
127 * incompatible or in conflict with the QOS class system will unset the QOS
128 * class requested with this interface and pthread_get_qos_class_np() will
129 * return QOS_CLASS_UNSPECIFIED thereafter. A thread so modified is permanently
130 * opted-out of the QOS class system and calls to this function to request a QOS
131 * class for such a thread will fail and return EPERM.
135 * - QOS_CLASS_USER_INTERACTIVE
136 * - QOS_CLASS_USER_INITIATED
137 * - QOS_CLASS_DEFAULT
138 * - QOS_CLASS_UTILITY
139 * - QOS_CLASS_BACKGROUND
140 * EINVAL will be returned if any other value is provided.
142 * @param __relative_priority
143 * A relative priority within the QOS class. This value is a negative offset
144 * from the maximum supported scheduler priority for the given class.
145 * EINVAL will be returned if the value is greater than zero or less than
146 * QOS_MIN_RELATIVE_PRIORITY.
149 * Zero if successful, otherwise an errno value.
151 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
)
153 pthread_set_qos_class_self_np(qos_class_t __qos_class
,
154 int __relative_priority
);
157 * @function pthread_get_qos_class_np
160 * Gets the requested QOS class and relative priority of a thread.
163 * The target thread to inspect.
166 * On output, a QOS class value:
167 * - QOS_CLASS_USER_INTERACTIVE
168 * - QOS_CLASS_USER_INITIATED
169 * - QOS_CLASS_DEFAULT
170 * - QOS_CLASS_UTILITY
171 * - QOS_CLASS_BACKGROUND
172 * - QOS_CLASS_UNSPECIFIED
173 * This value may be NULL in which case no value is returned.
175 * @param __relative_priority
176 * On output, a relative priority offset within the QOS class.
177 * This value may be NULL in which case no value is returned.
180 * Zero if successful, otherwise an errno value.
182 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
)
184 pthread_get_qos_class_np(pthread_t __pthread
,
185 qos_class_t
* _Nullable __restrict __qos_class
,
186 int * _Nullable __restrict __relative_priority
);
189 * @typedef pthread_override_t
192 * An opaque object representing a QOS class override of a thread.
195 * A QOS class override of a target thread expresses that an item of pending
196 * work classified with a specific QOS class and relative priority depends on
197 * the completion of the work currently being executed by the thread (e.g. due
198 * to ordering requirements).
200 * While overrides are in effect, the target thread will execute at the maximum
201 * QOS class and relative priority of all overrides and of the QOS class
202 * requested by the thread itself.
204 * A QOS class override does not modify the target thread's requested QOS class
205 * value and the effect of an override is not visible to the qos_class_self()
206 * and pthread_get_qos_class_np() interfaces.
209 typedef struct pthread_override_s
* pthread_override_t
;
212 * @function pthread_override_qos_class_start_np
215 * Starts a QOS class override of the specified target thread.
218 * Starting a QOS class override of the specified target thread expresses that
219 * an item of pending work classified with the specified QOS class and relative
220 * priority depends on the completion of the work currently being executed by
221 * the thread (e.g. due to ordering requirements).
223 * While overrides are in effect, the specified target thread will execute at
224 * the maximum QOS class and relative priority of all overrides and of the QOS
225 * class requested by the thread itself.
227 * Starting a QOS class override does not modify the target thread's requested
228 * QOS class value and the effect of an override is not visible to the
229 * qos_class_self() and pthread_get_qos_class_np() interfaces.
231 * The returned newly allocated override object is intended to be associated
232 * with the item of pending work in question. Once the dependency has been
233 * satisfied and enabled that work to begin executing, the QOS class override
234 * must be ended by passing the associated override object to
235 * pthread_override_qos_class_end_np(). Failure to do so will result in the
236 * associated resources to be leaked and the target thread to be permanently
237 * executed at an inappropriately elevated QOS class.
240 * The target thread to modify.
244 * - QOS_CLASS_USER_INTERACTIVE
245 * - QOS_CLASS_USER_INITIATED
246 * - QOS_CLASS_DEFAULT
247 * - QOS_CLASS_UTILITY
248 * - QOS_CLASS_BACKGROUND
249 * NULL will be returned if any other value is provided.
251 * @param __relative_priority
252 * A relative priority within the QOS class. This value is a negative offset
253 * from the maximum supported scheduler priority for the given class.
254 * NULL will be returned if the value is greater than zero or less than
255 * QOS_MIN_RELATIVE_PRIORITY.
258 * A newly allocated override object if successful, or NULL if the override
259 * could not be started.
261 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
)
263 pthread_override_qos_class_start_np(pthread_t __pthread
,
264 qos_class_t __qos_class
, int __relative_priority
);
267 * @function pthread_override_qos_class_end_np
270 * Ends a QOS class override.
273 * Passing an override object returned by pthread_override_qos_class_start_np()
274 * ends the QOS class override started by that call and deallocates all
275 * associated resources as well as the override object itself.
277 * The thread starting and the thread ending a QOS class override need not be
278 * identical. If the thread ending the override is the the target thread of the
279 * override itself, it should take care to elevate its requested QOS class
280 * appropriately with pthread_set_qos_class_self_np() before ending the
284 * An override object returned by pthread_override_qos_class_start_np().
287 * Zero if successful, otherwise an errno value.
289 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
)
291 pthread_override_qos_class_end_np(pthread_override_t __override
);
294 #if __has_feature(assume_nonnull)
295 _Pragma("clang assume_nonnull end")
300 #endif // __DARWIN_C_LEVEL >= __DARWIN_C_FULL
302 #endif // _PTHREAD_QOS_H