From patchwork Fri Feb 2 17:04:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 126753 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp818738ljc; Fri, 2 Feb 2018 09:05:16 -0800 (PST) X-Google-Smtp-Source: AH8x224PeY0URw/epJzoRQaYSdkk67jLBEnXQfhbaqPk7+afwGaT3myg+W5DlUkoLZdfzxhAxbXa X-Received: by 10.98.103.131 with SMTP id t3mr5145546pfj.53.1517591115767; Fri, 02 Feb 2018 09:05:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517591115; cv=none; d=google.com; s=arc-20160816; b=RTw6t4P8MNVG02Dmi9LV8Umwqbf4AX+wP2f/oPzWW9266faBtRf3xliU5Wj37tLusi /DXJmVJX6HYnBVgHWnRmJyPm260s+D/cKbfmy7NYrlHxgfe3TIEZQq589fw/ry9xMrTn eBEISWFT4tB0KDjj3sfa0i4zITvBKgUregG855NVs0rvwaayDROx0Xw800FX5VDL5RLb t4J2K3jG4INAGwT2wslP0SWh/nzItjCGWgyoBYCd7F6YU0R3dmV2pXOxE+PCNnQ2xe21 TRJAjsikQ11MHqiKdDSrimaCiZlLbZZGbhrU8QyMuJumU4+XKEFF8ZYJAJa25pIibSk5 iz4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from:delivered-to :sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=Vadcpi4CPOtyRcqC0+HD4n8hFKjNSlpLc0DvdLda04c=; b=Wf5wY4Ig3Sbmjebq1Kha9ZxVNR8979Ry2KS8TohbsyhOjM/Y3C9xrdRCS7iCNIj/SL LbLJJn0QAlA6+xZroDG5/rG9ZoQejth6Bmyt4/pcGPxlKXo4ajhwdpqn8kW57X0C7C2m Q3cR0XIbNR/tZzzZWpwVCz+CfS/DJG/lsOAR74l5DpeDwXPk3iiFKkibtpYBQClauWly 7T/P9Fjby9DJalInMrnTa/olcaUho9VdlkDxchnUkrhkc/iW9fBzRqSIMUSCLoCVygvy dGfjWoMByW+JKpxctuHpqrk8nnq90TdSJbOFGPwbpbek3+UrAT7JqxYxddVhfcPTf4a8 PkZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=soQDdEhD; spf=pass (google.com: domain of libc-alpha-return-89921-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-89921-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id m39-v6si2095401plg.372.2018.02.02.09.05.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Feb 2018 09:05:15 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-89921-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=soQDdEhD; spf=pass (google.com: domain of libc-alpha-return-89921-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-89921-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=o9aAvuMBzkFjGXMqr9lQHgp6cRMlcVz HDBr1phO5Xot9fYjhDh6pTBONg9C9q2J9wWrWRfhTb4kmax/Wr8WwNVJIgL5j840 gvoE7saHG5NB2CzSNwCn30+pDCQqHdS07xsmywENqaKpByxMf73hheQ+7KU/Om5k lr1eqLysnT2A= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=53hpCZqpfjiLsT3xVccw0++DE/4=; b=soQDd EhDZ4WPBpr6j4rGiG9EobKQo2GzKDrtXP3RYttzVL9ET+rJyZ5xf+i0eFpns755g r+91zqRtbyIbjXiXEUtf7LaO7a1iuhHMOBqCEea1lwTlBXnvbWCPVqfD4dGsviQO YkQEvXJbDtvN2bgGpd3W2301VOHw3yd4SHYsvU= Received: (qmail 129026 invoked by alias); 2 Feb 2018 17:05:02 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 128885 invoked by uid 89); 2 Feb 2018 17:05:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f196.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Vadcpi4CPOtyRcqC0+HD4n8hFKjNSlpLc0DvdLda04c=; b=BSl00mPpNHclVIr7c/60LNjrPsgibyDa5zu0l2gv3Hw0/mVveJvErajTK16u2HOdX2 qZz76ktata7ccoi15dcpssyTU18xSpPiGZxH1JyJ1ocGYrDC8r70gu3C8X9SI+PzYbE/ Y/WPSs0jtQGDNfjjUd34n8KXJVMV5Vj0Tq2UoCPD/j2PpaOcZDRitHfz39Rah/58mXAj RLW/Dl48xiP2ithhey4KHE9irG0jxS/YbNKHH8qypDi5ydNh+wUi8y1I/rp4to5bwEHI n0/r9t3uOwFzgBdfNNWNbVByNoSR6fwYat/Utx9Uzt+pUzq+/usDUOLgb3VkJFDhMzmO yZeg== X-Gm-Message-State: AKwxyte3p61RwtFt2U98xvVV9Ux5ptX0UCRgwXMWECOGZ4hQuXKyKPzp RCw052c/K7ED2FK6ZahEbsdOI+ndIkc= X-Received: by 10.200.81.83 with SMTP id h19mr10235441qtn.63.1517591096922; Fri, 02 Feb 2018 09:04:56 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v8 3/8] nptl: Add C11 threads call_once functions Date: Fri, 2 Feb 2018 15:04:39 -0200 Message-Id: <1517591084-11347-4-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1517591084-11347-1-git-send-email-adhemerval.zanella@linaro.org> References: <1517591084-11347-1-git-send-email-adhemerval.zanella@linaro.org> This patch adds the call_* definitions from C11 threads (ISO/IEC 9899:2011), more specifically call_once and required types. Mostly of the definitions are composed based on POSIX conterparts,including once_flag (pthread_once_t). The idea is to make possible to share POSIX internal implementations for mostly of the code (and making adjustment only when required). Checked with a build for all major ABI (aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabi, i386-linux-gnu, ia64-linux-gnu, m68k-linux-gnu, microblaze-linux-gnu [1], mips{64}-linux-gnu, nios2-linux-gnu, powerpc{64le}-linux-gnu, s390{x}-linux-gnu, sparc{64}-linux-gnu, tile{pro,gx}-linux-gnu, and x86_64-linux-gnu). Also ran a full check on aarch64-linux-gnu, x86_64-linux-gnu, i686-linux-gnu, arm-linux-gnueabhf, and powerpc64le-linux-gnu. * conform/data/threads.h-data (ONCE_FLAG_INIT): New macro. (once_flag): New type. (call_once): New function. * nptl/Makefile (libpthread-routines): Add call_once object. * nptl/Versions (libphread) [GLIBC_2.27]: Add call_once symbol. * nptl/call_once.c: New file. * sysdeps/nptl/threads.h (ONCE_FLAG_INIT): New define. (once_flag): New type. (call_once): New prototype. --- ChangeLog | 10 ++++++++++ conform/data/threads.h-data | 5 +++++ nptl/Makefile | 2 +- nptl/Versions | 2 +- nptl/call_once.c | 31 +++++++++++++++++++++++++++++++ sysdeps/nptl/threads.h | 8 ++++++++ 6 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 nptl/call_once.c -- 2.7.4 diff --git a/conform/data/threads.h-data b/conform/data/threads.h-data index bb5ca75..70b2fe0 100644 --- a/conform/data/threads.h-data +++ b/conform/data/threads.h-data @@ -1,5 +1,7 @@ #if defined ISO11 +macro ONCE_FLAG_INIT + constant thrd_success constant thrd_busy constant thrd_error @@ -13,6 +15,7 @@ constant mtx_timed type thrd_t type thrd_start_t type mtx_t +type once_flag function int thrd_create (thrd_t*, thrd_start_t, void*) function int thrd_equal (thrd_t, thrd_t) @@ -30,6 +33,8 @@ function int mtx_trylock (mtx_t*) function int mtx_unlock (mtx_t*) function void mtx_destroy (mtx_t*) +function void call_once (once_flag*, void (*)(void)) + #include "time.h-data" #endif diff --git a/nptl/Makefile b/nptl/Makefile index 1b8a6a8..e539df8 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -143,7 +143,7 @@ libpthread-routines = nptl-init vars events version pt-interp \ thrd_create thrd_current thrd_detach thrd_equal \ thrd_exit thrd_join thrd_sleep thrd_yield \ mtx_destroy mtx_init mtx_lock mtx_timedlock \ - mtx_trylock mtx_unlock + mtx_trylock mtx_unlock call_once # pthread_setuid pthread_seteuid pthread_setreuid \ # pthread_setresuid \ # pthread_setgid pthread_setegid pthread_setregid \ diff --git a/nptl/Versions b/nptl/Versions index a1969e3..f09e295 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -269,7 +269,7 @@ libpthread { GLIBC_2.28 { thrd_create; thrd_current; thrd_detach; thrd_equal; thrd_exit; thrd_join; thrd_sleep; thrd_yield; mtx_init; mtx_lock; mtx_timedlock; mtx_trylock; - mtx_unlock; mtx_destroy; + mtx_unlock; mtx_destroy; call_once; } GLIBC_PRIVATE { diff --git a/nptl/call_once.c b/nptl/call_once.c new file mode 100644 index 0000000..d66d728 --- /dev/null +++ b/nptl/call_once.c @@ -0,0 +1,31 @@ +/* C11 threads call once implementation. + Copyright (C) 2018 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 "thrd_priv.h" + +void +call_once (once_flag *flag, void (*func)(void)) +{ + _Static_assert (sizeof (once_flag) == sizeof (pthread_once_t), + "once_flag size"); + _Static_assert (alignof (once_flag) == alignof (pthread_once_t), + "once_flag alignment"); + __pthread_once (flag, func); +} diff --git a/sysdeps/nptl/threads.h b/sysdeps/nptl/threads.h index 42d9b5c..6c9c3ef 100644 --- a/sysdeps/nptl/threads.h +++ b/sysdeps/nptl/threads.h @@ -27,8 +27,11 @@ __BEGIN_DECLS #include #include +#define ONCE_FLAG_INIT 0 + typedef unsigned long int thrd_t; typedef int (*thrd_start_t) (void*); +typedef int __ONCE_ALIGNMENT once_flag; /* Exit and error codes. */ enum @@ -129,6 +132,11 @@ extern int mtx_unlock (mtx_t *__mutex); /* Destroy the mutex object pointed by __MUTEX. */ extern void mtx_destroy (mtx_t *__mutex); + +/* Call function __FUNC exactly once, even if invoked from several threads. + All calls must be made with the same __FLAGS object. */ +extern void call_once (once_flag *__flag, void (*__func)(void)); + __END_DECLS #endif /* _THREADS_H */