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 <sys/_pthread/_pthread_attr_t.h> /* pthread_attr_t */
29 #include <sys/_pthread/_pthread_t.h> /* pthread_t */
30 #include <Availability.h>
32 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
38 #if __has_feature(assume_nonnull)
39 _Pragma("clang assume_nonnull begin")
44 * @function pthread_attr_set_qos_class_np
47 * Sets the QOS class and relative priority of a pthread attribute structure
48 * which may be used to specify the requested QOS class of newly created
52 * The QOS class and relative priority represent an overall combination of
53 * system quality of service attributes on a thread.
55 * Subsequent calls to interfaces such as pthread_attr_setschedparam() that are
56 * incompatible or in conflict with the QOS class system will unset the QOS
57 * class requested with this interface and pthread_attr_get_qos_class_np() will
58 * return QOS_CLASS_UNSPECIFIED.
61 * The pthread attribute structure to modify.
65 * - QOS_CLASS_USER_INTERACTIVE
66 * - QOS_CLASS_USER_INITIATED
69 * - QOS_CLASS_BACKGROUND
70 * EINVAL will be returned if any other value is provided.
72 * @param __relative_priority
73 * A relative priority within the QOS class. This value is a negative offset
74 * from the maximum supported scheduler priority for the given class.
75 * EINVAL will be returned if the value is greater than zero or less than
76 * QOS_MIN_RELATIVE_PRIORITY.
79 * Zero if successful, otherwise an errno value.
81 __API_AVAILABLE(macos(10.10), ios(8.0))
83 pthread_attr_set_qos_class_np(pthread_attr_t
*__attr
,
84 qos_class_t __qos_class
, int __relative_priority
);
87 * @function pthread_attr_get_qos_class_np
90 * Gets the QOS class and relative priority of a pthread attribute structure.
93 * The pthread attribute structure to inspect.
96 * On output, a QOS class value:
97 * - QOS_CLASS_USER_INTERACTIVE
98 * - QOS_CLASS_USER_INITIATED
100 * - QOS_CLASS_UTILITY
101 * - QOS_CLASS_BACKGROUND
102 * - QOS_CLASS_UNSPECIFIED
103 * This value may be NULL in which case no value is returned.
105 * @param __relative_priority
106 * On output, a relative priority offset within the QOS class.
107 * This value may be NULL in which case no value is returned.
110 * Zero if successful, otherwise an errno value.
112 __API_AVAILABLE(macos(10.10), ios(8.0))
114 pthread_attr_get_qos_class_np(pthread_attr_t
* __restrict __attr
,
115 qos_class_t
* _Nullable __restrict __qos_class
,
116 int * _Nullable __restrict __relative_priority
);
119 * @function pthread_set_qos_class_self_np
122 * Sets the requested QOS class and relative priority of the current thread.
125 * The QOS class and relative priority represent an overall combination of
126 * system quality of service attributes on a thread.
128 * Subsequent calls to interfaces such as pthread_setschedparam() that are
129 * incompatible or in conflict with the QOS class system will unset the QOS
130 * class requested with this interface and pthread_get_qos_class_np() will
131 * return QOS_CLASS_UNSPECIFIED thereafter. A thread so modified is permanently
132 * opted-out of the QOS class system and calls to this function to request a QOS
133 * class for such a thread will fail and return EPERM.
137 * - QOS_CLASS_USER_INTERACTIVE
138 * - QOS_CLASS_USER_INITIATED
139 * - QOS_CLASS_DEFAULT
140 * - QOS_CLASS_UTILITY
141 * - QOS_CLASS_BACKGROUND
142 * EINVAL will be returned if any other value is provided.
144 * @param __relative_priority
145 * A relative priority within the QOS class. This value is a negative offset
146 * from the maximum supported scheduler priority for the given class.
147 * EINVAL will be returned if the value is greater than zero or less than
148 * QOS_MIN_RELATIVE_PRIORITY.
151 * Zero if successful, otherwise an errno value.
153 __API_AVAILABLE(macos(10.10), ios(8.0))
155 pthread_set_qos_class_self_np(qos_class_t __qos_class
,
156 int __relative_priority
);
159 * @function pthread_get_qos_class_np
162 * Gets the requested QOS class and relative priority of a thread.
165 * The target thread to inspect.
168 * On output, a QOS class value:
169 * - QOS_CLASS_USER_INTERACTIVE
170 * - QOS_CLASS_USER_INITIATED
171 * - QOS_CLASS_DEFAULT
172 * - QOS_CLASS_UTILITY
173 * - QOS_CLASS_BACKGROUND
174 * - QOS_CLASS_UNSPECIFIED
175 * This value may be NULL in which case no value is returned.
177 * @param __relative_priority
178 * On output, a relative priority offset within the QOS class.
179 * This value may be NULL in which case no value is returned.
182 * Zero if successful, otherwise an errno value.
184 __API_AVAILABLE(macos(10.10), ios(8.0))
186 pthread_get_qos_class_np(pthread_t __pthread
,
187 qos_class_t
* _Nullable __restrict __qos_class
,
188 int * _Nullable __restrict __relative_priority
);
191 * @typedef pthread_override_t
194 * An opaque object representing a QOS class override of a thread.
197 * A QOS class override of a target thread expresses that an item of pending
198 * work classified with a specific QOS class and relative priority depends on
199 * the completion of the work currently being executed by the thread (e.g. due
200 * to ordering requirements).
202 * While overrides are in effect, the target thread will execute at the maximum
203 * QOS class and relative priority of all overrides and of the QOS class
204 * requested by the thread itself.
206 * A QOS class override does not modify the target thread's requested QOS class
207 * value and the effect of an override is not visible to the qos_class_self()
208 * and pthread_get_qos_class_np() interfaces.
211 typedef struct pthread_override_s
* pthread_override_t
;
214 * @function pthread_override_qos_class_start_np
217 * Starts a QOS class override of the specified target thread.
220 * Starting a QOS class override of the specified target thread expresses that
221 * an item of pending work classified with the specified QOS class and relative
222 * priority depends on the completion of the work currently being executed by
223 * the thread (e.g. due to ordering requirements).
225 * While overrides are in effect, the specified target thread will execute at
226 * the maximum QOS class and relative priority of all overrides and of the QOS
227 * class requested by the thread itself.
229 * Starting a QOS class override does not modify the target thread's requested
230 * QOS class value and the effect of an override is not visible to the
231 * qos_class_self() and pthread_get_qos_class_np() interfaces.
233 * The returned newly allocated override object is intended to be associated
234 * with the item of pending work in question. Once the dependency has been
235 * satisfied and enabled that work to begin executing, the QOS class override
236 * must be ended by passing the associated override object to
237 * pthread_override_qos_class_end_np(). Failure to do so will result in the
238 * associated resources to be leaked and the target thread to be permanently
239 * executed at an inappropriately elevated QOS class.
242 * The target thread to modify.
246 * - QOS_CLASS_USER_INTERACTIVE
247 * - QOS_CLASS_USER_INITIATED
248 * - QOS_CLASS_DEFAULT
249 * - QOS_CLASS_UTILITY
250 * - QOS_CLASS_BACKGROUND
251 * NULL will be returned if any other value is provided.
253 * @param __relative_priority
254 * A relative priority within the QOS class. This value is a negative offset
255 * from the maximum supported scheduler priority for the given class.
256 * NULL will be returned if the value is greater than zero or less than
257 * QOS_MIN_RELATIVE_PRIORITY.
260 * A newly allocated override object if successful, or NULL if the override
261 * could not be started.
263 __API_AVAILABLE(macos(10.10), ios(8.0))
265 pthread_override_qos_class_start_np(pthread_t __pthread
,
266 qos_class_t __qos_class
, int __relative_priority
);
269 * @function pthread_override_qos_class_end_np
272 * Ends a QOS class override.
275 * Passing an override object returned by pthread_override_qos_class_start_np()
276 * ends the QOS class override started by that call and deallocates all
277 * associated resources as well as the override object itself.
279 * The thread starting and the thread ending a QOS class override need not be
280 * identical. If the thread ending the override is the the target thread of the
281 * override itself, it should take care to elevate its requested QOS class
282 * appropriately with pthread_set_qos_class_self_np() before ending the
286 * An override object returned by pthread_override_qos_class_start_np().
289 * Zero if successful, otherwise an errno value.
291 __API_AVAILABLE(macos(10.10), ios(8.0))
293 pthread_override_qos_class_end_np(pthread_override_t __override
);
296 #if __has_feature(assume_nonnull)
297 _Pragma("clang assume_nonnull end")
302 #endif // __DARWIN_C_LEVEL >= __DARWIN_C_FULL
304 #endif // _PTHREAD_QOS_H