PATCH: Add memory barrier to malloc
H. J. Lu
hjl@lucon.org
Sun May 4 14:19:00 GMT 2003
On Sat, May 03, 2003 at 11:38:27PM -0700, Ulrich Drepper wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> H. J. Lu wrote:
>
> > I only found atomic_compare_and_exchange_val_acq and
> > atomic_compare_and_exchange_bool_acq in sysdeps/generic/bits/atomic.h.
>
> Look at include/atomic.h.
>
Here is the new patch.
H.J.
-------------- next part --------------
2003-05-04 H.J. Lu <hongjiu.lu@intel.com>
* malloc/arena.c (arena_get2): Add atomic_write_barrier.
* malloc/thread-m.h: Include <atomic.h>.
(atomic_full_barrier): Provide default.
(atomic_read_barrier): Likewise.
(atomic_write_barrier): Likewise.
* sysdeps/ia64/bits/atomic.h (atomic_full_barrier): New.
--- libc/malloc/arena.c.barrier 2002-12-26 16:36:41.000000000 -0800
+++ libc/malloc/arena.c 2003-05-03 23:56:59.000000000 -0700
@@ -758,6 +758,7 @@ arena_get2(a_tsd, size) mstate a_tsd; si
/* Add the new arena to the global list. */
(void)mutex_lock(&list_lock);
a->next = main_arena.next;
+ atomic_write_barrier ();
main_arena.next = a;
(void)mutex_unlock(&list_lock);
--- libc/malloc/thread-m.h.barrier 2003-04-07 08:09:36.000000000 -0700
+++ libc/malloc/thread-m.h 2003-05-04 00:22:29.000000000 -0700
@@ -31,6 +31,7 @@
#if defined(_LIBC) /* The GNU C library, a special case of Posix threads */
+#include <atomic.h>
#include <bits/libc-lock.h>
#ifdef PTHREAD_MUTEX_INITIALIZER
@@ -317,4 +318,16 @@ typedef void *tsd_key_t;
#endif /* defined(NO_THREADS) */
+#ifndef atomic_full_barrier
+# define atomic_full_barrier() __asm ("" ::: "memory")
+#endif
+
+#ifndef atomic_read_barrier
+# define atomic_read_barrier() atomic_full_barrier ()
+#endif
+
+#ifndef atomic_write_barrier
+# define atomic_write_barrier() atomic_full_barrier ()
+#endif
+
#endif /* !defined(_THREAD_M_H) */
--- libc/sysdeps/ia64/bits/atomic.h.barrier 2003-03-26 08:22:03.000000000 -0800
+++ libc/sysdeps/ia64/bits/atomic.h 2003-05-04 00:25:31.000000000 -0700
@@ -127,3 +127,5 @@ typedef uintmax_t uatomic_max_t;
} \
while (__builtin_expect (__val != __oldval, 0)); \
__oldval & __mask; })
+
+#define atomic_full_barrier() __sync_synchronize ()
More information about the Libc-alpha
mailing list