Return-Path: X-Original-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Delivered-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 560E2175B8 for ; Wed, 25 Mar 2015 08:57:11 +0000 (UTC) Received: (qmail 41032 invoked by uid 500); 25 Mar 2015 08:57:11 -0000 Delivered-To: apmail-httpd-modules-dev-archive@httpd.apache.org Received: (qmail 41004 invoked by uid 500); 25 Mar 2015 08:57:11 -0000 Mailing-List: contact modules-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: modules-dev@httpd.apache.org Delivered-To: mailing list modules-dev@httpd.apache.org Received: (qmail 40988 invoked by uid 99); 25 Mar 2015 08:57:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Mar 2015 08:57:10 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of ylavic.dev@gmail.com designates 209.85.223.181 as permitted sender) Received: from [209.85.223.181] (HELO mail-ie0-f181.google.com) (209.85.223.181) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Mar 2015 08:56:46 +0000 Received: by iedfl3 with SMTP id fl3so19264553ied.1 for ; Wed, 25 Mar 2015 01:56:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=yEbI37XVmUZlumRPovARFzj9J8q1Cca5JvTZmzGsEpY=; b=krmGK3ROcXDAHJPWfiYh4089GQy9KQREVRqPcM4ZaOpihrz5q1B4ahU95V7PN7mTZP dGi8JgZcpA0xpdiuxvmQ7hb/ht34u5hYc9sdN8gbiOvAZ3Odskk7G+dLXYEiyoAR7nv+ 6ObuCrdhHTbg5WwKJSUPrQ6LbJYxTjPHDADUQ5Ln/KwxMLNP/UY81eotUqYL8dQoncsK SQ+y5yWjsMQUYPWjdgcL86aMfBMEsoh/WsGqSG69ywj7dyNgfo53Lgj1l4kVdW3AnqXV DUjUVF9999D8yevA/0iKdNGq1KDROjgRCsAgNAT3WAQXPf5huEjzfoV8ybD/yI9BImz6 Bi5g== MIME-Version: 1.0 X-Received: by 10.107.132.39 with SMTP id g39mr12050136iod.62.1427273804486; Wed, 25 Mar 2015 01:56:44 -0700 (PDT) Received: by 10.42.255.7 with HTTP; Wed, 25 Mar 2015 01:56:44 -0700 (PDT) In-Reply-To: <55125380.7010408@lenk.info> References: <54295C2F.80307@lenk.info> <542AF4CB.90006@lenk.info> <55125380.7010408@lenk.info> Date: Wed, 25 Mar 2015 09:56:44 +0100 Message-ID: Subject: Re: How to wait on a global lock with timeout From: Yann Ylavic To: Micha Lenk Cc: modules-dev@httpd.apache.org Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked by ClamAV on apache.org Hi Micha, thanks for the review. On Wed, Mar 25, 2015 at 7:19 AM, Micha Lenk wrote: > > I only had time to review the code changes. I looked at the > implementation of apr_global_mutex_timedlock(). There I noticed that, if > APR_HAS_THREADS, you are doing 3 timed operations without checking the > remaining time. If all operations take almost the given timeout, this > can in the end result in almost 3 times the allowed value. The new _timedlocked() functions all take a third parameter (called absolute) which tells whether the given timeout is absolute (1) or relative (0). This is because some native implementations use an absolute time, and others a relative one, hence we do the conversion in the implementations when needed only. In apr_global_mutex_timedlock(), if the given timeout is relative, we force it to an absolute one and call apr_thread_mutex_timedlock() (if needed) and apr_proc_mutex_timedlock() accordingly, hence the timeout is assured globally. > > To mitigate that design flaw I would provide the timeout by reference > and update it by the functions using it. This has also the nice benefit > that the caller is able to retrieve the time it needed to wait. By doing so, you have to get the current time (call apr_time_now()) each time, and I wanted to avoid it when the native functions don't need it. The remaining time is not important if you can pass an absolute time (IMHO). Regards, Yann.