- /*
- * Check for normal preemption
- */
- reasons &= AST_BLOCK;
- if (reasons == 0) {
- disable_preemption();
- myprocessor = current_processor();
- if (csw_needed(self, myprocessor))
- reasons = AST_BLOCK;
- enable_preemption();
- }
- if ( (reasons & AST_BLOCK) &&
- wait_queue_assert_possible(self) ) {
- counter(c_ast_taken_block++);
- thread_block_reason(thread_exception_return, AST_BLOCK);
+ /*
+ * Thread APC hook.
+ */
+ if (reasons & AST_APC)
+ act_execute_returnhandlers();
+
+ ml_set_interrupts_enabled(FALSE);
+
+ /*
+ * Check for preemption.
+ */
+ if (reasons & AST_PREEMPT) {
+ processor_t myprocessor = current_processor();
+
+ if (csw_needed(thread, myprocessor))
+ reasons = AST_PREEMPT;
+ else
+ reasons = AST_NONE;
+ }
+ if ( (reasons & AST_PREEMPT) &&
+ wait_queue_assert_possible(thread) ) {
+ counter(c_ast_taken_block++);
+ thread_block_reason((thread_continue_t)thread_exception_return, NULL, AST_PREEMPT);
+ }
+ }