2012-09-04 23:42:08 +02:00
|
|
|
#ifndef _LINUX_WAIT_H
|
|
|
|
#define _LINUX_WAIT_H
|
|
|
|
|
2013-11-26 07:16:07 +01:00
|
|
|
|
2013-03-01 07:44:14 +01:00
|
|
|
#include <linux/list.h>
|
2013-01-22 16:16:44 +01:00
|
|
|
#include <syscall.h>
|
|
|
|
|
2012-09-04 23:42:08 +02:00
|
|
|
typedef struct __wait_queue wait_queue_t;
|
2013-03-19 07:14:59 +01:00
|
|
|
typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key);
|
2013-11-26 07:16:07 +01:00
|
|
|
int default_wake_function(wait_queue_t *wait, unsigned mode, int flags, void *key);
|
2013-03-19 07:14:59 +01:00
|
|
|
|
2012-09-04 23:42:08 +02:00
|
|
|
typedef struct __wait_queue_head wait_queue_head_t;
|
|
|
|
|
|
|
|
struct __wait_queue
|
|
|
|
{
|
2013-03-19 07:14:59 +01:00
|
|
|
wait_queue_func_t func;
|
2012-09-04 23:42:08 +02:00
|
|
|
struct list_head task_list;
|
|
|
|
evhandle_t evnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct __wait_queue_head
|
|
|
|
{
|
|
|
|
spinlock_t lock;
|
|
|
|
struct list_head task_list;
|
|
|
|
};
|
2013-11-26 07:16:07 +01:00
|
|
|
static inline int waitqueue_active(wait_queue_head_t *q)
|
|
|
|
{
|
|
|
|
return !list_empty(&q->task_list);
|
|
|
|
}
|
2012-09-04 23:42:08 +02:00
|
|
|
|
|
|
|
static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
|
|
|
|
{
|
|
|
|
list_add(&new->task_list, &head->task_list);
|
|
|
|
}
|
|
|
|
|
2013-04-26 13:01:23 +02:00
|
|
|
/*
|
2012-09-04 23:42:08 +02:00
|
|
|
#define __wait_event(wq, condition) \
|
|
|
|
do { \
|
|
|
|
DEFINE_WAIT(__wait); \
|
|
|
|
\
|
|
|
|
for (;;) { \
|
|
|
|
prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
|
|
|
|
if (condition) \
|
|
|
|
break; \
|
|
|
|
schedule(); \
|
|
|
|
} \
|
|
|
|
finish_wait(&wq, &__wait); \
|
|
|
|
} while (0)
|
|
|
|
|
2013-04-26 13:01:23 +02:00
|
|
|
*/
|
2012-11-12 22:22:52 +01:00
|
|
|
|
|
|
|
#define wait_event_timeout(wq, condition, timeout) \
|
|
|
|
({ \
|
|
|
|
long __ret = timeout; \
|
|
|
|
do{ \
|
|
|
|
wait_queue_t __wait = { \
|
|
|
|
.task_list = LIST_HEAD_INIT(__wait.task_list), \
|
|
|
|
.evnt = CreateEvent(NULL, MANUAL_DESTROY), \
|
|
|
|
}; \
|
2013-03-01 07:44:14 +01:00
|
|
|
unsigned long flags; \
|
2012-11-12 22:22:52 +01:00
|
|
|
\
|
|
|
|
spin_lock_irqsave(&wq.lock, flags); \
|
|
|
|
if (list_empty(&__wait.task_list)) \
|
|
|
|
__add_wait_queue(&wq, &__wait); \
|
|
|
|
spin_unlock_irqrestore(&wq.lock, flags); \
|
|
|
|
\
|
|
|
|
for(;;){ \
|
|
|
|
if (condition) \
|
|
|
|
break; \
|
2013-03-19 07:14:59 +01:00
|
|
|
WaitEventTimeout(__wait.evnt, timeout); \
|
2012-11-12 22:22:52 +01:00
|
|
|
}; \
|
2013-03-01 07:44:14 +01:00
|
|
|
if (!list_empty(&__wait.task_list)) { \
|
2012-11-12 22:22:52 +01:00
|
|
|
spin_lock_irqsave(&wq.lock, flags); \
|
|
|
|
list_del_init(&__wait.task_list); \
|
|
|
|
spin_unlock_irqrestore(&wq.lock, flags); \
|
|
|
|
}; \
|
|
|
|
DestroyEvent(__wait.evnt); \
|
|
|
|
} while (0); \
|
|
|
|
__ret; \
|
|
|
|
})
|
|
|
|
|
2013-01-22 16:16:44 +01:00
|
|
|
#define wait_event_interruptible_timeout(wq, condition, timeout) \
|
|
|
|
wait_event_timeout(wq, condition, timeout)
|
2012-11-12 22:22:52 +01:00
|
|
|
|
|
|
|
|
2012-09-04 23:42:08 +02:00
|
|
|
#define wait_event(wq, condition) \
|
2014-08-23 12:29:27 +02:00
|
|
|
do{ \
|
2012-09-04 23:42:08 +02:00
|
|
|
wait_queue_t __wait = { \
|
|
|
|
.task_list = LIST_HEAD_INIT(__wait.task_list), \
|
|
|
|
.evnt = CreateEvent(NULL, MANUAL_DESTROY), \
|
|
|
|
}; \
|
2013-03-01 07:44:14 +01:00
|
|
|
unsigned long flags; \
|
2012-09-04 23:42:08 +02:00
|
|
|
\
|
|
|
|
spin_lock_irqsave(&wq.lock, flags); \
|
|
|
|
if (list_empty(&__wait.task_list)) \
|
|
|
|
__add_wait_queue(&wq, &__wait); \
|
|
|
|
spin_unlock_irqrestore(&wq.lock, flags); \
|
|
|
|
\
|
|
|
|
for(;;){ \
|
|
|
|
if (condition) \
|
|
|
|
break; \
|
|
|
|
WaitEvent(__wait.evnt); \
|
|
|
|
}; \
|
|
|
|
if (!list_empty_careful(&__wait.task_list)) { \
|
|
|
|
spin_lock_irqsave(&wq.lock, flags); \
|
|
|
|
list_del_init(&__wait.task_list); \
|
|
|
|
spin_unlock_irqrestore(&wq.lock, flags); \
|
|
|
|
}; \
|
|
|
|
DestroyEvent(__wait.evnt); \
|
|
|
|
} while (0)
|
|
|
|
|
2014-08-23 12:29:27 +02:00
|
|
|
#define wait_event_interruptible(wq, condition) \
|
|
|
|
({ \
|
|
|
|
int __ret = 0; \
|
|
|
|
if (!(condition)) \
|
|
|
|
wait_event(wq, condition); \
|
|
|
|
__ret; \
|
|
|
|
})
|
2012-11-12 22:22:52 +01:00
|
|
|
|
|
|
|
|
2012-09-04 23:42:08 +02:00
|
|
|
static inline
|
|
|
|
void wake_up_all(wait_queue_head_t *q)
|
|
|
|
{
|
|
|
|
wait_queue_t *curr;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&q->lock, flags);
|
|
|
|
list_for_each_entry(curr, &q->task_list, task_list)
|
|
|
|
{
|
2013-03-01 07:44:14 +01:00
|
|
|
// printf("raise event \n");
|
|
|
|
|
2012-09-04 23:42:08 +02:00
|
|
|
kevent_t event;
|
|
|
|
event.code = -1;
|
|
|
|
RaiseEvent(curr->evnt, 0, &event);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&q->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
init_waitqueue_head(wait_queue_head_t *q)
|
|
|
|
{
|
|
|
|
spin_lock_init(&q->lock);
|
|
|
|
INIT_LIST_HEAD(&q->task_list);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-11-12 22:22:52 +01:00
|
|
|
struct completion {
|
|
|
|
unsigned int done;
|
|
|
|
wait_queue_head_t wait;
|
|
|
|
};
|
|
|
|
|
2013-03-19 07:14:59 +01:00
|
|
|
int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
|
|
|
|
|
|
|
|
|
|
|
|
#define DEFINE_WAIT_FUNC(name, function) \
|
|
|
|
wait_queue_t name = { \
|
|
|
|
.func = function, \
|
|
|
|
.task_list = LIST_HEAD_INIT((name).task_list), \
|
|
|
|
.evnt = CreateEvent(NULL, MANUAL_DESTROY), \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function)
|
|
|
|
|
2012-11-12 22:22:52 +01:00
|
|
|
|
2012-09-04 23:42:08 +02:00
|
|
|
#endif
|
|
|
|
|