context.h

Include dependency graph for context.h:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "7" [label="stdbool.h" tooltip="stdbool.h"] "24" [label="refc_binary.h" tooltip="refc_binary.h"] "4" [label="atom.h" tooltip="atom.h"] "10" [label="assert.h" tooltip="assert.h"] "22" [label="utils.h" tooltip="utils.h"] "15" [label="synclist.h" tooltip="synclist.h"] "14" [label="list.h" tooltip="list.h"] "3" [label="stdint.h" tooltip="stdint.h"] "5" [label="stdlib.h" tooltip="stdlib.h"] "1" [label="/__w/AtomVM/AtomVM/src/libAtomVM/context.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/context.h" fillcolor="#BFBFBF"] "21" [label="memory.h" tooltip="memory.h"] "25" [label="resources.h" tooltip="resources.h"] "18" [label="term.h" tooltip="term.h"] "23" [label="stddef.h" tooltip="stddef.h"] "8" [label="erl_nif.h" tooltip="erl_nif.h"] "11" [label="limits.h" tooltip="limits.h"] "6" [label="atom_table.h" tooltip="atom_table.h"] "19" [label="sys/types.h" tooltip="sys/types.h"] "20" [label="string.h" tooltip="string.h"] "9" [label="term_typedef.h" tooltip="term_typedef.h"] "2" [label="globalcontext.h" tooltip="globalcontext.h"] "17" [label="smp.h" tooltip="smp.h"] "27" [label="timer_list.h" tooltip="timer_list.h"] "26" [label="mailbox.h" tooltip="mailbox.h"] "16" [label="stdio.h" tooltip="stdio.h"] "13" [label="ets.h" tooltip="ets.h"] "12" [label="inttypes.h" tooltip="inttypes.h"] "24" -> "7" [dir=forward tooltip="include"] "24" -> "5" [dir=forward tooltip="include"] "24" -> "14" [dir=forward tooltip="include"] "24" -> "25" [dir=forward tooltip="include"] "4" -> "3" [dir=forward tooltip="include"] "4" -> "5" [dir=forward tooltip="include"] "22" -> "23" [dir=forward tooltip="include"] "22" -> "16" [dir=forward tooltip="include"] "22" -> "5" [dir=forward tooltip="include"] "15" -> "16" [dir=forward tooltip="include"] "15" -> "14" [dir=forward tooltip="include"] "15" -> "17" [dir=forward tooltip="include"] "14" -> "7" [dir=forward tooltip="include"] "1" -> "2" [dir=forward tooltip="include"] "1" -> "14" [dir=forward tooltip="include"] "1" -> "26" [dir=forward tooltip="include"] "1" -> "17" [dir=forward tooltip="include"] "1" -> "18" [dir=forward tooltip="include"] "1" -> "27" [dir=forward tooltip="include"] "21" -> "3" [dir=forward tooltip="include"] "21" -> "5" [dir=forward tooltip="include"] "21" -> "8" [dir=forward tooltip="include"] "21" -> "9" [dir=forward tooltip="include"] "21" -> "22" [dir=forward tooltip="include"] "25" -> "5" [dir=forward tooltip="include"] "25" -> "8" [dir=forward tooltip="include"] "25" -> "14" [dir=forward tooltip="include"] "25" -> "21" [dir=forward tooltip="include"] "25" -> "15" [dir=forward tooltip="include"] "18" -> "19" [dir=forward tooltip="include"] "18" -> "7" [dir=forward tooltip="include"] "18" -> "3" [dir=forward tooltip="include"] "18" -> "16" [dir=forward tooltip="include"] "18" -> "5" [dir=forward tooltip="include"] "18" -> "20" [dir=forward tooltip="include"] "18" -> "21" [dir=forward tooltip="include"] "18" -> "24" [dir=forward tooltip="include"] "18" -> "22" [dir=forward tooltip="include"] "18" -> "9" [dir=forward tooltip="include"] "8" -> "9" [dir=forward tooltip="include"] "6" -> "7" [dir=forward tooltip="include"] "6" -> "4" [dir=forward tooltip="include"] "9" -> "10" [dir=forward tooltip="include"] "9" -> "11" [dir=forward tooltip="include"] "9" -> "12" [dir=forward tooltip="include"] "9" -> "3" [dir=forward tooltip="include"] "2" -> "3" [dir=forward tooltip="include"] "2" -> "4" [dir=forward tooltip="include"] "2" -> "6" [dir=forward tooltip="include"] "2" -> "8" [dir=forward tooltip="include"] "2" -> "13" [dir=forward tooltip="include"] "2" -> "14" [dir=forward tooltip="include"] "2" -> "26" [dir=forward tooltip="include"] "2" -> "17" [dir=forward tooltip="include"] "2" -> "15" [dir=forward tooltip="include"] "2" -> "18" [dir=forward tooltip="include"] "2" -> "27" [dir=forward tooltip="include"] "17" -> "7" [dir=forward tooltip="include"] "27" -> "7" [dir=forward tooltip="include"] "27" -> "3" [dir=forward tooltip="include"] "27" -> "14" [dir=forward tooltip="include"] "26" -> "7" [dir=forward tooltip="include"] "26" -> "14" [dir=forward tooltip="include"] "26" -> "9" [dir=forward tooltip="include"] "26" -> "22" [dir=forward tooltip="include"] "13" -> "14" [dir=forward tooltip="include"] "13" -> "15" [dir=forward tooltip="include"] "13" -> "18" [dir=forward tooltip="include"] }

This graph shows which files directly or indirectly include context.h:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "23" [label="/__w/AtomVM/AtomVM/src/libAtomVM/interop.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/interop.c"] "15" [label="/__w/AtomVM/AtomVM/src/libAtomVM/refc_binary.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/refc_binary.c"] "19" [label="/__w/AtomVM/AtomVM/src/libAtomVM/interop.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/interop.h"] "10" [label="/__w/AtomVM/AtomVM/src/libAtomVM/erl_nif_priv.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/erl_nif_priv.h"] "5" [label="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.c"] "31" [label="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.h"] "6" [label="/__w/AtomVM/AtomVM/src/libAtomVM/context.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/context.c"] "3" [label="/__w/AtomVM/AtomVM/src/libAtomVM/bif.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/bif.c"] "1" [label="/__w/AtomVM/AtomVM/src/libAtomVM/context.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/context.h" fillcolor="#BFBFBF"] "2" [label="/__w/AtomVM/AtomVM/src/libAtomVM/bif.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/bif.h"] "24" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_crypto.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_crypto.c"] "37" [label="/__w/AtomVM/AtomVM/src/libAtomVM/portnifloader.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/portnifloader.c"] "32" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_crypto.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_crypto.h"] "9" [label="/__w/AtomVM/AtomVM/src/libAtomVM/memory.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/memory.c"] "36" [label="/__w/AtomVM/AtomVM/src/libAtomVM/portnifloader.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/portnifloader.h"] "30" [label="/__w/AtomVM/AtomVM/src/libAtomVM/sys.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/sys.h"] "4" [label="/__w/AtomVM/AtomVM/src/libAtomVM/module.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/module.c"] "26" [label="/__w/AtomVM/AtomVM/src/libAtomVM/module.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/module.h"] "22" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_net.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_net.c"] "33" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_net.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_net.h"] "16" [label="/__w/AtomVM/AtomVM/src/libAtomVM/resources.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/resources.c"] "21" [label="/__w/AtomVM/AtomVM/src/libAtomVM/inet.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/inet.c"] "25" [label="/__w/AtomVM/AtomVM/src/libAtomVM/term.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/term.c"] "20" [label="/__w/AtomVM/AtomVM/src/libAtomVM/inet.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/inet.h"] "8" [label="/__w/AtomVM/AtomVM/src/libAtomVM/debug.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/debug.c"] "7" [label="/__w/AtomVM/AtomVM/src/libAtomVM/debug.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/debug.h"] "18" [label="/__w/AtomVM/AtomVM/src/libAtomVM/externalterm.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/externalterm.c"] "11" [label="/__w/AtomVM/AtomVM/src/libAtomVM/globalcontext.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/globalcontext.c"] "27" [label="/__w/AtomVM/AtomVM/src/libAtomVM/platform_nifs.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/platform_nifs.h"] "40" [label="/__w/AtomVM/AtomVM/src/libAtomVM/scheduler.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/scheduler.h"] "12" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_socket.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_socket.c"] "34" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_socket.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_socket.h"] "29" [label="/__w/AtomVM/AtomVM/src/libAtomVM/stacktrace.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/stacktrace.c"] "28" [label="/__w/AtomVM/AtomVM/src/libAtomVM/stacktrace.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/stacktrace.h"] "13" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c"] "35" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_ssl.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_ssl.h"] "14" [label="/__w/AtomVM/AtomVM/src/libAtomVM/posix_nifs.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/posix_nifs.c"] "41" [label="/__w/AtomVM/AtomVM/src/libAtomVM/mailbox.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/mailbox.c"] "38" [label="/__w/AtomVM/AtomVM/src/libAtomVM/port.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/port.c"] "39" [label="/__w/AtomVM/AtomVM/src/libAtomVM/port.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/port.h"] "17" [label="/__w/AtomVM/AtomVM/src/libAtomVM/ets.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/ets.c"] "19" -> "3" [dir=back tooltip="include"] "19" -> "20" [dir=back tooltip="include"] "19" -> "23" [dir=back tooltip="include"] "19" -> "5" [dir=back tooltip="include"] "19" -> "24" [dir=back tooltip="include"] "19" -> "22" [dir=back tooltip="include"] "19" -> "12" [dir=back tooltip="include"] "19" -> "13" [dir=back tooltip="include"] "19" -> "14" [dir=back tooltip="include"] "19" -> "25" [dir=back tooltip="include"] "10" -> "6" [dir=back tooltip="include"] "10" -> "11" [dir=back tooltip="include"] "10" -> "9" [dir=back tooltip="include"] "10" -> "12" [dir=back tooltip="include"] "10" -> "13" [dir=back tooltip="include"] "10" -> "14" [dir=back tooltip="include"] "10" -> "15" [dir=back tooltip="include"] "10" -> "16" [dir=back tooltip="include"] "31" -> "4" [dir=back tooltip="include"] "31" -> "5" [dir=back tooltip="include"] "31" -> "24" [dir=back tooltip="include"] "31" -> "32" [dir=back tooltip="include"] "31" -> "22" [dir=back tooltip="include"] "31" -> "33" [dir=back tooltip="include"] "31" -> "12" [dir=back tooltip="include"] "31" -> "34" [dir=back tooltip="include"] "31" -> "13" [dir=back tooltip="include"] "31" -> "35" [dir=back tooltip="include"] "31" -> "36" [dir=back tooltip="include"] "31" -> "14" [dir=back tooltip="include"] "1" -> "2" [dir=back tooltip="include"] "1" -> "6" [dir=back tooltip="include"] "1" -> "7" [dir=back tooltip="include"] "1" -> "10" [dir=back tooltip="include"] "1" -> "17" [dir=back tooltip="include"] "1" -> "18" [dir=back tooltip="include"] "1" -> "11" [dir=back tooltip="include"] "1" -> "19" [dir=back tooltip="include"] "1" -> "9" [dir=back tooltip="include"] "1" -> "4" [dir=back tooltip="include"] "1" -> "26" [dir=back tooltip="include"] "1" -> "5" [dir=back tooltip="include"] "1" -> "31" [dir=back tooltip="include"] "1" -> "24" [dir=back tooltip="include"] "1" -> "22" [dir=back tooltip="include"] "1" -> "12" [dir=back tooltip="include"] "1" -> "13" [dir=back tooltip="include"] "1" -> "38" [dir=back tooltip="include"] "1" -> "39" [dir=back tooltip="include"] "1" -> "36" [dir=back tooltip="include"] "1" -> "15" [dir=back tooltip="include"] "1" -> "16" [dir=back tooltip="include"] "1" -> "40" [dir=back tooltip="include"] "1" -> "28" [dir=back tooltip="include"] "1" -> "25" [dir=back tooltip="include"] "2" -> "3" [dir=back tooltip="include"] "2" -> "4" [dir=back tooltip="include"] "2" -> "5" [dir=back tooltip="include"] "32" -> "24" [dir=back tooltip="include"] "36" -> "37" [dir=back tooltip="include"] "30" -> "6" [dir=back tooltip="include"] "30" -> "11" [dir=back tooltip="include"] "30" -> "4" [dir=back tooltip="include"] "30" -> "5" [dir=back tooltip="include"] "30" -> "12" [dir=back tooltip="include"] "30" -> "16" [dir=back tooltip="include"] "26" -> "2" [dir=back tooltip="include"] "26" -> "4" [dir=back tooltip="include"] "26" -> "5" [dir=back tooltip="include"] "26" -> "27" [dir=back tooltip="include"] "26" -> "28" [dir=back tooltip="include"] "26" -> "30" [dir=back tooltip="include"] "26" -> "25" [dir=back tooltip="include"] "33" -> "22" [dir=back tooltip="include"] "20" -> "21" [dir=back tooltip="include"] "20" -> "22" [dir=back tooltip="include"] "20" -> "12" [dir=back tooltip="include"] "20" -> "13" [dir=back tooltip="include"] "7" -> "8" [dir=back tooltip="include"] "7" -> "9" [dir=back tooltip="include"] "27" -> "5" [dir=back tooltip="include"] "40" -> "11" [dir=back tooltip="include"] "40" -> "41" [dir=back tooltip="include"] "40" -> "5" [dir=back tooltip="include"] "40" -> "12" [dir=back tooltip="include"] "34" -> "12" [dir=back tooltip="include"] "34" -> "13" [dir=back tooltip="include"] "28" -> "29" [dir=back tooltip="include"] "35" -> "13" [dir=back tooltip="include"] "39" -> "21" [dir=back tooltip="include"] "39" -> "5" [dir=back tooltip="include"] "39" -> "22" [dir=back tooltip="include"] "39" -> "12" [dir=back tooltip="include"] "39" -> "13" [dir=back tooltip="include"] "39" -> "38" [dir=back tooltip="include"] }

Context struct and related management functions.

A context represent the state of a running erlang process or port.

Defines

MAX_REG 16

Typedefs

typedef enum NativeHandlerResult NativeHandlerResult
typedef NativeHandlerResult (*native_handler_f)(Context *ctx)

Enums

enum NativeHandlerResult

Values:

enumerator NativeTerminate = 1
enumerator NativeContinue
enum ContextFlags

Values:

enumerator NoFlags = 0
enumerator WaitingTimeout = 1
enumerator WaitingTimeoutExpired = 2
enumerator Running = 4
enumerator Ready = 8
enumerator Killed = 16
enumerator Trap = 32
enum HeapGrowthStrategy

Values:

enumerator BoundedFreeHeapGrowth = 0
enumerator MinimumHeapGrowth
enumerator FibonacciHeapGrowth
enum ContextMonitorType

Values:

enumerator CONTEXT_MONITOR_MONITORING_LOCAL
enumerator CONTEXT_MONITOR_MONITORED_LOCAL
enumerator CONTEXT_MONITOR_RESOURCE

Functions

Context *context_new(GlobalContext *glb)

Creates a new context.

Allocates a new Context struct and initialize it. The newly created context is also inserted into the processes table, however it is not scheduled, allowing for further initialization.

Parameters:
  • glb – The global context of this virtual machine instance.

Returns:

created context.

void context_destroy(Context *c)

Destroys a context.

Frees context resources and memory and removes it from the processes table. This should be called from the scheduler only. To actually delete a context that was created with context_new, use scheduler_terminate.

Parameters:
  • c – the context that will be destroyed.

static inline void context_ensure_fpregs(Context *c)

Ensure we have FP registers, allocating them if necessary.

Parameters:
  • c – context fo allocate FP registers for

int context_execute_loop(Context *ctx, Module *mod, const char *function_name, int arity)

Starts executing a function.

Start executing bytecode for the specified function, this function will block until it terminates. The outcome is saved to x[0] register.

Parameters:
  • ctx – the context that will be used to run the specified functions, x registers must be set to function arguments.

  • mod – the module name C string.

  • function_name – the function name C string.

  • arity – the function arity (number of arguments that are required).

Returns:

1 if an error occurred, otherwise 0 is always returned.

static inline int context_is_port_driver(const Context *ctx)

Returns 1 if the context is a port driver.

Checks if the given context has a native_handler or not.

Parameters:
  • ctx – a valid context

Returns:

1 if ctx is a port driver, otherwise 0 is returned.

static inline void context_clean_registers(Context *ctx, int live)

Cleans up unused registers.

Sets to NIL unused registers, x[0] - x[live - 1] will not be overwritten.

Parameters:
  • ctx – a valid context

  • live – number of used registers

static inline term *context_stack_base(const Context *ctx)

Returns a context’s stack base.

Used for stack traces

Parameters:
  • ctx – a valid context.

Returns:

the stack base

static inline size_t context_stack_size(const Context *ctx)

Returns a context’s stack size.

Return the number of terms currently on the stack. Used for stack traces.

Parameters:
  • ctx – a valid context.

Returns:

stack size in terms

static inline size_t context_avail_free_memory(const Context *ctx)

Returns available free memory in term units.

Returns the number of terms that can fit either on the heap.

Parameters:
  • ctx – a valid context.

Returns:

available free memory that is avail_size_in_bytes / sizeof(term).

static inline bool context_is_term_equal_to_atom_string(Context *ctx, term atom_a, AtomString atom_string_b)

Compares a term with an AtomString.

Checks if the given term and the given AtomString refers to the same atom. This function is just a shortcut that uses the corresponding funtion from globalcontext.

Parameters:
  • ctx – the current Context.

  • atom_a – any term of any type, when it is not an atom false is always returned.

  • atom_string_b – an atom string, which is the atom length followed by atom characters.

Returns:

true if they both refer to the same atom, otherwise false.

size_t context_message_queue_len(Context *ctx)

Returns number of messages in the process’s mailbox.

Parameters:
  • ctx – a valid context.

Returns:

the number of messages in the process’s mailbox

size_t context_size(Context *ctx)

Returns total amount of size (in byes) occupied by the process.

Parameters:
  • ctx – a valid context.

Returns:

total amount of size (in byes) occupied by the process

void context_update_flags(Context *ctx, int mask, int value)

Set or clear a flag on another context.

atomically update flags <- (flags & mask) | value

Parameters:
  • ctx – the context to set/clear flag on.

  • mask – the mask to apply on flags

  • value – the value to set

static inline int context_get_flags(Context *ctx, int mask)

Get flags on a given context.

Parameters:
  • ctx – the context to get flags on.

  • mask – the mask to apply on flags

void context_process_kill_signal(Context *ctx, struct TermSignal *signal)

Process a kill signal, setting the exit reason and changing the killed flag.

Parameters:
  • ctx – the context being executed

  • signal – the kill message

void context_process_process_info_request_signal(Context *ctx, struct BuiltInAtomRequestSignal *signal, bool process_table_locked)

Process a process info request signal.

Parameters:
  • ctx – the context being executed

  • signal – the process info signal

  • process_table_locked – whether process table is already locked

bool context_process_signal_trap_answer(Context *ctx, struct TermSignal *signal)

Process a trap answer signal.

Parameters:
  • ctx – the context being executed

  • signal – the answer message

Returns:

true if successful, false in case of memory error

void context_process_flush_monitor_signal(Context *ctx, uint64_t ref_ticks, bool info)

Process a flush monitor signal.

Parameters:
  • ctx – the context being executed

  • ref_ticks – the monitor reference

  • info – whether to return FALSE_ATOM if no message was flushed.

Process a link exit signal.

Parameters:
  • ctx – the context being executed

  • signal – the signal with the exit info tuple

Returns:

true if the process is trapping exit and info tuple was enqueued as a message;

void context_process_monitor_down_signal(Context *ctx, struct TermSignal *signal)

Process a monitor down signal.

Parameters:
  • ctx – the context being executed

  • signal – the signal with the down info tuple

bool context_get_process_info(Context *ctx, term *out, size_t *term_size, term atom_key, Heap *heap)

Get process information.

Parameters:
  • ctx – the context being executed

  • out – the answer term. Can be NULL if only the size matters.

  • term_size – the size of the answer term, in words.

  • atom_key – the key representing the info to get

  • heap – the heap to allocate the answer to

Returns:

true if successful, false in case of an error in which case *out is filled with an exception atom if it was not NULL

Half-link process to another process.

Parameters:
  • monitor_pid – process to link to

Returns:

the allocated monitor or NULL if allocation failed

struct Monitor *monitor_new(term monitor_pid, uint64_t ref_ticks, bool is_monitoring)

Create a monitor on a process.

Parameters:
  • monitor_pid – monitoring process

  • ref_ticks – reference of the monitor

  • is_monitoring – if ctx is the monitoring process

Returns:

the allocated monitor or NULL if allocation failed

struct Monitor *monitor_resource_monitor_new(void *resource, uint64_t ref_ticks)

Create a resource monitor.

Parameters:
  • resource – resource object

  • ref_ticks – reference associated with the monitor

Returns:

the allocated resource monitor or NULL if allocation failed

Half-unlink process to another process.

If process is found, an unlink id is generated and the link is deactivated.

Parameters:
  • ctx – the context being executed

  • link_pid – process to unlink from

  • unlink_id – on output, unlink id to send to the target process

Returns:

true if process was found

Half-unlink process to another process.

Called within the process only when an UnlinkID signal is received. If link is found, remove it and sends an UnlinkIDAck signal to the linked process.

Parameters:
  • ctx – the context being executed

  • link_pid – process to unlink from

  • unlink_id – unlink id from the signal

  • process_table_locked – whether process table is already locked

Half-unlink process to another process.

Called within the process only when an UnlinkIDAck signal is received. If link is found and matches, remove it.

Parameters:
  • ctx – the context being executed

  • link_pid – process to unlink from

  • unlink_id – unlink id from the signal

void context_demonitor(Context *ctx, uint64_t ref_ticks)

Destroy a monitor on a process (monitoring, monitored or resource)

Called within the process only. This function is called from DemonitorSignal as well as demonitor nif on monitoring process.

Parameters:
  • ctx – the context being executed (monitoring or monitored)

  • ref_ticks – reference of the monitor to remove

term context_get_monitor_pid(Context *ctx, uint64_t ref_ticks, bool *is_monitoring)

Get target of a monitor.

Parameters:
  • ctx – the context being executed

  • ref_ticks – reference of the monitor to remove

  • is_monitoring – whether ctx is the monitoring process.

Returns:

pid of monitoring process, self() if process is monitoring (and not monitored) or term_invalid() if no monitor could be found.

bool context_add_monitor(Context *ctx, struct Monitor *new_monitor)

Add a monitor on a process.

Called within the process only. This function is called from MonitorSignal. Monitor is not added if it already exists. Monitors are identified by a reference, but links have no reference and a link can only exist once.

Parameters:
  • ctx – the context being executed

  • new_monitor – monitor object to add (ownership belongs to context afterwards)

Returns:

true if the monitor was added, false if it already existed and new_monitor waw freed.

struct Context
#include <context.h>

Collaboration diagram for Context:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "23" [label="SpinLock" tooltip="SpinLock"] "20" [label="ResourceType" tooltip="ResourceType"] "6" [label="Module" tooltip="Module"] "5" [label="ListHead" tooltip="ListHead"] "10" [label="HeapFragment" tooltip="HeapFragment"] "18" [label="RefcBinaryQueueItem" tooltip="RefcBinaryQueueItem"] "11" [label="GlobalContext" tooltip="GlobalContext"] "12" [label="Ets" tooltip="Ets"] "17" [label="HNodeGroup" tooltip="HNodeGroup"] "22" [label="TimerList" tooltip="TimerList"] "8" [label="LiteralEntry" tooltip="LiteralEntry"] "3" [label="MailboxMessage" tooltip="MailboxMessage"] "9" [label="Heap" tooltip="Heap"] "1" [label="Context" tooltip="Context" fillcolor="#BFBFBF"] "14" [label="MessageQueueItem" tooltip="MessageQueueItem"] "21" [label="AtomsHashTable" tooltip="AtomsHashTable"] "19" [label="RefcBinary" tooltip="RefcBinary"] "2" [label="Mailbox" tooltip="Mailbox"] "15" [label="AtomTable" tooltip="AtomTable"] "7" [label="ExportedFunction" tooltip="ExportedFunction"] "4" [label="TimerListItem" tooltip="TimerListItem"] "13" [label="SyncList" tooltip="SyncList"] "16" [label="HNode" tooltip="HNode"] "20" -> "13" [dir=forward tooltip="usage"] "20" -> "11" [dir=forward tooltip="usage"] "20" -> "5" [dir=forward tooltip="usage"] "6" -> "7" [dir=forward tooltip="usage"] "6" -> "8" [dir=forward tooltip="usage"] "6" -> "5" [dir=forward tooltip="usage"] "5" -> "5" [dir=forward tooltip="usage"] "10" -> "10" [dir=forward tooltip="usage"] "18" -> "19" [dir=forward tooltip="usage"] "18" -> "18" [dir=forward tooltip="usage"] "11" -> "12" [dir=forward tooltip="usage"] "11" -> "14" [dir=forward tooltip="usage"] "11" -> "15" [dir=forward tooltip="usage"] "11" -> "18" [dir=forward tooltip="usage"] "11" -> "13" [dir=forward tooltip="usage"] "11" -> "6" [dir=forward tooltip="usage"] "11" -> "21" [dir=forward tooltip="usage"] "11" -> "22" [dir=forward tooltip="usage"] "11" -> "23" [dir=forward tooltip="usage"] "11" -> "5" [dir=forward tooltip="usage"] "12" -> "13" [dir=forward tooltip="usage"] "17" -> "16" [dir=forward tooltip="usage"] "17" -> "17" [dir=forward tooltip="usage"] "22" -> "5" [dir=forward tooltip="usage"] "3" -> "3" [dir=forward tooltip="usage"] "9" -> "10" [dir=forward tooltip="usage"] "1" -> "1" [dir=forward tooltip="usage"] "1" -> "2" [dir=forward tooltip="usage"] "1" -> "4" [dir=forward tooltip="usage"] "1" -> "6" [dir=forward tooltip="usage"] "1" -> "9" [dir=forward tooltip="usage"] "1" -> "11" [dir=forward tooltip="usage"] "1" -> "5" [dir=forward tooltip="usage"] "14" -> "3" [dir=forward tooltip="usage"] "14" -> "14" [dir=forward tooltip="usage"] "21" -> "16" [dir=forward tooltip="usage"] "19" -> "20" [dir=forward tooltip="usage"] "19" -> "5" [dir=forward tooltip="usage"] "2" -> "3" [dir=forward tooltip="usage"] "15" -> "16" [dir=forward tooltip="usage"] "15" -> "17" [dir=forward tooltip="usage"] "4" -> "5" [dir=forward tooltip="usage"] "13" -> "5" [dir=forward tooltip="usage"] "16" -> "16" [dir=forward tooltip="usage"] "16" -> "9" [dir=forward tooltip="usage"] }

Public Members

GlobalContext *global
Heap heap
term *e
term x[16 + 1]
struct ListHead extended_x_regs
struct ListHead processes_list_head
struct ListHead processes_table_head
int32_t process_id
struct TimerListItem timer_list_head
struct ListHead monitors_head
avm_float_t *fr
size_t min_heap_size
size_t max_heap_size
enum HeapGrowthStrategy heap_growth_strategy
unsigned long cp
Module *saved_module
const void *saved_ip
void *restore_trap_handler
Mailbox mailbox
struct ListHead dictionary
native_handler_f native_handler
unsigned int leader
unsigned int has_min_heap_size
unsigned int has_max_heap_size
bool trap_exit
unsigned int trace_calls
unsigned int trace_call_args
unsigned int trace_returns
unsigned int trace_send
unsigned int trace_receive
enum ContextFlags flags
void *platform_data
term group_leader
term bs
size_t bs_offset
term exit_reason
struct Monitor
#include <context.h>

Collaboration diagram for Monitor:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "1" [label="Monitor" tooltip="Monitor" fillcolor="#BFBFBF"] "2" [label="ListHead" tooltip="ListHead"] "1" -> "2" [dir=forward tooltip="usage"] "2" -> "2" [dir=forward tooltip="usage"] }

A regular monitor or a half link.

Public Members

struct ListHead monitor_list_head
enum ContextMonitorType monitor_type
struct LinkLocalMonitor
#include <context.h>

Collaboration diagram for LinkLocalMonitor:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "2" [label="Monitor" tooltip="Monitor"] "3" [label="ListHead" tooltip="ListHead"] "1" [label="LinkLocalMonitor" tooltip="LinkLocalMonitor" fillcolor="#BFBFBF"] "2" -> "3" [dir=forward tooltip="usage"] "3" -> "3" [dir=forward tooltip="usage"] "1" -> "2" [dir=forward tooltip="usage"] }

Public Members

struct Monitor monitor
struct MonitorLocalMonitor
#include <context.h>

Collaboration diagram for MonitorLocalMonitor:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "1" [label="MonitorLocalMonitor" tooltip="MonitorLocalMonitor" fillcolor="#BFBFBF"] "2" [label="Monitor" tooltip="Monitor"] "3" [label="ListHead" tooltip="ListHead"] "1" -> "2" [dir=forward tooltip="usage"] "2" -> "3" [dir=forward tooltip="usage"] "3" -> "3" [dir=forward tooltip="usage"] }

Public Members

struct Monitor monitor
uint64_t ref_ticks
term monitor_obj
struct ResourceContextMonitor
#include <context.h>

Collaboration diagram for ResourceContextMonitor:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "2" [label="Monitor" tooltip="Monitor"] "3" [label="ListHead" tooltip="ListHead"] "1" [label="ResourceContextMonitor" tooltip="ResourceContextMonitor" fillcolor="#BFBFBF"] "2" -> "3" [dir=forward tooltip="usage"] "3" -> "3" [dir=forward tooltip="usage"] "1" -> "2" [dir=forward tooltip="usage"] }

Public Members

struct Monitor monitor
uint64_t ref_ticks
void *resource_obj
struct ExtendedRegister
#include <context.h>

Collaboration diagram for ExtendedRegister:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "2" [label="ListHead" tooltip="ListHead"] "1" [label="ExtendedRegister" tooltip="ExtendedRegister" fillcolor="#BFBFBF"] "2" -> "2" [dir=forward tooltip="usage"] "1" -> "2" [dir=forward tooltip="usage"] }

Public Members

struct ListHead head
unsigned int index
term value