From patchwork Tue Jun 27 18:31:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 106466 Delivered-To: patch@linaro.org Received: by 10.182.135.102 with SMTP id pr6csp2693569obb; Tue, 27 Jun 2017 11:32:04 -0700 (PDT) X-Received: by 10.99.152.18 with SMTP id q18mr6558600pgd.91.1498588324131; Tue, 27 Jun 2017 11:32:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498588324; cv=none; d=google.com; s=arc-20160816; b=E9dhp2vn57YtlGiCjsIX7vTombclQxNMyFGeaqY+1etEDRHdq1mPdC+WU/MNs8xdAl MCa/bXGiF5Fr8rQjgBv44Z5yMGrCV4W6EOw8GOro0WkM43i4zdEGaiSlK8IyksdWH3f+ TmJ4wgLifwUCheRL4ODb5pM3YjugZlCDyHoKLMJuJIe8KCDm+mylxr8/shGvSGJ7RYUu 7q9p5wMetEaNo1vLXNtkWjnOB63SZHkSQf0+YwNZF+hpi1B+2RUVHviDPXOhe18XYT4E yoDeEG9eaZJm3QNm2pJY96XTNapqwxPCqoM/rZT70jGgPxhXRREyB3WfPq3k95YQFZ8N gerg== 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=Qy8Oy5FvqIXIlvqOZqlvzwXzzr89tIJOVNWoeoMhJEA=; b=Gq11zaP8F5QXqU6QsZRrXtrmEdTFfBHzAt/7Hh/vuuV0OwqKObvkbhdfDh9DKY4jzn Q0xTp+wDQvJCg+p0EPFS4Qz7fbHXxoHzmJ3KYPZBhLixxXnaWlNb0SbSVm4o5tKNCF7P lviw5yv/CD0MT2nLPRKeeaKqZ6WDjsIWz0PyOSLrUxNBUprLivp8/OGf1OaRJTCULNWi J150K0YX4fMOnnQe2s3AaHMfzyL0EyQScfX4Afp8yhQ/y6g++8nwIubTBln9pLWX2Btd iaKkA+gwN8UW6PU7g5xyiNP9NfRKiWLhjREXhhbDL+IIHGKPwyHWd3TBHASmmCfHrj+L hwzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.b=deAGjIdK; spf=pass (google.com: domain of libc-alpha-return-81302-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-81302-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 37si2645565plc.105.2017.06.27.11.32.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Jun 2017 11:32:04 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-81302-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.b=deAGjIdK; spf=pass (google.com: domain of libc-alpha-return-81302-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-81302-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=Dj3V5fcBYvWX+j1eesr2LbAGuEHTSkD ZPXmk/obchT5bO+LQlKqWZkYaYLZdLPR2lzkqeIDh14rAEpqmhbBOA+1BGdqqqqq nodmJ2WzqEoZ1Xi5CLdrnm4E9V+X84OYNUauk8Qqdy+EKOSHJXcDLXf7zNu+8kdm 8yFFA1W6j1+s= 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=/gCt0M/YDVGJRJw0iaKDslPqet8=; b=deAGj IdKDdxjiCCMkSR3FSGD99+eub8oNpAeepishZzX1KWcTlYDH4gSo8CoHRQSikqmm +6O10VN7DZ/aLD01rd/9QyocbQl13VGcIzkU4VVjyUCrGXSEpAOlQMgf8YpiCCHA rHVFaDKXrRZwkT+iepV6dTXZwsDf5jo3frC7+8= Received: (qmail 20380 invoked by alias); 27 Jun 2017 18:31:46 -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 20260 invoked by uid 89); 27 Jun 2017 18:31:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-27.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f182.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=Qy8Oy5FvqIXIlvqOZqlvzwXzzr89tIJOVNWoeoMhJEA=; b=V6tadx4Hbc0F00yAgJoHV1B1u6VcjgH00Rj7siD7/URMs+2Q9PQsaBWX9W6KqOOGpR s/QMYeCjTocFeSylejhtSZA8FGTmqC2saufCIUUU2QlR+Zx2kxde9wAEybm0QUpaYFj/ x7nkLNcR/N/FI2tdNCp7j5RAz9IgwT8y2SrRi+b/CqAMwWKHS5p5TpTO8B5RXisU8D+G W0ptYk1WZhlzzEL9lVSqSv3qzQOEG21g0rez53qiHP5tUdtcEqRTIvhWYRpU4MmRx4fq qjAc+9V9G0pTY9MO59/u2eHr8t80zDh6iK/JAdeMU4CmFGSd8rlHBgy9d9Kg6SEqAq2p MnLQ== X-Gm-Message-State: AKS2vOywbvsoxMQIBin14ttQZMCTKxx1WWiIz4LL1xUwOKSCMieoJbmH DHWZp7CobYhUT9TlvOnwSw== X-Received: by 10.200.0.213 with SMTP id d21mr8208276qtg.28.1498588301160; Tue, 27 Jun 2017 11:31:41 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 3/8] nptl: Add C11 threads call_once functions Date: Tue, 27 Jun 2017 15:31:27 -0300 Message-Id: <1498588292-23093-4-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1498588292-23093-1-git-send-email-adhemerval.zanella@linaro.org> References: <1498588292-23093-1-git-send-email-adhemerval.zanella@linaro.org> This patch adds the mtx_* 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.26]: 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 | 27 +++++++++++++++++++++++++++ sysdeps/nptl/threads.h | 7 +++++++ 6 files changed, 51 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 157ebe1..4d65c57 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -142,7 +142,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 2fd362f..07f3aeb 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -269,7 +269,7 @@ libpthread { GLIBC_2.26 { 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..460e917 --- /dev/null +++ b/nptl/call_once.c @@ -0,0 +1,27 @@ +/* C11 threads call once implementation. + Copyright (C) 2017 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" + +/* Call function func exactly once, even if invoked from several threads. + All calls must be made with the same flag object. */ +void +call_once (once_flag *flag, void (*func)(void)) +{ + __pthread_once (flag, func); +} diff --git a/sysdeps/nptl/threads.h b/sysdeps/nptl/threads.h index f6d4f1a..9784983 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 @@ -130,6 +133,10 @@ 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 __flag object. */ +extern void call_once (once_flag *__flag, void (*__func)(void)); + __END_DECLS #endif /* _THREADS_H */