From patchwork Mon Nov 23 19:52:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41171 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 F37D1383F841; Mon, 23 Nov 2020 19:53:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F37D1383F841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606161208; bh=HU96DbSUu+nrkwaiKnYH3RcFgWf2fa3SzX/2yTGJOCQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=XSmh3pljundEwhrooJ/FXXwHG1XsApv0/Vk86UQcssYDB17BWBRgKYWS/I8OCwsHB EVTuJ3AofqBjn9Bq/jEppDjI6hJet2h7NAZameANddmXKvxrM2ioxFFQ/XLTZnxgH9 xLlhBNMswwNNXnQbkvOvlyRXvaxJ1gINTYUKkH7g= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by sourceware.org (Postfix) with ESMTPS id 05A31383F86C for ; Mon, 23 Nov 2020 19:53:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 05A31383F86C Received: by mail-qt1-x841.google.com with SMTP id f15so10808671qto.13 for ; Mon, 23 Nov 2020 11:53:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HU96DbSUu+nrkwaiKnYH3RcFgWf2fa3SzX/2yTGJOCQ=; b=NXcPGMkLqQzIjoRCHh1eTK1CCe6YkT0kD4DKoxi2QgWCVSfY9zHRSw9mzbODDkNCW2 d89mbKxf0xzSX2wUBLv32yg1Jb3gERrs1cvLqBsZ7Xbrh8it7spNTa6KXSHuPJq2y+I+ Z07XTOlpWd/8v0KtUB6ibZ2L4OmZ/cvIBpXXHrqQ6bN5ROc1krrHVnXQ6Z3olPJiyczG eFUyYi+78nKgc+qL34enJ94Ymnr2m3gr0+4PwFXo/s9cDFvO03oJutav6++NsdDONkRu hbpNsC/WIXnRh2fKeMZObsz+8wa2t1KzbcJSnkbzWRF/pJbFVmGC4jda/qs6UcyUTCJb qvUg== X-Gm-Message-State: AOAM5314nxFPoF0fqfWUWtHkvuSLDM045h5XReyp4lNN25PMXQKR3Bxb ixGLqfeoSMQoZeDcRUnldV9jB2UouHC2iA== X-Google-Smtp-Source: ABdhPJwd/pyOUv7+keOj72GO1Hf4CnbwPvY1+Ii/AataiclPIzKtxT+4pyaO8gaoCapsZjL0bEZEOg== X-Received: by 2002:a05:622a:d1:: with SMTP id p17mr806844qtw.233.1606161204308; Mon, 23 Nov 2020 11:53:24 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v9sm10440432qkv.34.2020.11.23.11.53.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 11:53:23 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 13/13] linux: Return EINVAL for invalid clock for pthread_clockjoin_np Date: Mon, 23 Nov 2020 16:52:56 -0300 Message-Id: <20201123195256.3336217-13-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> References: <20201123195256.3336217-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Michael Kerrisk Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The align the GNU extension with the others one that accept specify which clock to wait for (such as pthread_mutex_clocklock). Check on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski Tested-by: Lukasz Majewski --- nptl/pthread_clockjoin.c | 4 ++ sysdeps/pthread/Makefile | 2 +- sysdeps/pthread/tst-join15.c | 80 ++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 sysdeps/pthread/tst-join15.c diff --git a/nptl/pthread_clockjoin.c b/nptl/pthread_clockjoin.c index 0baba1e83d..3d54fe588f 100644 --- a/nptl/pthread_clockjoin.c +++ b/nptl/pthread_clockjoin.c @@ -17,12 +17,16 @@ . */ #include +#include #include "pthreadP.h" int __pthread_clockjoin_np64 (pthread_t threadid, void **thread_return, clockid_t clockid, const struct __timespec64 *abstime) { + if (!futex_abstimed_supported_clockid (clockid)) + return EINVAL; + return __pthread_clockjoin_ex (threadid, thread_return, clockid, abstime, true); } diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile index 45a15b0b1a..8f335c13b5 100644 --- a/sysdeps/pthread/Makefile +++ b/sysdeps/pthread/Makefile @@ -77,7 +77,7 @@ tests += tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \ tst-getpid3 \ tst-join1 tst-join2 tst-join3 tst-join4 tst-join5 tst-join6 tst-join7 \ tst-join8 tst-join9 tst-join10 tst-join11 tst-join12 tst-join13 \ - tst-join14 \ + tst-join14 tst-join15 \ tst-key1 tst-key2 tst-key3 tst-key4 \ tst-kill1 tst-kill2 tst-kill3 tst-kill4 tst-kill5 tst-kill6 \ tst-locale1 tst-locale2 \ diff --git a/sysdeps/pthread/tst-join15.c b/sysdeps/pthread/tst-join15.c new file mode 100644 index 0000000000..4ed767e733 --- /dev/null +++ b/sysdeps/pthread/tst-join15.c @@ -0,0 +1,80 @@ +/* Check pthread_clockjoin_np clock support. + Copyright (C) 2020 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 +#include + +#include +#include +#include +#include + +static void * +tf (void *arg) +{ + pause (); + return NULL; +} + + +static int +do_test (void) +{ + const clockid_t clocks[] = { + CLOCK_REALTIME, + CLOCK_MONOTONIC, + CLOCK_PROCESS_CPUTIME_ID, + CLOCK_THREAD_CPUTIME_ID, + CLOCK_THREAD_CPUTIME_ID, + CLOCK_MONOTONIC_RAW, + CLOCK_REALTIME_COARSE, + CLOCK_MONOTONIC_COARSE, +#ifdef CLOCK_BOOTTIME + CLOCK_BOOTTIME, +#endif +#ifdef CLOCK_REALTIME_ALARM + CLOCK_REALTIME_ALARM, +#endif +#ifdef CLOCK_BOOTTIME_ALARM + CLOCK_BOOTTIME_ALARM, +#endif +#ifdef CLOCK_TAI + CLOCK_TAI +#endif + }; + + pthread_t thr = xpthread_create (NULL, tf, NULL); + + for (int t = 0; t < array_length (clocks); t++) + { + /* A valid timeout so valid clock timeout. */ + struct timespec tmo = timespec_add (xclock_now (clocks[t]), + make_timespec (0, 100000000)); + + int ret = clocks[t] == CLOCK_REALTIME || clocks[t] == CLOCK_MONOTONIC + ? ETIMEDOUT : EINVAL; + + TEST_COMPARE (pthread_clockjoin_np (thr, NULL, clocks[t], &tmo), ret); + } + + return 0; +} + +#include