authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-28 13:52:48-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-28 13:52:48-04:00
log0d79e0381601404b844b4912d15d20f4b529e837
treefe3f1b4546ce0116ec5bf7d5ee8e9d71104721b2
parent05456eb275dd1d5aee6630ffdc743057db73872f

canceling an await also cancels things awaiting it


1 files changed, 16 insertions(+), 0 deletions(-)

src/ir.cpp+16
......@@ -6831,6 +6831,8 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
68316831 IrBasicBlock *cleanup_block = ir_create_basic_block(irb, scope, "SuspendCleanup");
68326832 IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "SuspendResume");
68336833 IrBasicBlock *cancel_target_block = ir_create_basic_block(irb, scope, "CancelTarget");
6834 IrBasicBlock *do_cancel_block = ir_create_basic_block(irb, scope, "DoCancel");
6835 IrBasicBlock *do_defers_block = ir_create_basic_block(irb, scope, "DoDefers");
68346836
68356837 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);
68366838 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,
......@@ -6912,6 +6914,20 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
69126914 ir_mark_gen(ir_build_br(irb, scope, node, cleanup_block, const_bool_false));
69136915
69146916 ir_set_cursor_at_end_and_append_block(irb, cleanup_block);
6917 IrInstruction *my_mask_bits = ir_build_bin_op(irb, scope, node, IrBinOpBinOr, ptr_mask, is_canceled_mask, false);
6918 IrInstruction *my_prev_atomic_value = ir_build_atomic_rmw(irb, scope, node,
6919 usize_type_val, irb->exec->atomic_state_field_ptr, nullptr, my_mask_bits, nullptr,
6920 AtomicRmwOp_or, AtomicOrderSeqCst);
6921 IrInstruction *my_await_handle_addr = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, my_prev_atomic_value, ptr_mask, false);
6922 IrInstruction *have_my_await_handle = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, my_await_handle_addr, zero, false);
6923 ir_build_cond_br(irb, scope, node, have_my_await_handle, do_cancel_block, do_defers_block, const_bool_false);
6924
6925 ir_set_cursor_at_end_and_append_block(irb, do_cancel_block);
6926 IrInstruction *my_await_handle = ir_build_int_to_ptr(irb, scope, node, promise_type_val, my_await_handle_addr);
6927 ir_gen_cancel_target(irb, scope, node, my_await_handle);
6928 ir_mark_gen(ir_build_br(irb, scope, node, do_defers_block, const_bool_false));
6929
6930 ir_set_cursor_at_end_and_append_block(irb, do_defers_block);
69156931 ir_gen_defers_for_block(irb, scope, outer_scope, true);
69166932 ir_mark_gen(ir_build_br(irb, scope, node, irb->exec->coro_final_cleanup_block, const_bool_false));
69176933