File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -367,14 +367,14 @@ bool mailbox_peek(Context *c, term *out)
367367 return true;
368368}
369369
370- void mailbox_remove_message (Mailbox * mbox , Heap * heap )
370+ MailboxMessage * mailbox_take_message (Mailbox * mbox )
371371{
372372 // This is called from OP_REMOVE_MESSAGE opcode, so we cannot make any
373373 // assumption about the state and should perform a nop if the mailbox
374374 // is empty.
375375 if (UNLIKELY (mbox -> receive_pointer == NULL )) {
376376 fprintf (stderr , "OP_REMOVE_MESSAGE on empty mailbox\n" );
377- return ;
377+ return NULL ;
378378 }
379379 MailboxMessage * removed = mbox -> receive_pointer ;
380380 if (mbox -> receive_pointer_prev ) {
@@ -393,9 +393,18 @@ void mailbox_remove_message(Mailbox *mbox, Heap *heap)
393393 }
394394 }
395395
396- mailbox_message_dispose (removed , heap );
397396 // Reset receive pointers
398397 mailbox_reset (mbox );
398+
399+ return removed ;
400+ }
401+
402+ void mailbox_remove_message (Mailbox * mbox , Heap * heap )
403+ {
404+ MailboxMessage * removed = mailbox_take_message (mbox );
405+ if (LIKELY (removed != NULL )) {
406+ mailbox_message_dispose (removed , heap );
407+ }
399408}
400409
401410Message * mailbox_first (Mailbox * mbox )
Original file line number Diff line number Diff line change @@ -263,6 +263,16 @@ static inline bool mailbox_has_next(Mailbox *mbox)
263263 */
264264bool mailbox_peek (Context * ctx , term * out );
265265
266+ /**
267+ * @brief Take next message from mailbox.
268+ *
269+ * @details Remove the first message from the mailbox and return it.
270+ * To be called from the process only.
271+ * This function is intended for some corner cases, such as certain port drivers.
272+ * @param mbox the mailbox to take the next message from.
273+ */
274+ MailboxMessage * mailbox_take_message (Mailbox * mbox );
275+
266276/**
267277 * @brief Remove next message from mailbox.
268278 *
You can’t perform that action at this time.
0 commit comments