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
39 * @function pthread_attr_set_qos_class_np
42 * Sets the QOS class and relative priority of a pthread attribute structure
43 * which may be used to specify the requested QOS class of newly created
47 * The QOS class and relative priority represent an overall combination of
48 * system quality of service attributes on a thread.
50 * Subsequent calls to interfaces such as pthread_attr_setschedparam() that are
51 * incompatible or in conflict with the QOS class system will unset the QOS
52 * class requested with this interface and pthread_attr_get_qos_class_np() will
53 * return QOS_CLASS_UNSPECIFIED.
56 * The pthread attribute structure to modify.
60 * - QOS_CLASS_USER_INTERACTIVE
61 * - QOS_CLASS_USER_INITIATED
64 * - QOS_CLASS_BACKGROUND
65 * EINVAL will be returned if any other value is provided.
67 * @param __relative_priority
68 * A relative priority within the QOS class. This value is a negative offset
69 * from the maximum supported scheduler priority for the given class.
70 * EINVAL will be returned if the value is greater than zero or less than
71 * QOS_MIN_RELATIVE_PRIORITY.
74 * Zero if successful, otherwise an errno value.
76 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
)
78 pthread_attr_set_qos_class_np(pthread_attr_t
*__attr
,
79 qos_class_t __qos_class
, int __relative_priority
);
82 * @function pthread_attr_get_qos_class_np
85 * Gets the QOS class and relative priority of a pthread attribute structure.
88 * The pthread attribute structure to inspect.
91 * On output, a QOS class value:
92 * - QOS_CLASS_USER_INTERACTIVE
93 * - QOS_CLASS_USER_INITIATED
96 * - QOS_CLASS_BACKGROUND
97 * - QOS_CLASS_UNSPECIFIED
98 * This value may be NULL in which case no value is returned.
100 * @param __relative_priority
101 * On output, a relative priority offset within the QOS class.
102 * This value may be NULL in which case no value is returned.
105 * Zero if successful, otherwise an errno value.
107 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
)
109 pthread_attr_get_qos_class_np(pthread_attr_t
* __restrict __attr
,
110 qos_class_t
* __restrict __qos_class
,
111 int * __restrict __relative_priority
);
114 * @function pthread_set_qos_class_self_np
117 * Sets the requested QOS class and relative priority of the current thread.
120 * The QOS class and relative priority represent an overall combination of
121 * system quality of service attributes on a thread.
123 * Subsequent calls to interfaces such as pthread_setschedparam() that are
124 * incompatible or in conflict with the QOS class system will unset the QOS
125 * class requested with this interface and pthread_get_qos_class_np() will
126 * return QOS_CLASS_UNSPECIFIED thereafter. A thread so modified is permanently
127 * opted-out of the QOS class system and calls to this function to request a QOS
128 * class for such a thread will fail and return EPERM.
132 * - QOS_CLASS_USER_INTERACTIVE
133 * - QOS_CLASS_USER_INITIATED
134 * - QOS_CLASS_DEFAULT
135 * - QOS_CLASS_UTILITY
136 * - QOS_CLASS_BACKGROUND
137 * EINVAL will be returned if any other value is provided.
139 * @param __relative_priority
140 * A relative priority within the QOS class. This value is a negative offset
141 * from the maximum supported scheduler priority for the given class.
142 * EINVAL will be returned if the value is greater than zero or less than
143 * QOS_MIN_RELATIVE_PRIORITY.
146 * Zero if successful, otherwise an errno value.
148 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
)
150 pthread_set_qos_class_self_np(qos_class_t __qos_class
,
151 int __relative_priority
);
154 * @function pthread_get_qos_class_np
157 * Gets the requested QOS class and relative priority of a thread.
160 * The target thread to inspect.
163 * On output, a QOS class value:
164 * - QOS_CLASS_USER_INTERACTIVE
165 * - QOS_CLASS_USER_INITIATED
166 * - QOS_CLASS_DEFAULT
167 * - QOS_CLASS_UTILITY
168 * - QOS_CLASS_BACKGROUND
169 * - QOS_CLASS_UNSPECIFIED
170 * This value may be NULL in which case no value is returned.
172 * @param __relative_priority
173 * On output, a relative priority offset within the QOS class.
174 * This value may be NULL in which case no value is returned.
177 * Zero if successful, otherwise an errno value.
179 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
)
181 pthread_get_qos_class_np(pthread_t __pthread
,
182 qos_class_t
* __restrict __qos_class
,
183 int * __restrict __relative_priority
);
186 * @typedef pthread_override_t
189 * An opaque object representing a QOS class override of a thread.
192 * A QOS class override of a target thread expresses that an item of pending
193 * work classified with a specific QOS class and relative priority depends on
194 * the completion of the work currently being executed by the thread (e.g. due
195 * to ordering requirements).
197 * While overrides are in effect, the target thread will execute at the maximum
198 * QOS class and relative priority of all overrides and of the QOS class
199 * requested by the thread itself.
201 * A QOS class override does not modify the target thread's requested QOS class
202 * value and the effect of an override is not visible to the qos_class_self()
203 * and pthread_get_qos_class_np() interfaces.
206 typedef struct pthread_override_s
* pthread_override_t
;
209 * @function pthread_override_qos_class_start_np
212 * Starts a QOS class override of the specified target thread.
215 * Starting a QOS class override of the specified target thread expresses that
216 * an item of pending work classified with the specified QOS class and relative
217 * priority depends on the completion of the work currently being executed by
218 * the thread (e.g. due to ordering requirements).
220 * While overrides are in effect, the specified target thread will execute at
221 * the maximum QOS class and relative priority of all overrides and of the QOS
222 * class requested by the thread itself.
224 * Starting a QOS class override does not modify the target thread's requested
225 * QOS class value and the effect of an override is not visible to the
226 * qos_class_self() and pthread_get_qos_class_np() interfaces.
228 * The returned newly allocated override object is intended to be associated
229 * with the item of pending work in question. Once the dependency has been
230 * satisfied and enabled that work to begin executing, the QOS class override
231 * must be ended by passing the associated override object to
232 * pthread_override_qos_class_end_np(). Failure to do so will result in the
233 * associated resources to be leaked and the target thread to be permanently
234 * executed at an inappropriately elevated QOS class.
237 * The target thread to modify.
241 * - QOS_CLASS_USER_INTERACTIVE
242 * - QOS_CLASS_USER_INITIATED
243 * - QOS_CLASS_DEFAULT
244 * - QOS_CLASS_UTILITY
245 * - QOS_CLASS_BACKGROUND
246 * NULL will be returned if any other value is provided.
248 * @param __relative_priority
249 * A relative priority within the QOS class. This value is a negative offset
250 * from the maximum supported scheduler priority for the given class.
251 * NULL will be returned if the value is greater than zero or less than
252 * QOS_MIN_RELATIVE_PRIORITY.
255 * A newly allocated override object if successful, or NULL if the override
256 * could not be started.
258 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
)
260 pthread_override_qos_class_start_np(pthread_t __pthread
,
261 qos_class_t __qos_class
, int __relative_priority
);
264 * @function pthread_override_qos_class_end_np
267 * Ends a QOS class override.
270 * Passing an override object returned by pthread_override_qos_class_start_np()
271 * ends the QOS class override started by that call and deallocates all
272 * associated resources as well as the override object itself.
274 * The thread starting and the thread ending a QOS class override need not be
275 * identical. If the thread ending the override is the the target thread of the
276 * override itself, it should take care to elevate its requested QOS class
277 * appropriately with pthread_set_qos_class_self_np() before ending the
281 * An override object returned by pthread_override_qos_class_start_np().
284 * Zero if successful, otherwise an errno value.
286 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_8_0
)
288 pthread_override_qos_class_end_np(pthread_override_t __override
);
294 #endif // __DARWIN_C_LEVEL >= __DARWIN_C_FULL
296 #endif // _PTHREAD_QOS_H