Subversion Repositories Kolibri OS

Rev

Rev 5270 | Rev 6125 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5270 Rev 6102
Line 5... Line 5...
5
 */
5
 */
6
#include 
6
#include 
7
#include 
7
#include 
8
#include 
8
#include 
9
#include 
9
#include 
10
 
-
 
11
 
-
 
12
 
-
 
13
#include 
10
#include 
Line 14... Line 11...
14
 
11
 
15
typedef struct __wait_queue wait_queue_t;
12
typedef struct __wait_queue wait_queue_t;
16
typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key);
13
typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key);
Line 17... Line 14...
17
int default_wake_function(wait_queue_t *wait, unsigned mode, int flags, void *key);
14
int default_wake_function(wait_queue_t *wait, unsigned mode, int flags, void *key);
-
 
15
 
-
 
16
/* __wait_queue::flags */
18
 
17
#define WQ_FLAG_EXCLUSIVE	0x01
19
typedef struct __wait_queue_head wait_queue_head_t;
18
#define WQ_FLAG_WOKEN		0x02
-
 
19
 
20
 
20
struct __wait_queue {
21
struct __wait_queue
21
	unsigned int		flags;
22
{
22
	void			*private;
23
    wait_queue_func_t func;
23
	wait_queue_func_t	func;
24
    struct list_head task_list;
24
	struct list_head	task_list;
Line -... Line 25...
-
 
25
	evhandle_t evnt;
-
 
26
};
-
 
27
 
-
 
28
struct wait_bit_key {
-
 
29
	void			*flags;
-
 
30
	int			bit_nr;
-
 
31
#define WAIT_ATOMIC_T_BIT_NR	-1
25
    evhandle_t evnt;
32
	unsigned long		timeout;
-
 
33
};
-
 
34
 
-
 
35
struct wait_bit_queue {
26
};
36
	struct wait_bit_key	key;
-
 
37
	wait_queue_t		wait;
27
 
38
};
28
struct __wait_queue_head
39
 
29
{
40
struct __wait_queue_head {
-
 
41
	spinlock_t		lock;
-
 
42
	struct list_head	task_list;
-
 
43
};
-
 
44
typedef struct __wait_queue_head wait_queue_head_t;
-
 
45
 
-
 
46
struct task_struct;
-
 
47
 
-
 
48
/*
-
 
49
 * Macros for declaration and initialisaton of the datatypes
-
 
50
 */
-
 
51
 
-
 
52
#define __WAITQUEUE_INITIALIZER(name, tsk) {				\
-
 
53
	.private	= tsk,						\
-
 
54
	.func		= default_wake_function,			\
-
 
55
	.task_list	= { NULL, NULL } }
-
 
56
 
-
 
57
#define DECLARE_WAITQUEUE(name, tsk)					\
-
 
58
	wait_queue_t name = __WAITQUEUE_INITIALIZER(name, tsk)
-
 
59
 
-
 
60
#define __WAIT_QUEUE_HEAD_INITIALIZER(name) {				\
-
 
61
	.lock		= __SPIN_LOCK_UNLOCKED(name.lock),		\
-
 
62
	.task_list	= { &(name).task_list, &(name).task_list } }
-
 
63
 
-
 
64
#define DECLARE_WAIT_QUEUE_HEAD(name) \
-
 
65
	wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
-
 
66
 
-
 
67
#define __WAIT_BIT_KEY_INITIALIZER(word, bit)				\
-
 
68
	{ .flags = word, .bit_nr = bit, }
-
 
69
 
-
 
70
#define __WAIT_ATOMIC_T_KEY_INITIALIZER(p)				\
-
 
71
	{ .flags = p, .bit_nr = WAIT_ATOMIC_T_BIT_NR, }
-
 
72
 
-
 
73
extern void __init_waitqueue_head(wait_queue_head_t *q, const char *name, struct lock_class_key *);
-
 
74
 
-
 
75
#ifdef CONFIG_LOCKDEP
-
 
76
# define __WAIT_QUEUE_HEAD_INIT_ONSTACK(name) \
-
 
77
	({ init_waitqueue_head(&name); name; })
-
 
78
# define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) \
-
 
79
	wait_queue_head_t name = __WAIT_QUEUE_HEAD_INIT_ONSTACK(name)
-
 
80
#else
-
 
81
# define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) DECLARE_WAIT_QUEUE_HEAD(name)
-
 
82
#endif
-
 
83
 
-
 
84
static inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p)
-
 
85
{
-
 
86
	q->flags	= 0;
-
 
87
	q->private	= p;
-
 
88
	q->func		= default_wake_function;
-
 
89
}
-
 
90
 
-
 
91
static inline void
-
 
92
init_waitqueue_func_entry(wait_queue_t *q, wait_queue_func_t func)
-
 
93
{
-
 
94
	q->flags	= 0;
-
 
95
	q->private	= NULL;
30
    spinlock_t lock;
96
	q->func		= func;
31
    struct list_head task_list;
97
}
32
};
98
 
33
static inline int waitqueue_active(wait_queue_head_t *q)
99
static inline int waitqueue_active(wait_queue_head_t *q)
Line 43... Line 109...
43
{
109
{
44
    list_add(&new->task_list, &head->task_list);
110
	list_add(&new->task_list, &head->task_list);
45
}
111
}
Line 46... Line 112...
46
 
112
 
-
 
113
/*
-
 
114
 * Used for wake-one threads:
-
 
115
 */
-
 
116
static inline void
-
 
117
__add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
-
 
118
{
-
 
119
	wait->flags |= WQ_FLAG_EXCLUSIVE;
-
 
120
	__add_wait_queue(q, wait);
-
 
121
}
-
 
122
 
-
 
123
static inline void __add_wait_queue_tail(wait_queue_head_t *head,
-
 
124
					 wait_queue_t *new)
-
 
125
{
-
 
126
	list_add_tail(&new->task_list, &head->task_list);
-
 
127
}
-
 
128
 
-
 
129
static inline void
-
 
130
__add_wait_queue_tail_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
-
 
131
{
-
 
132
	wait->flags |= WQ_FLAG_EXCLUSIVE;
-
 
133
	__add_wait_queue_tail(q, wait);
-
 
134
}
-
 
135
 
-
 
136
static inline void
-
 
137
__remove_wait_queue(wait_queue_head_t *head, wait_queue_t *old)
-
 
138
{
-
 
139
	list_del(&old->task_list);
-
 
140
}
-
 
141
 
-
 
142
typedef int wait_bit_action_f(struct wait_bit_key *, int mode);
-
 
143
void __wake_up(wait_queue_head_t *q, unsigned int mode, int nr, void *key);
-
 
144
void __wake_up_locked_key(wait_queue_head_t *q, unsigned int mode, void *key);
-
 
145
void __wake_up_sync_key(wait_queue_head_t *q, unsigned int mode, int nr, void *key);
-
 
146
void __wake_up_locked(wait_queue_head_t *q, unsigned int mode, int nr);
-
 
147
void __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr);
-
 
148
void __wake_up_bit(wait_queue_head_t *, void *, int);
-
 
149
int __wait_on_bit(wait_queue_head_t *, struct wait_bit_queue *, wait_bit_action_f *, unsigned);
-
 
150
int __wait_on_bit_lock(wait_queue_head_t *, struct wait_bit_queue *, wait_bit_action_f *, unsigned);
-
 
151
void wake_up_bit(void *, int);
-
 
152
void wake_up_atomic_t(atomic_t *);
-
 
153
int out_of_line_wait_on_bit(void *, int, wait_bit_action_f *, unsigned);
-
 
154
int out_of_line_wait_on_bit_timeout(void *, int, wait_bit_action_f *, unsigned, unsigned long);
-
 
155
int out_of_line_wait_on_bit_lock(void *, int, wait_bit_action_f *, unsigned);
-
 
156
int out_of_line_wait_on_atomic_t(atomic_t *, int (*)(atomic_t *), unsigned);
-
 
157
wait_queue_head_t *bit_waitqueue(void *, int);
-
 
158
 
-
 
159
/*
47
/*
160
 
48
#define __wait_event(wq, condition)                                     \
161
#define __wait_event(wq, condition)                                     \
49
do {                                                                    \
162
do {                                                                    \
50
        DEFINE_WAIT(__wait);                                            \
163
        DEFINE_WAIT(__wait);                                            \
51
                                                                        \
164
                                                                        \
Line 126... Line 239...
126
    if (!(condition))                                       \
239
    if (!(condition))                                       \
127
        wait_event(wq, condition);                          \
240
        wait_event(wq, condition);                          \
128
    __ret;                                                  \
241
    __ret;                                                  \
129
})
242
})
Line -... Line 243...
-
 
243
 
-
 
244
static inline
-
 
245
void wake_up(wait_queue_head_t *q)
-
 
246
{
-
 
247
    wait_queue_t *curr;
-
 
248
    unsigned long flags;
-
 
249
 
-
 
250
    spin_lock_irqsave(&q->lock, flags);
-
 
251
    curr = list_first_entry(&q->task_list, typeof(*curr), task_list);
-
 
252
    {
-
 
253
//        printf("raise event \n");
-
 
254
        kevent_t event;
-
 
255
        event.code = -1;
-
 
256
        RaiseEvent(curr->evnt, 0, &event);
-
 
257
    }
-
 
258
    spin_unlock_irqrestore(&q->lock, flags);
-
 
259
}
-
 
260
 
-
 
261
static inline
-
 
262
void wake_up_interruptible(wait_queue_head_t *q)
-
 
263
{
-
 
264
    wait_queue_t *curr;
-
 
265
    unsigned long flags;
-
 
266
 
-
 
267
    spin_lock_irqsave(&q->lock, flags);
-
 
268
    curr = list_first_entry(&q->task_list, typeof(*curr), task_list);
-
 
269
    {
-
 
270
//        printf("raise event \n");
-
 
271
        kevent_t event;
-
 
272
        event.code = -1;
-
 
273
        RaiseEvent(curr->evnt, 0, &event);
-
 
274
    }
-
 
275
    spin_unlock_irqrestore(&q->lock, flags);
Line 130... Line 276...
130
 
276
}
131
 
277
 
132
static inline
278
static inline
133
void wake_up_all(wait_queue_head_t *q)
279
void wake_up_all(wait_queue_head_t *q)
Line 137... Line 283...
137
 
283
 
138
    spin_lock_irqsave(&q->lock, flags);
284
    spin_lock_irqsave(&q->lock, flags);
139
    list_for_each_entry(curr, &q->task_list, task_list)
285
    list_for_each_entry(curr, &q->task_list, task_list)
140
    {
286
    {
141
//        printf("raise event \n");
-
 
142
 
287
//        printf("raise event \n");
143
        kevent_t event;
288
        kevent_t event;
144
        event.code = -1;
289
        event.code = -1;
145
        RaiseEvent(curr->evnt, 0, &event);
290
        RaiseEvent(curr->evnt, 0, &event);
146
    }
291
    }