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 / include / lwk / waitq.h
1 #ifndef _LWK_WAITQ_H
2 #define _LWK_WAITQ_H
3
4 #include <lwk/spinlock.h>
5 #include <lwk/list.h>
6 #include <lwk/task.h>
7
8 typedef struct waitq {
9         spinlock_t           lock;
10         struct list_head     waitq;
11 } waitq_t;
12
13 typedef struct waitq_entry {
14         struct task_struct * task;
15         struct list_head     link;
16 } waitq_entry_t;
17
18 #define DECLARE_WAITQ(name)                             \
19         waitq_t name = {                                \
20             .lock  = SPIN_LOCK_UNLOCKED,                \
21             .waitq = { &(name).waitq, &(name).waitq }   \
22         }
23
24 #define DECLARE_WAITQ_ENTRY(name, tsk)                  \
25         waitq_entry_t name = {                          \
26             .task  = tsk,                               \
27             .link  = { &(name).link, &(name).link }     \
28         }
29
30 extern void waitq_init(waitq_t *waitq);
31 extern void waitq_init_entry(waitq_entry_t *entry, struct task_struct *task);
32 extern bool waitq_active(waitq_t *waitq);
33 extern void waitq_add_entry(waitq_t *waitq, waitq_entry_t *entry);
34 extern void waitq_prepare_to_wait(waitq_t *waitq, waitq_entry_t *entry,
35                                   taskstate_t state);
36 extern void waitq_finish_wait(waitq_t *waitq, waitq_entry_t *entry);
37 extern void waitq_wakeup(waitq_t *waitq);
38
39 /**
40  * This puts the task to sleep until condition becomes true.
41  * This must be a macro because condition is tested repeatedly, not just
42  * when wait_event() is first called.
43  */
44 #define wait_event(waitq, condition)                               \
45 do {                                                               \
46         DECLARE_WAITQ_ENTRY(__entry, current);                     \
47         for (;;) {                                                 \
48                 waitq_prepare_to_wait(&waitq, &__entry,            \
49                                       TASKSTATE_UNINTERRUPTIBLE);  \
50                 if (condition)                                     \
51                         break;                                     \
52                 schedule();                                        \
53         }                                                          \
54         waitq_finish_wait(&waitq, &__entry);                       \
55 } while (0)
56
57 #endif