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.


44530a42a974fda4611db5f7ec126529f4e7bbd4
[palacios.git] / palacios / src / geekos / queue.c
1 /* Northwestern University */
2 /* (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> */
3
4 #include <geekos/queue.h>
5
6
7
8 void init_queue(struct gen_queue * queue) {
9   queue->num_entries = 0;
10   INIT_LIST_HEAD(&(queue->entries));
11 }
12
13
14 struct gen_queue * create_queue() {
15   struct gen_queue * tmp_queue = Malloc(sizeof(struct gen_queue));
16   init_queue(tmp_queue);
17   return tmp_queue;
18 }
19
20 void enqueue(struct gen_queue * queue, void * entry) {
21   struct queue_entry * q_entry = Malloc(sizeof(struct queue_entry));
22
23   q_entry->entry = entry;
24   list_add_tail(&(q_entry->entry_list), &(queue->entries));
25   queue->num_entries++;
26 }
27
28
29 void * dequeue(struct gen_queue * queue) {
30   void * entry_val = 0;
31   
32   if (!list_empty(&(queue->entries))) {
33     struct list_head * q_entry = queue->entries.next;
34     struct queue_entry * tmp_entry = list_entry(q_entry, struct queue_entry, entry_list);
35
36     entry_val = tmp_entry->entry;
37     list_del(q_entry);
38     Free(tmp_entry);
39   }
40
41   return entry_val;
42 }