]> git.saurik.com Git - apple/libpthread.git/blobdiff - private/workqueue_private.h
libpthread-416.60.2.tar.gz
[apple/libpthread.git] / private / workqueue_private.h
index 74b3a1bab4ffdccbfbeeb38a69ba3c6f5042d219..11b0e5e143b565b685b34d4b6defe52dadb37d55 100644 (file)
@@ -24,6 +24,7 @@
 #ifndef __PTHREAD_WORKQUEUE_H__
 #define __PTHREAD_WORKQUEUE_H__
 
+#include <stdbool.h>
 #include <sys/cdefs.h>
 #include <sys/event.h>
 #include <Availability.h>
@@ -33,7 +34,7 @@
 #include <pthread/qos_private.h>
 #endif
 
-#define PTHREAD_WORKQUEUE_SPI_VERSION 20150304
+#define PTHREAD_WORKQUEUE_SPI_VERSION 20170201
 
 /* Feature checking flags, returned by _pthread_workqueue_supported()
  *
@@ -43,7 +44,8 @@
 #define WORKQ_FEATURE_DISPATCHFUNC     0x01    // pthread_workqueue_setdispatch_np is supported (or not)
 #define WORKQ_FEATURE_FINEPRIO         0x02    // fine grained pthread workq priorities
 #define WORKQ_FEATURE_MAINTENANCE      0x10    // QOS class maintenance
-#define WORKQ_FEATURE_KEVENT        0x20    // Support for direct kevent delivery
+#define WORKQ_FEATURE_KEVENT        0x40    // Support for direct kevent delivery
+#define WORKQ_FEATURE_WORKLOOP      0x80    // Support for direct workloop requests
 
 /* Legacy dispatch priority bands */
 
@@ -64,89 +66,144 @@ __BEGIN_DECLS
 typedef void (*pthread_workqueue_function_t)(int queue_priority, int options, void *ctxt);
 // New callback prototype, used with pthread_workqueue_init
 typedef void (*pthread_workqueue_function2_t)(pthread_priority_t priority);
+
 // Newer callback prototype, used in conjection with function2 when there are kevents to deliver
 // both parameters are in/out parameters
+#define WORKQ_KEVENT_EVENT_BUFFER_LEN 16
 typedef void (*pthread_workqueue_function_kevent_t)(void **events, int *nevents);
 
+typedef void (*pthread_workqueue_function_workloop_t)(uint64_t *workloop_id, void **events, int *nevents);
+
+#define PTHREAD_WORKQUEUE_CONFIG_VERSION               2
+#define PTHREAD_WORKQUEUE_CONFIG_MIN_SUPPORTED_VERSION 1
+#define PTHREAD_WORKQUEUE_CONFIG_SUPPORTED_FLAGS       0
+struct pthread_workqueue_config {
+       uint32_t flags;
+       uint32_t version;
+       pthread_workqueue_function_kevent_t kevent_cb;
+       pthread_workqueue_function_workloop_t workloop_cb;
+       pthread_workqueue_function2_t workq_cb;
+       uint64_t queue_serialno_offs;
+       uint64_t queue_label_offs;
+};
+
+__API_AVAILABLE(macos(10.15), ios(13.0))
+int
+pthread_workqueue_setup(struct pthread_workqueue_config *cfg, size_t cfg_size);
+
 // Initialises the pthread workqueue subsystem, passing the new-style callback prototype,
 // the dispatchoffset and an unused flags field.
-__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
+__API_AVAILABLE(macos(10.10), ios(8.0))
 int
 _pthread_workqueue_init(pthread_workqueue_function2_t func, int offset, int flags);
 
-__OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0)
+__API_AVAILABLE(macos(10.11), ios(9.0))
 int
 _pthread_workqueue_init_with_kevent(pthread_workqueue_function2_t queue_func, pthread_workqueue_function_kevent_t kevent_func, int offset, int flags);
 
+__API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
+int
+_pthread_workqueue_init_with_workloop(pthread_workqueue_function2_t queue_func, pthread_workqueue_function_kevent_t kevent_func, pthread_workqueue_function_workloop_t workloop_func, int offset, int flags);
+
 // Non-zero enables kill on current thread, zero disables it.
-__OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2)
+__API_AVAILABLE(macos(10.6), ios(3.2))
 int
 __pthread_workqueue_setkill(int);
 
 // Dispatch function to be called when new worker threads are created.
-__OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_6_0)
+__API_AVAILABLE(macos(10.8), ios(6.0))
 int
 pthread_workqueue_setdispatch_np(pthread_workqueue_function_t worker_func);
 
 // Dispatch offset to be set in the kernel.
-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
+__API_AVAILABLE(macos(10.9), ios(7.0))
 void
 pthread_workqueue_setdispatchoffset_np(int offset);
 
 // Request additional worker threads.
-__OSX_AVAILABLE_STARTING(__MAC_10_8, __IPHONE_6_0)
+__API_AVAILABLE(macos(10.8), ios(6.0))
 int
 pthread_workqueue_addthreads_np(int queue_priority, int options, int numthreads);
 
 // Retrieve the supported pthread feature set
-__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
+__API_AVAILABLE(macos(10.10), ios(8.0))
 int
 _pthread_workqueue_supported(void);
 
 // Request worker threads (fine grained priority)
-__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
+__API_AVAILABLE(macos(10.10), ios(8.0))
 int
 _pthread_workqueue_addthreads(int numthreads, pthread_priority_t priority);
 
-__OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0)
+// Should this thread return to the kernel?
+__API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
+bool
+_pthread_workqueue_should_narrow(pthread_priority_t priority);
+
+__API_AVAILABLE(macos(10.11), ios(9.0))
 int
 _pthread_workqueue_set_event_manager_priority(pthread_priority_t priority);
 
 // Apply a QoS override without allocating userspace memory
-__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
+__API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
+int
+_pthread_qos_override_start_direct(mach_port_t thread, pthread_priority_t priority, void *resource);
+
+// Drop a corresponding QoS override made above, if the resource matches
+__API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
+int
+_pthread_qos_override_end_direct(mach_port_t thread, void *resource);
+
+// Apply a QoS override without allocating userspace memory
+__API_DEPRECATED_WITH_REPLACEMENT("_pthread_qos_override_start_direct",
+               macos(10.10, 10.12), ios(8.0, 10.0), tvos(8.0, 10.0), watchos(1.0, 3.0))
 int
 _pthread_override_qos_class_start_direct(mach_port_t thread, pthread_priority_t priority);
 
 // Drop a corresponding QoS override made above.
-__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
+__API_DEPRECATED_WITH_REPLACEMENT("_pthread_qos_override_end_direct",
+               macos(10.10, 10.12), ios(8.0, 10.0), tvos(8.0, 10.0), watchos(1.0, 3.0))
 int
 _pthread_override_qos_class_end_direct(mach_port_t thread);
 
 // Apply a QoS override on a given workqueue thread.
-__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
+__API_AVAILABLE(macos(10.10), ios(8.0))
 int
 _pthread_workqueue_override_start_direct(mach_port_t thread, pthread_priority_t priority);
 
+// Apply a QoS override on a given workqueue thread.
+__API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
+int
+_pthread_workqueue_override_start_direct_check_owner(mach_port_t thread, pthread_priority_t priority, mach_port_t *ulock_addr);
+
 // Drop all QoS overrides on the current workqueue thread.
-__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0)
+__API_AVAILABLE(macos(10.10), ios(8.0))
 int
 _pthread_workqueue_override_reset(void);
 
 // Apply a QoS override on a given thread (can be non-workqueue as well) with a resource/queue token
-__OSX_AVAILABLE_STARTING(__MAC_10_10_2, __IPHONE_NA)
+__API_AVAILABLE(macos(10.10.2))
 int
 _pthread_workqueue_asynchronous_override_add(mach_port_t thread, pthread_priority_t priority, void *resource);
 
 // Reset overrides for the given resource for the current thread
-__OSX_AVAILABLE_STARTING(__MAC_10_10_2, __IPHONE_NA)
+__API_AVAILABLE(macos(10.10.2))
 int
 _pthread_workqueue_asynchronous_override_reset_self(void *resource);
 
 // Reset overrides for all resources for the current thread
-__OSX_AVAILABLE_STARTING(__MAC_10_10_2, __IPHONE_NA)
+__API_AVAILABLE(macos(10.10.2))
 int
 _pthread_workqueue_asynchronous_override_reset_all_self(void);
 
+__API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+int
+_pthread_workloop_create(uint64_t workloop_id, uint64_t options, pthread_attr_t *attr);
+
+__API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+int
+_pthread_workloop_destroy(uint64_t workloop_id);
+
 __END_DECLS
 
 #endif // __PTHREAD_WORKQUEUE_H__