X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_queue.c;h=a4b5144cddd800c3f67a74919449ec8b71e33d36;hb=28cd2d6deca639fe40256c4d3f2c8f9491ec777a;hp=8a90edc8bc227843e24920426ef3d0c30fe1f083;hpb=4f7c3b759e3889870c5b5e7d09b3ffcc168e5632;p=palacios.git diff --git a/palacios/src/palacios/vmm_queue.c b/palacios/src/palacios/vmm_queue.c index 8a90edc..a4b5144 100644 --- a/palacios/src/palacios/vmm_queue.c +++ b/palacios/src/palacios/vmm_queue.c @@ -1,42 +1,87 @@ -/* Northwestern University */ -/* (c) 2008, Jack Lange */ +/* + * 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 + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ #include -void v3_init_queue(struct gen_queue * queue) { - queue->num_entries = 0; - INIT_LIST_HEAD(&(queue->entries)); + +void v3_init_queue(struct v3_queue * queue) { + queue->num_entries = 0; + INIT_LIST_HEAD(&(queue->entries)); + v3_lock_init(&queue->lock); +} + +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"); + } -struct gen_queue * v3_create_queue() { - struct gen_queue * tmp_queue = V3_Malloc(sizeof(struct gen_queue)); - v3_init_queue(tmp_queue); - return tmp_queue; + v3_lock_deinit(&(queue->lock)); } -void v3_enqueue(struct gen_queue * queue, addr_t entry) { - struct queue_entry * q_entry = V3_Malloc(sizeof(struct queue_entry)); - q_entry->entry = entry; - list_add_tail(&(q_entry->entry_list), &(queue->entries)); - queue->num_entries++; + + +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 ; + } + + flags = v3_lock_irqsave(queue->lock); + q_entry->entry = entry; + list_add_tail(&(q_entry->entry_list), &(queue->entries)); + queue->num_entries++; + v3_unlock_irqrestore(queue->lock, flags); } -addr_t v3_dequeue(struct gen_queue * queue) { - addr_t entry_val = 0; +addr_t v3_dequeue(struct v3_queue * queue) { + addr_t entry_val = 0; + unsigned int flags = 0; - 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); + 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); - entry_val = tmp_entry->entry; - list_del(q_entry); - V3_Free(tmp_entry); - } + entry_val = tmp_entry->entry; + list_del(q_entry); + V3_Free(tmp_entry); + } + v3_unlock_irqrestore(queue->lock, flags); - return entry_val; + return entry_val; }