From patchwork Fri Sep 22 20:27:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 114094 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp3474139edb; Fri, 22 Sep 2017 13:28:19 -0700 (PDT) X-Received: by 10.84.229.7 with SMTP id b7mr273842plk.75.1506112099026; Fri, 22 Sep 2017 13:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506112099; cv=none; d=google.com; s=arc-20160816; b=iIqQq9keZr88lOM2Yq8x6CiBTVqU8qcsfngavoTDjv0oOzAecVvLjTj3s2/TTqg5pN DiXFkUbxsfuz6qcAB+ifXwdFT0zZFQ4wHH9KqkYlvJOXgkvan1k6e3laZ1Mik0M9hPJR 7KZVymGLSmB4oIU0jYIIzExIfoIs+S7eE4z9dbgQgNoEbv7BK12csDw3wF1M0TxxYa7a 7huE9TukcLPX/EIWT2oR1caeWZ1Fx8rWd8TPE/yhMXQw7+1RPlwMLtygle1Nn3ITSW4W YQpuLuSYkf2gOlr/CUhydx5Ef09lFQ+VV9iALM1QxjvqrMhLQlv0JuY0gH8YD96QB2Ep RP5w== 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=uWLaFcEXgUeTBDuJf7Yo4Fa7i4ae6L4piyxTJcP7tTY=; b=GZpVMaWrpCTm7FLUox+Z1Kx6CuRr5ys981M3mua4aKAlfc+1Z7/u/9qLOe+nCG8Jsd +Ek5Zlk1z5bb/k338oHflSMmryda6MrRhXtjdH+ZbNFaUf/R1Dnk1UnLHBA9hNYPSiyF 1vk9cAo63zL9E/uIUvdL/zc9b3aAwbL6coxUqhzqzl+nvCfVlTV0pCjVLsuL9L6ZKG/w FLQODh70WTWrXJsa6YsAu6ovY5FSL3A+9NwdzSthod/OK8+82I1KCkingvHorVATxQXS dcGzHp2blHFFAF5Y3/aZsXWQ9v/oRn4yczENoomcg93p1foRUM8JrSvMKGwqGjDH1HRU 7aIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=EVwVKBOT; spf=pass (google.com: domain of libc-alpha-return-84878-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-84878-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 l4si326691plb.627.2017.09.22.13.28.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Sep 2017 13:28:19 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-84878-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=EVwVKBOT; spf=pass (google.com: domain of libc-alpha-return-84878-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-84878-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=EXlq8AWpGhx9bOFDQZLdWYisu4DfMPz gqglRX2q4MXkD4ou+F9nL1XNiAQLf4nxtYfHuUp54+YruFVizlM1cLQL/6+dT/4q 3B2KqpwprUYpqIJOLcVxhSdBf4gFjM5OhFBv121F0ZmoS/oX1w7DZ4VRtwdpOhAn yZs4zu/MnX+Y= 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=rvlGDzBX7D4ieG6o1+hbAB0tsko=; b=EVwVK BOTiX5b9LOC8Umf0dtYMQ2Yi8M8RvUHWYx2hy9dq0DI1xJ4xGhNxcVAoCmEq7QiA CC7v1VqaT8fw/xiK3QR9Kh8PffDZmGcwx35jyRQpSUjkHn1bNpde/HHBzD/gSdx1 jDn/G8MdqZgN0vykqTe1sVVu2jC9Z5QcpdT8+Q= Received: (qmail 66512 invoked by alias); 22 Sep 2017 20:27:24 -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 66459 invoked by uid 89); 22 Sep 2017 20:27:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qk0-f172.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=uWLaFcEXgUeTBDuJf7Yo4Fa7i4ae6L4piyxTJcP7tTY=; b=f9Xo35Z+U48KFHFPFnIMeM9DUjqKL/yFS7+bXthlVXzGkq4nlafkCkXdSaHKHHTxrO cIRlZHukEXnQNJsDD09S2ZU4SHGW0LeohKzd7OWK4J1nC7P+ESDI8wlqxw4UjurrDtGd 0kZKzNNCS1SY37rzErf4Z8SIAP1Zxqxy41EjMkt4Ly6bBKM7WZPC76xs01nrRxrJkmsG /42Og9Rf5laGdKEAtFmQ+T1qwmK0xYhqzCBu7XEY2dIKcv5Mfe4DWVHvXBy6WtGBBTWG lowuUFhlhvbszI/H7Kmrlze1NZb2zLy4ffSxwNJ2BzDvErZ+koz6t/SvUYtQRA6AKvE8 lErg== X-Gm-Message-State: AHPjjUhKD0eaBAZlYfjQnKg7wFTifUi6E4qPwbZ+DccCcqwBNC71P++j UixtJC2FP5FR0a0gTFcOutqpHN6ShPU= X-Google-Smtp-Source: AOwi7QCfBvYax5Dlc5CWVOj+dmqNqtDZkcbliCXaAYFqyw3e5hhTIFO1uKKOsKpdYl5zvY5dv4tAJQ== X-Received: by 10.55.156.147 with SMTP id f141mr585181qke.72.1506112039616; Fri, 22 Sep 2017 13:27:19 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 5/8] nptl: Add C11 threads tss_* functions Date: Fri, 22 Sep 2017 17:27:01 -0300 Message-Id: <1506112024-22601-6-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1506112024-22601-1-git-send-email-adhemerval.zanella@linaro.org> References: <1506112024-22601-1-git-send-email-adhemerval.zanella@linaro.org> This patch adds the tss_* definitions from C11 threads (ISO/IEC 9899:2011), more specifically tss_create, tss_delete, tss_get, tss_set, and required types. Mostly of the definitions are composed based on POSIX conterparts, including tss_t (pthread_key_t). 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 (thread_local): New macro. (TSS_DTOR_ITERATIONS): Likewise. (tss_t): New type. (tss_dtor_t): Likewise. (tss_create): New function. (tss_get): Likewise. (tss_set): Likewise. (tss_delete): Likewise. * nptl/Makefile (libpthread-routines): Add tss_create, tss_delete, tss_get, and tss_set objects. * nptl/Versions (libpthread) [GLIBC_2.27]: Likewise. * nptl/tss_create.c: New file. * nptl/tss_delete.c: Likewise. * nptl/tss_get.c: Likewise. * nptl/tss_set.c: Likewise. * sysdeps/nptl/threads.h (thread_local): New define. (TSS_DTOR_ITERATIONS): Likewise. (tss_t): New typedef. (tss_dtor_t): Likewise. (tss_create): New prototype. (tss_get): Likewise. (tss_set): Likewise. (tss_delete): Likewise. --- ChangeLog | 24 ++++++++++++++++++++++++ conform/data/threads.h-data | 9 +++++++++ nptl/Makefile | 3 ++- nptl/Versions | 3 ++- nptl/tss_create.c | 31 +++++++++++++++++++++++++++++++ nptl/tss_delete.c | 27 +++++++++++++++++++++++++++ nptl/tss_get.c | 27 +++++++++++++++++++++++++++ nptl/tss_set.c | 28 ++++++++++++++++++++++++++++ sysdeps/nptl/threads.h | 23 +++++++++++++++++++++++ 9 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 nptl/tss_create.c create mode 100644 nptl/tss_delete.c create mode 100644 nptl/tss_get.c create mode 100644 nptl/tss_set.c -- 2.7.4 diff --git a/conform/data/threads.h-data b/conform/data/threads.h-data index d7c562e..406e497 100644 --- a/conform/data/threads.h-data +++ b/conform/data/threads.h-data @@ -1,6 +1,8 @@ #if defined ISO11 macro ONCE_FLAG_INIT +macro thread_local +macro-int-constant TSS_DTOR_ITERATIONS constant thrd_success constant thrd_busy @@ -17,6 +19,8 @@ type thrd_start_t type mtx_t type once_flag type cnd_t +type tss_t +type tss_dtor_t function int thrd_create (thrd_t*, thrd_start_t, void*) function int thrd_equal (thrd_t, thrd_t) @@ -43,6 +47,11 @@ function int cnd_wait (cnd_t*, mtx_t*) function int cnd_timedwait (cnd_t*, mtx_t*, const struct timespec*) function void cnd_destroy (cnd_t*) +function int tss_create (tss_t*, tss_dtor_t) +function {void*} tss_get (tss_t) +function int tss_set (tss_t, void*) +function void tss_delete (tss_t) + #include "time.h-data" #endif diff --git a/nptl/Makefile b/nptl/Makefile index ddef534..0bf46ce 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -143,7 +143,8 @@ libpthread-routines = nptl-init vars events version pt-interp \ thrd_exit thrd_join thrd_sleep thrd_yield \ mtx_destroy mtx_init mtx_lock mtx_timedlock \ mtx_trylock mtx_unlock call_once cnd_broadcast \ - cnd_destroy cnd_init cnd_signal cnd_timedwait cnd_wait + cnd_destroy cnd_init cnd_signal cnd_timedwait cnd_wait \ + tss_create tss_delete tss_get tss_set # pthread_setuid pthread_seteuid pthread_setreuid \ # pthread_setresuid \ # pthread_setgid pthread_setegid pthread_setregid \ diff --git a/nptl/Versions b/nptl/Versions index 53e6b9a..d4dc750 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -270,7 +270,8 @@ libpthread { 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; call_once; cnd_broadcast; cnd_destroy; cnd_init; - cnd_signal; cnd_timedwait; cnd_wait; mtx_destroy; + cnd_signal; cnd_timedwait; cnd_wait; mtx_destroy; tss_create; tss_delete; + tss_get; tss_set; } GLIBC_PRIVATE { diff --git a/nptl/tss_create.c b/nptl/tss_create.c new file mode 100644 index 0000000..ef6d7bb --- /dev/null +++ b/nptl/tss_create.c @@ -0,0 +1,31 @@ +/* C11 threads thread-specific creation 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" + +/* Create new thread-specific storage key and stores it in the object + pointed by tss_id. If destructor is not NULL, destructor function is + called when the thread terminates. */ +int +tss_create (tss_t *tss_id, tss_dtor_t destructor) +{ + _Static_assert (sizeof (tss_t) == sizeof (pthread_key_t), "tss_t size"); + + int err_code = __pthread_key_create (tss_id, destructor); + return thrd_err_map (err_code); +} diff --git a/nptl/tss_delete.c b/nptl/tss_delete.c new file mode 100644 index 0000000..bcbc748 --- /dev/null +++ b/nptl/tss_delete.c @@ -0,0 +1,27 @@ +/* C11 threads thread-specific delete 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" + +/* Destroys the thread-specific storage identified by tss_id. The + destructor is not called until thrd_exit is called. */ +void +tss_delete (tss_t tss_id) +{ + __pthread_key_delete (tss_id); +} diff --git a/nptl/tss_get.c b/nptl/tss_get.c new file mode 100644 index 0000000..784a1cf --- /dev/null +++ b/nptl/tss_get.c @@ -0,0 +1,27 @@ +/* C11 threads thread-specific get 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" + +/* Return the value held in thread-specific storage for the current + thread identified by tss_id. */ +void * +tss_get (tss_t tss_id) +{ + return __pthread_getspecific (tss_id); +} diff --git a/nptl/tss_set.c b/nptl/tss_set.c new file mode 100644 index 0000000..16a0b04 --- /dev/null +++ b/nptl/tss_set.c @@ -0,0 +1,28 @@ +/* C11 threads thread-specific set 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" + +/* Sets the value of the thread-specific storage identified by tss_id for + the current thread to val. */ +int +tss_set (tss_t tss_id, void *val) +{ + int err_code = __pthread_setspecific (tss_id, val); + return thrd_err_map (err_code); +} diff --git a/sysdeps/nptl/threads.h b/sysdeps/nptl/threads.h index 568e2d4..9ca3695 100644 --- a/sysdeps/nptl/threads.h +++ b/sysdeps/nptl/threads.h @@ -28,6 +28,10 @@ __BEGIN_DECLS #include #define ONCE_FLAG_INIT 0 +#define thread_local _Thread_local +#define TSS_DTOR_ITERATIONS 4 +typedef unsigned int tss_t; +typedef void (*tss_dtor_t) (void*); typedef unsigned long int thrd_t; typedef int (*thrd_start_t) (void*); @@ -170,6 +174,25 @@ extern int cnd_timedwait (cnd_t *__restrict __cond, resources. */ extern void cnd_destroy (cnd_t *__cond); +/* Thread specific storage functions. */ + +/* Create new thread-specific storage key and stores it in the object pointed + by __tss_id. If __destructor is not NULL, __destructor function is called + when the thread terminates. */ +extern int tss_create (tss_t *__tss_id, tss_dtor_t __destructor); + +/* Return the value held in thread-specific storage for the current thread + identified by __tss_id. */ +extern void *tss_get (tss_t __tss_id); + +/* Sets the value of the thread-specific storage identified by __tss_id for + the current thread to __val. */ +extern int tss_set (tss_t __tss_id, void *__val); + +/* Destroys the thread-specific storage identified by __tss_id. The + destructor is not called until thrd_exit is called. */ +extern void tss_delete (tss_t __tss_id); + __END_DECLS #endif /* _THREADS_H */