+static zone_t thread_call_zone;
+static struct wait_queue daemon_wqueue;
+
+struct thread_call_group {
+ queue_head_t pending_queue;
+ uint32_t pending_count;
+
+ queue_head_t delayed_queue;
+ uint32_t delayed_count;
+
+ timer_call_data_t delayed_timer;
+ timer_call_data_t dealloc_timer;
+
+ struct wait_queue idle_wqueue;
+ uint32_t idle_count, active_count;
+
+ integer_t pri;
+ uint32_t target_thread_count;
+ uint64_t idle_timestamp;
+
+ uint32_t flags;
+ sched_call_t sched_call;
+};
+
+typedef struct thread_call_group *thread_call_group_t;
+
+#define TCG_PARALLEL 0x01
+#define TCG_DEALLOC_ACTIVE 0x02
+
+#define THREAD_CALL_GROUP_COUNT 4
+#define THREAD_CALL_THREAD_MIN 4
+#define INTERNAL_CALL_COUNT 768
+#define THREAD_CALL_DEALLOC_INTERVAL_NS (5 * 1000 * 1000) /* 5 ms */
+#define THREAD_CALL_ADD_RATIO 4
+#define THREAD_CALL_MACH_FACTOR_CAP 3
+
+static struct thread_call_group thread_call_groups[THREAD_CALL_GROUP_COUNT];
+static boolean_t thread_call_daemon_awake;
+static thread_call_data_t internal_call_storage[INTERNAL_CALL_COUNT];
+static queue_head_t thread_call_internal_queue;
+static uint64_t thread_call_dealloc_interval_abs;
+
+static __inline__ thread_call_t _internal_call_allocate(void);
+static __inline__ void _internal_call_release(thread_call_t call);
+static __inline__ boolean_t _pending_call_enqueue(thread_call_t call, thread_call_group_t group);
+static __inline__ boolean_t _delayed_call_enqueue(thread_call_t call, thread_call_group_t group, uint64_t deadline);
+static __inline__ boolean_t _call_dequeue(thread_call_t call, thread_call_group_t group);
+static __inline__ void thread_call_wake(thread_call_group_t group);
+static __inline__ void _set_delayed_call_timer(thread_call_t call, thread_call_group_t group);
+static boolean_t _remove_from_pending_queue(thread_call_func_t func, thread_call_param_t param0, boolean_t remove_all);
+static boolean_t _remove_from_delayed_queue(thread_call_func_t func, thread_call_param_t param0, boolean_t remove_all);
+static void thread_call_daemon(void *arg);
+static void thread_call_thread(thread_call_group_t group, wait_result_t wres);
+extern void thread_call_delayed_timer(timer_call_param_t p0, timer_call_param_t p1);
+static void thread_call_dealloc_timer(timer_call_param_t p0, timer_call_param_t p1);
+static void thread_call_group_setup(thread_call_group_t group, thread_call_priority_t pri, uint32_t target_thread_count, boolean_t parallel);
+static void sched_call_thread(int type, thread_t thread);
+static void thread_call_start_deallocate_timer(thread_call_group_t group);
+static void thread_call_wait_locked(thread_call_t call);