From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754682AbYIZPCT (ORCPT ); Fri, 26 Sep 2008 11:02:19 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752772AbYIZPCK (ORCPT ); Fri, 26 Sep 2008 11:02:10 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:53456 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752188AbYIZPCJ (ORCPT ); Fri, 26 Sep 2008 11:02:09 -0400 Date: Fri, 26 Sep 2008 08:01:12 -0700 (PDT) From: Linus Torvalds To: Anirban Sinha cc: linux-kernel@vger.kernel.org, mingo@elte.hu, Oleg Nesterov Subject: Re: [PATCH]: add a new wait_event_interruptible_timeout_modify helper In-Reply-To: Message-ID: References: User-Agent: Alpine 1.10 (LFD 962 2008-03-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.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