From patchwork Tue Jul 10 10:09:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Crowe X-Patchwork-Id: 941899 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-481280-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mcrowe.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="smMQQwMA"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=brightsigninfo.onmicrosoft.com header.i=@brightsigninfo.onmicrosoft.com header.b="oQX5AWjs"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Pycz1d20z9s0W for ; Tue, 10 Jul 2018 20:10:27 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=gbwM1CfqGLUD/0hbdDz5WWUnldJ6TTB7VMQ2Ki530faK3B7FHTEj/ kkOwFDTflOn2LAzaYoR5PLrZOZAHu5Pai5Kaw/TsMn9FSoAdeNMnHcHXQUj2Ow9c i+6eIads/b9svM5ThYdFsNGIDQTGhk8L2EbHX1jaQbq9evBgk6tw3A= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=eGMVgwKjFDWZiBzOSYBcEoWfA0o=; b=smMQQwMAzLMmLRoHpoGQY7BrV+yI y3vp+IhN1JMZUZK//VaaXv7yj0NIoByWX9lb8y1tI58LQ0ZZPVF3LnbdcAZl/ycU tVZnh/tEAVJkF1LtA33tDIW+KS94pcHy2DgKtn7RnEVuTAMZz0QECWy8W9O5ZxQ5 v2yjl3d1Xo2xMPg= Received: (qmail 25368 invoked by alias); 10 Jul 2018 10:09:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 25265 invoked by uid 89); 10 Jul 2018 10:09:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_INFOUSMEBIZ, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=H*RU:202, Hx-spam-relays-external:202 X-HELO: NAM05-DM3-obe.outbound.protection.outlook.com Received: from mail-eopbgr730093.outbound.protection.outlook.com (HELO NAM05-DM3-obe.outbound.protection.outlook.com) (40.107.73.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Jul 2018 10:09:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brightsigninfo.onmicrosoft.com; s=selector1-brightsign-biz; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M85+YDYV4CSnC33kivXrS7ZXOVtr8fI14QBR15XUwRU=; b=oQX5AWjsw47U50vCk4cT0rS3hvmCK6Ic4TRrstqSL/YgCWkIO/VP9OnzTro4MQOmTJwaHsQqqDVQLc5fyPetd+M+C6DOM4l6VHWGc+qIZsBFf301g21fjHF7hqG34nE2LpPENxPCOv0cmqOTQDjf87f615rALqkRJgtL4srGRkw= Received: from DM3PR08CA0008.namprd08.prod.outlook.com (2603:10b6:0:52::18) by BYAPR08MB3910.namprd08.prod.outlook.com (2603:10b6:a02:84::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.930.21; Tue, 10 Jul 2018 10:09:42 +0000 Received: from BN3NAM04FT043.eop-NAM04.prod.protection.outlook.com (2a01:111:f400:7e4e::202) by DM3PR08CA0008.outlook.office365.com (2603:10b6:0:52::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.930.19 via Frontend Transport; Tue, 10 Jul 2018 10:09:41 +0000 Authentication-Results: spf=pass (sender IP is 213.210.30.29) smtp.mailfrom=brightsign.biz; gcc.gnu.org; dkim=none (message not signed) header.d=none; gcc.gnu.org; dmarc=none action=none header.from=mcrowe.com; Received-SPF: Pass (protection.outlook.com: domain of brightsign.biz designates 213.210.30.29 as permitted sender) receiver=protection.outlook.com; client-ip=213.210.30.29; helo=elite.brightsign; Received: from elite.brightsign (213.210.30.29) by BN3NAM04FT043.mail.protection.outlook.com (10.152.93.79) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.930.16 via Frontend Transport; Tue, 10 Jul 2018 10:09:41 +0000 Received: from chuckie.brightsign ([fd44:d8b8:cab5:cb01::19] helo=chuckie) by elite.brightsign with esmtp (Exim 4.89) (envelope-from ) id 1fcpaW-0000f9-GK; Tue, 10 Jul 2018 11:09:40 +0100 Received: from mac by chuckie with local (Exim 4.89) (envelope-from ) id 1fcpaW-0001YC-D3; Tue, 10 Jul 2018 11:09:40 +0100 From: Mike Crowe To: , CC: Mike Crowe Subject: [PATCH 2/2] condition_variable: Use steady_clock to implement wait_for Date: Tue, 10 Jul 2018 11:09:29 +0100 Message-ID: <20180710100929.32704-2-mac@mcrowe.com> In-Reply-To: <20180710100929.32704-1-mac@mcrowe.com> References: <20180710100929.32704-1-mac@mcrowe.com> MIME-Version: 1.0 I believe[1][2] that the C++ standard says that std::condition_variable::wait_for should be implemented to be equivalent to: return wait_until(lock, chrono::steady_clock::now() + rel_time); But the existing implementation uses chrono::system_clock. Now that wait_until has potentially-different behaviour for chrono::steady_clock, let's at least try to wait using the correct clock. [1] https://en.cppreference.com/w/cpp/thread/condition_variable/wait_for [2] https://github.com/cplusplus/draft/blob/master/source/threads.tex --- libstdc++-v3/ChangeLog | 3 +++ libstdc++-v3/include/std/condition_variable | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) -- 2.11.0 BrightSign considers your privacy to be very important. The emails you send to us will be protected and secured. Furthermore, we will only use your email and contact information for the reasons you sent them to us and for tracking how effectively we respond to your requests. diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ea7875ace9f..4500273ace7 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,4 +1,7 @@ 2018-07-09 Mike Crowe + * include/std/condition_variable (wait_for): Use steady_clock. + +2018-07-09 Mike Crowe * include/std/condition_variable (wait_until): Only report timeout if we really have timed out when measured against the caller-supplied clock. diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable index a2d146a9b09..ce583990b9d 100644 --- a/libstdc++-v3/include/std/condition_variable +++ b/libstdc++-v3/include/std/condition_variable @@ -65,6 +65,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class condition_variable { typedef chrono::system_clock __clock_t; + typedef chrono::steady_clock __steady_clock_t; typedef __gthread_cond_t __native_type; #ifdef __GTHREAD_COND_INIT @@ -142,11 +143,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION wait_for(unique_lock& __lock, const chrono::duration<_Rep, _Period>& __rtime) { - using __dur = typename __clock_t::duration; + using __dur = typename __steady_clock_t::duration; auto __reltime = chrono::duration_cast<__dur>(__rtime); if (__reltime < __rtime) ++__reltime; - return wait_until(__lock, __clock_t::now() + __reltime); + return wait_until(__lock, __steady_clock_t::now() + __reltime); } template