1/* 2 * Copyright (c) 2012, 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 <string.h> 11#include "capqueue.h" 12 13static void 14queue_complete(void *arg) 15{ 16 struct capqueue_queue *q = (struct capqueue_queue*)arg; 17 q->running = false; 18 if (q->retrigger) { 19 q->retrigger = false; 20 capqueue_notify(q); 21 } 22} 23 24void 25capqueue_notify(struct capqueue_queue *q) 26{ 27 if (q->retrigger) { 28 return; 29 } 30 31 if (q->running) { 32 q->retrigger = true; 33 return; 34 } 35 36 q->on_first = !q->on_first; 37 q->running = true; 38 capqueue_wait(q, &q->queue_end, MKCLOSURE(queue_complete, q)); 39 // event queue is in continuous mode, does not need triggering 40} 41 42void 43capqueue_init(struct capqueue_queue *q, struct waitset *ws) 44{ 45 memset(q, 0, sizeof(*q)); 46 event_queue_init(&q->queues[0], ws, EVENT_QUEUE_CONTINUOUS); 47 event_queue_init(&q->queues[1], ws, EVENT_QUEUE_CONTINUOUS); 48 q->on_first = true; 49} 50