context.c
Include dependency graph for context.c:
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 *ctx)
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.
-
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.
-
bool context_process_link_exit_signal(Context *ctx, struct TermSignal *signal)
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
-
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
-
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
-
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
-
struct Monitor *monitor_link_new(term link_pid)
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
-
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.
-
bool context_set_unlink_id(Context *ctx, term link_pid, uint64_t *unlink_id)
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
-
void context_ack_unlink(Context *ctx, term link_pid, uint64_t unlink_id, bool process_table_locked)
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
-
void context_unlink_ack(Context *ctx, term link_pid, uint64_t unlink_id)
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.