1/*
2 * Copyright (c) 2007, 2008, 2009, 2010, ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#include <bulk_transfer/bulk_sm.h>
11
12errval_t bulk_sm_multiple_event_dispatch_non_block(struct bulk_sm_ws_item *item)
13{
14    assert(item);
15    errval_t err = SYS_ERR_OK;
16    bool event_found = false;
17
18    while (item) {
19        if (item->ws) {
20            err = event_dispatch_non_block(item->ws);
21            if (err_is_fail(err)) {
22                if (err != LIB_ERR_NO_EVENT) {
23                    // should report dispatching problem
24                    break;
25                }
26            } else {
27                event_found = true;
28            }
29        }
30
31        item = item->next;
32    }
33
34    if (err_is_fail(err) && err != LIB_ERR_NO_EVENT) {
35        return err; // dispatch error
36    } else if (!event_found) {
37        return LIB_ERR_NO_EVENT;
38    } else {
39        return SYS_ERR_OK;
40    }
41}
42
43errval_t bulk_sm_multiple_event_dispatch(struct bulk_sm_ws_item *item)
44{
45    while (1) {
46        errval_t err = bulk_sm_multiple_event_dispatch_non_block(item);
47
48        if (err_is_fail(err) && err != LIB_ERR_NO_EVENT) {
49            return err;
50        } else if (err == LIB_ERR_NO_EVENT) {
51           // debug_printf("No event. yielding....\n");
52            thread_yield();
53        } else {
54            return SYS_ERR_OK;
55        }
56    }
57}
58