From a2816bbfb17101d2faa45c8b557da257a98fe729 Mon Sep 17 00:00:00 2001 From: Dean Nelson Date: Sun, 20 Jun 2004 04:54:29 -0700 Subject: [PATCH] add wait_event_interruptible_exclusive() macro This patch defines a macro that does exactly what wait_event_interruptible() does except that it adds the current task to the wait queue as an exclusive task (i.e., sets the WQ_FLAG_EXCLUSIVE flag) rather than as a non-exclusive task as wait_event_interruptible() does. This allows one to do a wake_up_nr() to wake up a specific number of tasks. I'm in the process of submitting a patch to linux-ia64 that requires this capability. (Its subject line is "[PATCH 3/4] SGI Altix cross partition functionality".) Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- include/linux/wait.h | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'include/linux/wait.h') diff --git a/include/linux/wait.h b/include/linux/wait.h index 52edb1786b14..4a9f996bb6cc 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -200,7 +200,36 @@ do { \ __wait_event_interruptible_timeout(wq, condition, __ret); \ __ret; \ }) - + +#define __wait_event_interruptible_exclusive(wq, condition, ret) \ +do { \ + wait_queue_t __wait; \ + init_waitqueue_entry(&__wait, current); \ + \ + add_wait_queue_exclusive(&wq, &__wait); \ + for (;;) { \ + set_current_state(TASK_INTERRUPTIBLE); \ + if (condition) \ + break; \ + if (!signal_pending(current)) { \ + schedule(); \ + continue; \ + } \ + ret = -ERESTARTSYS; \ + break; \ + } \ + current->state = TASK_RUNNING; \ + remove_wait_queue(&wq, &__wait); \ +} while (0) + +#define wait_event_interruptible_exclusive(wq, condition) \ +({ \ + int __ret = 0; \ + if (!(condition)) \ + __wait_event_interruptible_exclusive(wq, condition, __ret);\ + __ret; \ +}) + /* * Must be called with the spinlock in the wait_queue_head_t held. */ -- cgit v1.2.3