* [PATCH] Completion API extension
@ 2004-10-20 16:31 Thomas Gleixner
2004-10-21 20:49 ` Thomas Gleixner
[not found] ` <200410212118.32981.dtor_core@ameritech.net>
0 siblings, 2 replies; 3+ messages in thread
From: Thomas Gleixner @ 2004-10-20 16:31 UTC (permalink / raw)
To: Andrew Morton; +Cc: Linus Torvalds, LKML
Additional functions for the completion API.
wait_for_completion_interruptible()
wait_for_completion_timeout()
wait_for_completion_interruptible_timeout()
Those are neccecary to convert the users of the racy and
obsolete sleep_on variants to the completion API
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
---
2.6.9-bk-041020-thomas/include/linux/completion.h | 6 +
2.6.9-bk-041020-thomas/kernel/sched.c | 94
++++++++++++++++++++++
2 files changed, 100 insertions(+)
diff -puN include/linux/completion.h~completion
include/linux/completion.h
--- 2.6.9-bk-041020/include/linux/completion.h~completion 2004-10-20
15:22:47.000000000 +0200
+++ 2.6.9-bk-041020-thomas/include/linux/completion.h 2004-10-20
15:22:47.000000000 +0200
@@ -28,6 +28,12 @@ static inline void init_completion(struc
}
extern void FASTCALL(wait_for_completion(struct completion *));
+extern int FASTCALL(wait_for_completion_interruptible(struct completion
*));
+extern unsigned long FASTCALL(wait_for_completion_timeout(struct
completion *,
+ unsigned long));
+extern unsigned long FASTCALL(wait_for_completion_timeout_interruptible
+ (struct completion *, unsigned long));
+
extern void FASTCALL(complete(struct completion *));
extern void FASTCALL(complete_all(struct completion *));
diff -puN kernel/sched.c~completion kernel/sched.c
--- 2.6.9-bk-041020/kernel/sched.c~completion 2004-10-20
15:22:47.000000000 +0200
+++ 2.6.9-bk-041020-thomas/kernel/sched.c 2004-10-20 15:22:47.000000000
+0200
@@ -2811,6 +2811,100 @@ void fastcall __sched wait_for_completio
}
EXPORT_SYMBOL(wait_for_completion);
+unsigned long fastcall __sched
+wait_for_completion_timeout(struct completion *x, unsigned long
timeout)
+{
+ might_sleep();
+
+ spin_lock_irq(&x->wait.lock);
+ if (!x->done) {
+ DECLARE_WAITQUEUE(wait, current);
+
+ wait.flags |= WQ_FLAG_EXCLUSIVE;
+ __add_wait_queue_tail(&x->wait, &wait);
+ do {
+ __set_current_state(TASK_UNINTERRUPTIBLE);
+ spin_unlock_irq(&x->wait.lock);
+ timeout = schedule_timeout(timeout);
+ if (!timeout)
+ goto out;
+ spin_lock_irq(&x->wait.lock);
+ } while (!x->done);
+ __remove_wait_queue(&x->wait, &wait);
+ }
+ x->done--;
+out:
+ spin_unlock_irq(&x->wait.lock);
+
+ return timeout;
+}
+EXPORT_SYMBOL(wait_for_completion_timeout);
+
+int fastcall __sched wait_for_completion_interruptible(struct
completion *x)
+{
+ int ret = 0;
+
+ might_sleep();
+
+ spin_lock_irq(&x->wait.lock);
+ if (!x->done) {
+ DECLARE_WAITQUEUE(wait, current);
+
+ wait.flags |= WQ_FLAG_EXCLUSIVE;
+ __add_wait_queue_tail(&x->wait, &wait);
+ do {
+ if (signal_pending(current)) {
+ ret = -ERESTARTSYS;
+ goto out;
+ }
+ __set_current_state(TASK_INTERRUPTIBLE);
+ spin_unlock_irq(&x->wait.lock);
+ schedule();
+ spin_lock_irq(&x->wait.lock);
+ } while (!x->done);
+ __remove_wait_queue(&x->wait, &wait);
+ }
+ x->done--;
+out:
+ spin_unlock_irq(&x->wait.lock);
+
+ return ret;
+}
+EXPORT_SYMBOL(wait_for_completion_interruptible);
+
+unsigned long fastcall __sched
+wait_for_completion_interruptible_timeout(struct completion *x,
+ unsigned long timeout)
+{
+ might_sleep();
+
+ spin_lock_irq(&x->wait.lock);
+ if (!x->done) {
+ DECLARE_WAITQUEUE(wait, current);
+
+ wait.flags |= WQ_FLAG_EXCLUSIVE;
+ __add_wait_queue_tail(&x->wait, &wait);
+ do {
+ if (signal_pending(current)) {
+ timeout = -ERESTARTSYS;
+ goto out;
+ }
+ __set_current_state(TASK_INTERRUPTIBLE);
+ spin_unlock_irq(&x->wait.lock);
+ schedule();
+ spin_lock_irq(&x->wait.lock);
+ } while (!x->done);
+ __remove_wait_queue(&x->wait, &wait);
+ }
+ x->done--;
+out:
+ spin_unlock_irq(&x->wait.lock);
+
+ return timeout;
+}
+EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
+
+
#define SLEEP_ON_VAR \
unsigned long flags; \
wait_queue_t wait; \
_
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Completion API extension
2004-10-20 16:31 [PATCH] Completion API extension Thomas Gleixner
@ 2004-10-21 20:49 ` Thomas Gleixner
[not found] ` <200410212118.32981.dtor_core@ameritech.net>
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Gleixner @ 2004-10-21 20:49 UTC (permalink / raw)
To: Andrew Morton; +Cc: Linus Torvalds, LKML
Corrected Version. We missed some bits (:
Additional functions for the completion API.
wait_for_completion_interruptible()
wait_for_completion_timeout()
wait_for_completion_interruptible_timeout()
Those are neccecary to convert the users of the racy and
obsolete sleep_on variants to the completion API
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
---
2.6.9-bk-041020-thomas/include/linux/completion.h | 6 +
2.6.9-bk-041020-thomas/kernel/sched.c | 95
++++++++++++++++++++++
2 files changed, 101 insertions(+)
diff -puN include/linux/completion.h~completion
include/linux/completion.h
--- 2.6.9-bk-041020/include/linux/completion.h~completion 2004-10-20
15:22:47.000000000 +0200
+++ 2.6.9-bk-041020-thomas/include/linux/completion.h 2004-10-20
15:22:47.000000000 +0200
@@ -28,6 +28,12 @@ static inline void init_completion(struc
}
extern void FASTCALL(wait_for_completion(struct completion *));
+extern int FASTCALL(wait_for_completion_interruptible(struct completion
*));
+extern unsigned long FASTCALL(wait_for_completion_timeout(struct
completion *,
+ unsigned long));
+extern unsigned long FASTCALL(wait_for_completion_timeout_interruptible
+ (struct completion *, unsigned long));
+
extern void FASTCALL(complete(struct completion *));
extern void FASTCALL(complete_all(struct completion *));
diff -puN kernel/sched.c~completion kernel/sched.c
--- 2.6.9-bk-041020/kernel/sched.c~completion 2004-10-20
15:22:47.000000000 +0200
+++ 2.6.9-bk-041020-thomas/kernel/sched.c 2004-10-21 20:13:09.000000000
+0200
@@ -2811,6 +2811,101 @@ void fastcall __sched wait_for_completio
}
EXPORT_SYMBOL(wait_for_completion);
+unsigned long fastcall __sched
+wait_for_completion_timeout(struct completion *x, unsigned long
timeout)
+{
+ might_sleep();
+
+ spin_lock_irq(&x->wait.lock);
+ if (!x->done) {
+ DECLARE_WAITQUEUE(wait, current);
+
+ wait.flags |= WQ_FLAG_EXCLUSIVE;
+ __add_wait_queue_tail(&x->wait, &wait);
+ do {
+ __set_current_state(TASK_UNINTERRUPTIBLE);
+ spin_unlock_irq(&x->wait.lock);
+ timeout = schedule_timeout(timeout);
+ if (!timeout)
+ goto out;
+ spin_lock_irq(&x->wait.lock);
+ } while (!x->done);
+ __remove_wait_queue(&x->wait, &wait);
+ }
+ x->done--;
+ spin_unlock_irq(&x->wait.lock);
+out:
+ return timeout;
+}
+EXPORT_SYMBOL(wait_for_completion_timeout);
+
+int fastcall __sched wait_for_completion_interruptible(struct
completion *x)
+{
+ int ret = 0;
+
+ might_sleep();
+
+ spin_lock_irq(&x->wait.lock);
+ if (!x->done) {
+ DECLARE_WAITQUEUE(wait, current);
+
+ wait.flags |= WQ_FLAG_EXCLUSIVE;
+ __add_wait_queue_tail(&x->wait, &wait);
+ do {
+ if (signal_pending(current)) {
+ ret = -ERESTARTSYS;
+ goto out;
+ }
+ __set_current_state(TASK_INTERRUPTIBLE);
+ spin_unlock_irq(&x->wait.lock);
+ schedule();
+ spin_lock_irq(&x->wait.lock);
+ } while (!x->done);
+ __remove_wait_queue(&x->wait, &wait);
+ }
+ x->done--;
+out:
+ spin_unlock_irq(&x->wait.lock);
+
+ return ret;
+}
+EXPORT_SYMBOL(wait_for_completion_interruptible);
+
+unsigned long fastcall __sched
+wait_for_completion_interruptible_timeout(struct completion *x,
+ unsigned long timeout)
+{
+ might_sleep();
+
+ spin_lock_irq(&x->wait.lock);
+ if (!x->done) {
+ DECLARE_WAITQUEUE(wait, current);
+
+ wait.flags |= WQ_FLAG_EXCLUSIVE;
+ __add_wait_queue_tail(&x->wait, &wait);
+ do {
+ if (signal_pending(current)) {
+ timeout = -ERESTARTSYS;
+ goto out_unlock;
+ }
+ __set_current_state(TASK_INTERRUPTIBLE);
+ spin_unlock_irq(&x->wait.lock);
+ timeout = schedule_timeout(timeout);
+ if (!timeout)
+ goto out;
+ spin_lock_irq(&x->wait.lock);
+ } while (!x->done);
+ __remove_wait_queue(&x->wait, &wait);
+ }
+ x->done--;
+out_unlock:
+ spin_unlock_irq(&x->wait.lock);
+out:
+ return timeout;
+}
+EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
+
+
#define SLEEP_ON_VAR \
unsigned long flags; \
wait_queue_t wait; \
_
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Completion API extension
[not found] ` <200410212118.32981.dtor_core@ameritech.net>
@ 2004-10-22 6:45 ` Thomas Gleixner
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Gleixner @ 2004-10-22 6:45 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: LKML, Andrew Morton, Linus Torvalds
On Fri, 2004-10-22 at 04:18, Dmitry Torokhov wrote:
Hi,
it's resubmitted in a correct version already.
Thanks,
tglx
> Hi,
>
> On Wednesday 20 October 2004 11:31 am, Thomas Gleixner wrote:
> > +unsigned long fastcall __sched
> > +wait_for_completion_interruptible_timeout(struct completion *x,
> > + unsigned long timeout)
> > +{
> > + might_sleep();
> > +
> > + spin_lock_irq(&x->wait.lock);
> > + if (!x->done) {
> > + DECLARE_WAITQUEUE(wait, current);
> > +
> > + wait.flags |= WQ_FLAG_EXCLUSIVE;
> > + __add_wait_queue_tail(&x->wait, &wait);
> > + do {
> > + if (signal_pending(current)) {
> > + timeout = -ERESTARTSYS;
> > + goto out;
> > + }
> > + __set_current_state(TASK_INTERRUPTIBLE);
> > + spin_unlock_irq(&x->wait.lock);
> > + schedule();
>
> ^^^^^^^^^^^^^^^^^^
>
> schedule_timeout perhaps?
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-10-22 7:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-20 16:31 [PATCH] Completion API extension Thomas Gleixner
2004-10-21 20:49 ` Thomas Gleixner
[not found] ` <200410212118.32981.dtor_core@ameritech.net>
2004-10-22 6:45 ` Thomas Gleixner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).