]> git.saurik.com Git - apple/libpthread.git/blob - private/workqueue_private.h
libpthread-218.51.1.tar.gz
[apple/libpthread.git] / private / workqueue_private.h
1 /*
2 * Copyright (c) 2007, 2012 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 __PTHREAD_WORKQUEUE_H__
25 #define __PTHREAD_WORKQUEUE_H__
26
27 #include <sys/cdefs.h>
28 #include <sys/event.h>
29 #include <Availability.h>
30 #include <pthread/pthread.h>
31 #include <pthread/qos.h>
32 #ifndef _PTHREAD_BUILDING_PTHREAD_
33 #include <pthread/qos_private.h>
34 #endif
35
36 #define PTHREAD_WORKQUEUE_SPI_VERSION 20160427
37
38 /* Feature checking flags, returned by _pthread_workqueue_supported()
39 *
40 * Note: These bits should match the definition of PTHREAD_FEATURE_*
41 * bits defined in libpthread/kern/kern_internal.h */
42
43 #define WORKQ_FEATURE_DISPATCHFUNC 0x01 // pthread_workqueue_setdispatch_np is supported (or not)
44 #define WORKQ_FEATURE_FINEPRIO 0x02 // fine grained pthread workq priorities
45 #define WORKQ_FEATURE_MAINTENANCE 0x10 // QOS class maintenance
46 #define WORKQ_FEATURE_KEVENT 0x40 // Support for direct kevent delivery
47
48 /* Legacy dispatch priority bands */
49
50 #define WORKQ_NUM_PRIOQUEUE 4
51
52 #define WORKQ_HIGH_PRIOQUEUE 0 // high priority queue
53 #define WORKQ_DEFAULT_PRIOQUEUE 1 // default priority queue
54 #define WORKQ_LOW_PRIOQUEUE 2 // low priority queue
55 #define WORKQ_BG_PRIOQUEUE 3 // background priority queue
56 #define WORKQ_NON_INTERACTIVE_PRIOQUEUE 128 // libdispatch SPI level
57
58 /* Legacy dispatch workqueue function flags */
59 #define WORKQ_ADDTHREADS_OPTION_OVERCOMMIT 0x00000001
60
61 __BEGIN_DECLS
62
63 // Legacy callback prototype, used with pthread_workqueue_setdispatch_np
64 typedef void (*pthread_workqueue_function_t)(int queue_priority, int options, void *ctxt);
65 // New callback prototype, used with pthread_workqueue_init
66 typedef void (*pthread_workqueue_function2_t)(pthread_priority_t priority);
67
68 // Newer callback prototype, used in conjection with function2 when there are kevents to deliver
69 // both parameters are in/out parameters
70 #define WORKQ_KEVENT_EVENT_BUFFER_LEN 16
71 typedef void (*pthread_workqueue_function_kevent_t)(void **events, int *nevents);
72
73 // Initialises the pthread workqueue subsystem, passing the new-style callback prototype,
74 // the dispatchoffset and an unused flags field.
75 __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
76 int
77 _pthread_workqueue_init(pthread_workqueue_function2_t func, int offset, int flags);
78
79 __OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0)
80 int
81 _pthread_workqueue_init_with_kevent(pthread_workqueue_function2_t queue_func, pthread_workqueue_function_kevent_t kevent_func, int offset, int flags);
82
83 // Non-zero enables kill on current thread, zero disables it.
84 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2)
85 int
86 __pthread_workqueue_setkill(int);
87
88 // Dispatch function to be called when new worker threads are created.
89 __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_6_0)
90 int
91 pthread_workqueue_setdispatch_np(pthread_workqueue_function_t worker_func);
92
93 // Dispatch offset to be set in the kernel.
94 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
95 void
96 pthread_workqueue_setdispatchoffset_np(int offset);
97
98 // Request additional worker threads.
99 __OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_6_0)
100 int
101 pthread_workqueue_addthreads_np(int queue_priority, int options, int numthreads);
102
103 // Retrieve the supported pthread feature set
104 __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
105 int
106 _pthread_workqueue_supported(void);
107
108 // Request worker threads (fine grained priority)
109 __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
110 int
111 _pthread_workqueue_addthreads(int numthreads, pthread_priority_t priority);
112
113 __OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0)
114 int
115 _pthread_workqueue_set_event_manager_priority(pthread_priority_t priority);
116
117 // Apply a QoS override without allocating userspace memory
118 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
119 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
120 int
121 _pthread_qos_override_start_direct(mach_port_t thread, pthread_priority_t priority, void *resource);
122
123 // Drop a corresponding QoS override made above, if the resource matches
124 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
125 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
126 int
127 _pthread_qos_override_end_direct(mach_port_t thread, void *resource);
128
129 // Apply a QoS override without allocating userspace memory
130 __OSX_DEPRECATED(10.10, 10.12, "use _pthread_qos_override_start_direct()")
131 __IOS_DEPRECATED(8.0, 10.0, "use _pthread_qos_override_start_direct()")
132 __TVOS_DEPRECATED(8.0, 10.0, "use _pthread_qos_override_start_direct()")
133 __WATCHOS_DEPRECATED(1.0, 3.0, "use _pthread_qos_override_start_direct()")
134 int
135 _pthread_override_qos_class_start_direct(mach_port_t thread, pthread_priority_t priority);
136
137 // Drop a corresponding QoS override made above.
138 __OSX_DEPRECATED(10.10, 10.12, "use _pthread_qos_override_end_direct()")
139 __IOS_DEPRECATED(8.0, 10.0, "use _pthread_qos_override_end_direct()")
140 __TVOS_DEPRECATED(8.0, 10.0, "use _pthread_qos_override_end_direct()")
141 __WATCHOS_DEPRECATED(1.0, 3.0, "use _pthread_qos_override_end_direct()")
142 int
143 _pthread_override_qos_class_end_direct(mach_port_t thread);
144
145 // Apply a QoS override on a given workqueue thread.
146 __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
147 int
148 _pthread_workqueue_override_start_direct(mach_port_t thread, pthread_priority_t priority);
149
150 // Apply a QoS override on a given workqueue thread.
151 __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
152 __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
153 int
154 _pthread_workqueue_override_start_direct_check_owner(mach_port_t thread, pthread_priority_t priority, mach_port_t *ulock_addr);
155
156 // Drop all QoS overrides on the current workqueue thread.
157 __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
158 int
159 _pthread_workqueue_override_reset(void);
160
161 // Apply a QoS override on a given thread (can be non-workqueue as well) with a resource/queue token
162 __OSX_AVAILABLE_STARTING(__MAC_10_10_2, __IPHONE_NA)
163 int
164 _pthread_workqueue_asynchronous_override_add(mach_port_t thread, pthread_priority_t priority, void *resource);
165
166 // Reset overrides for the given resource for the current thread
167 __OSX_AVAILABLE_STARTING(__MAC_10_10_2, __IPHONE_NA)
168 int
169 _pthread_workqueue_asynchronous_override_reset_self(void *resource);
170
171 // Reset overrides for all resources for the current thread
172 __OSX_AVAILABLE_STARTING(__MAC_10_10_2, __IPHONE_NA)
173 int
174 _pthread_workqueue_asynchronous_override_reset_all_self(void);
175
176 __END_DECLS
177
178 #endif // __PTHREAD_WORKQUEUE_H__