1/**
2 * \file
3 * \brief Queue to deal with flounder continuations.
4 */
5
6/*
7 * Copyright (c) 2011, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#include <stdio.h>
16#include "queue.h"
17
18static void oct_rpc_send_next(void *arg)
19{
20    struct octopus_binding *b = arg;
21
22    struct oct_reply_state* current = oct_rpc_dequeue_reply(b);
23
24    // If more state in the queue, send them
25    if (current) {
26        current->reply(b, current);
27    }
28}
29
30void oct_rpc_enqueue_reply(struct octopus_binding *b,
31        struct oct_reply_state* st)
32{
33    if (b->st == NULL) {
34        struct waitset *ws = get_default_waitset();
35        b->register_send(b, ws, MKCONT(oct_rpc_send_next, b));
36    }
37
38    struct oct_reply_state** walk = (struct oct_reply_state**) &(b->st);
39    for (; *walk != NULL; walk = &(*walk)->next) {
40        // continue
41    }
42    *walk = st;
43    st->next = NULL;
44}
45
46struct oct_reply_state* oct_rpc_dequeue_reply(struct octopus_binding *b)
47{
48    struct oct_reply_state* head = b->st;
49    b->st = head->next;
50
51    // Reregister for sending, if we need to send more
52    if (b->st != NULL) {
53        struct waitset *ws = get_default_waitset();
54        errval_t err = b->register_send(b, ws, MKCONT(oct_rpc_send_next, b));
55        assert(err_is_ok(err));
56    }
57
58    return head;
59}
60
61