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.


Context-based output infrastructure (V3_Print, etc) and modifications to use it
[palacios.git] / palacios / src / palacios / vmm_queue.c
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20 #include <palacios/vmm_queue.h>
21
22
23
24
25 void v3_init_queue(struct v3_queue * queue) {
26     queue->num_entries = 0;
27     INIT_LIST_HEAD(&(queue->entries));
28     v3_lock_init(&queue->lock);
29 }
30
31 struct v3_queue * v3_create_queue() {
32     struct v3_queue * tmp_queue = V3_Malloc(sizeof(struct v3_queue));
33
34     if (!tmp_queue) {
35         PrintError(VM_NONE, VCORE_NONE,"Cannot allocate a queue\n");
36         return NULL;
37     }
38
39     v3_init_queue(tmp_queue);
40     return tmp_queue;
41 }
42
43 void v3_deinit_queue(struct v3_queue * queue) {
44     while (v3_dequeue(queue)) {
45         PrintError(VM_NONE, VCORE_NONE,"ERROR: Freeing non-empty queue. PROBABLE MEMORY LEAK DETECTED\n");
46     }
47
48     v3_lock_deinit(&(queue->lock));
49 }
50
51
52
53
54 void v3_enqueue(struct v3_queue * queue, addr_t entry) {
55     struct v3_queue_entry * q_entry = V3_Malloc(sizeof(struct v3_queue_entry));
56     unsigned int flags = 0;
57
58     if (!q_entry) {
59         PrintError(VM_NONE, VCORE_NONE,"Cannot allocate a queue entry for enqueue\n");
60         return ;
61     }
62
63     flags = v3_lock_irqsave(queue->lock);
64     q_entry->entry = entry;
65     list_add_tail(&(q_entry->entry_list), &(queue->entries));
66     queue->num_entries++;
67     v3_unlock_irqrestore(queue->lock, flags);
68 }
69
70
71 addr_t v3_dequeue(struct v3_queue * queue) {
72     addr_t entry_val = 0;
73     unsigned int flags = 0;
74
75     flags = v3_lock_irqsave(queue->lock);
76     if (!list_empty(&(queue->entries))) {
77         struct list_head * q_entry = queue->entries.next;
78         struct v3_queue_entry * tmp_entry = list_entry(q_entry, struct v3_queue_entry, entry_list);
79
80         entry_val = tmp_entry->entry;
81         list_del(q_entry);
82         V3_Free(tmp_entry);
83     }
84     v3_unlock_irqrestore(queue->lock, flags);
85
86     return entry_val;
87 }