X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_module%2Futil-queue.c;h=0dba00b8c8a794f4d4e737500882713694f5cc32;hb=8cd246c3830733c2850cef049a7ad153daf0dd13;hp=ee32439beab5543face00ca7cf43e01057357998;hpb=95908965b5963c53a40e9eae8ad0307a2bc27434;p=palacios.git diff --git a/linux_module/util-queue.c b/linux_module/util-queue.c index ee32439..0dba00b 100644 --- a/linux_module/util-queue.c +++ b/linux_module/util-queue.c @@ -1,10 +1,11 @@ /* - * Queue implementation - * Jack Lange 2011 - */ + * Queue implementation + * Jack Lange 2011 + */ #include +#include "palacios.h" #include "util-queue.h" void init_queue(struct gen_queue * queue, unsigned int max_entries) { @@ -12,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; } @@ -29,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; } @@ -47,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; @@ -55,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; }