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.


Merge branch 'devel'
[palacios.git] / kitten / kernel / waitq.c
1 #include <lwk/kernel.h>
2 #include <lwk/waitq.h>
3 #include <lwk/sched.h>
4
5 void
6 waitq_init(waitq_t *waitq)
7 {
8         spin_lock_init(&waitq->lock);
9         list_head_init(&waitq->waitq);
10 }
11
12 void
13 waitq_init_entry(waitq_entry_t *entry, struct task_struct *task)
14 {
15         entry->task = task;
16         list_head_init(&entry->link);
17 }
18
19 bool
20 waitq_active(waitq_t *waitq)
21 {
22         bool active;
23         unsigned long irqstate;
24
25         spin_lock_irqsave(&waitq->lock, irqstate);
26         active = !list_empty(&waitq->waitq);
27         spin_unlock_irqrestore(&waitq->lock, irqstate);
28
29         return active;
30 }
31
32 void
33 waitq_add_entry(waitq_t *waitq, waitq_entry_t *entry)
34 {
35         unsigned long irqstate;
36
37         spin_lock_irqsave(&waitq->lock, irqstate);
38         BUG_ON(!list_empty(&entry->link));
39         list_add(&entry->link, &waitq->waitq);
40         spin_unlock_irqrestore(&waitq->lock, irqstate);
41 }
42
43 void
44 waitq_remove_entry(waitq_t *waitq, waitq_entry_t *entry)
45 {
46         unsigned long irqstate;
47
48         spin_lock_irqsave(&waitq->lock, irqstate);
49         BUG_ON(list_empty(&entry->link));
50         list_del_init(&entry->link);
51         spin_unlock_irqrestore(&waitq->lock, irqstate);
52 }
53
54 void
55 waitq_prepare_to_wait(waitq_t *waitq, waitq_entry_t *entry, taskstate_t state)
56 {
57         unsigned long irqstate;
58
59         spin_lock_irqsave(&waitq->lock, irqstate);
60         if (list_empty(&entry->link))
61                 list_add(&entry->link, &waitq->waitq);
62         set_mb(entry->task->state, state);
63         spin_unlock_irqrestore(&waitq->lock, irqstate);
64 }
65
66 void
67 waitq_finish_wait(waitq_t *waitq, waitq_entry_t *entry)
68 {
69         set_mb(entry->task->state, TASKSTATE_READY);
70         waitq_remove_entry(waitq, entry);
71 }
72
73 void
74 waitq_wakeup(waitq_t *waitq)
75 {
76         unsigned long irqstate;
77         struct list_head *tmp;
78         waitq_entry_t *entry;
79
80         spin_lock_irqsave(&waitq->lock, irqstate);
81         list_for_each(tmp, &waitq->waitq) {
82                 entry  = list_entry(tmp, waitq_entry_t, link);
83                 sched_wakeup_task(
84                         entry->task,
85                         (TASKSTATE_UNINTERRUPTIBLE | TASKSTATE_INTERRUPTIBLE)
86                 );
87         }
88         spin_unlock_irqrestore(&waitq->lock, irqstate);
89 }