From patchwork Fri Nov 6 16:08:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 541028 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 293BA1402D7 for ; Sat, 7 Nov 2015 03:08:24 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=EEKW93BG; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:message-id:date:mime-version :content-type; q=dns; s=default; b=YzbbtIv8eadVfVX+HERycSW31b6G/ PJCoNzKZDXo/dbAKmveKgJHp0e3HQFreL7dhD8Orcn36raC4EuK743go9jjJswLx Jn8Bpopr/nT6PCag9p0QMh1xJZT8YvTwOYRGabJut7gjrHgMX5NEcYrXuGyS9arE OvPmY6zX4GrzPw= 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:to:from:subject:message-id:date:mime-version :content-type; s=default; bh=oJfNobvlSSV5LHWm/WAUOQzlXRw=; b=EEK W93BGYzdAuVQbWp8MiKjHvb70+mK2+DjO3dCXB/SvODE9ACpRhLBRNT79klWlblf Vi3iBmVFSSBzQBJp5YPTYE2KWtl3Kb30OZKGJD6j7rOFPlc7j/BUc84ZorRgeANM MckUgDHV4TEDDP0HmwFe881N7ZIi910j+KrGq3e0= Received: (qmail 333 invoked by alias); 6 Nov 2015 16:08:16 -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 308 invoked by uid 89); 6 Nov 2015 16:08:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD, UNWANTED_LANGUAGE_BODY autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com To: GNU C Library From: Florian Weimer Subject: [PATCH] Replace MUTEX_INITIALIZER with _LIBC_LOCK_INITIALIZER in generic code Message-ID: <563CD06B.1070309@redhat.com> Date: Fri, 6 Nov 2015 17:08:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 This is a requirement before I can switch malloc to the _libc_lock infrastructure. Florian 2015-11-06 Florian Weimer Replace MUTEX_INITIALIZER with _LIBC_LOCK_INITIALIZER in generic code. * sysdeps/mach/hurd/libc-lock.h (_LIBC_LOCK_INITIALIZER): Define. (__libc_lock_define_initialized): Use it. * sysdeps/nptl/libc-lockP.h (_LIBC_LOCK_INITIALIZER): Define. * malloc/arena.c (list_lock): Use _LIBC_LOCK_INITIALIZER. * malloc/malloc.c (main_arena): Likewise. * sysdeps/generic/malloc-machine.h (MUTEX_INITIALIZER): Remove. * sysdeps/nptl/malloc-machine.h (MUTEX_INITIALIZER): Remove. diff --git a/malloc/arena.c b/malloc/arena.c index 0f00afa..3dab7bb 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -73,7 +73,7 @@ static __thread mstate thread_arena attribute_tls_model_ie; objects. No other (malloc) locks must be taken while list_lock is active, otherwise deadlocks may occur. */ -static mutex_t list_lock = MUTEX_INITIALIZER; +static mutex_t list_lock = _LIBC_LOCK_INITIALIZER; static size_t narenas = 1; static mstate free_list; diff --git a/malloc/malloc.c b/malloc/malloc.c index 839263e..a030109 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -1760,7 +1760,7 @@ struct malloc_par static struct malloc_state main_arena = { - .mutex = MUTEX_INITIALIZER, + .mutex = _LIBC_LOCK_INITIALIZER, .next = &main_arena, .attached_threads = 1 }; diff --git a/sysdeps/generic/malloc-machine.h b/sysdeps/generic/malloc-machine.h index 802d1f5..7b7eae8 100644 --- a/sysdeps/generic/malloc-machine.h +++ b/sysdeps/generic/malloc-machine.h @@ -38,7 +38,6 @@ typedef int mutex_t; # define mutex_lock(m) ({ *(m) = 1; 0; }) # define mutex_trylock(m) (*(m) ? 1 : ((*(m) = 1), 0)) # define mutex_unlock(m) (*(m) = 0) -# define MUTEX_INITIALIZER (0) #endif /* !defined mutex_init */ diff --git a/sysdeps/mach/hurd/libc-lock.h b/sysdeps/mach/hurd/libc-lock.h index b67a049..4f3bb5c 100644 --- a/sysdeps/mach/hurd/libc-lock.h +++ b/sysdeps/mach/hurd/libc-lock.h @@ -50,8 +50,9 @@ typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t; CLASS __libc_lock_t NAME; /* Define an initialized lock variable NAME with storage class CLASS. */ +#define _LIBC_LOCK_INITIALIZER MUTEX_INITIALIZER #define __libc_lock_define_initialized(CLASS,NAME) \ - CLASS __libc_lock_t NAME = MUTEX_INITIALIZER; + CLASS __libc_lock_t NAME = _LIBC_LOCK_INITIALIZER; /* Initialize the named lock variable, leaving it in a consistent, unlocked state. */ diff --git a/sysdeps/nptl/libc-lockP.h b/sysdeps/nptl/libc-lockP.h index 29494fd..3881b45 100644 --- a/sysdeps/nptl/libc-lockP.h +++ b/sysdeps/nptl/libc-lockP.h @@ -75,6 +75,7 @@ typedef pthread_key_t __libc_key_t; initialized locks must be set to one due to the lack of normal atomic operations.) */ +#define _LIBC_LOCK_INITIALIZER LLL_LOCK_INITIALIZER #if IS_IN (libc) || IS_IN (libpthread) # if LLL_LOCK_INITIALIZER == 0 # define __libc_lock_define_initialized(CLASS,NAME) \ diff --git a/sysdeps/nptl/malloc-machine.h b/sysdeps/nptl/malloc-machine.h index 8dea606..d46a9d9 100644 --- a/sysdeps/nptl/malloc-machine.h +++ b/sysdeps/nptl/malloc-machine.h @@ -31,7 +31,6 @@ __libc_lock_define (typedef, mutex_t) #define mutex_lock(m) __libc_lock_lock (*(m)) #define mutex_trylock(m) __libc_lock_trylock (*(m)) #define mutex_unlock(m) __libc_lock_unlock (*(m)) -#define MUTEX_INITIALIZER LLL_LOCK_INITIALIZER /* This is defined by newer gcc version unique for each module. */ extern void *__dso_handle __attribute__ ((__weak__));