From 75fdce43ef567668bb89508b9b8ce0df7efaa569 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson
Date: Mon, 6 Feb 2017 17:15:52 +0100
Subject: erts: Add enif_monitor_process and enif_demonitor_process
---
erts/doc/src/erl_nif.xml | 67 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 65 insertions(+), 2 deletions(-)
(limited to 'erts/doc/src/erl_nif.xml')
diff --git a/erts/doc/src/erl_nif.xml b/erts/doc/src/erl_nif.xml
index 8cdfc80879..bd72bdb691 100644
--- a/erts/doc/src/erl_nif.xml
+++ b/erts/doc/src/erl_nif.xml
@@ -711,6 +711,21 @@ typedef struct {
typedef void ErlNifResourceDtor(ErlNifEnv* env, void* obj);
The function prototype of a resource destructor function.
+ The obj argument is a pointer to the resource. The only
+ allowed use for the resource in the destructor is to access its
+ user data one final time. The destructor is guaranteed to be the
+ last callback before the resource is deallocated.
+
+ ErlNifResourceDown
+ -
+
+typedef void ErlNifResourceDown(ErlNifEnv* env, void* obj, const ErlNifPid* pid, const ErlNifMonitor* mon);
+ The function prototype of a resource down function,
+ called on the behalf of
+ enif_monitor_process. obj is the resource, pid
+ is the identity of the monitored process that is exiting, and mon
+ is the identity of the monitor.
+
ErlNifResourceStop
-
@@ -1021,6 +1036,29 @@ typedef enum {
+
+ intenif_demonitor_process(ErlNifEnv* env, void* obj,
+ const ErlNifMonitor* mon)
+ Cancel a process monitor.
+
+
+
Cancels a monitor created earlier with
+ enif_monitor_process. Argument obj is a pointer
+ to the resource holding the monitor and *mon identifies the monitor.
+ Returns 0 if the monitor was successfully identified and removed.
+ Returns a non-zero value if the monitor could not be identified, which means
+ it was either
+
+ - never created for this resource
+ - already triggered
+ - just about to be triggered by a concurrent thread
+
+ This function is only thread-safe when the emulator with SMP support
+ is used. It can only be used in a non-SMP emulator from a NIF-calling
+ thread.
+
+
+
int
enif_equal_tids(ErlNifTid tid1, ErlNifTid tid2)
@@ -2136,6 +2174,31 @@ enif_map_iterator_destroy(env, &iter);
+
+ intenif_monitor_process(ErlNifEnv* env, void* obj,
+ const ErlNifPid* target_pid, ErlNifMonitor* mon)
+ Monitor a process from a resource.
+
+
+ Starts monitoring a process from a resource. When a process is
+ monitored, a process exit results in a call to the provided
+
+ down callback associated with the resource type.
+ Argument obj is pointer to the resource to hold the monitor and
+ *target_pid identifies the local process to be monitored.
+ If mon is not NULL, a successful call stores the
+ identity of the monitor in the struct pointed to by mon.
+ This identifier is used to refer to the monitor for later removal or
+ compare. A monitor is automatically removed when it triggers or when
+ the resource is deallocated.
+ Returns 0 on success, < 0 if no down callback is
+ provided, and > 0 if the process is no longer alive.
+ This function is only thread-safe when the emulator with SMP support
+ is used. It can only be used in a non-SMP emulator from a NIF-calling
+ thread.
+
+
+
ErlNifTime
enif_monotonic_time(ErlNifTimeUnit time_unit)
@@ -2268,8 +2331,8 @@ enif_map_iterator_destroy(env, &iter);
used together with enif_select.
Argument init is a pointer to an
ErlNifResourceTypeInit
- structure that contains the function pointers for the destructor and the stop callback
- of the resource type.
+ structure that contains the function pointers for destructor, down and stop callbacks
+ for the resource type.
--
cgit v1.2.3