mailbox.c
Include dependency graph for mailbox.c:
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
-
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.