mailbox.c

Include dependency graph for mailbox.c:

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

Defines

ADDITIONAL_PROCESSING_MEMORY_SIZE 4

Functions

void mailbox_init(Mailbox *mbx)

Initialize the mailbox.

Parameters:
  • mbox – the mailbox to initialize.

_Static_assert (offsetof(struct Message, base)+offsetof(struct MailboxMessage, next)==offsetof(HeapFragment, next) ? 1 :0, "Message.base.next doesn't match HeapFragment.next")
_Static_assert (offsetof(struct Message, base)+offsetof(struct MailboxMessage, type)==offsetof(HeapFragment, heap_end) ? 1 :0, "Message.base.type doesn't match HeapFragment.heap_end")
_Static_assert (offsetof(struct Message, message)==offsetof(HeapFragment, storage) ? 1 :0, "Message.message doesn't match HeapFragment.storage[0]")
_Static_assert (offsetof(struct Message, heap_end)==offsetof(HeapFragment, storage[1]) ? 1 :0, "Message.heap_end doesn't match HeapFragment.storage[1]")
_Static_assert (sizeof(struct Message)==sizeof(HeapFragment)+2 *sizeof(term) ? 1 :0, "sizeof(Message) doesn't match sizeof(HeapFragment) + 2 terms")
_Static_assert (offsetof(struct TermSignal, base)+offsetof(struct MailboxMessage, next)==offsetof(HeapFragment, next) ? 1 :0, "TermSignal.base.next doesn't match HeapFragment.next")
_Static_assert (offsetof(struct TermSignal, base)+offsetof(struct MailboxMessage, type)==offsetof(HeapFragment, heap_end) ? 1 :0, "TermSignal.base.type doesn't match HeapFragment.heap_end")
_Static_assert (offsetof(struct TermSignal, signal_term)==offsetof(HeapFragment, storage) ? 1 :0, "TermSignal.signal_term doesn't match HeapFragment.storage[0]")
_Static_assert (offsetof(struct TermSignal, heap_end)==offsetof(HeapFragment, storage[1]) ? 1 :0, "TermSignal.heap_end doesn't match HeapFragment.storage[1]")
_Static_assert (sizeof(struct TermSignal)==sizeof(HeapFragment)+2 *sizeof(term) ? 1 :0, "sizeof(TermSignal) doesn't match sizeof(HeapFragment) + 2 terms")
HeapFragment *mailbox_message_to_heap_fragment(void *m, term *heap_end)
void mailbox_message_dispose(MailboxMessage *m, Heap *heap)

Dispose a (processed) mailbox message. The message will be freed or appended to current heap and will be destroyed on garbage collect. This function is called by mailbox_remove and is only needed for signal messages.

Parameters:
  • m – the message to free.

  • heap – heap to append the message to.

void mailbox_destroy(Mailbox *mbox, Heap *heap)

Free memory associated with a mailbox.

All messages in the mailbox will be freed or appended to the heap.

Parameters:
  • mbox – the mailbox to free.

  • heap – the heap to add messages to.

size_t mailbox_len(Mailbox *mbox)

Compute the mailbox length, in messages.

To be called from the process only.

Parameters:
  • mbox – the mailbox to get the length of.

size_t mailbox_size(Mailbox *mbox)

Compute the mailbox size, in bytes.

To be called from the process only.

Parameters:
  • mbox – the mailbox to get the size of.

inline void mailbox_enqueue_message(Context *c, MailboxMessage *m)

Enqueue message.

This function does not signal the process to be ready and is only meant to be called from a task by globalcontext_send_message_from_task.

Parameters:
  • c – the process context.

  • m – the message to enqueue

static void mailbox_post_message(Context *c, MailboxMessage *m)
MailboxMessage *mailbox_message_create_from_term(enum MessageType type, term t)

Allocate and serialize a term to a mailbox message.

Can be called from a task or even ISR (provided malloc works).

Parameters:
  • type – the message type, can be NormalMessage or a signal type

  • t – the term that will be sent

void mailbox_send(Context *c, term t)

Sends a message to a certain mailbox.

Sends a term to a certain process or port mailbox. Can be called from another process. Cannot be called from a task or from ISR.

Parameters:
  • c – the process context.

  • t – the term that will be sent.

void mailbox_send_term_signal(Context *c, enum MessageType type, term t)

Sends a term-based signal to a certain mailbox.

Parameters:
  • c – the process context.

  • type – the type of the signal

  • t – the term added to the message

void mailbox_send_built_in_atom_signal(Context *c, enum MessageType type, term atom)

Sends a built-in atom signal to a certain mailbox.

Parameters:
  • c – the process context.

  • type – the type of the signal

  • atom – the built-in atom

void mailbox_send_built_in_atom_request_signal(Context *c, enum MessageType type, int32_t pid, term atom)

Sends a built-in atom-based request signal to a certain mailbox.

Parameters:
  • c – the process context.

  • type – the type of the signal

  • sender_pid – the sender of the signal (to get the answer)

  • atom – the built-in atom

void mailbox_send_ref_signal(Context *c, enum MessageType type, uint64_t ref_ticks)

Sends a ref signal to a certain mailbox.

Parameters:
  • c – the process context.

  • type – the type of the signal

  • ref_ticks – the ref

void mailbox_send_empty_body_signal(Context *c, enum MessageType type)

Sends an empty body signal to a certain mailbox.

Parameters:
  • c – the process context.

  • type – the type of the signal

void mailbox_reset(Mailbox *mbox)

Reset mailbox receive pointer.

To be called from the process only.

Parameters:
  • mbox – the mailbox to work with

MailboxMessage *mailbox_process_outer_list(Mailbox *mbox)

Process the outer list of messages.

To be called from the process only

Parameters:
  • mbox – the mailbox to work with

Returns:

the signal messages in received order.

void mailbox_next(Mailbox *mbox)

Advance pointer to next message in a receive loop.

To be called from the process only.

Parameters:
  • mbox – the mailbox to work with

bool mailbox_peek(Context *c, term *out)

Gets next message from a mailbox (without removing it).

Peek the mailbox and retrieve a term that has been previously queued on a certain process or driver mailbox. To be called from the process only.

Parameters:
  • ctx – the calling context, owning the mailbox and where the message should be copied to.

  • out – the allocated term.

Returns:

true if a term was available

MailboxMessage *mailbox_take_message(Mailbox *mbox)

Take next message from mailbox.

Remove the first message from the mailbox and return it. To be called from the process only. This function is intended for some corner cases, such as certain port drivers.

Parameters:
  • mbox – the mailbox to take the next message from.

Message *mailbox_first(Mailbox *mbox)

Get first message from mailbox.

Get the first message and sets the receive pointer to it so it can be removed later. Used by ports & drivers. To be called from the process only.

Parameters:
  • mbox – the mailbox to get the current message from.

Returns:

first message or NULL.

void mailbox_crashdump(Context *ctx)

Output mailbox to stderr for crashdump reporting.

Parameters:
  • ctx – the owner of the mailbox to dump