X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_queue.c;h=a4b5144cddd800c3f67a74919449ec8b71e33d36;hb=4454a172129d12e97793c9c353339b85d3335af4;hp=03cfb6d5098b7fcb9d19b743a2d8e23ab9939dd8;hpb=43cf194456fcf1cc7bf4850aa0200a50e7a27920;p=palacios.git diff --git a/palacios/src/palacios/vmm_queue.c b/palacios/src/palacios/vmm_queue.c index 03cfb6d..a4b5144 100644 --- a/palacios/src/palacios/vmm_queue.c +++ b/palacios/src/palacios/vmm_queue.c @@ -19,6 +19,9 @@ #include + + + void v3_init_queue(struct v3_queue * queue) { queue->num_entries = 0; INIT_LIST_HEAD(&(queue->entries)); @@ -27,25 +30,49 @@ void v3_init_queue(struct v3_queue * 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_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 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 v3_queue_entry * tmp_entry = list_entry(q_entry, struct v3_queue_entry, entry_list); @@ -54,7 +81,7 @@ addr_t v3_dequeue(struct v3_queue * queue) { list_del(q_entry); V3_Free(tmp_entry); } - v3_unlock(queue->lock); + v3_unlock_irqrestore(queue->lock, flags); return entry_val; }