1#include <queue.h> 2 3static void send_next(void *arg) 4{ 5 struct monitor_binding *b = arg; 6 7 struct mon_msg_state* current = dequeue_msg_state(b); 8 9 // If more state in the queue, send it 10 if (current) { 11 current->send(b, current); 12 } 13} 14 15void enqueue_msg_state(struct monitor_binding *b, struct mon_msg_state *st) 16{ 17 if(b->st == NULL) { 18 struct waitset *ws = get_default_waitset(); 19 b->register_send(b, ws, MKCONT(send_next, b)); 20 } 21 22 struct mon_msg_state** walk = (struct mon_msg_state**) &(b->st); 23 for(; *walk != NULL; walk = &(*walk)->next) { 24 // continue 25 } 26 *walk = st; 27 st->next = NULL; 28} 29 30struct mon_msg_state* dequeue_msg_state(struct monitor_binding *b) 31{ 32 struct mon_msg_state *head = b->st; 33 b->st = head->next; 34 35 // Reregister for sending, if we need to send more 36 if (b->st != NULL) { 37 struct waitset *ws = get_default_waitset(); 38 errval_t err = b->register_send(b, ws, MKCONT(send_next, b)); 39 assert(err_is_ok(err)); 40 } 41 42 return head; 43} 44 45