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>
25 void v3_init_queue(struct v3_queue * queue) {
26 queue->num_entries = 0;
27 INIT_LIST_HEAD(&(queue->entries));
28 v3_lock_init(&queue->lock);
31 struct v3_queue * v3_create_queue() {
32 struct v3_queue * tmp_queue = V3_Malloc(sizeof(struct v3_queue));
35 PrintError(VM_NONE, VCORE_NONE,"Cannot allocate a queue\n");
39 v3_init_queue(tmp_queue);
43 void v3_deinit_queue(struct v3_queue * queue) {
44 while (v3_dequeue(queue)) {
45 PrintError(VM_NONE, VCORE_NONE,"ERROR: Freeing non-empty queue. PROBABLE MEMORY LEAK DETECTED\n");
48 v3_lock_deinit(&(queue->lock));
54 void v3_enqueue(struct v3_queue * queue, addr_t entry) {
55 struct v3_queue_entry * q_entry = V3_Malloc(sizeof(struct v3_queue_entry));
56 unsigned int flags = 0;
59 PrintError(VM_NONE, VCORE_NONE,"Cannot allocate a queue entry for enqueue\n");
63 flags = v3_lock_irqsave(queue->lock);
64 q_entry->entry = entry;
65 list_add_tail(&(q_entry->entry_list), &(queue->entries));
67 v3_unlock_irqrestore(queue->lock, flags);
71 addr_t v3_dequeue(struct v3_queue * queue) {
73 unsigned int flags = 0;
75 flags = v3_lock_irqsave(queue->lock);
76 if (!list_empty(&(queue->entries))) {
77 struct list_head * q_entry = queue->entries.next;
78 struct v3_queue_entry * tmp_entry = list_entry(q_entry, struct v3_queue_entry, entry_list);
80 entry_val = tmp_entry->entry;
84 v3_unlock_irqrestore(queue->lock, flags);