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 and sanity-checking of integer overflow, null comparisons, dead code (Coverit...
[palacios.git] / palacios / src / palacios / vmm_queue.c
index b06ff73..a4b5144 100644 (file)
 
 #include <palacios/vmm_queue.h>
 
-void v3_init_queue(struct gen_queue * queue) {
+
+
+
+void v3_init_queue(struct v3_queue * queue) {
     queue->num_entries = 0;
     INIT_LIST_HEAD(&(queue->entries));
     v3_lock_init(&queue->lock);
 }
 
-struct gen_queue * v3_create_queue() {
-    struct gen_queue * tmp_queue = V3_Malloc(sizeof(struct gen_queue));
+struct v3_queue * v3_create_queue() {
+    struct v3_queue * tmp_queue = V3_Malloc(sizeof(struct v3_queue));
+
+    if (!tmp_queue) {
+        PrintError(VM_NONE, VCORE_NONE,"Cannot allocate a queue\n");
+       return NULL;
+    }
+
     v3_init_queue(tmp_queue);
     return tmp_queue;
 }
 
-void v3_enqueue(struct gen_queue * queue, addr_t entry) {
-    struct queue_entry * q_entry = V3_Malloc(sizeof(struct queue_entry));
+void v3_deinit_queue(struct v3_queue * queue) {
+    while (v3_dequeue(queue)) {
+       PrintError(VM_NONE, VCORE_NONE,"ERROR: Freeing non-empty queue. PROBABLE MEMORY LEAK DETECTED\n");
+    }
+
+    v3_lock_deinit(&(queue->lock));
+}
+
+
+
+
+void v3_enqueue(struct v3_queue * queue, addr_t entry) {
+    struct v3_queue_entry * q_entry = V3_Malloc(sizeof(struct v3_queue_entry));
+    unsigned int flags = 0;
+
+    if (!q_entry) {
+       PrintError(VM_NONE, VCORE_NONE,"Cannot allocate a queue entry for enqueue\n");
+       return ;
+    }
 
-    v3_lock(queue->lock);
+    flags = v3_lock_irqsave(queue->lock);
     q_entry->entry = entry;
     list_add_tail(&(q_entry->entry_list), &(queue->entries));
     queue->num_entries++;
-    v3_unlock(queue->lock);
+    v3_unlock_irqrestore(queue->lock, flags);
 }
 
 
-addr_t v3_dequeue(struct gen_queue * queue) {
+addr_t v3_dequeue(struct v3_queue * queue) {
     addr_t entry_val = 0;
+    unsigned int flags = 0;
 
-    v3_lock(queue->lock);
+    flags = v3_lock_irqsave(queue->lock);
     if (!list_empty(&(queue->entries))) {
        struct list_head * q_entry = queue->entries.next;
-       struct queue_entry * tmp_entry = list_entry(q_entry, struct queue_entry, entry_list);
+       struct v3_queue_entry * tmp_entry = list_entry(q_entry, struct v3_queue_entry, entry_list);
 
        entry_val = tmp_entry->entry;
        list_del(q_entry);
        V3_Free(tmp_entry);
     }
-    v3_unlock(queue->lock);
+    v3_unlock_irqrestore(queue->lock, flags);
 
     return entry_val;
 }