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"]
    "4" [label="atom.h" tooltip="atom.h"]
    "10" [label="assert.h" tooltip="assert.h"]
    "18" [label="synclist.h" tooltip="synclist.h"]
    "3" [label="stdint.h" tooltip="stdint.h"]
    "5" [label="stdlib.h" tooltip="stdlib.h"]
    "1" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.h" fillcolor="#BFBFBF"]
    "15" [label="utils.h" tooltip="utils.h"]
    "6" [label="atom_table.h" tooltip="atom_table.h"]
    "9" [label="term_typedef.h" tooltip="term_typedef.h"]
    "16" [label="stddef.h" tooltip="stddef.h"]
    "11" [label="limits.h" tooltip="limits.h"]
    "23" [label="refc_binary.h" tooltip="refc_binary.h"]
    "21" [label="string.h" tooltip="string.h"]
    "14" [label="mailbox.h" tooltip="mailbox.h"]
    "20" [label="term.h" tooltip="term.h"]
    "8" [label="erl_nif.h" tooltip="erl_nif.h"]
    "24" [label="resources.h" tooltip="resources.h"]
    "17" [label="smp.h" tooltip="smp.h"]
    "2" [label="globalcontext.h" tooltip="globalcontext.h"]
    "22" [label="memory.h" tooltip="memory.h"]
    "19" [label="stdio.h" tooltip="stdio.h"]
    "25" [label="timer_list.h" tooltip="timer_list.h"]
    "13" [label="list.h" tooltip="list.h"]
    "12" [label="inttypes.h" tooltip="inttypes.h"]
    "4" -> "3" [dir=forward tooltip="include"]
    "4" -> "5" [dir=forward tooltip="include"]
    "18" -> "13" [dir=forward tooltip="include"]
    "18" -> "19" [dir=forward tooltip="include"]
    "18" -> "17" [dir=forward tooltip="include"]
    "1" -> "2" [dir=forward tooltip="include"]
    "1" -> "13" [dir=forward tooltip="include"]
    "1" -> "14" [dir=forward tooltip="include"]
    "1" -> "17" [dir=forward tooltip="include"]
    "1" -> "20" [dir=forward tooltip="include"]
    "1" -> "25" [dir=forward tooltip="include"]
    "15" -> "16" [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"]
    "23" -> "7" [dir=forward tooltip="include"]
    "23" -> "5" [dir=forward tooltip="include"]
    "23" -> "13" [dir=forward tooltip="include"]
    "23" -> "24" [dir=forward tooltip="include"]
    "14" -> "7" [dir=forward tooltip="include"]
    "14" -> "13" [dir=forward tooltip="include"]
    "14" -> "9" [dir=forward tooltip="include"]
    "14" -> "15" [dir=forward tooltip="include"]
    "20" -> "7" [dir=forward tooltip="include"]
    "20" -> "3" [dir=forward tooltip="include"]
    "20" -> "19" [dir=forward tooltip="include"]
    "20" -> "5" [dir=forward tooltip="include"]
    "20" -> "21" [dir=forward tooltip="include"]
    "20" -> "22" [dir=forward tooltip="include"]
    "20" -> "23" [dir=forward tooltip="include"]
    "20" -> "15" [dir=forward tooltip="include"]
    "20" -> "9" [dir=forward tooltip="include"]
    "8" -> "9" [dir=forward tooltip="include"]
    "24" -> "5" [dir=forward tooltip="include"]
    "24" -> "8" [dir=forward tooltip="include"]
    "24" -> "13" [dir=forward tooltip="include"]
    "24" -> "22" [dir=forward tooltip="include"]
    "17" -> "7" [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" -> "17" [dir=forward tooltip="include"]
    "2" -> "18" [dir=forward tooltip="include"]
    "2" -> "20" [dir=forward tooltip="include"]
    "2" -> "25" [dir=forward tooltip="include"]
    "22" -> "8" [dir=forward tooltip="include"]
    "22" -> "9" [dir=forward tooltip="include"]
    "22" -> "15" [dir=forward tooltip="include"]
    "22" -> "3" [dir=forward tooltip="include"]
    "22" -> "5" [dir=forward tooltip="include"]
    "25" -> "7" [dir=forward tooltip="include"]
    "25" -> "3" [dir=forward tooltip="include"]
    "25" -> "13" [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"]
    "3" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/bif.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/bif.c"]
    "2" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/bif.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/bif.h"]
    "27" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/platform_nifs.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/platform_nifs.h"]
    "15" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/posix_nifs.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/posix_nifs.c"]
    "21" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/inet.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/inet.c"]
    "20" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/inet.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/inet.h"]
    "10" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/scheduler.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/scheduler.c"]
    "38" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/scheduler.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/scheduler.h"]
    "6" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.c"]
    "1" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.h" fillcolor="#BFBFBF"]
    "36" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/port.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/port.c"]
    "37" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/port.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/port.h"]
    "29" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.c"]
    "28" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.h"]
    "16" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/refc_binary.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/refc_binary.c"]
    "39" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/mailbox.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/mailbox.c"]
    "4" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.c"]
    "26" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.h"]
    "25" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/term.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/term.c"]
    "23" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/interop.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/interop.c"]
    "14" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c"]
    "19" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/interop.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/interop.h"]
    "35" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.h"]
    "17" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/resources.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/resources.c"]
    "24" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_crypto.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_crypto.c"]
    "32" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_crypto.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_crypto.h"]
    "22" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_net.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_net.c"]
    "33" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_net.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_net.h"]
    "11" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/erl_nif_priv.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/erl_nif_priv.h"]
    "30" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/sys.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/sys.h"]
    "5" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/nifs.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/nifs.c"]
    "31" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/nifs.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/nifs.h"]
    "8" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/debug.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/debug.c"]
    "7" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/debug.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/debug.h"]
    "12" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/globalcontext.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/globalcontext.c"]
    "9" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/memory.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/memory.c"]
    "13" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.c"]
    "34" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.h"]
    "18" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/externalterm.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/externalterm.c"]
    "2" -> "3" [dir=back tooltip="include"]
    "2" -> "4" [dir=back tooltip="include"]
    "2" -> "5" [dir=back tooltip="include"]
    "27" -> "5" [dir=back tooltip="include"]
    "20" -> "21" [dir=back tooltip="include"]
    "20" -> "22" [dir=back tooltip="include"]
    "20" -> "13" [dir=back tooltip="include"]
    "20" -> "14" [dir=back tooltip="include"]
    "38" -> "12" [dir=back tooltip="include"]
    "38" -> "39" [dir=back tooltip="include"]
    "38" -> "5" [dir=back tooltip="include"]
    "38" -> "13" [dir=back tooltip="include"]
    "38" -> "10" [dir=back tooltip="include"]
    "1" -> "2" [dir=back tooltip="include"]
    "1" -> "6" [dir=back tooltip="include"]
    "1" -> "7" [dir=back tooltip="include"]
    "1" -> "11" [dir=back tooltip="include"]
    "1" -> "18" [dir=back tooltip="include"]
    "1" -> "12" [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" -> "13" [dir=back tooltip="include"]
    "1" -> "14" [dir=back tooltip="include"]
    "1" -> "36" [dir=back tooltip="include"]
    "1" -> "37" [dir=back tooltip="include"]
    "1" -> "16" [dir=back tooltip="include"]
    "1" -> "17" [dir=back tooltip="include"]
    "1" -> "38" [dir=back tooltip="include"]
    "1" -> "28" [dir=back tooltip="include"]
    "1" -> "25" [dir=back tooltip="include"]
    "37" -> "21" [dir=back tooltip="include"]
    "37" -> "5" [dir=back tooltip="include"]
    "37" -> "22" [dir=back tooltip="include"]
    "37" -> "13" [dir=back tooltip="include"]
    "37" -> "14" [dir=back tooltip="include"]
    "37" -> "36" [dir=back tooltip="include"]
    "28" -> "29" [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"]
    "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" -> "13" [dir=back tooltip="include"]
    "19" -> "14" [dir=back tooltip="include"]
    "19" -> "15" [dir=back tooltip="include"]
    "19" -> "25" [dir=back tooltip="include"]
    "35" -> "14" [dir=back tooltip="include"]
    "32" -> "24" [dir=back tooltip="include"]
    "33" -> "22" [dir=back tooltip="include"]
    "11" -> "6" [dir=back tooltip="include"]
    "11" -> "12" [dir=back tooltip="include"]
    "11" -> "9" [dir=back tooltip="include"]
    "11" -> "13" [dir=back tooltip="include"]
    "11" -> "14" [dir=back tooltip="include"]
    "11" -> "15" [dir=back tooltip="include"]
    "11" -> "16" [dir=back tooltip="include"]
    "11" -> "17" [dir=back tooltip="include"]
    "30" -> "6" [dir=back tooltip="include"]
    "30" -> "12" [dir=back tooltip="include"]
    "30" -> "4" [dir=back tooltip="include"]
    "30" -> "5" [dir=back tooltip="include"]
    "30" -> "13" [dir=back tooltip="include"]
    "30" -> "17" [dir=back tooltip="include"]
    "30" -> "10" [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" -> "13" [dir=back tooltip="include"]
    "31" -> "34" [dir=back tooltip="include"]
    "31" -> "14" [dir=back tooltip="include"]
    "31" -> "35" [dir=back tooltip="include"]
    "31" -> "15" [dir=back tooltip="include"]
    "7" -> "8" [dir=back tooltip="include"]
    "7" -> "9" [dir=back tooltip="include"]
    "7" -> "10" [dir=back tooltip="include"]
    "34" -> "13" [dir=back tooltip="include"]
    "34" -> "14" [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

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)

Process a process info request signal.

Parameters:
  • ctx – the context being executed

  • signal – the kill message

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.

bool context_get_process_info(Context *ctx, term *out, term atom_key)

Get process information.

Parameters:
  • ctx – the context being executed

  • out – the answer term

  • atom_key – the key representing the info to get

Returns:

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

Half-link process to another process.

Caller must hold the global process lock. This creates one half of the link.

Parameters:
  • ctx – context to link

  • monitor_pid – process to link ctx to

Returns:

0 on success

uint64_t context_monitor(Context *ctx, term monitor_pid)

Create a monitor on a process.

Caller must hold the global process lock.

Parameters:
  • ctx – context to monitor

  • monitor_pid – monitoring process

Returns:

the ref ticks

struct ResourceMonitor *context_resource_monitor(Context *ctx, void *resource)

Create a resource monitor on a process.

Caller must hold the global process lock. The returned resource monitor is not added to the monitors list on the resource type.

Parameters:
  • ctx – context to monitor

  • resource – resource object

Returns:

the resource monitor

Remove a half-link from a process.

Caller must hold the global process lock. This removes one half of the link.

Parameters:
  • ctx – context to monitor

  • monitor_pid – process to unlink

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"]
    "19" [label="SpinLock" tooltip="SpinLock"]
    "6" [label="Module" tooltip="Module"]
    "5" [label="ListHead" tooltip="ListHead"]
    "11" [label="HeapFragment" tooltip="HeapFragment"]
    "12" [label="GlobalContext" tooltip="GlobalContext"]
    "8" [label="ModuleFilename" tooltip="ModuleFilename"]
    "15" [label="HNodeGroup" tooltip="HNodeGroup"]
    "18" [label="TimerList" tooltip="TimerList"]
    "9" [label="LiteralEntry" tooltip="LiteralEntry"]
    "3" [label="MailboxMessage" tooltip="MailboxMessage"]
    "10" [label="Heap" tooltip="Heap"]
    "1" [label="Context" tooltip="Context" fillcolor="#BFBFBF"]
    "17" [label="AtomsHashTable" tooltip="AtomsHashTable"]
    "2" [label="Mailbox" tooltip="Mailbox"]
    "13" [label="AtomTable" tooltip="AtomTable"]
    "7" [label="ExportedFunction" tooltip="ExportedFunction"]
    "4" [label="TimerListItem" tooltip="TimerListItem"]
    "16" [label="SyncList" tooltip="SyncList"]
    "14" [label="HNode" tooltip="HNode"]
    "6" -> "7" [dir=forward tooltip="usage"]
    "6" -> "8" [dir=forward tooltip="usage"]
    "6" -> "9" [dir=forward tooltip="usage"]
    "6" -> "5" [dir=forward tooltip="usage"]
    "5" -> "5" [dir=forward tooltip="usage"]
    "11" -> "11" [dir=forward tooltip="usage"]
    "12" -> "13" [dir=forward tooltip="usage"]
    "12" -> "16" [dir=forward tooltip="usage"]
    "12" -> "6" [dir=forward tooltip="usage"]
    "12" -> "17" [dir=forward tooltip="usage"]
    "12" -> "18" [dir=forward tooltip="usage"]
    "12" -> "19" [dir=forward tooltip="usage"]
    "12" -> "5" [dir=forward tooltip="usage"]
    "15" -> "14" [dir=forward tooltip="usage"]
    "15" -> "15" [dir=forward tooltip="usage"]
    "18" -> "5" [dir=forward tooltip="usage"]
    "3" -> "3" [dir=forward tooltip="usage"]
    "10" -> "11" [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" -> "10" [dir=forward tooltip="usage"]
    "1" -> "12" [dir=forward tooltip="usage"]
    "1" -> "5" [dir=forward tooltip="usage"]
    "17" -> "14" [dir=forward tooltip="usage"]
    "2" -> "3" [dir=forward tooltip="usage"]
    "13" -> "14" [dir=forward tooltip="usage"]
    "13" -> "15" [dir=forward tooltip="usage"]
    "4" -> "5" [dir=forward tooltip="usage"]
    "16" -> "5" [dir=forward tooltip="usage"]
    "14" -> "14" [dir=forward tooltip="usage"]
}

Public Members

GlobalContext *global
Heap heap
term *e
term x[MAX_REG + 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
uint64_t reductions
unsigned int leader
unsigned int has_min_heap_size
unsigned int has_max_heap_size
bool trap_exit
enum ContextFlags ATOMIC 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
uint64_t ref_ticks
term monitor_obj
struct ResourceMonitor
#include <context.h>

Collaboration diagram for ResourceMonitor:

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="ResourceMonitor" tooltip="ResourceMonitor" fillcolor="#BFBFBF"]
    "2" -> "3" [dir=forward tooltip="usage"]
    "3" -> "3" [dir=forward tooltip="usage"]
    "1" -> "2" [dir=forward tooltip="usage"]
    "1" -> "3" [dir=forward tooltip="usage"]
}

A resource monitor.

Public Members

struct Monitor base
struct ListHead resource_list_head
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