@@ -150,18 +150,45 @@ struct Context
150
150
typedef struct Context Context ;
151
151
#endif
152
152
153
- #define CONTEXT_MONITOR_RESOURCE_TAG 0x2
154
- #define CONTEXT_MONITOR_MONITORED_PID_TAG 0x3
155
- #define CONTEXT_MONITOR_MONITORING_PID_TAG 0x1
153
+ enum ContextMonitorType
154
+ {
155
+ CONTEXT_MONITOR_LINK_LOCAL ,
156
+ CONTEXT_MONITOR_MONITORING_LOCAL ,
157
+ CONTEXT_MONITOR_MONITORED_LOCAL ,
158
+ CONTEXT_MONITOR_RESOURCE ,
159
+ };
160
+
161
+ #define UNLINK_ID_LINK_ACTIVE 0x0
156
162
157
163
/**
158
164
* @brief A regular monitor or a half link.
159
165
*/
160
166
struct Monitor
161
167
{
162
168
struct ListHead monitor_list_head ;
163
- uint64_t ref_ticks ; // 0 for links
164
- term monitor_obj ; // pid for links, CONTEXT_MONITOR_*_TAG for monitors
169
+ enum ContextMonitorType monitor_type ;
170
+ };
171
+
172
+ struct LinkLocalMonitor
173
+ {
174
+ struct Monitor monitor ;
175
+ uint64_t unlink_id ;
176
+ term link_local_process_id ;
177
+ };
178
+
179
+ struct MonitorLocalMonitor
180
+ {
181
+ struct Monitor monitor ;
182
+ uint64_t ref_ticks ;
183
+ term monitor_obj ;
184
+ };
185
+
186
+ // The other half is called ResourceMonitor and is a linked list of resources
187
+ struct ResourceContextMonitor
188
+ {
189
+ struct Monitor monitor ;
190
+ uint64_t ref_ticks ;
191
+ void * resource_obj ;
165
192
};
166
193
167
194
struct ExtendedRegister
@@ -364,9 +391,10 @@ void context_process_kill_signal(Context *ctx, struct TermSignal *signal);
364
391
* @brief Process a process info request signal.
365
392
*
366
393
* @param ctx the context being executed
367
- * @param signal the kill message
394
+ * @param signal the process info signal
395
+ * @param process_table_locked whether process table is already locked
368
396
*/
369
- void context_process_process_info_request_signal (Context * ctx , struct BuiltInAtomRequestSignal * signal );
397
+ void context_process_process_info_request_signal (Context * ctx , struct BuiltInAtomRequestSignal * signal , bool process_table_locked );
370
398
371
399
/**
372
400
* @brief Process a trap answer signal.
@@ -395,6 +423,23 @@ void context_process_flush_monitor_signal(Context *ctx, uint64_t ref_ticks, bool
395
423
*/
396
424
bool context_process_signal_set_group_leader (Context * ctx , struct TermSignal * signal );
397
425
426
+ /**
427
+ * @brief Process a link exit signal.
428
+ *
429
+ * @param ctx the context being executed
430
+ * @param signal the signal with the exit info tuple
431
+ * @return true if the process is trapping exit and info tuple was enqueued as a message;
432
+ */
433
+ bool context_process_link_exit_signal (Context * ctx , struct TermSignal * signal );
434
+
435
+ /**
436
+ * @brief Process a monitor down signal.
437
+ *
438
+ * @param ctx the context being executed
439
+ * @param signal the signal with the down info tuple
440
+ */
441
+ void context_process_monitor_down_signal (Context * ctx , struct TermSignal * signal );
442
+
398
443
/**
399
444
* @brief Get process information.
400
445
*
@@ -431,30 +476,53 @@ struct Monitor *monitor_new(term monitor_pid, uint64_t ref_ticks, bool is_monito
431
476
*
432
477
* @param resource resource object
433
478
* @param ref_ticks reference associated with the monitor
434
- * @param process_id process being monitored
435
479
* @return the allocated resource monitor or NULL if allocation failed
436
480
*/
437
481
struct Monitor * monitor_resource_monitor_new (void * resource , uint64_t ref_ticks );
438
482
439
483
/**
440
484
* @brief Half-unlink process to another process
441
- * @details Called within the process only. For the other end of the
442
- * link, an UnlinkSignal is sent that calls this function .
485
+ * @details If process is found, an unlink id is generated and the link is
486
+ * deactivated .
443
487
*
444
488
* @param ctx the context being executed
445
- * @param monitor_pid process to unlink from
446
- * @return 0 on success
489
+ * @param link_pid process to unlink from
490
+ * @param unlink_id on output, unlink id to send to the target process
491
+ * @return true if process was found
447
492
*/
448
- void context_unlink (Context * ctx , term monitor_pid );
493
+ bool context_set_unlink_id (Context * ctx , term link_pid , uint64_t * unlink_id );
449
494
450
495
/**
451
- * @brief Destroy a monitor on a process.
452
- * @details Called within the process only. This function is called from
453
- * DemonitorSignal.
496
+ * @brief Half-unlink process to another process
497
+ * @details Called within the process only when an UnlinkID signal is received.
498
+ * If link is found, remove it and sends an UnlinkIDAck signal to the linked
499
+ * process.
500
+ *
501
+ * @param ctx the context being executed
502
+ * @param link_pid process to unlink from
503
+ * @param unlink_id unlink id from the signal
504
+ * @param process_table_locked whether process table is already locked
505
+ */
506
+ void context_ack_unlink (Context * ctx , term link_pid , uint64_t unlink_id , bool process_table_locked );
507
+
508
+ /**
509
+ * @brief Half-unlink process to another process
510
+ * @details Called within the process only when an UnlinkIDAck signal is received.
511
+ * If link is found and matches, remove it.
454
512
*
455
513
* @param ctx the context being executed
514
+ * @param link_pid process to unlink from
515
+ * @param unlink_id unlink id from the signal
516
+ */
517
+ void context_unlink_ack (Context * ctx , term link_pid , uint64_t unlink_id );
518
+
519
+ /**
520
+ * @brief Destroy a monitor on a process (monitoring, monitored or resource)
521
+ * @details Called within the process only. This function is called from
522
+ * DemonitorSignal as well as demonitor nif on monitoring process.
523
+ *
524
+ * @param ctx the context being executed (monitoring or monitored)
456
525
* @param ref_ticks reference of the monitor to remove
457
- * @return 0 on success
458
526
*/
459
527
void context_demonitor (Context * ctx , uint64_t ref_ticks );
460
528
@@ -477,9 +545,12 @@ term context_get_monitor_pid(Context *ctx, uint64_t ref_ticks, bool *is_monitori
477
545
* only exist once.
478
546
*
479
547
* @param ctx the context being executed
480
- * @param new_monitor monitor object to add
548
+ * @param new_monitor monitor object to add (ownership belongs to context
549
+ * afterwards)
550
+ * @return true if the monitor was added, false if it already existed and
551
+ * new_monitor waw freed.
481
552
*/
482
- void context_add_monitor (Context * ctx , struct Monitor * new_monitor );
553
+ bool context_add_monitor (Context * ctx , struct Monitor * new_monitor );
483
554
484
555
#ifdef __cplusplus
485
556
}
0 commit comments