waitqueue: Implement wake_up_{nr,one,all}.
authorKeir Fraser <keir@xen.org>
Fri, 25 Nov 2011 20:27:11 +0000 (20:27 +0000)
committerKeir Fraser <keir@xen.org>
Fri, 25 Nov 2011 20:27:11 +0000 (20:27 +0000)
Signed-off-by: Keir Fraser <keir@xen.org>
xen/common/wait.c
xen/include/xen/wait.h

index d4feecb56ee38d94272418682aa944205b352469..a05ac4f57f2bd7c92f7ada45d756946e44e885c7 100644 (file)
@@ -87,13 +87,13 @@ void init_waitqueue_head(struct waitqueue_head *wq)
     INIT_LIST_HEAD(&wq->list);
 }
 
-void wake_up(struct waitqueue_head *wq)
+void wake_up_nr(struct waitqueue_head *wq, unsigned int nr)
 {
     struct waitqueue_vcpu *wqv;
 
     spin_lock(&wq->lock);
 
-    while ( !list_empty(&wq->list) )
+    while ( !list_empty(&wq->list) && nr-- )
     {
         wqv = list_entry(wq->list.next, struct waitqueue_vcpu, list);
         list_del_init(&wqv->list);
@@ -103,6 +103,16 @@ void wake_up(struct waitqueue_head *wq)
     spin_unlock(&wq->lock);
 }
 
+void wake_up_one(struct waitqueue_head *wq)
+{
+    wake_up_nr(wq, 1);
+}
+
+void wake_up_all(struct waitqueue_head *wq)
+{
+    wake_up_nr(wq, UINT_MAX);
+}
+
 #ifdef CONFIG_X86
 
 static void __prepare_to_wait(struct waitqueue_vcpu *wqv)
index dd3db9f872f895e9a8d7c45f5a31d0666c8aee61..f16eb6a114f4fc0eac36a56cf66c76b18f39124a 100644 (file)
@@ -28,8 +28,10 @@ struct waitqueue_head {
 /* Dynamically initialise a waitqueue. */
 void init_waitqueue_head(struct waitqueue_head *wq);
 
-/* Wake all VCPUs waiting on specified waitqueue. */
-void wake_up(struct waitqueue_head *wq);
+/* Wake VCPU(s) waiting on specified waitqueue. */
+void wake_up_nr(struct waitqueue_head *wq, unsigned int nr);
+void wake_up_one(struct waitqueue_head *wq);
+void wake_up_all(struct waitqueue_head *wq);
 
 /* Wait on specified waitqueue until @condition is true. */
 #define wait_event(wq, condition)               \