+ if (wait_option) {
+ assert_wait_timeout((event_t)assert_wait_timeout, interruptible, option_time, scale_factor);
+ } else {
+ disable_preemption();
+ bool should_yield = SCHED(thread_should_yield)(current_processor(), current_thread());
+ enable_preemption();
+
+ if (should_yield == false) {
+ /* Early-return if yielding to the scheduler will not be beneficial */
+ return KERN_SUCCESS;
+ }
+
+ if (depress_option) {
+ thread_depress_ms(option_time);
+ }
+ }
+
+ thread_yield_with_continuation(thread_switch_continue, (void *)(intptr_t)option);
+ __builtin_unreachable();
+}
+
+void
+thread_yield_with_continuation(
+ thread_continue_t continuation,
+ void *parameter)
+{
+ assert(continuation);
+ thread_block_reason(continuation, parameter, AST_YIELD);
+ __builtin_unreachable();
+}
+
+/* This function is called after an assert_wait(), therefore it must not
+ * cause another wait until after the thread_run() or thread_block()
+ *
+ * Following are the calling convention for thread ref deallocation.
+ *
+ * 1) If no continuation is provided, then thread ref is consumed.
+ * (thread_handoff_deallocate convention).
+ *
+ * 2) If continuation is provided with option THREAD_HANDOFF_SETRUN_NEEDED
+ * then thread ref is always consumed.
+ *
+ * 3) If continuation is provided with option THREAD_HANDOFF_NONE then thread
+ * ref is not consumed and it is upto the continuation to deallocate
+ * the thread reference.
+ */
+static wait_result_t
+thread_handoff_internal(thread_t thread, thread_continue_t continuation,
+ void *parameter, thread_handoff_option_t option)
+{
+ thread_t self = current_thread();