From patchwork Tue Jun 20 17:17:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonggang Luo X-Patchwork-Id: 71426 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB7953857718 for ; Tue, 20 Jun 2023 17:18:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB7953857718 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1687281494; bh=K1yWvNkM5LWUp8SLPHRrbz8JMz3LgffCK1UKBjTQpQ4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ITAoiTigI4e05j6l4+h+tqrYu/v48cdE7+VOXwQoevGbUtRQWWZPq65ZL4zA2mN43 pPOMPg5SP8OqPzNkXjlAFglbsM/opk47H1p7DG7zVYWKQsTv3FdhyhzAgdvNfu4pQ0 LjHw1Oj+QHY5CBGqxhKalfUQTgRtaagWgRNlo9d0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 70EBD3858D28 for ; Tue, 20 Jun 2023 17:17:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 70EBD3858D28 Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-6b44b5adfd3so3639924a34.3 for ; Tue, 20 Jun 2023 10:17:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687281469; x=1689873469; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K1yWvNkM5LWUp8SLPHRrbz8JMz3LgffCK1UKBjTQpQ4=; b=cvNrC75Uzk+Y25h0Nf1JyDU/h+53l2i5SD45WwUuW2rjYaL5f+DwKY1arUCZWhr8vk H+QTGfCVW4TqyYXi/E+wZZhICc95vXd2TcJ9Jf1AHD5kxXtaAbgz4EYBYT38dbqE6E99 GB7ERTW5ab8cwkQndKy9Qs+o3TA93UzzfebS0OHaW37g6VC2IIfsdR+f++CxvXpddnCT XqlZ3ZPoboua1hcF8lqIP96bKfDbz/5wa4AgMddboKDBWTzfMpEADwTulJbgd9HXaZxJ Xwdwuyq90jKcNlwqXhx++j7wTkrqqctuMACKHFb2gKACgm0XGApsDwx3YLQ00Zk8DzKU q+bw== X-Gm-Message-State: AC+VfDxwgYoMYQgEyzipB5N27wr79MvHsWIepjaDeIwj3HQ4WK9pl7me NCSqHO4oguKHXq1mRJfR4BP/lXXOcb29BveC X-Google-Smtp-Source: ACHHUZ5qnQSxkW1/G81RqGTAR+NcNx09lt+j0CRP9RvePzpG5h4FTqgJdpBdgj7UtnTDmAB3+OdbOg== X-Received: by 2002:a05:6359:d1f:b0:129:c325:fd5 with SMTP id gp31-20020a0563590d1f00b00129c3250fd5mr9047807rwb.2.1687281468059; Tue, 20 Jun 2023 10:17:48 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id r23-20020a634417000000b005143448896csm1652930pga.58.2023.06.20.10.17.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 10:17:47 -0700 (PDT) To: Jens Gustedt , libc-alpha@sourceware.org Cc: Florian Weimer , Yonggang Luo Subject: [PATCH v2 1/4] clang-format: should format with 2 space and do not usage tab Date: Wed, 21 Jun 2023 01:17:28 +0800 Message-Id: <20230620171731.230-2-luoyonggang@gmail.com> X-Mailer: git-send-email 2.39.0.windows.1 In-Reply-To: <20230620171731.230-1-luoyonggang@gmail.com> References: <20230620171731.230-1-luoyonggang@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yonggang Luo via Libc-alpha From: Yonggang Luo Reply-To: Yonggang Luo Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Signed-off-by: Yonggang Luo --- .clang-format | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index 36c169e007..6e8ef236be 100644 --- a/.clang-format +++ b/.clang-format @@ -146,8 +146,8 @@ SpacesInParentheses: false SpacesInSquareBrackets: false SpaceBeforeSquareBrackets: false Standard: Cpp03 -TabWidth: 8 -UseTab: Always +TabWidth: 2 +UseTab: Never ForEachMacros: - 'FOR_EACH_IMPL' - 'list_for_each' From patchwork Tue Jun 20 17:17:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonggang Luo X-Patchwork-Id: 71428 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 60D8B385841A for ; Tue, 20 Jun 2023 17:18:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 60D8B385841A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1687281534; bh=s5xAnTBoCuOZm3px/uGPG96Z9S4eOD8XBG2XupxKvIo=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ZmHv0VQxOV5y5kU9g+DI909ckR/8raRIGvzeByLK3hegmrC8ES6dNn3tRcR15TSQL z/svOEUbioU+7KVOOFVXjiAznoPvbA3bmfqCesfApK7hWA48+8eyVv3e9hjEo9ivEt Hbe45d04f8nIPOFfSFAzBPCRaTWl+quHc94GValE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 631F43858D35 for ; Tue, 20 Jun 2023 17:17:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 631F43858D35 Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6b45cfe3110so3223902a34.0 for ; Tue, 20 Jun 2023 10:17:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687281470; x=1689873470; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s5xAnTBoCuOZm3px/uGPG96Z9S4eOD8XBG2XupxKvIo=; b=ODYNkBxqMQwA4tpFaRMxyCZpQb2ULV1+at2Jqb+d47WFRuYqLSrb3X6WKnCHfiRr+u aTiRQaXwrP4aYNUIIqYdW5ralMwH9/7L64U3nKPfvXSKg7K488PgOx/1C56z8jAfzwHz tBSUGzA9E5R2FaHFg3nDUgRPTE7L6fA8BcHpjGgISF7VccfPDiI3MKoMRAnNTRZDSPXY Bn6sJ9eSgJpv8H3yupbIazW5PAQr6r2WqDKdI7dCARSIxpbz1IMFtLokQFN92IUjuzg6 TYd0UtPrAkDSavHB6+sGo5zIUOGmzZZApiOQWx6Q4GY7eNoefYmybxZHZ2Db/BLOHIaH Y2mQ== X-Gm-Message-State: AC+VfDzvPwFyRgl2idbQFO5okRGfeRerVdKmGQN5TMbEWpzYHmmyxvhx cg9Dckf1KmCYmeM3NVKFTPY= X-Google-Smtp-Source: ACHHUZ7CY7G4ek7sb6wp3eT069bEVgkCR2yV/CRgkwV6n5MTYbrN87nwVV95rtBkwyxolowF3BTVHQ== X-Received: by 2002:a05:6830:4d1:b0:6b4:62d3:25e2 with SMTP id s17-20020a05683004d100b006b462d325e2mr11014504otd.19.1687281470660; Tue, 20 Jun 2023 10:17:50 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id r23-20020a634417000000b005143448896csm1652930pga.58.2023.06.20.10.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 10:17:50 -0700 (PDT) To: Jens Gustedt , libc-alpha@sourceware.org Cc: Florian Weimer , Yonggang Luo Subject: [PATCH v2 2/4] time: Implement c23 timespec_get base Date: Wed, 21 Jun 2023 01:17:29 +0800 Message-Id: <20230620171731.230-3-luoyonggang@gmail.com> X-Mailer: git-send-email 2.39.0.windows.1 In-Reply-To: <20230620171731.230-1-luoyonggang@gmail.com> References: <20230620171731.230-1-luoyonggang@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yonggang Luo via Libc-alpha From: Yonggang Luo Reply-To: Yonggang Luo Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" These are implemented https://gustedt.gitlabpages.inria.fr/c23-library/#time_monotonic-time_active-time_thread_active with: # define TIME_MONOTONIC 2 # define TIME_ACTIVE 3 # define TIME_THREAD_ACTIVE 4 # define TIME_MONOTONIC_RAW 5 # define TIME_UTC_COARSE 6 # define TIME_MONOTONIC_COARSE 7 # define TIME_BOOTTIME 8 # define TIME_UTC_ALARM 9 # define TIME_BOOTTIME_ALARM 10 # define TIME_SGI_CYCLE 11 # define TIME_TAI 12 Signed-off-by: Yonggang Luo --- time/time.h | 13 +++++++++++- time/timespec_get.c | 51 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/time/time.h b/time/time.h index 368f4dc588..660cbb200b 100644 --- a/time/time.h +++ b/time/time.h @@ -62,7 +62,18 @@ typedef __pid_t pid_t; #ifdef __USE_ISOC11 /* Time base values for timespec_get. */ -# define TIME_UTC 1 +# define TIME_UTC 1 +# define TIME_MONOTONIC 2 +# define TIME_ACTIVE 3 +# define TIME_THREAD_ACTIVE 4 +# define TIME_MONOTONIC_RAW 5 +# define TIME_UTC_COARSE 6 +# define TIME_MONOTONIC_COARSE 7 +# define TIME_BOOTTIME 8 +# define TIME_UTC_ALARM 9 +# define TIME_BOOTTIME_ALARM 10 +# define TIME_SGI_CYCLE 11 +# define TIME_TAI 12 #endif __BEGIN_DECLS diff --git a/time/timespec_get.c b/time/timespec_get.c index 9b1d4f22ed..20c0e4d9aa 100644 --- a/time/timespec_get.c +++ b/time/timespec_get.c @@ -17,15 +17,58 @@ #include - /* Set TS to calendar time based in time base BASE. */ int timespec_get (struct timespec *ts, int base) { - if (base == TIME_UTC) + clockid_t clockid = -1; + switch (base) + { + default: + break; + case TIME_UTC: + clockid = CLOCK_REALTIME; + break; + case TIME_MONOTONIC: + clockid = CLOCK_MONOTONIC; + break; + case TIME_ACTIVE: + clockid = CLOCK_PROCESS_CPUTIME_ID; + break; + case TIME_THREAD_ACTIVE: + clockid = CLOCK_THREAD_CPUTIME_ID; + break; + case TIME_MONOTONIC_RAW: + clockid = CLOCK_MONOTONIC_RAW; + break; + case TIME_UTC_COARSE: + clockid = CLOCK_REALTIME_COARSE; + break; + case TIME_MONOTONIC_COARSE: + clockid = CLOCK_MONOTONIC_COARSE; + break; + case TIME_BOOTTIME: + clockid = CLOCK_BOOTTIME; + break; + case TIME_UTC_ALARM: + clockid = CLOCK_REALTIME_ALARM; + break; + case TIME_BOOTTIME_ALARM: + clockid = CLOCK_BOOTTIME_ALARM; + break; + case TIME_SGI_CYCLE: + clockid = CLOCK_SGI_CYCLE; + break; + case TIME_TAI: + clockid = CLOCK_TAI; + break; + } + if (clockid >= 0) { - __clock_gettime (CLOCK_REALTIME, ts); - return base; + if (__clock_gettime (clockid, ts) >= 0) + { + return base; + } } return 0; } From patchwork Tue Jun 20 17:17:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonggang Luo X-Patchwork-Id: 71427 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 43F40385734F for ; Tue, 20 Jun 2023 17:18:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43F40385734F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1687281498; bh=oHxGd+i4XNCRpDC+8cWdK9I94diANM8pSQVyCrg/gwg=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=DFEJj1T/dwGJAU4Q+KzbSpbrj62f0rNYUYOtI2XEH+2U3flLBFLG9xajr5tzvmnjT AeBdA4K7dmvqlF/5A3FR3VC+QKrwch4zCMCnOgaEBvmL1a5ELS0bEjqeZKWnmJh801 TcJHVZRoydWuZKPv0hF3Nmmxu7vMriVIHhcteHtI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id EB596385828D for ; Tue, 20 Jun 2023 17:17:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EB596385828D Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-6b46e61638eso2509850a34.0 for ; Tue, 20 Jun 2023 10:17:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687281473; x=1689873473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oHxGd+i4XNCRpDC+8cWdK9I94diANM8pSQVyCrg/gwg=; b=Ozo674eIMLyih4jJtxbikdkaShLhowYvBcpgD/BG8YvOWy4tFwPKqPWEhhFSM8HbiC nmswC6xxCJnHx1Ef+85jx2ot3mlirHqu0iNRMwnjqGqvvu6aEZ2QsVg+YZj2R7bMF/Li 8hrO+T0lsS9wFRpKEDbk6d8AIr0aX+AYKYdjruNjHNTdhAJtDPhk6g0yPh7DfjJHdZYU mclcjcDl7Ru2u8wvKQ5YF0GqsPDBr9r2tNG6lyZs8MSL1/ybGXqlF3kD2PB4m7uXjvMl 71PJn817L3Ol4dz3FWLUmir+dTtnmQ+bLyNApZOSJaMZ0rx9U7OKLFSYfQ6Bpm54plWl bZbw== X-Gm-Message-State: AC+VfDzXHCjlEv9iXrHmfEugrQAHMi8tyNPB49SLtjNY18qriX7AOd3c p70KzE6htYmj6lZSP3x2eIM= X-Google-Smtp-Source: ACHHUZ6cVJZKDm5feZaBPN9TUH7H8W3GyATzWDE2drKOnPZ9oQk5M51wqJD1xZNP8H53wS3KYb1RlQ== X-Received: by 2002:a05:6358:7018:b0:12b:cdd2:8b33 with SMTP id 24-20020a056358701800b0012bcdd28b33mr3591485rwo.7.1687281473191; Tue, 20 Jun 2023 10:17:53 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id r23-20020a634417000000b005143448896csm1652930pga.58.2023.06.20.10.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 10:17:52 -0700 (PDT) To: Jens Gustedt , libc-alpha@sourceware.org Cc: Florian Weimer , Yonggang Luo Subject: [PATCH v2 3/4] c11: Switch to use pthread_mutex_clocklock and pthread_cond_clockwait to implement cnd and mtx lock and wait Date: Wed, 21 Jun 2023 01:17:30 +0800 Message-Id: <20230620171731.230-4-luoyonggang@gmail.com> X-Mailer: git-send-email 2.39.0.windows.1 In-Reply-To: <20230620171731.230-1-luoyonggang@gmail.com> References: <20230620171731.230-1-luoyonggang@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yonggang Luo via Libc-alpha From: Yonggang Luo Reply-To: Yonggang Luo Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Signed-off-by: Yonggang Luo --- sysdeps/pthread/cnd_timedwait.c | 8 ++++---- sysdeps/pthread/mtx_timedlock.c | 6 +++--- sysdeps/unix/sysv/linux/cnd_timedwait.c | 4 ++-- sysdeps/unix/sysv/linux/mtx_timedlock.c | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sysdeps/pthread/cnd_timedwait.c b/sysdeps/pthread/cnd_timedwait.c index 25df50cb3a..ea2921a35c 100644 --- a/sysdeps/pthread/cnd_timedwait.c +++ b/sysdeps/pthread/cnd_timedwait.c @@ -20,10 +20,10 @@ int cnd_timedwait (cnd_t *restrict cond, mtx_t *restrict mutex, - const struct timespec* restrict time_point) + const struct timespec *restrict time_point) { - int err_code = __pthread_cond_timedwait ((pthread_cond_t *) cond, - (pthread_mutex_t *) mutex, - time_point); + int err_code = __pthread_cond_clockwait ((pthread_cond_t *) cond, + (pthread_mutex_t *) mutex, + CLOCK_REALTIME, time_point); return thrd_err_map (err_code); } diff --git a/sysdeps/pthread/mtx_timedlock.c b/sysdeps/pthread/mtx_timedlock.c index a3d236f3e1..77ab39a72c 100644 --- a/sysdeps/pthread/mtx_timedlock.c +++ b/sysdeps/pthread/mtx_timedlock.c @@ -20,9 +20,9 @@ int mtx_timedlock (mtx_t *restrict mutex, - const struct timespec *restrict time_point) + const struct timespec *restrict time_point) { - int err_code = __pthread_mutex_timedlock ((pthread_mutex_t *)mutex, - time_point); + int err_code = __pthread_mutex_clocklock ((pthread_mutex_t *) mutex, + CLOCK_REALTIME, time_point); return thrd_err_map (err_code); } diff --git a/sysdeps/unix/sysv/linux/cnd_timedwait.c b/sysdeps/unix/sysv/linux/cnd_timedwait.c index 9fa6d71d1a..c612d4f94d 100644 --- a/sysdeps/unix/sysv/linux/cnd_timedwait.c +++ b/sysdeps/unix/sysv/linux/cnd_timedwait.c @@ -24,9 +24,9 @@ int __cnd_timedwait64 (cnd_t *restrict cond, mtx_t *restrict mutex, const struct __timespec64 *restrict time_point) { - int err_code = __pthread_cond_timedwait64 ((pthread_cond_t *) cond, + int err_code = __pthread_cond_clockwait64 ((pthread_cond_t *) cond, (pthread_mutex_t *) mutex, - time_point); + CLOCK_REALTIME, time_point); return thrd_err_map (err_code); } diff --git a/sysdeps/unix/sysv/linux/mtx_timedlock.c b/sysdeps/unix/sysv/linux/mtx_timedlock.c index 8019792868..b8f6d51940 100644 --- a/sysdeps/unix/sysv/linux/mtx_timedlock.c +++ b/sysdeps/unix/sysv/linux/mtx_timedlock.c @@ -24,8 +24,8 @@ int __mtx_timedlock64 (mtx_t *restrict mutex, const struct __timespec64 *restrict time_point) { - int err_code = __pthread_mutex_timedlock64 ((pthread_mutex_t *)mutex, - time_point); + int err_code = __pthread_mutex_clocklock64 ((pthread_mutex_t *) mutex, + CLOCK_REALTIME, time_point); return thrd_err_map (err_code); } From patchwork Tue Jun 20 17:17:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonggang Luo X-Patchwork-Id: 71429 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6ACC1385841B for ; Tue, 20 Jun 2023 17:19:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6ACC1385841B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1687281578; bh=g7noJlFHzJyv0hmJnoLiu3rALwVoNLKaKh/HFtyVv8o=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=We0l0I8Xp2xoPZ6RE1ROMiLqYDXPeUpBpvpcZBF8I48NJ/kvcdPITlLDURBvD+ndu g0gfmRz1DUgV7l2ElqFZ0akfYKj/q/bAVjnLk5MFWwKhztheR2o4T9MktCp2rKV86T NxytbmF4XOKEBsH4hGREOOgSJvo7HPNIzE+qI8xk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id EAAD43857C43 for ; Tue, 20 Jun 2023 17:17:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAAD43857C43 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-666fb8b1bc8so3554678b3a.1 for ; Tue, 20 Jun 2023 10:17:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687281476; x=1689873476; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g7noJlFHzJyv0hmJnoLiu3rALwVoNLKaKh/HFtyVv8o=; b=WaVh1SUR/DHoIyyHag7bJI+n6q2zyX+piZxddvZk2Y0i15Y8T12bVlSPz7XHfxnhIF l5iQYDvub6TOedp8RH6lrI4ACfxgxRlbYDQuzrCdBWJpUmGSMjkFkFvAoJ5EIFqMpU2N 4CGLeMU9zJ2a4KCVqtJ2via9O9Ftax0DQ+sOkLjHSVs+2pHc0cRtTu0/gkOWDjj1Hlp5 ls5t9m21fr5yT/gl13yukFvy+HB4pFQ9o3EtD03hfBsZrq54CGV+qyS5I6vxyYxIfWUR vcVeGnDq+gOy4NzNjCRvbct6fVITVRl+SopxuMnOMJMho8KIq3+qVl8gW1bVtZbgoeuv V0QQ== X-Gm-Message-State: AC+VfDzZkaAX/YD+HAtt7lBsnCtZg42O/wj0QSAeZ2YAtyk59P8zV2/k RcmGPxGi0VPcOO1w86i2AjM= X-Google-Smtp-Source: ACHHUZ4o+qGAwqcq17JAiSfQZSoUOmubJR1r24I3QwWbNHPA3LECOjVKQp76aFoJHJCyueYSLEekkA== X-Received: by 2002:a05:6a20:428b:b0:122:2bc1:8857 with SMTP id o11-20020a056a20428b00b001222bc18857mr5401846pzj.52.1687281475703; Tue, 20 Jun 2023 10:17:55 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id r23-20020a634417000000b005143448896csm1652930pga.58.2023.06.20.10.17.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 10:17:55 -0700 (PDT) To: Jens Gustedt , libc-alpha@sourceware.org Cc: Florian Weimer , Yonggang Luo Subject: [PATCH v2 4/4] c2y: Add function cnd_timedwait_base and mtx_timedlock_base Date: Wed, 21 Jun 2023 01:17:31 +0800 Message-Id: <20230620171731.230-5-luoyonggang@gmail.com> X-Mailer: git-send-email 2.39.0.windows.1 In-Reply-To: <20230620171731.230-1-luoyonggang@gmail.com> References: <20230620171731.230-1-luoyonggang@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yonggang Luo via Libc-alpha From: Yonggang Luo Reply-To: Yonggang Luo Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" For c11 threads, the mtx and cnd doesn't support for monotonic timedlock and timedwait; So add two proposal function mtx_timedlock_base cnd_timedwait_base to do that. The protype of these two functions is: int mtx_timedlock_base(mtx_t *restrict m, int time_base, const struct timespec *restrict ts); int cnd_timedwait_base(cnd_t *restrict c, mtx_t *restrict m, int time_base, const struct timespec *restrict ts); The time_base at least can be TIME_UTC/TIME_MONOTONIC, the implementer can implement it with any provided TIME_* base parameter provided in c2y time.h, if TIME_MONOTONIC can not natively supported, fallback to TIME_UTC should provided, for other TIME_* base parameter, it's implementer's choice. Signed-off-by: Yonggang Luo --- conform/data/threads.h-data | 2 + htl/Versions | 5 ++ nptl/Versions | 5 ++ sysdeps/pthread/Makefile | 2 + sysdeps/pthread/cnd_timedwait_base.c | 29 +++++++++++ sysdeps/pthread/mtx_timedlock_base.c | 28 +++++++++++ sysdeps/pthread/threads.h | 18 +++++++ sysdeps/unix/sysv/linux/Versions | 6 +++ sysdeps/unix/sysv/linux/cnd_timedwait_base.c | 53 ++++++++++++++++++++ sysdeps/unix/sysv/linux/mtx_timedlock_base.c | 50 ++++++++++++++++++ sysdeps/unix/sysv/linux/thrd_priv.h | 10 ++++ 11 files changed, 208 insertions(+) create mode 100644 sysdeps/pthread/cnd_timedwait_base.c create mode 100644 sysdeps/pthread/mtx_timedlock_base.c create mode 100644 sysdeps/unix/sysv/linux/cnd_timedwait_base.c create mode 100644 sysdeps/unix/sysv/linux/mtx_timedlock_base.c diff --git a/conform/data/threads.h-data b/conform/data/threads.h-data index 406e497726..e938e0512c 100644 --- a/conform/data/threads.h-data +++ b/conform/data/threads.h-data @@ -34,6 +34,7 @@ function void thrd_yield (void) function int mtx_init (mtx_t*, int) function int mtx_lock (mtx_t*) function int mtx_timedlock (mtx_t*, const struct timespec*) +function int mtx_timedlock_base (mtx_t*, int, const struct timespec*) function int mtx_trylock (mtx_t*) function int mtx_unlock (mtx_t*) function void mtx_destroy (mtx_t*) @@ -45,6 +46,7 @@ function int cnd_signal (cnd_t*) function int cnd_broadcast (cnd_t*) function int cnd_wait (cnd_t*, mtx_t*) function int cnd_timedwait (cnd_t*, mtx_t*, const struct timespec*) +function int cnd_timedwait_base (cnd_t*, mtx_t*, int, const struct timespec*) function void cnd_destroy (cnd_t*) function int tss_create (tss_t*, tss_dtor_t) diff --git a/htl/Versions b/htl/Versions index 70fa44631a..804005bfb9 100644 --- a/htl/Versions +++ b/htl/Versions @@ -170,6 +170,11 @@ libpthread { sem_clockwait; } + GLIBC_2.38 { + cnd_timedwait_base; + mtx_timedlock_base; + } + GLIBC_PRIVATE { __pthread_initialize_minimal; diff --git a/nptl/Versions b/nptl/Versions index 3221de89d1..d44ab2b12d 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -525,6 +525,11 @@ libpthread { GLIBC_2.31 { __libpthread_version_placeholder; } + + GLIBC_2.38 { + cnd_timedwait_base; + mtx_timedlock_base; + } } ld { diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile index 32cf4eb119..a4a9d1b2cc 100644 --- a/sysdeps/pthread/Makefile +++ b/sysdeps/pthread/Makefile @@ -40,11 +40,13 @@ $(libpthread-routines-var) += \ cnd_init \ cnd_signal \ cnd_timedwait \ + cnd_timedwait_base \ cnd_wait \ mtx_destroy \ mtx_init \ mtx_lock \ mtx_timedlock \ + mtx_timedlock_base \ mtx_trylock \ mtx_unlock \ pthread_atfork_compat \ diff --git a/sysdeps/pthread/cnd_timedwait_base.c b/sysdeps/pthread/cnd_timedwait_base.c new file mode 100644 index 0000000000..e9be66ca0e --- /dev/null +++ b/sysdeps/pthread/cnd_timedwait_base.c @@ -0,0 +1,29 @@ +/* C11 threads conditional timed wait implementation. + Copyright (C) 2018-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include "thrd_priv.h" + +int +cnd_timedwait_base (cnd_t *restrict cond, mtx_t *restrict mutex, int time_base, + const struct timespec *restrict time_point) +{ + int err_code = __pthread_cond_clockwait ((pthread_cond_t *) cond, + (pthread_mutex_t *) mutex, + time_base, time_point); + return thrd_err_map (err_code); +} diff --git a/sysdeps/pthread/mtx_timedlock_base.c b/sysdeps/pthread/mtx_timedlock_base.c new file mode 100644 index 0000000000..9aecf84440 --- /dev/null +++ b/sysdeps/pthread/mtx_timedlock_base.c @@ -0,0 +1,28 @@ +/* C11 threads mutex timed lock implementation. + Copyright (C) 2018-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include "thrd_priv.h" + +int +mtx_timedlock_base (mtx_t *restrict mutex, int time_base, + const struct timespec *restrict time_point) +{ + int err_code = __pthread_mutex_clocklock ((pthread_mutex_t *) mutex, + time_base, time_point); + return thrd_err_map (err_code); +} diff --git a/sysdeps/pthread/threads.h b/sysdeps/pthread/threads.h index d88d7a3ddd..4f61ad9236 100644 --- a/sysdeps/pthread/threads.h +++ b/sysdeps/pthread/threads.h @@ -146,14 +146,22 @@ extern int mtx_lock (mtx_t *__mutex); #ifndef __USE_TIME_BITS64 extern int mtx_timedlock (mtx_t *__restrict __mutex, const struct timespec *__restrict __time_point); +extern int mtx_timedlock_base (mtx_t *__restrict __mutex, int time_base, + const struct timespec *__restrict __time_point); #else # ifdef __REDIRECT extern int __REDIRECT (mtx_timedlock, (mtx_t *__restrict __mutex, const struct timespec *__restrict __time_point), __mtx_timedlock64); +extern int __REDIRECT (mtx_timedlock_base, (mtx_t *__restrict __mutex, + int time_base, + const struct timespec *__restrict + __time_point), + __mtx_timedlock_base64); # else # define mtx_timedlock __mtx_timedlock64 +# define mtx_timedlock_base __mtx_timedlock_base64 # endif #endif @@ -198,6 +206,9 @@ extern int cnd_wait (cnd_t *__cond, mtx_t *__mutex); extern int cnd_timedwait (cnd_t *__restrict __cond, mtx_t *__restrict __mutex, const struct timespec *__restrict __time_point); +extern int cnd_timedwait_base (cnd_t *__restrict __cond, + mtx_t *__restrict __mutex, int time_base, + const struct timespec *__restrict __time_point); #else # ifdef __REDIRECT extern int __REDIRECT (cnd_timedwait, (cnd_t *__restrict __cond, @@ -205,8 +216,15 @@ extern int __REDIRECT (cnd_timedwait, (cnd_t *__restrict __cond, const struct timespec *__restrict __time_point), __cnd_timedwait64); +extern int __REDIRECT (cnd_timedwait_base, (cnd_t *__restrict __cond, + mtx_t *__restrict __mutex, + int time_base, + const struct timespec *__restrict + __time_point), + __cnd_timedwait_base64); # else # define cnd_timedwait __cnd_timedwait64 +# define cnd_timedwait_base __cnd_timedwait_base64 # endif #endif diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions index bc59bce42f..73ce24bea6 100644 --- a/sysdeps/unix/sysv/linux/Versions +++ b/sysdeps/unix/sysv/linux/Versions @@ -319,6 +319,12 @@ libc { GLIBC_2.37 { %ifdef TIME64_NON_DEFAULT __ppoll64_chk; +%endif + } + GLIBC_2.38 { +%ifdef TIME64_NON_DEFAULT + __cnd_timedwait_base64; + __mtx_timedlock_base64; %endif } GLIBC_PRIVATE { diff --git a/sysdeps/unix/sysv/linux/cnd_timedwait_base.c b/sysdeps/unix/sysv/linux/cnd_timedwait_base.c new file mode 100644 index 0000000000..2e851a7aec --- /dev/null +++ b/sysdeps/unix/sysv/linux/cnd_timedwait_base.c @@ -0,0 +1,53 @@ +/* C11 threads conditional timed wait implementation - Linux variant. + Copyright (C) 2020-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include "thrd_priv.h" + +int +__cnd_timedwait_base64 (cnd_t *restrict cond, mtx_t *restrict mutex, + int time_base, + const struct __timespec64 *restrict time_point) +{ + int err_code = __pthread_cond_clockwait64 ((pthread_cond_t *) cond, + (pthread_mutex_t *) mutex, + time_base, time_point); + return thrd_err_map (err_code); +} + +#if __TIMESIZE == 64 +strong_alias (__cnd_timedwait_base64, ___cnd_timedwait_base) +#else +libc_hidden_def (__cnd_timedwait_base64) + +int +___cnd_timedwait_base (cnd_t *restrict cond, mtx_t *restrict mutex, + int time_base, + const struct timespec *restrict time_point) +{ + struct __timespec64 ts64 = valid_timespec_to_timespec64 (*time_point); + + return __cnd_timedwait_base64 (cond, mutex, time_base, &ts64); +} +#endif /* __TIMESIZE == 64 */ +versioned_symbol (libc, ___cnd_timedwait_base, cnd_timedwait_base, GLIBC_2_34); + +#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_28, GLIBC_2_34) +compat_symbol (libpthread, ___cnd_timedwait_base, cnd_timedwait_base, GLIBC_2_28); +#endif diff --git a/sysdeps/unix/sysv/linux/mtx_timedlock_base.c b/sysdeps/unix/sysv/linux/mtx_timedlock_base.c new file mode 100644 index 0000000000..046fb86091 --- /dev/null +++ b/sysdeps/unix/sysv/linux/mtx_timedlock_base.c @@ -0,0 +1,50 @@ +/* C11 threads mutex timed lock implementation - Linux variant. + Copyright (C) 2020-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include "thrd_priv.h" + +int +__mtx_timedlock_base64 (mtx_t *restrict mutex, int time_base, + const struct __timespec64 *restrict time_point) +{ + int err_code = __pthread_mutex_clocklock64 ((pthread_mutex_t *) mutex, + time_base, time_point); + return thrd_err_map (err_code); +} + +#if __TIMESIZE == 64 +strong_alias (__mtx_timedlock_base64, ___mtx_timedlock_base) +#else +libc_hidden_def (__mtx_timedlock_base64) + +int +___mtx_timedlock_base (mtx_t *restrict mutex, int time_base, + const struct timespec *restrict time_point) +{ + struct __timespec64 ts64 = valid_timespec_to_timespec64 (*time_point); + + return __mtx_timedlock_base64 (mutex, time_base, &ts64); +} +#endif /* __TIMESIZE == 64 */ +versioned_symbol (libc, ___mtx_timedlock_base, mtx_timedlock_base, GLIBC_2_34); + +#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_28, GLIBC_2_34) +compat_symbol (libpthread, ___mtx_timedlock_base, mtx_timedlock_base, GLIBC_2_28); +#endif diff --git a/sysdeps/unix/sysv/linux/thrd_priv.h b/sysdeps/unix/sysv/linux/thrd_priv.h index af23a10a07..8ea9ced507 100644 --- a/sysdeps/unix/sysv/linux/thrd_priv.h +++ b/sysdeps/unix/sysv/linux/thrd_priv.h @@ -20,15 +20,25 @@ #if __TIMESIZE == 64 # define __cnd_timedwait64 __cnd_timedwait +# define __cnd_timedwait_base64 __cnd_timedwait_base # define __mtx_timedlock64 __mtx_timedlock +# define __mtx_timedlock_base64 __mtx_timedlock_base # define __thrd_sleep64 __thrd_sleep #else extern int __cnd_timedwait64 (cnd_t *restrict cond, mtx_t *restrict mutex, const struct __timespec64 *restrict time_point); libc_hidden_proto (__cnd_timedwait64) +extern int __cnd_timedwait_base64 (cnd_t *restrict cond, mtx_t *restrict mutex, + int time_base, + const struct __timespec64 *restrict time_point); +libc_hidden_proto (__cnd_timedwait_base64) extern int __mtx_timedlock64 (mtx_t *restrict mutex, const struct __timespec64 *restrict time_point); libc_hidden_proto (__mtx_timedlock64) +extern int __mtx_timedlock_base64 (mtx_t *restrict mutex, int time_base, + const struct __timespec64 *restrict + time_point); +libc_hidden_proto (__mtx_timedlock_base64) extern int __thrd_sleep64 (const struct __timespec64 *time_point, struct __timespec64 *remaining); libc_hidden_proto (__thrd_sleep64)