/*
- * This file is part of the Palacios Virtual Machine Monitor developed
- * by the V3VEE Project with funding from the United States National
- * Science Foundation and the Department of Energy.
- *
- * The V3VEE Project is a joint project between Northwestern University
- * and the University of New Mexico. You can find out more at
- * http://www.v3vee.org
- *
- * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
- * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
- * All rights reserved.
- *
- * Author: Jack Lange <jarusl@cs.northwestern.edu>
- *
- * This is free software. You are permitted to use,
- * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ * Queue implementation
+ * Jack Lange 2011
*/
#include <linux/slab.h>
+#include "palacios.h"
#include "util-queue.h"
void init_queue(struct gen_queue * queue, unsigned int max_entries) {
queue->max_entries = max_entries;
INIT_LIST_HEAD(&(queue->entries));
- spin_lock_init(&(queue->lock));
+ palacios_spinlock_init(&(queue->lock));
+}
+
+void deinit_queue(struct gen_queue * queue) {
+ while (dequeue(queue)) {
+ ERROR("Freeing non-empty queue. PROBABLE MEMORY LEAK DETECTED\n");
+ }
+ palacios_spinlock_deinit(&(queue->lock));
}
struct gen_queue * create_queue(unsigned int max_entries) {
- struct gen_queue * tmp_queue = kmalloc(sizeof(struct gen_queue), GFP_KERNEL);
+ struct gen_queue * tmp_queue = palacios_alloc(sizeof(struct gen_queue));
+ if (!tmp_queue) {
+ ERROR("Unable to allocate a queue\n");
+ return NULL;
+ }
init_queue(tmp_queue, max_entries);
return tmp_queue;
}
return -1;
}
- q_entry = kmalloc(sizeof(struct queue_entry), GFP_KERNEL);
+ q_entry = palacios_alloc(sizeof(struct queue_entry));
+
+ if (!q_entry) {
+ ERROR("Unable to allocate a queue entry on enqueue\n");
+ return -1;
+ }
- spin_lock_irqsave(&(queue->lock), flags);
+ palacios_spinlock_lock_irqsave(&(queue->lock), flags);
q_entry->entry = entry;
list_add_tail(&(q_entry->node), &(queue->entries));
queue->num_entries++;
- spin_unlock_irqrestore(&(queue->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(queue->lock), flags);
return 0;
}
void * entry_val = 0;
unsigned long flags;
- spin_lock_irqsave(&(queue->lock), flags);
+ palacios_spinlock_lock_irqsave(&(queue->lock), flags);
if (!list_empty(&(queue->entries))) {
struct list_head * q_entry = queue->entries.next;
entry_val = tmp_entry->entry;
list_del(q_entry);
- kfree(tmp_entry);
+ palacios_free(tmp_entry);
queue->num_entries--;
}
- spin_unlock_irqrestore(&(queue->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(queue->lock), flags);
return entry_val;
}