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"]
    "23" [label="refc_binary.h" tooltip="refc_binary.h"]
    "4" [label="atom.h" tooltip="atom.h"]
    "10" [label="assert.h" tooltip="assert.h"]
    "21" [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"]
    "20" [label="memory.h" tooltip="memory.h"]
    "24" [label="resources.h" tooltip="resources.h"]
    "18" [label="term.h" tooltip="term.h"]
    "22" [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="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"]
    "26" [label="timer_list.h" tooltip="timer_list.h"]
    "25" [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"]
    "23" -> "7" [dir=forward tooltip="include"]
    "23" -> "5" [dir=forward tooltip="include"]
    "23" -> "14" [dir=forward tooltip="include"]
    "23" -> "24" [dir=forward tooltip="include"]
    "4" -> "3" [dir=forward tooltip="include"]
    "4" -> "5" [dir=forward tooltip="include"]
    "21" -> "22" [dir=forward tooltip="include"]
    "21" -> "16" [dir=forward tooltip="include"]
    "21" -> "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" -> "25" [dir=forward tooltip="include"]
    "1" -> "17" [dir=forward tooltip="include"]
    "1" -> "18" [dir=forward tooltip="include"]
    "1" -> "26" [dir=forward tooltip="include"]
    "20" -> "3" [dir=forward tooltip="include"]
    "20" -> "5" [dir=forward tooltip="include"]
    "20" -> "8" [dir=forward tooltip="include"]
    "20" -> "9" [dir=forward tooltip="include"]
    "20" -> "21" [dir=forward tooltip="include"]
    "24" -> "5" [dir=forward tooltip="include"]
    "24" -> "8" [dir=forward tooltip="include"]
    "24" -> "14" [dir=forward tooltip="include"]
    "24" -> "20" [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" -> "19" [dir=forward tooltip="include"]
    "18" -> "20" [dir=forward tooltip="include"]
    "18" -> "23" [dir=forward tooltip="include"]
    "18" -> "21" [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" -> "25" [dir=forward tooltip="include"]
    "2" -> "17" [dir=forward tooltip="include"]
    "2" -> "15" [dir=forward tooltip="include"]
    "2" -> "18" [dir=forward tooltip="include"]
    "2" -> "26" [dir=forward tooltip="include"]
    "17" -> "7" [dir=forward tooltip="include"]
    "26" -> "7" [dir=forward tooltip="include"]
    "26" -> "3" [dir=forward tooltip="include"]
    "26" -> "14" [dir=forward tooltip="include"]
    "25" -> "7" [dir=forward tooltip="include"]
    "25" -> "14" [dir=forward tooltip="include"]
    "25" -> "9" [dir=forward tooltip="include"]
    "25" -> "21" [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" -> "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

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"]
    "24" [label="SpinLock" tooltip="SpinLock"]
    "21" [label="ResourceType" tooltip="ResourceType"]
    "6" [label="Module" tooltip="Module"]
    "5" [label="ListHead" tooltip="ListHead"]
    "11" [label="HeapFragment" tooltip="HeapFragment"]
    "19" [label="RefcBinaryQueueItem" tooltip="RefcBinaryQueueItem"]
    "12" [label="GlobalContext" tooltip="GlobalContext"]
    "8" [label="ModuleFilename" tooltip="ModuleFilename"]
    "13" [label="Ets" tooltip="Ets"]
    "18" [label="HNodeGroup" tooltip="HNodeGroup"]
    "23" [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"]
    "15" [label="MessageQueueItem" tooltip="MessageQueueItem"]
    "22" [label="AtomsHashTable" tooltip="AtomsHashTable"]
    "20" [label="RefcBinary" tooltip="RefcBinary"]
    "2" [label="Mailbox" tooltip="Mailbox"]
    "16" [label="AtomTable" tooltip="AtomTable"]
    "7" [label="ExportedFunction" tooltip="ExportedFunction"]
    "4" [label="TimerListItem" tooltip="TimerListItem"]
    "14" [label="SyncList" tooltip="SyncList"]
    "17" [label="HNode" tooltip="HNode"]
    "21" -> "12" [dir=forward tooltip="usage"]
    "21" -> "5" [dir=forward tooltip="usage"]
    "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"]
    "19" -> "20" [dir=forward tooltip="usage"]
    "19" -> "19" [dir=forward tooltip="usage"]
    "12" -> "13" [dir=forward tooltip="usage"]
    "12" -> "15" [dir=forward tooltip="usage"]
    "12" -> "16" [dir=forward tooltip="usage"]
    "12" -> "19" [dir=forward tooltip="usage"]
    "12" -> "14" [dir=forward tooltip="usage"]
    "12" -> "6" [dir=forward tooltip="usage"]
    "12" -> "22" [dir=forward tooltip="usage"]
    "12" -> "23" [dir=forward tooltip="usage"]
    "12" -> "24" [dir=forward tooltip="usage"]
    "12" -> "5" [dir=forward tooltip="usage"]
    "13" -> "14" [dir=forward tooltip="usage"]
    "18" -> "17" [dir=forward tooltip="usage"]
    "18" -> "18" [dir=forward tooltip="usage"]
    "23" -> "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"]
    "15" -> "3" [dir=forward tooltip="usage"]
    "15" -> "15" [dir=forward tooltip="usage"]
    "22" -> "17" [dir=forward tooltip="usage"]
    "20" -> "21" [dir=forward tooltip="usage"]
    "20" -> "5" [dir=forward tooltip="usage"]
    "2" -> "3" [dir=forward tooltip="usage"]
    "16" -> "17" [dir=forward tooltip="usage"]
    "16" -> "18" [dir=forward tooltip="usage"]
    "4" -> "5" [dir=forward tooltip="usage"]
    "14" -> "5" [dir=forward tooltip="usage"]
    "17" -> "17" [dir=forward tooltip="usage"]
    "17" -> "10" [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
uint64_t reductions
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
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