mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Anirban Sinha <kernel@anirban.org>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu,
	Oleg Nesterov <oleg@tv-sign.ru>
Subject: Re: [PATCH]: add a new wait_event_interruptible_timeout_modify helper
Date: Fri, 26 Sep 2008 08:01:12 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.1.10.0809260752350.3265@nehalem.linux-foundation.org> (raw)
In-Reply-To: <A1326102-87D8-44AE-856F-A7E49D9E5538@anirban.org>



On Thu, 25 Sep 2008, Anirban Sinha wrote:
> +
> +/**
> + * wait_event_interruptible_timeout_modify - sleep until a condition gets true or a timeout elapses.
> + * @wq: the waitqueue to wait on
> + * @condition: a C expression for the event to wait for
> + * @timeout: timeout, in jiffies
> + *
> + * The process is put to sleep (TASK_INTERRUPTIBLE) until the
> + * @condition evaluates to true or a signal is received.
> + * The @condition is checked each time the waitqueue @wq is woken up.
> + *
> + * wake_up() has to be called after changing any variable that could
> + * change the result of the wait condition.
> + *
> + * The function returns 0 if the @timeout elapsed, -ERESTARTSYS if it
> + * was interrupted by a signal, and the remaining jiffies otherwise
> + * if the condition evaluated to true before the timeout elapsed.
> + * It also modifies the @timeout value so that if the sleep is interrupted
> + * by a signal, the caller can call this helper again with the updated
> + * timeout.

Grr.

I'd _much_ rather just have a

	wait_event_interruptible_until(wr, condition, abs_timeout)

where the timeout is just given as an end value, and the user can just 
pre-calculate it once and the return code handling is simpler (either 
"success" or "EINTR").

Giving an absolute value also means that there is no rounding creep or 
anything like that in a loop, which otherwise happens very easily (even 
if we wouldn't normally really care).

And quite frankly, people can do that themselves even without a helper 
function, with simply

	unsigned long end = jiffies + timeout;
	...

	rc = wait_event_interruptible_timeout(wq, event, end - jiffies);
	if (rc < 0)
		goto out;

and now you always know the end-point, and 'end - jiffies' is always the 
remaining timeout.

		Linus

      parent reply	other threads:[~2008-09-26 15:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-26  2:57 Anirban Sinha
     [not found] ` <816CA40C-41C0-4CCF-A75B-F67F1A2B0510@anirban.org>
2008-09-26  7:11   ` [PATCH]: correction: " Anirban Sinha
2008-09-26 15:21     ` Oleg Nesterov
2008-09-26 15:01 ` Linus Torvalds [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.1.10.0809260752350.3265@nehalem.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=kernel@anirban.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@tv-sign.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®