From patchwork Fri Sep 22 20:27:00 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: 114093 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp3474004edb; Fri, 22 Sep 2017 13:28:07 -0700 (PDT) X-Received: by 10.84.179.67 with SMTP id a61mr295016plc.230.1506112087220; Fri, 22 Sep 2017 13:28:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506112087; cv=none; d=google.com; s=arc-20160816; b=C22fdp9M9MW5WDGNqG7g03DmWX73Q3tzirdCfaYa4UiXzIO1uMl5KLNcfM5p0B0EJW pHkmnpuPipASBLzBapDJhkfVLbhu2jrBY1UYS1SIAB/8xSFbyyk2VWzuaAduvk2YwW7g AYO3Q/XKoNc64/l8VKQ67VwxsiHfRg04ukuzkuQ3IUBYq/La75r2aSJV+IGXGlvNUVnA H+I56AAxlWuW71P6wcYyywdiFwSvi9rXVyUXugZcSJCD64/gFH2ayslXkzF4elQMq7GE 15nrNDn5/cCJAQXQchLQkXYAhArbkmrM5o5fs+PpmTNdwY3e/8Y2apZYGNoJp7dGboGH V4nQ== 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=23qWRd6sZWbyf2GKLVEfN1Y7WkPIvwuT0l8d535bHZk=; b=BUTda2f6veCsDdUZv9sXceHLaGuOVhn9iabzuH/nVo77DnWWxAuooWQb3pbxgc7QRk 0U6qIzSaQmNJNAeCGebn5EJ5DCSWwa4OVC2GPLHFTgBzJIJHhk6/CDCE/5Wi1MLRqQWh S4THm5M6k5E6VyhKWSOJONHnbVhbXvViQ6mwM/3dcns8MmfUDy2JNdMVqdtZlqJzo0Zi EBucBHMHCHaDUzaKw7vXYLAOoL/Mh9ZB+q/ffzL1pjDibzYe0o5VA2fhszXTvh1EvOXt n48CGzS/1WqfK7+q5W+h6+llBz7w7mHtE+BeMgOxG/Is0oz00ZhMXwLBdjvUU3gagDUR oTnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=D1on6+Vu; spf=pass (google.com: domain of libc-alpha-return-84877-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-84877-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 w22si336016pge.598.2017.09.22.13.28.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Sep 2017 13:28:07 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-84877-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=D1on6+Vu; spf=pass (google.com: domain of libc-alpha-return-84877-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-84877-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=X9PDzVkZjvQ8jtdmjIK6hYPIZuOPYwc kuVNJq0NOa5PqhKFMEx0aDUw6PVYP2X2vDveVQvWm2hgDxGidNmpJvMesp+0xJHe j5/HDWU8FqzXRgGeB2fndSAXeiZUVJ+egnllTTn67/N4eFhqkcX6N7TGgER91kxT zrcj610vN1Uw= 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=RJUpVbXuHxNQTkda+de6tN61fPQ=; b=D1on6 +VuEpjdvnL9OiJ3Nmsdwg8m0j4hzPqIdu/q3Oze6VkquMUkWZftVTIegTdT8JZSS TEOWTA04B4T1gaV6lQ+g8KiDiJ2kxadi+rj9zWMYpCg9TJKrP2LwKAinS1A/ijiC XU5Y1LuLhoN+22IpEqVAQSRX2Io4PjhUph9l30= Received: (qmail 66401 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 66337 invoked by uid 89); 22 Sep 2017 20:27:23 -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-f178.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=23qWRd6sZWbyf2GKLVEfN1Y7WkPIvwuT0l8d535bHZk=; b=AHWxLZIWw2vrnYDRCfyvM+zlWnNJr4ytRCT+E05TY319p+Bs4d9P6m2k2oJrDUdLtU jx6hplSEadVIpl0IWJ1LwC7AapXiwK6NA5KxKaUJ7AABM1uSXD3f/X2e2rVscGKewC/e 5kF+Gui//P4/F+s259SE0rLWI0ZcxNaxiddaV3ofvyZqw5E9uWj84gyN2dconsy6bgXd OncHAYPU3zgNAatDSAqoiAzeKtwsXs0RFZvSaFmwr+c8YaWP1gEFvsX13rQ+vtLP4xt1 vYw+aSTMWCv60nqipXl0NRTMHIrD77vATtNcxgxkV33dV+Cz3I/lEcjFgqgm1F7qjjrq JkHA== X-Gm-Message-State: AHPjjUgVH5mZzKhpJ9Ugt71jsLBmwn2NxgEKnZofi+ph7pxxbGV0rJyx iPElE7PH7HKE8fYn8gvB/NqBB+TSHCU= X-Google-Smtp-Source: AOwi7QDZtQPNN418cRGp3irENZt8TqvlUs589RUdWHtK0/9oISILlNDS0g1qyWvDA5QKxCftwOdtkg== X-Received: by 10.55.36.3 with SMTP id w3mr544547qkg.284.1506112037999; Fri, 22 Sep 2017 13:27:17 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 4/8] nptl: Add C11 threads cnd_* functions Date: Fri, 22 Sep 2017 17:27:00 -0300 Message-Id: <1506112024-22601-5-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 cnd_* definitions from C11 threads (ISO/IEC 9899:2011), more specifically cnd_broadcast, cnd_destroy, cnd_init, cnd_signal, cnd_timedwait, cnd_wait, and required types. Mostly of the definitions are composed based on POSIX conterparts, and cnd_t is also based on internal pthreads fields, but with distinct internal layout to avoid possible issues with code interchange (such as trying to pass POSIX structure on C11 functions and to avoid inclusion of pthread.h). The idea is to make it possible to share POSIX internal implementation for mostly of the code making adjust where only 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 (cnd_t): New type. (cnd_init): New function. (cnd_signal): Likewise. (cnd_broadcast): Likewise. (cnd_wait): Likewise. (cnd_timedwait): Likewise. (cnd_destroy): Likewise. * nptl/Makefile (libpthread-routines): Add cnd_broadcast, cnd_destroy, cnd_init, cnd_signal, cnd_timedwait, and cnd_wait object. * nptl/Versions (libpthread) [GLIBC_2.27]: Likewise. * nptl/cnd_broadcast.c: New file. * nptl/cnd_destroy.c: Likewise. * nptl/cnd_init.c: Likewise. * nptl/cnd_signal.c: Likewise. * nptl/cnd_timedwait.c: Likewise. * nptl/cnd_wait.c: Likewise. * sysdeps/nptl/threads.h (cnd_t): New type. (cnd_init): New prototype. (cnd_signa): Likewise. (cnd_broadcast): Likewise. (cnd_wait): Likewise. (cnd_timedwait): Likewise. (cnd_destroy): Likewise. --- ChangeLog | 25 +++++++++++++++++++++++++ conform/data/threads.h-data | 8 ++++++++ nptl/Makefile | 3 ++- nptl/Versions | 3 ++- nptl/cnd_broadcast.c | 28 ++++++++++++++++++++++++++++ nptl/cnd_destroy.c | 28 ++++++++++++++++++++++++++++ nptl/cnd_init.c | 33 +++++++++++++++++++++++++++++++++ nptl/cnd_signal.c | 28 ++++++++++++++++++++++++++++ nptl/cnd_timedwait.c | 31 +++++++++++++++++++++++++++++++ nptl/cnd_wait.c | 28 ++++++++++++++++++++++++++++ sysdeps/nptl/threads.h | 34 ++++++++++++++++++++++++++++++++++ 11 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 nptl/cnd_broadcast.c create mode 100644 nptl/cnd_destroy.c create mode 100644 nptl/cnd_init.c create mode 100644 nptl/cnd_signal.c create mode 100644 nptl/cnd_timedwait.c create mode 100644 nptl/cnd_wait.c -- 2.7.4 diff --git a/conform/data/threads.h-data b/conform/data/threads.h-data index 70b2fe0..d7c562e 100644 --- a/conform/data/threads.h-data +++ b/conform/data/threads.h-data @@ -16,6 +16,7 @@ type thrd_t type thrd_start_t type mtx_t type once_flag +type cnd_t function int thrd_create (thrd_t*, thrd_start_t, void*) function int thrd_equal (thrd_t, thrd_t) @@ -35,6 +36,13 @@ function void mtx_destroy (mtx_t*) function void call_once (once_flag*, void (*)(void)) +function int cnd_init (cnd_t*) +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 void cnd_destroy (cnd_t*) + #include "time.h-data" #endif diff --git a/nptl/Makefile b/nptl/Makefile index 7d2b83f..ddef534 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -142,7 +142,8 @@ 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 call_once + mtx_trylock mtx_unlock call_once cnd_broadcast \ + cnd_destroy cnd_init cnd_signal cnd_timedwait cnd_wait # pthread_setuid pthread_seteuid pthread_setreuid \ # pthread_setresuid \ # pthread_setgid pthread_setegid pthread_setregid \ diff --git a/nptl/Versions b/nptl/Versions index b055860..53e6b9a 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -269,7 +269,8 @@ libpthread { GLIBC_2.27 { 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; + mtx_unlock; mtx_destroy; call_once; cnd_broadcast; cnd_destroy; cnd_init; + cnd_signal; cnd_timedwait; cnd_wait; mtx_destroy; } GLIBC_PRIVATE { diff --git a/nptl/cnd_broadcast.c b/nptl/cnd_broadcast.c new file mode 100644 index 0000000..8e5f165 --- /dev/null +++ b/nptl/cnd_broadcast.c @@ -0,0 +1,28 @@ +/* C11 thread conditional broadcast 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" + +/* Unblock all threads currently waiting on condition variable pointed + by cond. */ +int +cnd_broadcast (cnd_t *cond) +{ + int err_code = __pthread_cond_broadcast ((pthread_cond_t*) cond); + return thrd_err_map (err_code); +} diff --git a/nptl/cnd_destroy.c b/nptl/cnd_destroy.c new file mode 100644 index 0000000..4b46132 --- /dev/null +++ b/nptl/cnd_destroy.c @@ -0,0 +1,28 @@ +/* C11 threads conditional destroy 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" +#include "pthreadP.h" + +/* Destroy condition variable pointed by cond and free all of its + resources. */ +void +cnd_destroy (cnd_t *cond) +{ + __pthread_cond_destroy ((pthread_cond_t *) cond); +} diff --git a/nptl/cnd_init.c b/nptl/cnd_init.c new file mode 100644 index 0000000..eb8a544 --- /dev/null +++ b/nptl/cnd_init.c @@ -0,0 +1,33 @@ +/* C11 thread conditional initialization 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 + +#include "thrd_priv.h" + +/* Initialize new condition variable pointed by cond. */ +int +cnd_init (cnd_t *cond) +{ + _Static_assert (sizeof (cnd_t) == sizeof (pthread_cond_t), "cnd_t size"); + _Static_assert (alignof (cnd_t) == alignof (pthread_cond_t), + "cnd_t alignment"); + + int err_code = __pthread_cond_init ((pthread_cond_t *)cond, NULL); + return thrd_err_map (err_code); +} diff --git a/nptl/cnd_signal.c b/nptl/cnd_signal.c new file mode 100644 index 0000000..e843957 --- /dev/null +++ b/nptl/cnd_signal.c @@ -0,0 +1,28 @@ +/* C11 threads conditional signal 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" + +/* Unblock one thread that currently waits on condition variable pointed + by cond. */ +int +cnd_signal (cnd_t *cond) +{ + int err_code = __pthread_cond_signal ((pthread_cond_t *) cond); + return thrd_err_map (err_code); +} diff --git a/nptl/cnd_timedwait.c b/nptl/cnd_timedwait.c new file mode 100644 index 0000000..b3c60e8 --- /dev/null +++ b/nptl/cnd_timedwait.c @@ -0,0 +1,31 @@ +/* C11 threads conditional timed wait 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" + +/* Block current thread on the condition variable until condition variable + pointed by cond is signaled or time pointed by time_point is reached. */ +int +cnd_timedwait (cnd_t *restrict cond, mtx_t *restrict mutex, + const struct timespec* restrict time_point) +{ + int err_code = __pthread_cond_timedwait ((pthread_cond_t *) cond, + (pthread_mutex_t *) mutex, + time_point); + return thrd_err_map (err_code); +} diff --git a/nptl/cnd_wait.c b/nptl/cnd_wait.c new file mode 100644 index 0000000..298d049 --- /dev/null +++ b/nptl/cnd_wait.c @@ -0,0 +1,28 @@ +/* C11 threads conditional wait implementaiton. + 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" + +/* Block current thread on the condition variable pointed by cond. */ +int +cnd_wait (cnd_t *cond, mtx_t *mutex) +{ + int err_code = __pthread_cond_wait ((pthread_cond_t *) cond, + (pthread_mutex_t *) mutex); + return thrd_err_map (err_code); +} diff --git a/sysdeps/nptl/threads.h b/sysdeps/nptl/threads.h index 53fe731..568e2d4 100644 --- a/sysdeps/nptl/threads.h +++ b/sysdeps/nptl/threads.h @@ -57,6 +57,12 @@ typedef union long int __align __LOCK_ALIGNMENT; } mtx_t; +typedef union +{ + char __size[__SIZEOF_PTHREAD_COND_T]; + __extension__ long long int __align __LOCK_ALIGNMENT; +} cnd_t; + /* Threads functions. */ /* Create a new thread executing the function __func. Arguments to __func @@ -136,6 +142,34 @@ extern void mtx_destroy (mtx_t *__mutex); All calls must be made with the same __flag object. */ extern void call_once (once_flag *__flag, void (*__func)(void)); + +/* Condition variable functions. */ + +/* Initialize new condition variable pointed by __cond. */ +extern int cnd_init (cnd_t *__cond); + +/* Unblock one thread that currently waits on condition variable pointed + by __cond. */ +extern int cnd_signal (cnd_t *__cond); + +/* Unblock all threads currently waiting on condition variable pointed by + __cond. */ +extern int cnd_broadcast (cnd_t *__cond); + +/* Block current thread on the condition variable pointed by __cond. */ +extern int cnd_wait (cnd_t *__cond, mtx_t *__mutex); + +/* Block current thread on the condition variable until condition variable + pointed by __cond is signaled or time pointed by __time_point is + reached. */ +extern int cnd_timedwait (cnd_t *__restrict __cond, + mtx_t *__restrict __mutex, + const struct timespec *__restrict __time_point); + +/* Destroy condition variable pointed by __cond and free all of its + resources. */ +extern void cnd_destroy (cnd_t *__cond); + __END_DECLS #endif /* _THREADS_H */