Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Cleanup of linkage issues for non-Linux hosts
[palacios.git] / linux_module / util-queue.c
index 58221a6..0dba00b 100644 (file)
@@ -1,24 +1,11 @@
 /* 
- * 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) {
@@ -26,11 +13,22 @@ 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;
 }
@@ -43,15 +41,20 @@ int enqueue(struct gen_queue * queue, void * entry) {
        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;
 }
@@ -61,7 +64,7 @@ void * dequeue(struct gen_queue * queue) {
     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;
@@ -69,13 +72,13 @@ void * dequeue(struct gen_queue * queue) {
        
        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;
 }