diff -urN linux.orig/include/linux/wait.h linux.wrk/include/linux/wait.h --- linux.orig/include/linux/wait.h Tue Jan 15 19:13:22 2002 +++ linux.wrk/include/linux/wait.h Thu Feb 7 05:50:20 2002 @@ -19,13 +19,16 @@ #include #include +typedef struct __wait_queue wait_queue_t; +typedef void (*wait_queue_func_t)(wait_queue_t *wait); + struct __wait_queue { unsigned int flags; #define WQ_FLAG_EXCLUSIVE 0x01 struct task_struct * task; + wait_queue_func_t func; struct list_head task_list; }; -typedef struct __wait_queue wait_queue_t; /* * 'dual' spinlock architecture. Can be switched between spinlock_t and @@ -74,6 +77,7 @@ #define __WAITQUEUE_INITIALIZER(name, tsk) { \ task: tsk, \ + func: NULL, \ task_list: { NULL, NULL } } #define DECLARE_WAITQUEUE(name, tsk) \ @@ -96,6 +100,15 @@ { q->flags = 0; q->task = p; + q->func = NULL; +} + +static inline void init_waitqueue_func_entry(wait_queue_t *q, + wait_queue_func_t func) +{ + q->flags = 0; + q->task = NULL; + q->func = func; } static inline int waitqueue_active(wait_queue_head_t *q) @@ -123,6 +136,22 @@ list_del(&old->task_list); } +#define add_wait_queue_cond(q, wait, cond) \ + ({ \ + unsigned long flags; \ + int _raced = 0; \ + wq_write_lock_irqsave(&(q)->lock, flags); \ + (wait)->flags = 0; \ + __add_wait_queue((q), (wait)); \ + rmb(); \ + if (!(cond)) { \ + _raced = 1; \ + __remove_wait_queue((q), (wait)); \ + } \ + wq_write_unlock_irqrestore(&(q)->lock, flags); \ + _raced; \ + }) + #endif /* __KERNEL__ */ #endif diff -urN linux.orig/kernel/sched.c linux.wrk/kernel/sched.c --- linux.orig/kernel/sched.c Thu Feb 7 05:38:57 2002 +++ linux.wrk/kernel/sched.c Thu Feb 7 05:51:38 2002 @@ -716,13 +716,22 @@ static inline void __wake_up_common (wait_queue_head_t *q, unsigned int mode, int nr_exclusive, const int sync) { - struct list_head *tmp; + struct list_head *tmp, *next; task_t *p; - list_for_each(tmp,&q->task_list) { + list_for_each_safe(tmp, next, &q->task_list) { unsigned int state; wait_queue_t *curr = list_entry(tmp, wait_queue_t, task_list); + wait_queue_func_t func; + func = curr->func; + if (func) { + unsigned flags = curr->flags; + func(curr); + if ((flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive) + break; + continue; + } p = curr->task; state = p->state; if ((state & mode) &&