OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [include/] [l4/] [lib/] [wait.h] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#ifndef __LIB_WAIT_H__
2
#define __LIB_WAIT_H__
3
 
4
#include <l4/lib/list.h>
5
#include <l4/lib/spinlock.h>
6
 
7
struct ktcb;
8
struct waitqueue {
9
        struct link task_list;
10
        struct ktcb *task;
11
};
12
 
13
#define WAKEUP_ASYNC                    0
14
 
15
enum wakeup_flags {
16
        WAKEUP_INTERRUPT = (1 << 0),     /* Set interrupt flag for task */
17
        WAKEUP_SYNC      = (1 << 1),    /* Wake it up synchronously */
18
};
19
 
20
#define CREATE_WAITQUEUE_ON_STACK(wq, tsk)              \
21
struct waitqueue wq = {                                 \
22
        .task_list = { &wq.task_list, &wq.task_list },  \
23
        .task = tsk,                                    \
24
};
25
 
26
struct waitqueue_head {
27
        int sleepers;
28
        struct spinlock slock;
29
        struct link task_list;
30
};
31
 
32
static inline void waitqueue_head_init(struct waitqueue_head *head)
33
{
34
        memset(head, 0, sizeof(struct waitqueue_head));
35
        link_init(&head->task_list);
36
}
37
 
38
void task_set_wqh(struct ktcb *task, struct waitqueue_head *wqh,
39
                  struct waitqueue *wq);
40
 
41
void task_unset_wqh(struct ktcb *task);
42
 
43
 
44
/*
45
 * Sleep if the given condition isn't true.
46
 * ret will tell whether condition was met
47
 * or we got interrupted.
48
 */
49
#define WAIT_EVENT(wqh, condition, ret)                         \
50
do {                                                            \
51
        ret = 0;                                         \
52
        for (;;) {                                              \
53
                unsigned long irqsave;                          \
54
                spin_lock_irq(&(wqh)->slock, &irqsave);         \
55
                if (condition) {                                \
56
                        spin_unlock_irq(&(wqh)->slock, irqsave);\
57
                        break;                                  \
58
                }                                               \
59
                CREATE_WAITQUEUE_ON_STACK(wq, current);         \
60
                task_set_wqh(current, wqh, &wq);                \
61
                (wqh)->sleepers++;                              \
62
                list_insert_tail(&wq.task_list,                 \
63
                                 &(wqh)->task_list);            \
64
                /* printk("(%d) waiting...\n", current->tid); */\
65
                sched_prepare_sleep();                          \
66
                spin_unlock_irq(&(wqh)->slock, irqsave);        \
67
                schedule();                                     \
68
                /* Did we wake up normally or get interrupted */\
69
                if (current->flags & TASK_INTERRUPTED) {        \
70
                        current->flags &= ~TASK_INTERRUPTED;    \
71
                        ret = -EINTR;                           \
72
                        break;                                  \
73
                }                                               \
74
        }                                                       \
75
} while(0);
76
 
77
 
78
void wake_up(struct waitqueue_head *wqh, unsigned int flags);
79
int wake_up_task(struct ktcb *task, unsigned int flags);
80
void wake_up_all(struct waitqueue_head *wqh, unsigned int flags);
81
 
82
int wait_on(struct waitqueue_head *wqh);
83
int wait_on_prepare(struct waitqueue_head *wqh, struct waitqueue *wq);
84
int wait_on_prepared_wait(void);
85
#endif /* __LIB_WAIT_H__ */
86
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.