diff mbox

Replace MUTEX_INITIALIZER with _LIBC_LOCK_INITIALIZER in generic code

Message ID 20160820144801.GC1620@var.home
State New
Headers show

Commit Message

Samuel Thibault Aug. 20, 2016, 2:48 p.m. UTC
Samuel Thibault, on Sat 20 Aug 2016 16:36:10 +0200, wrote:
> And anyway, either malloc should be made to just use libc-lock or lll
> explicitly, or the malloc-machine.h layer should be providing a complete
> interface and users shouldn't be assuming anything about it.

Put another way, I'd tend to commit this.

Samuel

commit 0f0af158aabda65027634a369f4ce25aa0f20c1a
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Sat Aug 20 16:46:59 2016 +0200

    malloc: Restore using MUTEX_INITIALIZER
    
    	* malloc/malloc.c (main_arena): Use MUTEX_INITIALIZER instead of
    	_LIBC_LOCK_INITIALIZER.
    	* sysdeps/nptl/malloc-machine.h (MUTEX_INITIALIZER): Define.
    	* sysdeps/mach/hurd/malloc-machine.h (MUTEX_INITIALIZER): Comment
    	about macro definition coming from cthreads.h.

Comments

Florian Weimer Aug. 20, 2016, 5:19 p.m. UTC | #1
On 08/20/2016 04:48 PM, Samuel Thibault wrote:
> +	* malloc/malloc.c (main_arena): Use MUTEX_INITIALIZER instead of
> +	_LIBC_LOCK_INITIALIZER.

No, you need to define _LIBC_LOCK_INITIALIZER in terms of 
MUTEX_INITIALIZER.  If this is not possible, you need to select a lock 
which is compatible with the libc_lock infrastructure for the malloc mutex.

Florian
diff mbox

Patch

diff --git a/ChangeLog b/ChangeLog
index ae29267..a9ddf8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@ 
+2016-08-20  Samuel Thibault  <samuel.thibault@ens-lyon.org>
+
+	* malloc/malloc.c (main_arena): Use MUTEX_INITIALIZER instead of
+	_LIBC_LOCK_INITIALIZER.
+	* sysdeps/nptl/malloc-machine.h (MUTEX_INITIALIZER): Define.
+	* sysdeps/mach/hurd/malloc-machine.h (MUTEX_INITIALIZER): Comment
+	about macro definition coming from cthreads.h.
+
 2016-08-16  Joseph Myers  <joseph@codesourcery.com>
 
 	* soft-fp/extended.h [_FP_W_TYPE_SIZE < 64] (FP_UNPACK_RAW_E):
diff --git a/malloc/malloc.c b/malloc/malloc.c
index bb52b3e..a42d846 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -1687,7 +1687,7 @@  struct malloc_par
 
 static struct malloc_state main_arena =
 {
-  .mutex = _LIBC_LOCK_INITIALIZER,
+  .mutex = MUTEX_INITIALIZER,
   .next = &main_arena,
   .attached_threads = 1
 };
diff --git a/sysdeps/mach/hurd/malloc-machine.h b/sysdeps/mach/hurd/malloc-machine.h
index f778b0d..803d96a 100644
--- a/sysdeps/mach/hurd/malloc-machine.h
+++ b/sysdeps/mach/hurd/malloc-machine.h
@@ -41,6 +41,8 @@ 
 
 #define mutex_trylock(m) (!__mutex_trylock(m))
 
+/* MUTEX_INITIALIZER already defined by cthreads.h.  */
+
 /* No we're *not* using pthreads.  */
 #define __pthread_initialize ((void (*)(void))0)
 
diff --git a/sysdeps/nptl/malloc-machine.h b/sysdeps/nptl/malloc-machine.h
index 1a2af6f..6d16f90 100644
--- a/sysdeps/nptl/malloc-machine.h
+++ b/sysdeps/nptl/malloc-machine.h
@@ -29,6 +29,7 @@  __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
 
 #include <sysdeps/generic/malloc-machine.h>