public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] malloc: Manual part of conversion to __libc_lock
@ 2016-08-22 12:44 Florian Weimer
  2016-08-25 20:22 ` Adhemerval Zanella
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Weimer @ 2016-08-22 12:44 UTC (permalink / raw)
  To: libc-alpha

This removes the old mutex_t-related definitions from malloc-machine.h,
too.

2016-08-22  Florian Weimer  <fweimer@redhat.com>

	malloc: Use __libc_lock wrappers.
	* malloc/arena.c (list_lock, free_list_lock): Define using
	__libc_lock_define_initialized.
	(arena_lock): Adjust formatting.
	* malloc/malloc.c (struct malloc_state): Define mutex using
	__libc_lock_define.
	* sysdeps/generic/malloc-machine.h (mutex_t, mutex_init)
	(mutex_lock, mutex_trylock, mutex_unlock): Remove.
	* sysdeps/mach/hurd/malloc-machine.h (mutex_t, mutex_lock)
	(mutex_unlock, mutex_trylock): Remove.
	(__pthread_initialize): Remove unused macro.
	* sysdeps/nptl/malloc-machine.h (mutex_t, mutex_lock)
	(mutex_unlock, mutex_trylock): Remove.

diff --git a/malloc/arena.c b/malloc/arena.c
index 922ae49..9760483 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -73,7 +73,7 @@ static __thread mstate thread_arena attribute_tls_model_ie;
    members of struct malloc_state objects.  No other locks must be
    acquired after free_list_lock has been acquired.  */
 
-static mutex_t free_list_lock = _LIBC_LOCK_INITIALIZER;
+__libc_lock_define_initialized (static, free_list_lock);
 static size_t narenas = 1;
 static mstate free_list;
 
@@ -89,7 +89,7 @@ static mstate free_list;
    acquired, no arena lock must have been acquired, but it is
    permitted to acquire arena locks subsequently, while list_lock is
    acquired.  */
-static mutex_t list_lock = _LIBC_LOCK_INITIALIZER;
+__libc_lock_define_initialized (static, list_lock);
 
 /* Already initialized? */
 int __malloc_initialized = -1;
@@ -112,7 +112,7 @@ int __malloc_initialized = -1;
 
 #define arena_lock(ptr, size) do {					      \
       if (ptr && !arena_is_corrupt (ptr))				      \
-        __libc_lock_lock (ptr->mutex);				      \
+        __libc_lock_lock (ptr->mutex);					      \
       else								      \
         ptr = arena_get2 ((size), NULL);				      \
   } while (0)
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 20acb73..ef04360 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -1616,7 +1616,7 @@ typedef struct malloc_chunk *mfastbinptr;
 struct malloc_state
 {
   /* Serialize access.  */
-  mutex_t mutex;
+  __libc_lock_define (, mutex);
 
   /* Flags (formerly in max_fast).  */
   int flags;
diff --git a/sysdeps/mach/hurd/malloc-machine.h b/sysdeps/mach/hurd/malloc-machine.h
index f778b0d..87a5d19 100644
--- a/sysdeps/mach/hurd/malloc-machine.h
+++ b/sysdeps/mach/hurd/malloc-machine.h
@@ -23,27 +23,6 @@
 #include <atomic.h>
 #include <libc-lock.h>
 
-/* Assume hurd, with cthreads */
-
-/* Cthreads `mutex_t' is a pointer to a mutex, and malloc wants just the
-   mutex itself.  */
-#undef mutex_t
-#define mutex_t struct mutex
-
-#undef mutex_init
-#define mutex_init(m) ({ __mutex_init(m); 0; })
-
-#undef mutex_lock
-#define mutex_lock(m) ({ __mutex_lock(m); 0; })
-
-#undef mutex_unlock
-#define mutex_unlock(m) ({ __mutex_unlock(m); 0; })
-
-#define mutex_trylock(m) (!__mutex_trylock(m))
-
-/* No we're *not* using pthreads.  */
-#define __pthread_initialize ((void (*)(void))0)
-
 /* madvise is a stub on Hurd, so don't bother calling it.  */
 
 #include <sys/mman.h>
diff --git a/sysdeps/nptl/malloc-machine.h b/sysdeps/nptl/malloc-machine.h
index 1a2af6f..b20c423 100644
--- a/sysdeps/nptl/malloc-machine.h
+++ b/sysdeps/nptl/malloc-machine.h
@@ -22,14 +22,6 @@
 
 #include <atomic.h>
 #include <libc-lock.h>
-
-__libc_lock_define (typedef, mutex_t)
-
-#define mutex_init(m)		__libc_lock_init (*(m))
-#define mutex_lock(m)		__libc_lock_lock (*(m))
-#define mutex_trylock(m)	__libc_lock_trylock (*(m))
-#define mutex_unlock(m)		__libc_lock_unlock (*(m))
-
 #include <sysdeps/generic/malloc-machine.h>
 
 #endif /* !defined(_MALLOC_MACHINE_H) */

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] malloc: Manual part of conversion to __libc_lock
  2016-08-22 12:44 [PATCH] malloc: Manual part of conversion to __libc_lock Florian Weimer
@ 2016-08-25 20:22 ` Adhemerval Zanella
  2016-09-21 15:16   ` Florian Weimer
  0 siblings, 1 reply; 3+ messages in thread
From: Adhemerval Zanella @ 2016-08-25 20:22 UTC (permalink / raw)
  To: libc-alpha

LGMT with just one comment:

On 22/08/2016 09:44, Florian Weimer wrote:

> diff --git a/malloc/arena.c b/malloc/arena.c
> index 922ae49..9760483 100644
> --- a/malloc/arena.c
> +++ b/malloc/arena.c
> @@ -73,7 +73,7 @@ static __thread mstate thread_arena attribute_tls_model_ie;
>     members of struct malloc_state objects.  No other locks must be
>     acquired after free_list_lock has been acquired.  */
>  
> -static mutex_t free_list_lock = _LIBC_LOCK_INITIALIZER;
> +__libc_lock_define_initialized (static, free_list_lock);
>  static size_t narenas = 1;
>  static mstate free_list;
>  
> @@ -89,7 +89,7 @@ static mstate free_list;
>     acquired, no arena lock must have been acquired, but it is
>     permitted to acquire arena locks subsequently, while list_lock is
>     acquired.  */
> -static mutex_t list_lock = _LIBC_LOCK_INITIALIZER;
> +__libc_lock_define_initialized (static, list_lock);
>  
>  /* Already initialized? */
>  int __malloc_initialized = -1;
> @@ -112,7 +112,7 @@ int __malloc_initialized = -1;
>  
>  #define arena_lock(ptr, size) do {					      \
>        if (ptr && !arena_is_corrupt (ptr))				      \
> -        __libc_lock_lock (ptr->mutex);				      \
> +        __libc_lock_lock (ptr->mutex);					      \
>        else								      \
>          ptr = arena_get2 ((size), NULL);				      \
>    } while (0)

I would avoid push these kind of indentation changes.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] malloc: Manual part of conversion to __libc_lock
  2016-08-25 20:22 ` Adhemerval Zanella
@ 2016-09-21 15:16   ` Florian Weimer
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Weimer @ 2016-09-21 15:16 UTC (permalink / raw)
  To: Adhemerval Zanella, libc-alpha

On 08/25/2016 10:22 PM, Adhemerval Zanella wrote:

>>  #define arena_lock(ptr, size) do {					      \
>>        if (ptr && !arena_is_corrupt (ptr))				      \
>> -        __libc_lock_lock (ptr->mutex);				      \
>> +        __libc_lock_lock (ptr->mutex);					      \
>>        else								      \
>>          ptr = arena_get2 ((size), NULL);				      \
>>    } while (0)
>
> I would avoid push these kind of indentation changes.

It's required to restore alignment after the automated changes.

I have committed this now.  Thanks.

Florian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-21 15:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-22 12:44 [PATCH] malloc: Manual part of conversion to __libc_lock Florian Weimer
2016-08-25 20:22 ` Adhemerval Zanella
2016-09-21 15:16   ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).