libc/ 2003-05-02 H.J. Lu * malloc/arena.c (arena_get2): Add WRITE_MEMORY_BARRIER. * thread-m.h: Include for glibc. (MEMORY_BARRIER): Provide default. (READ_MEMORY_BARRIER): Likewise. (WRITE_MEMORY_BARRIER): Likewise. * sysdeps/generic/memory-barrier.h: New file. linuxthreads/ 2003-05-02 H.J. Lu * sysdeps/pthread/memory-barrier.h : New file. nptl/ 2003-05-02 H.J. Lu * sysdeps/ia64/memory-barrier.h : New file. --- libc/linuxthreads/sysdeps/pthread/memory-barrier.h.barrier 2003-05-03 12:52:37.000000000 -0700 +++ libc/linuxthreads/sysdeps/pthread/memory-barrier.h 2003-05-03 12:52:37.000000000 -0700 @@ -0,0 +1,38 @@ +/* Pthread memory barrier. + + Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _PTHREAD_MEMORY_BARRIER_H +#define _PTHREAD_MEMORY_BARRIER_H 1 + +#include + +/* If MEMORY_BARRIER isn't defined in pt-machine.h, assume the + architecture doesn't need a memory barrier instruction (e.g. Intel + x86). Still we need the compiler to respect the barrier and emit + all outstanding operations which modify memory. Some architectures + distinguish between full, read and write barriers. */ + +#ifndef MEMORY_BARRIER +#define MEMORY_BARRIER() asm ("" : : : "memory") +#endif + +#include + +#endif /* memory-barrier.h */ --- libc/malloc/arena.c.barrier 2002-12-26 16:36:41.000000000 -0800 +++ libc/malloc/arena.c 2003-05-03 12:52:37.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; + WRITE_MEMORY_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-03 12:52:37.000000000 -0700 @@ -32,6 +32,7 @@ #if defined(_LIBC) /* The GNU C library, a special case of Posix threads */ #include +#include #ifdef PTHREAD_MUTEX_INITIALIZER @@ -317,4 +318,14 @@ typedef void *tsd_key_t; #endif /* defined(NO_THREADS) */ +#ifndef MEMORY_BARRIER +#define MEMORY_BARRIER() +#endif +#ifndef READ_MEMORY_BARRIER +#define READ_MEMORY_BARRIER() MEMORY_BARRIER() +#endif +#ifndef WRITE_MEMORY_BARRIER +#define WRITE_MEMORY_BARRIER() MEMORY_BARRIER() +#endif + #endif /* !defined(_THREAD_M_H) */ --- libc/nptl/sysdeps/ia64/memory-barrier.h.barrier 2003-05-03 12:52:37.000000000 -0700 +++ libc/nptl/sysdeps/ia64/memory-barrier.h 2003-05-03 13:03:40.000000000 -0700 @@ -0,0 +1,23 @@ +/* IA-64 memory barrier. + + Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#define MEMORY_BARRIER() __sync_synchronize () + +#include --- libc/sysdeps/generic/memory-barrier.h.barrier 2003-05-03 12:52:37.000000000 -0700 +++ libc/sysdeps/generic/memory-barrier.h 2003-05-03 12:52:37.000000000 -0700 @@ -0,0 +1,34 @@ +/* Generic memory barrier. + + Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _MEMORY_BARRIER_H +#define _MEMORY_BARRIER_H 1 + +#ifndef MEMORY_BARRIER +#define MEMORY_BARRIER() +#endif +#ifndef READ_MEMORY_BARRIER +#define READ_MEMORY_BARRIER() MEMORY_BARRIER() +#endif +#ifndef WRITE_MEMORY_BARRIER +#define WRITE_MEMORY_BARRIER() MEMORY_BARRIER() +#endif + +#endif /* memory-barrier.h */