From patchwork Tue Jan 14 18:52:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1222995 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-108662-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha1 header.s=default header.b=kL8MGN27; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47y0372w1yz9s29 for ; Wed, 15 Jan 2020 05:53:23 +1100 (AEDT) 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:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; q=dns; s= default; b=setQv2dSamWjQPa0MwOyA5NMuu0dp7naXKsv0YQ3LhAXM8BKKr0Oc Y0TJfc5XJ4NkhvSR+48evH9Agr+DxotisPon1lDMVMX++eUjT4EjCOS0Zp9a5T6C wyeQ5b1BSbe4it6lZbYRxfJ665qmnVp3YUX58uN3/wd1oB6gy2e228= 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:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; s=default; bh=uPzuev83uDzuWYpE/dB17lZLHC4=; b=kL8MGN27cufy0b9tT7d9jHys1tVN RRKSQz7xpc4di262FgngnIXGluLIyYiUbF3mR3rXLJ2iVnMA/udfxr3MXeIy2u/e a9cyeTIRtqVM2COr0SO0Z8Pp36qPAztLxjQROr+PEA1xRRDGC02f8Q2GwdObbsTp YZ1Hr0bFhAAUM6M= Received: (qmail 91834 invoked by alias); 14 Jan 2020 18:53:17 -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 91807 invoked by uid 89); 14 Jan 2020 18:53:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault Subject: [PATCH 03/10] htl: Add support for C11 threads behavior Date: Tue, 14 Jan 2020 19:52:48 +0100 Message-Id: <20200114185255.25813-5-samuel.thibault@ens-lyon.org> In-Reply-To: <20200114185255.25813-1-samuel.thibault@ens-lyon.org> References: <20200114185255.25813-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Essentially properly calling the thread function which returns an int instead of a void*. Reviewed-by: Adhemerval Zanella --- htl/pt-create.c | 20 +++++++++++++++++++- htl/pt-internal.h | 3 +++ sysdeps/htl/pthreadP.h | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/htl/pt-create.c b/htl/pt-create.c index 0b3237f46a..090d394f53 100644 --- a/htl/pt-create.c +++ b/htl/pt-create.c @@ -59,7 +59,17 @@ entry_point (struct __pthread *self, void *(*start_routine) (void *), void *arg) __pthread_startup (); - __pthread_exit (start_routine (arg)); + if (self->c11) + { + /* The function pointer of the c11 thread start is cast to an incorrect + type on __pthread_create call, however it is casted back to correct + one so the call behavior is well-defined (it is assumed that pointers + to void are able to represent all values of int). */ + int (*start)(void*) = (int (*) (void*)) start_routine; + __pthread_exit ((void*) (uintptr_t) start (arg)); + } + else + __pthread_exit (start_routine (arg)); } /* Create a thread with attributes given by ATTR, executing @@ -99,6 +109,14 @@ __pthread_create_internal (struct __pthread **thread, if (err) goto failed; + if (attr == ATTR_C11_THREAD) + { + attr = NULL; + pthread->c11 = true; + } + else + pthread->c11 = false; + /* Use the default attributes if ATTR is NULL. */ setup = attr ? attr : &__pthread_default_attr; diff --git a/htl/pt-internal.h b/htl/pt-internal.h index f8d7d74244..8a45854070 100644 --- a/htl/pt-internal.h +++ b/htl/pt-internal.h @@ -100,6 +100,9 @@ struct __pthread /* Resolver state. */ struct __res_state res_state; + /* Indicates whether is a C11 thread created by thrd_creat. */ + bool c11; + /* Thread context. */ struct pthread_mcontext mcontext; diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h index b1c7575f89..fc8c9bc591 100644 --- a/sysdeps/htl/pthreadP.h +++ b/sysdeps/htl/pthreadP.h @@ -21,6 +21,9 @@ #include +/* Attribute to indicate thread creation was issued from C11 thrd_create. */ +#define ATTR_C11_THREAD ((void*)(uintptr_t)-1) + /* These represent the interface used by glibc itself. */ extern pthread_t __pthread_self (void);