- STK_CHK_GEN( WDS(2), R1_PTR, unblockAsyncExceptionszh_fast);
-
- if (StgTSO_blocked_exceptions(CurrentTSO) != NULL) {
-#if defined(GRAN) || defined(PAR)
- foreign "C" awakenBlockedQueue(MyCapability() "ptr", StgTSO_blocked_exceptions(CurrentTSO) "ptr",
- StgTSO_block_info(CurrentTSO) "ptr");
-#else
- foreign "C" awakenBlockedQueue(MyCapability() "ptr", StgTSO_blocked_exceptions(CurrentTSO) "ptr");
-#endif
- StgTSO_blocked_exceptions(CurrentTSO) = NULL;
+ STK_CHK_GEN( WDS(4), R1_PTR, stg_unmaskAsyncExceptionszh);
+ /* 4 words: one for the unblock frame, 3 for setting up the
+ * stack to call maybePerformBlockedException() below.
+ */
+
+ /* If exceptions are already unblocked, there's nothing to do */
+ if ((TO_W_(StgTSO_flags(CurrentTSO)) & TSO_BLOCKEX) != 0) {
+
+ /* avoid growing the stack unnecessarily */
+ if (Sp(0) == stg_unmaskAsyncExceptionszh_ret_info) {
+ Sp_adj(1);
+ } else {
+ Sp_adj(-1);
+ if ((TO_W_(StgTSO_flags(CurrentTSO)) & TSO_INTERRUPTIBLE) != 0) {
+ Sp(0) = stg_maskAsyncExceptionszh_ret_info;
+ } else {
+ Sp(0) = stg_maskUninterruptiblezh_ret_info;
+ }
+ }
+
+ StgTSO_flags(CurrentTSO) = %lobits32(
+ TO_W_(StgTSO_flags(CurrentTSO)) & ~(TSO_BLOCKEX|TSO_INTERRUPTIBLE));
+
+ /* Eagerly raise a blocked exception, if there is one */
+ if (StgTSO_blocked_exceptions(CurrentTSO) != END_TSO_QUEUE) {
+ /*
+ * We have to be very careful here, as in killThread#, since
+ * we are about to raise an async exception in the current
+ * thread, which might result in the thread being killed.
+ *
+ * Now, if we are to raise an exception in the current
+ * thread, there might be an update frame above us on the
+ * stack due to unsafePerformIO. Hence, the stack must
+ * make sense, because it is about to be snapshotted into
+ * an AP_STACK.
+ */
+ Sp_adj(-3);
+ Sp(2) = stg_ap_v_info;
+ Sp(1) = R1;
+ Sp(0) = stg_enter_info;
+
+ SAVE_THREAD_STATE();
+ (r) = foreign "C" maybePerformBlockedException (MyCapability() "ptr",
+ CurrentTSO "ptr") [R1];
+
+ if (r != 0::CInt) {
+ if (StgTSO_what_next(CurrentTSO) == ThreadKilled::I16) {
+ jump stg_threadFinished;
+ } else {
+ LOAD_THREAD_STATE();
+ ASSERT(StgTSO_what_next(CurrentTSO) == ThreadRunGHC::I16);
+ jump %ENTRY_CODE(Sp(0));
+ }
+ } else {
+ /* we'll just call R1 directly, below */
+ Sp_adj(3);
+ }
+ }