@@ -248,6 +248,15 @@ void context_destroy(Context *ctx)
248
248
free (ctx );
249
249
}
250
250
251
+ static inline term term_pid_or_port_from_context (const Context * ctx )
252
+ {
253
+ if (ctx -> native_handler != NULL ) {
254
+ return term_port_from_local_process_id (ctx -> process_id );
255
+ } else {
256
+ return term_from_local_process_id (ctx -> process_id );
257
+ }
258
+ }
259
+
251
260
void context_process_kill_signal (Context * ctx , struct TermSignal * signal )
252
261
{
253
262
// exit_reason is one of the roots when garbage collecting
@@ -589,11 +598,7 @@ static struct ResourceContextMonitor *context_monitors_handle_terminate(Context
589
598
// Prepare the message on ctx's heap which will be freed afterwards.
590
599
term info_tuple = term_alloc_tuple (3 , & ctx -> heap );
591
600
term_put_tuple_element (info_tuple , 0 , EXIT_ATOM );
592
- if (ctx -> native_handler != NULL ) {
593
- term_put_tuple_element (info_tuple , 1 , term_port_from_local_process_id (ctx -> process_id ));
594
- } else {
595
- term_put_tuple_element (info_tuple , 1 , term_from_local_process_id (ctx -> process_id ));
596
- }
601
+ term_put_tuple_element (info_tuple , 1 , term_pid_or_port_from_context (ctx ));
597
602
term_put_tuple_element (info_tuple , 2 , ctx -> exit_reason );
598
603
mailbox_send_term_signal (target , LinkExitSignal , info_tuple );
599
604
}
@@ -616,16 +621,15 @@ static struct ResourceContextMonitor *context_monitors_handle_terminate(Context
616
621
// Prepare the message on ctx's heap which will be freed afterwards.
617
622
term ref = term_from_ref_ticks (monitored_monitor -> ref_ticks , & ctx -> heap );
618
623
624
+ term port_or_process = term_pid_or_port_from_context (ctx );
625
+ term port_or_process_atom
626
+ = term_is_local_port (port_or_process ) ? PORT_ATOM : PROCESS_ATOM ;
627
+
619
628
term info_tuple = term_alloc_tuple (5 , & ctx -> heap );
620
629
term_put_tuple_element (info_tuple , 0 , DOWN_ATOM );
621
630
term_put_tuple_element (info_tuple , 1 , ref );
622
- if (ctx -> native_handler != NULL ) {
623
- term_put_tuple_element (info_tuple , 2 , PORT_ATOM );
624
- term_put_tuple_element (info_tuple , 3 , term_port_from_local_process_id (ctx -> process_id ));
625
- } else {
626
- term_put_tuple_element (info_tuple , 2 , PROCESS_ATOM );
627
- term_put_tuple_element (info_tuple , 3 , term_from_local_process_id (ctx -> process_id ));
628
- }
631
+ term_put_tuple_element (info_tuple , 2 , port_or_process_atom );
632
+ term_put_tuple_element (info_tuple , 3 , port_or_process );
629
633
term_put_tuple_element (info_tuple , 4 , ctx -> exit_reason );
630
634
631
635
mailbox_send_term_signal (target , MonitorDownSignal , info_tuple );
@@ -770,12 +774,7 @@ void context_ack_unlink(Context *ctx, term link_pid, uint64_t unlink_id, bool pr
770
774
target = globalcontext_get_process_lock (ctx -> global , local_process_id );
771
775
}
772
776
if (LIKELY (target )) {
773
- term self_pid ;
774
- if (ctx -> native_handler != NULL ) {
775
- self_pid = term_port_from_local_process_id (ctx -> process_id );
776
- } else {
777
- self_pid = term_from_local_process_id (ctx -> process_id );
778
- }
777
+ term self_pid = term_pid_or_port_from_context (ctx );
779
778
mailbox_send_immediate_ref_signal (target , UnlinkIDAckSignal , self_pid , unlink_id );
780
779
if (!process_table_locked ) {
781
780
globalcontext_get_process_unlock (ctx -> global , target );
0 commit comments