]>
Commit | Line | Data |
---|---|---|
f1a1da6c A |
1 | /* |
2 | * Copyright (c) 2013-2014 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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 | |
11 | * file. | |
12 | * | |
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. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
24 | #ifndef _QOS_PRIVATE_H | |
25 | #define _QOS_PRIVATE_H | |
26 | ||
27 | #include <pthread/qos.h> | |
214d78a2 | 28 | #include <pthread/priority_private.h> |
a0619f9c | 29 | #include <sys/qos.h> /* qos_class_t */ |
f1a1da6c A |
30 | #include <sys/qos_private.h> |
31 | ||
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> | |
35 | #endif | |
36 | ||
f1a1da6c A |
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 | |
2546420a A |
39 | #define __QOS_AVAILABLE_10_10 |
40 | #define __QOS_AVAILABLE_10_11 | |
41 | #define __QOS_AVAILABLE_10_12 | |
f1a1da6c A |
42 | |
43 | #if defined(__has_feature) && defined(__has_extension) | |
44 | #if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums) | |
45 | #undef __QOS_ENUM | |
46 | #define __QOS_ENUM(name, type, ...) typedef enum : type { __VA_ARGS__ } name##_t | |
47 | #endif | |
48 | #if __has_feature(enumerator_attributes) | |
2546420a | 49 | #undef __QOS_AVAILABLE_10_10 |
a0619f9c | 50 | #define __QOS_AVAILABLE_10_10 __API_AVAILABLE(macos(10.10), ios(8.0)) |
2546420a | 51 | #undef __QOS_AVAILABLE_10_11 |
a0619f9c | 52 | #define __QOS_AVAILABLE_10_11 __API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0), watchos(2.0)) |
2546420a | 53 | #undef __QOS_AVAILABLE_10_12 |
a0619f9c | 54 | #define __QOS_AVAILABLE_10_12 __API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) |
f1a1da6c A |
55 | #endif |
56 | #endif | |
57 | ||
58 | __QOS_ENUM(_pthread_set_flags, unsigned int, | |
2546420a A |
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, | |
f1a1da6c A |
64 | ); |
65 | ||
66 | #undef __QOS_ENUM | |
2546420a A |
67 | #undef __QOS_AVAILABLE_10_10 |
68 | #undef __QOS_AVAILABLE_10_11 | |
69 | #undef __QOS_AVAILABLE_10_12 | |
f1a1da6c A |
70 | |
71 | #ifndef KERNEL | |
72 | ||
73 | __BEGIN_DECLS | |
74 | ||
75 | /*! | |
76 | * @function pthread_set_qos_class_np | |
77 | * | |
78 | * @abstract | |
79 | * Sets the requested QOS class and relative priority of the current thread. | |
80 | * | |
81 | * @discussion | |
82 | * The QOS class and relative priority represent an overall combination of | |
83 | * system quality of service attributes on a thread. | |
84 | * | |
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. | |
91 | * | |
92 | * @param __pthread | |
93 | * The current thread as returned by pthread_self(). | |
94 | * EINVAL will be returned if any other thread is provided. | |
95 | * | |
96 | * @param __qos_class | |
97 | * A QOS class value: | |
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. | |
105 | * | |
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. | |
111 | * | |
112 | * @return | |
113 | * Zero if successful, othwerise an errno value. | |
114 | */ | |
a0619f9c | 115 | __API_DEPRECATED_WITH_REPLACEMENT("pthread_set_qos_class_self_np", macos(10.10, 10.10), ios(8.0, 8.0)) |
f1a1da6c A |
116 | int |
117 | pthread_set_qos_class_np(pthread_t __pthread, | |
118 | qos_class_t __qos_class, | |
119 | int __relative_priority); | |
120 | ||
121 | /* Private interfaces for libdispatch to encode/decode specific values of pthread_priority_t. */ | |
122 | ||
123 | // Encode a class+priority pair into a pthread_priority_t, | |
a0619f9c | 124 | __API_AVAILABLE(macos(10.10), ios(8.0)) |
f1a1da6c A |
125 | pthread_priority_t |
126 | _pthread_qos_class_encode(qos_class_t qos_class, int relative_priority, unsigned long flags); | |
127 | ||
128 | // Decode a pthread_priority_t into a class+priority pair. | |
a0619f9c | 129 | __API_AVAILABLE(macos(10.10), ios(8.0)) |
f1a1da6c A |
130 | qos_class_t |
131 | _pthread_qos_class_decode(pthread_priority_t priority, int *relative_priority, unsigned long *flags); | |
132 | ||
a0619f9c A |
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)) | |
f1a1da6c A |
136 | pthread_priority_t |
137 | _pthread_qos_class_encode_workqueue(int queue_priority, unsigned long flags); | |
138 | ||
139 | #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL | |
a0619f9c | 140 | |
f1a1da6c | 141 | // Set QoS or voucher, or both, on pthread_self() |
a0619f9c | 142 | __API_AVAILABLE(macos(10.10), ios(8.0)) |
f1a1da6c A |
143 | int |
144 | _pthread_set_properties_self(_pthread_set_flags_t flags, pthread_priority_t priority, mach_port_t voucher); | |
145 | ||
146 | // Set self to fixed priority without disturbing QoS or priority | |
a0619f9c | 147 | __API_AVAILABLE(macos(10.10), ios(8.0)) |
f1a1da6c A |
148 | int |
149 | pthread_set_fixedpriority_self(void); | |
150 | ||
964d3577 | 151 | // Inverse of pthread_set_fixedpriority_self() |
a0619f9c | 152 | __API_AVAILABLE(macos(10.10), ios(8.0)) |
964d3577 A |
153 | int |
154 | pthread_set_timeshare_self(void); | |
155 | ||
a0619f9c A |
156 | /*! |
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). | |
161 | */ | |
162 | #define PTHREAD_MAX_PARALLELISM_PHYSICAL 0x1 | |
163 | ||
164 | /*! | |
165 | * @function pthread_qos_max_parallelism | |
166 | * | |
167 | * @abstract | |
168 | * Returns the number of compute units available for parallel computation at | |
169 | * a specified QoS class. | |
170 | * | |
171 | * @param qos | |
172 | * The specified QoS class. | |
173 | * | |
174 | * @param flags | |
175 | * 0 or PTHREAD_MAX_PARALLELISM_PHYSICAL. | |
176 | * | |
177 | * @return | |
178 | * The number of compute units available for parallel computation for the | |
179 | * specified QoS, or -1 on failure (with errno set accordingly). | |
180 | */ | |
181 | __API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0)) | |
182 | int | |
183 | pthread_qos_max_parallelism(qos_class_t qos, unsigned long flags); | |
184 | ||
185 | /*! | |
186 | * @function pthread_time_constraint_max_parallelism() | |
187 | * | |
188 | * @abstract | |
189 | * Returns the number of compute units available for parallel computation on | |
190 | * realtime threads. | |
191 | * | |
192 | * @param flags | |
193 | * 0 or PTHREAD_MAX_PARALLELISM_PHYSICAL. | |
194 | * | |
195 | * @return | |
196 | * The number of compute units available for parallel computation on realtime | |
197 | * threads, or -1 on failure (with errno set accordingly). | |
198 | */ | |
199 | __API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0)) | |
200 | int | |
201 | pthread_time_constraint_max_parallelism(unsigned long flags); | |
202 | ||
203 | #endif // __DARWIN_C_LEVEL >= __DARWIN_C_FULL | |
f1a1da6c A |
204 | |
205 | __END_DECLS | |
206 | ||
207 | #endif // KERNEL | |
208 | ||
209 | #endif //_QOS_PRIVATE_H |