2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
11 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20 #include <palacios/vmm_queue.h>
22 void v3_init_queue(struct v3_queue * queue) {
23 queue->num_entries = 0;
24 INIT_LIST_HEAD(&(queue->entries));
25 v3_lock_init(&queue->lock);
28 struct v3_queue * v3_create_queue() {
29 struct v3_queue * tmp_queue = V3_Malloc(sizeof(struct v3_queue));
32 PrintError("Cannot allocate a queue\n");
36 v3_init_queue(tmp_queue);
40 void v3_enqueue(struct v3_queue * queue, addr_t entry) {
41 struct v3_queue_entry * q_entry = V3_Malloc(sizeof(struct v3_queue_entry));
42 unsigned int flags = 0;
45 PrintError("Cannot allocate a queue entry for enqueue\n");
49 flags = v3_lock_irqsave(queue->lock);
50 q_entry->entry = entry;
51 list_add_tail(&(q_entry->entry_list), &(queue->entries));
53 v3_unlock_irqrestore(queue->lock, flags);
57 addr_t v3_dequeue(struct v3_queue * queue) {
59 unsigned int flags = 0;
61 flags = v3_lock_irqsave(queue->lock);
62 if (!list_empty(&(queue->entries))) {
63 struct list_head * q_entry = queue->entries.next;
64 struct v3_queue_entry * tmp_entry = list_entry(q_entry, struct v3_queue_entry, entry_list);
66 entry_val = tmp_entry->entry;
70 v3_unlock_irqrestore(queue->lock, flags);