X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_module%2Futil-queue.c;h=0dba00b8c8a794f4d4e737500882713694f5cc32;hb=2cb41f7db5b9f89113432d6b3daff4807ba8e5f2;hp=58221a64d8cf9c384d8b915d32048ad73311bd79;hpb=276cfa264720edddc1677e35c6a300596965de7d;p=palacios.git diff --git a/linux_module/util-queue.c b/linux_module/util-queue.c index 58221a6..0dba00b 100644 --- a/linux_module/util-queue.c +++ b/linux_module/util-queue.c @@ -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 - * 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". + * Queue implementation + * Jack Lange 2011 */ #include +#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; }