Skip to contentSkip to conversation

add wait_event() to <linux/completion.h>

PATCH David Brownell 1 participant 1 message Dec 12, 2002 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 3 lines · Milton D. Miller II

__remove_wait_queue(&x->wait, &wait);

should be under spin_lock_irq(&x->wait.lock);

Duh! Updated patch is attached.

- Dave

include/linux/completion.h renamed from include/linux-dist/completion.h +1 -0
@@ -28,6 +28,7 @@
 }
 
 extern void FASTCALL(wait_for_completion(struct completion *));
+extern int FASTCALL(wait_timeout(struct completion *, signed long jiffies));
 extern void FASTCALL(complete(struct completion *));
 extern void FASTCALL(complete_all(struct completion *));
 
kernel/ksyms.c renamed from kernel-dist/ksyms.c +2 -0
@@ -404,7 +404,9 @@ EXPORT_SYMBOL(autoremove_wake_function);
 
 /* completion handling */
 EXPORT_SYMBOL(wait_for_completion);
+EXPORT_SYMBOL(wait_timeout);
 EXPORT_SYMBOL(complete);
+EXPORT_SYMBOL(complete_all);
 
 /* The notion of irq probe/assignment is foreign to S/390 */
 
kernel/sched.c renamed from kernel-dist/sched.c +13 -3
@@ -1204,6 +1204,11 @@ void complete_all(struct completion *x)
 
 void wait_for_completion(struct completion *x)
 {
+	(void) wait_timeout (x, MAX_SCHEDULE_TIMEOUT);
+}
+
+int wait_timeout(struct completion *x, signed long timeout)
+{
 	might_sleep();
 	spin_lock_irq(&x->wait.lock);
 	if (!x->done) {
@@ -1214,13 +1219,18 @@ void wait_for_completion(struct completi
 		do {
 			__set_current_state(TASK_UNINTERRUPTIBLE);
 			spin_unlock_irq(&x->wait.lock);
-			schedule();
+			timeout = schedule_timeout(timeout);
 			spin_lock_irq(&x->wait.lock);
-		} while (!x->done);
+		} while (!x->done && timeout != 0);
 		__remove_wait_queue(&x->wait, &wait);
 	}
-	x->done--;
+	if (x->done) {
+		timeout = 1;
+		x->done--;
+	}
 	spin_unlock_irq(&x->wait.lock);
+	/* nonzero return means we timed out */
+	return timeout == 0;
 }
 
 #define	SLEEP_ON_VAR				\