2003-03-19  Ulrich Drepper  <drepper@redhat.com>

	* Makefile (distribute): Add include/atomic.h and bits/atomic.h.
	* include/atomic.h: New file.
	* sysdeps/i386/i486/bits/atomic.h: New file.
	* sysdeps/x86_64/bits/atomic.h: New file.
	* sysdeps/s390/bits/atomic.h: New file.
	* sysdeps/sh/bits/atomic.h: New file.
	* sysdeps/ia64/bits/atomic.h: New file.
	* sysdeps/powerpc/bits/atomic.h: New file.
	* sysdeps/generic/bits/atomic.h: New file.
	* sysdeps/i386/i486/atomicity.h: Removed.
	* sysdeps/x86_64/atomicity.h: Removed.
	* sysdeps/s390/s390-32/atomicity.h: Removed.
	* sysdeps/s390/s390-64/atomicity.h: Removed.
	* sysdeps/ia64/atomicity.h: Removed.
	* sysdeps/powerpc/powerpc32/atomicity.h: Removed.
	* sysdeps/powerpc/powerpc64/atomicity.h: Removed.
	* elf/dl-profile.c: Use atomic.h instead of atomicity.h.  Adjust
	use of macros from atomicity.h to new names and semantics.
	* gmon_mcount.c: Likewise.
	* malloc/set-freeres.c: Likewise.
	* nscd/cache.c: Likewise.
	* stdlib/cxa_finalize.c: Likewise.
	* sysdeps/unix/sysv/linux/getsysstats.c: Likewise.

	* sysdeps/mips/ieee754.h: New file, suitable to replace both
	* stdlib/strtod.c (INTERNAL): While eating trailing zeros handle
This commit is contained in:
Ulrich Drepper 2003-03-20 07:19:17 +00:00
parent 85b5767c57
commit 4009bf4044
25 changed files with 91 additions and 575 deletions

View File

@ -1,12 +1,38 @@
2003-03-19 Ulrich Drepper <drepper@redhat.com>
* Makefile (distribute): Add include/atomic.h and bits/atomic.h.
* include/atomic.h: New file.
* sysdeps/i386/i486/bits/atomic.h: New file.
* sysdeps/x86_64/bits/atomic.h: New file.
* sysdeps/s390/bits/atomic.h: New file.
* sysdeps/sh/bits/atomic.h: New file.
* sysdeps/ia64/bits/atomic.h: New file.
* sysdeps/powerpc/bits/atomic.h: New file.
* sysdeps/generic/bits/atomic.h: New file.
* sysdeps/i386/i486/atomicity.h: Removed.
* sysdeps/x86_64/atomicity.h: Removed.
* sysdeps/s390/s390-32/atomicity.h: Removed.
* sysdeps/s390/s390-64/atomicity.h: Removed.
* sysdeps/ia64/atomicity.h: Removed.
* sysdeps/powerpc/powerpc32/atomicity.h: Removed.
* sysdeps/powerpc/powerpc64/atomicity.h: Removed.
* elf/dl-profile.c: Use atomic.h instead of atomicity.h. Adjust
use of macros from atomicity.h to new names and semantics.
* gmon_mcount.c: Likewise.
* malloc/set-freeres.c: Likewise.
* nscd/cache.c: Likewise.
* stdlib/cxa_finalize.c: Likewise.
* sysdeps/unix/sysv/linux/getsysstats.c: Likewise.
2003-03-19 Alexandre Oliva <aoliva@redhat.com>
* sysdeps/mips/ieee754.h: New file, suitable to replace both
* sysdeps/mips/ieee754.h: New file, suitable to replace both
../ieee754/ieee754.h and ../ieee754/ldbl-128/ieee754.h, kept
mips-specific for now.
2003-03-19 Ulrich Drepper <drepper@redhat.com>
* stdlib/strtod.c (INTERNAL): While eating trailing zeros handling
* stdlib/strtod.c (INTERNAL): While eating trailing zeros handle
hexdigits correctly. Reported by Fred Tydeman <tydeman@tybor.com>.
* stdlib/tst-strtod.c: Add test for the bug.

View File

@ -274,6 +274,7 @@ distribute := README README.libm INSTALL FAQ FAQ.in NOTES NEWS BUGS \
include/shlib-compat.h include/pthread.h Versions.def \
cppflags-iterator.mk tls.make.c \
include/stubs-prologue.h include/gnu/stubs.h \
include/atomic.h bits/atomic.h \
INTERFACE CONFORMANCE NAMESPACE LICENSES \
$(addprefix scripts/, \
rellns-sh config.sub config.guess \

View File

@ -1,6 +1,6 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
/* Copyright (C) 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@ -17,4 +17,15 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include "../../i486/bits/atomic.h"
#ifndef _BITS_ATOMIC_H
#define _BITS_ATOMIC_H 1
/* We have by default no support for atomic operations. So define
them non-atomic. If this is a problem somebody will have to come
up with real definitions. */
/* The only basic operation needed is compare and exchange. */
#define arch_compare_and_exchange_acq(mem, newval, oldval) \
({ *(mem) == (oldval) ? 1 : (*(mem) = (newval), 0); })
#endif /* bits/atomic.h */

View File

@ -1,5 +1,5 @@
/* Profiling of shared libraries.
Copyright (C) 1997,1998,1999,2000,2001,2002 Free Software Foundation, Inc.
Copyright (C) 1997-2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
Based on the BSD mcount implementation.
@ -34,7 +34,7 @@
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <atomicity.h>
#include <atomic.h>
/* The LD_PROFILE feature has to be implemented different to the
normal profiling using the gmon/ functions. The problem is that an
@ -516,24 +516,24 @@ _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc)
size_t newfromidx;
to_index = (data[narcs].self_pc
/ (hashfraction * sizeof (*tos)));
newfromidx = exchange_and_add (&fromidx, 1) + 1;
newfromidx = atomic_exchange_and_add (&fromidx, 1) + 1;
froms[newfromidx].here = &data[narcs];
froms[newfromidx].link = tos[to_index];
tos[to_index] = newfromidx;
atomic_add (&narcs, 1);
atomic_increment (&narcs);
}
/* If we still have no entry stop searching and insert. */
if (*topcindex == 0)
{
uint_fast32_t newarc = exchange_and_add (narcsp, 1);
uint_fast32_t newarc = atomic_exchange_and_add (narcsp, 1);
/* In rare cases it could happen that all entries in FROMS are
occupied. So we cannot count this anymore. */
if (newarc >= fromlimit)
goto done;
*topcindex = exchange_and_add (&fromidx, 1) + 1;
*topcindex = atomic_exchange_and_add (&fromidx, 1) + 1;
fromp = &froms[*topcindex];
fromp->here = &data[newarc];
@ -541,7 +541,7 @@ _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc)
data[newarc].self_pc = selfpc;
data[newarc].count = 0;
fromp->link = 0;
atomic_add (&narcs, 1);
atomic_increment (&narcs);
break;
}
@ -554,7 +554,7 @@ _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc)
}
/* Increment the counter. */
atomic_add (&fromp->here->count, 1);
atomic_increment (&fromp->here->count);
done:
;

View File

@ -39,7 +39,7 @@ static char sccsid[] = "@(#)mcount.c 8.1 (Berkeley) 6/4/93";
and MCOUNT macros. */
#include "machine-gmon.h"
#include <atomicity.h>
#include <atomic.h>
/*
* mcount is called on entry to each function compiled with the profiling
@ -69,7 +69,8 @@ _MCOUNT_DECL(frompc, selfpc) /* _mcount; may be static, inline, etc */
* check that we are profiling
* and that we aren't recursively invoked.
*/
if (! compare_and_swap (&p->state, GMON_PROF_ON, GMON_PROF_BUSY))
if (atomic_compare_and_exchange_acq (&p->state, GMON_PROF_BUSY,
GMON_PROF_ON))
return;
/*

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
/* Copyright (C) 1997,1999,2000,2001,2002,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
@ -16,7 +16,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <atomicity.h>
#include <atomic.h>
#include <stdlib.h>
#include <set-hooks.h>
#include <libc-internal.h>
@ -36,7 +36,7 @@ __libc_freeres (void)
protect for multiple executions since these are fatal. */
static long int already_called;
if (compare_and_swap (&already_called, 0, 1))
if (! atomic_compare_and_exchange_acq (&already_called, 1, 0))
{
void * const *p;

View File

@ -1,5 +1,15 @@
2003-03-19 Ulrich Drepper <drepper@redhat.com>
* sysdeps/i386/i686/bits/atomic.h: Removed.
* sysdeps/i386/i586/bits/atomic.h: Removed.
* sysdeps/i386/i486/bits/atomic.h: Removed. Moved to glibc.
* sysdeps/x86_64/bits/atomic.h: Removed. Moved to glibc.
* sysdeps/s390/bits/atomic.h: Removed. Moved to glibc.
* sysdeps/sh/bits/atomic.h: Removed. Moved to glibc.
* sysdeps/ia64/bits/atomic.h: Removed. Moved to glibc.
* sysdeps/powerpc/bits/atomic.h: Removed. Moved to glibc.
* atomic.h: Removed. Moved to glibc.
* sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Add
support for clock selection.

View File

@ -17,7 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <atomicity.h>
#include <atomic.h>
#include <errno.h>
#include <error.h>
#include <limits.h>
@ -101,8 +101,8 @@ cache_add (int type, void *key, size_t len, const void *packet, size_t total,
/* Put the new entry in the first position. */
do
newp->next = table->array[hash];
while (! compare_and_swap ((volatile long int *) &table->array[hash],
(long int) newp->next, (long int) newp));
while (atomic_compare_and_exchange_acq (&table->array[hash], newp,
newp->next));
/* Update the statistics. */
if (data == (void *) -1)

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
/* Copyright (C) 1999, 2001, 2002, 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
@ -18,7 +18,7 @@
#include <assert.h>
#include <stdlib.h>
#include <atomicity.h>
#include <atomic.h>
#include "exit.h"
#include <fork.h>
@ -36,7 +36,8 @@ __cxa_finalize (void *d)
for (f = &funcs->fns[funcs->idx - 1]; f >= &funcs->fns[0]; --f)
if ((d == NULL || d == f->func.cxa.dso_handle)
/* We don't want to run this cleanup more than once. */
&& compare_and_swap (&f->flavor, ef_cxa, ef_free))
&& (atomic_compare_and_exchange_acq (&f->flavor, ef_free, ef_cxa)
== 0))
(*f->func.cxa.fn) (f->func.cxa.arg, 0);
}

View File

@ -1,6 +1,6 @@
/* Copyright (C) 2002 Free Software Foundation, Inc.
/* Copyright (C) 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@ -17,4 +17,15 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include "../../i486/bits/atomic.h"
#ifndef _BITS_ATOMIC_H
#define _BITS_ATOMIC_H 1
/* We have by default no support for atomic operations. So define
them non-atomic. If this is a problem somebody will have to come
up with real definitions. */
/* The only basic operation needed is compare and exchange. */
#define arch_compare_and_exchange_acq(mem, newval, oldval) \
({ *(mem) == (oldval) ? 1 : (*(mem) = (newval), 0); })
#endif /* bits/atomic.h */

View File

@ -1,57 +0,0 @@
/* Low-level functions for atomic operations. ix86 version, x >= 4.
Copyright (C) 1997, 2000, 2001 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 _ATOMICITY_H
#define _ATOMICITY_H 1
#include <inttypes.h>
static inline uint32_t
__attribute__ ((unused))
exchange_and_add (volatile uint32_t *mem, uint32_t val)
{
register uint32_t result;
__asm__ __volatile__ ("lock; xaddl %0,%1"
: "=r" (result), "=m" (*mem) : "0" (val), "1" (*mem));
return result;
}
static inline void
__attribute__ ((unused))
atomic_add (volatile uint32_t *mem, int val)
{
__asm__ __volatile__ ("lock; addl %1,%0"
: "=m" (*mem) : "ir" (val), "0" (*mem));
}
static inline char
__attribute__ ((unused))
compare_and_swap (volatile long int *p, long int oldval, long int newval)
{
char ret;
long int readval;
__asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
: "=q" (ret), "=m" (*p), "=a" (readval)
: "r" (newval), "1" (*p), "a" (oldval));
return ret;
}
#endif /* atomicity.h */

View File

@ -1,48 +0,0 @@
/* Low-level functions for atomic operations. IA-64 version.
Copyright (C) 2001 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 _ATOMICITY_H
#define _ATOMICITY_H 1
#include <inttypes.h>
#include <ia64intrin.h>
static inline uint32_t
__attribute__ ((unused))
exchange_and_add (volatile uint32_t *mem, uint32_t val)
{
return __sync_fetch_and_add (mem, val);
}
static inline void
__attribute__ ((unused))
atomic_add (volatile uint32_t *mem, int val)
{
__sync_fetch_and_add (mem, val);
}
static inline int
__attribute__ ((unused))
compare_and_swap (volatile long int *p, long int oldval, long int newval)
{
return __sync_bool_compare_and_swap (p, oldval, newval);
}
#endif /* atomicity.h */

View File

@ -1,98 +0,0 @@
/* Low-level functions for atomic operations. PowerPC version.
Copyright (C) 1997, 1998, 1999, 2000 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 _ATOMICITY_H
#define _ATOMICITY_H 1
#include <inttypes.h>
static inline int
__attribute__ ((unused))
exchange_and_add (volatile uint32_t *mem, int val)
{
int tmp, result;
__asm__ ("\n\
0: lwarx %0,0,%2 \n\
add%I3 %1,%0,%3 \n\
stwcx. %1,0,%2 \n\
bne- 0b \n\
" : "=&b"(result), "=&r"(tmp) : "r" (mem), "Ir"(val) : "cr0", "memory");
return result;
}
static inline void
__attribute__ ((unused))
atomic_add (volatile uint32_t *mem, int val)
{
int tmp;
__asm__ ("\n\
0: lwarx %0,0,%1 \n\
add%I2 %0,%0,%2 \n\
stwcx. %0,0,%1 \n\
bne- 0b \n\
" : "=&b"(tmp) : "r" (mem), "Ir"(val) : "cr0", "memory");
}
static inline int
__attribute__ ((unused))
compare_and_swap (volatile long int *p, long int oldval, long int newval)
{
int result;
__asm__ ("\n\
0: lwarx %0,0,%1 \n\
sub%I2c. %0,%0,%2 \n\
cntlzw %0,%0 \n\
bne- 1f \n\
stwcx. %3,0,%1 \n\
bne- 0b \n\
1: \n\
" : "=&b"(result) : "r"(p), "Ir"(oldval), "r"(newval) : "cr0", "memory");
return result >> 5;
}
static inline long int
__attribute__ ((unused))
always_swap (volatile long int *p, long int newval)
{
long int result;
__asm__ ("\n\
0: lwarx %0,0,%1 \n\
stwcx. %2,0,%1 \n\
bne- 0b \n\
" : "=&r"(result) : "r"(p), "r"(newval) : "cr0", "memory");
return result;
}
static inline int
__attribute__ ((unused))
test_and_set (volatile long int *p, long int newval)
{
int result;
__asm__ ("\n\
0: lwarx %0,0,%1 \n\
cmpwi %0,0 \n\
bne- 1f \n\
stwcx. %2,0,%1 \n\
bne- 0b \n\
1: \n\
" : "=&r"(result) : "r"(p), "r"(newval) : "cr0", "memory");
return result;
}
#endif /* atomicity.h */

View File

@ -1,132 +0,0 @@
/* Low-level functions for atomic operations. PowerPC64 version.
Copyright (C) 1997, 1998, 1999, 2000, 2002 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 Library General Public License as
published by the Free Software Foundation; either version 2 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _ATOMICITY_H
#define _ATOMICITY_H 1
#include <inttypes.h>
#if BROKEN_PPC_ASM_CR0
# define __ATOMICITY_INLINE /* nothing */
#else
# define __ATOMICITY_INLINE inline
#endif
static __ATOMICITY_INLINE int
__attribute__ ((unused))
exchange_and_add (volatile uint32_t *mem, int val)
{
int tmp, result;
__asm__ ("\n\
0: lwarx %0,0,%2 \n\
add%I3 %1,%0,%3 \n\
stwcx. %1,0,%2 \n\
bne- 0b \n\
" : "=&b"(result), "=&r"(tmp) : "r" (mem), "Ir"(val) : "cr0", "memory");
return result;
}
static __ATOMICITY_INLINE void
__attribute__ ((unused))
atomic_add_long (volatile long *mem, int val)
{
int tmp;
__asm__ ("\n\
0: ldarx %0,0,%1 \n\
add%I2 %0,%0,%2 \n\
stdcx. %0,0,%1 \n\
bne- 0b \n\
" : "=&b"(tmp) : "r" (mem), "Ir"(val) : "cr0", "memory");
}
static __ATOMICITY_INLINE int
__attribute__ ((unused))
exchange_and_add_long (volatile long *mem, int val)
{
int tmp, result;
__asm__ ("\n\
0: ldarx %0,0,%2 \n\
add%I3 %1,%0,%3 \n\
stdcx. %1,0,%2 \n\
bne- 0b \n\
" : "=&b"(result), "=&r"(tmp) : "r" (mem), "Ir"(val) : "cr0", "memory");
return result;
}
static __ATOMICITY_INLINE void
__attribute__ ((unused))
atomic_add (volatile uint32_t *mem, int val)
{
int tmp;
__asm__ ("\n\
0: lwarx %0,0,%1 \n\
add%I2 %0,%0,%2 \n\
stwcx. %0,0,%1 \n\
bne- 0b \n\
" : "=&b"(tmp) : "r" (mem), "Ir"(val) : "cr0", "memory");
}
static __ATOMICITY_INLINE int
__attribute__ ((unused))
compare_and_swap (volatile long int *p, long int oldval, long int newval)
{
int result;
__asm__ ("\n\
0: ldarx %0,0,%1 \n\
sub%I2c. %0,%0,%2 \n\
cntlzw %0,%0 \n\
bne- 1f \n\
stdcx. %3,0,%1 \n\
bne- 0b \n\
1: \n\
" : "=&b"(result) : "r"(p), "Ir"(oldval), "r"(newval) : "cr0", "memory");
return result >> 5;
}
static __ATOMICITY_INLINE long int
__attribute__ ((unused))
always_swap (volatile long int *p, long int newval)
{
long int result;
__asm__ ("\n\
0: ldarx %0,0,%1 \n\
stdcx. %2,0,%1 \n\
bne- 0b \n\
" : "=&r"(result) : "r"(p), "r"(newval) : "cr0", "memory");
return result;
}
static __ATOMICITY_INLINE int
__attribute__ ((unused))
test_and_set (volatile long int *p, long int newval)
{
int result;
__asm__ ("\n\
0: ldarx %0,0,%1 \n\
cmpdi %0,0 \n\
bne- 1f \n\
stdcx. %2,0,%1 \n\
bne- 0b \n\
1: \n\
" : "=&r"(result) : "r"(p), "r"(newval) : "cr0", "memory");
return result;
}
#endif /* atomicity.h */

View File

@ -1,76 +0,0 @@
/* Low-level functions for atomic operations. S390 version.
Copyright (C) 2000, 2001 Free Software Foundation, Inc.
Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
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 _ATOMICITY_H
#define _ATOMICITY_H 1
#include <inttypes.h>
static inline int
__attribute__ ((unused))
exchange_and_add (volatile uint32_t *mem, int val)
{
int result;
__asm__ __volatile__(
" L %0,%2\n"
" LA 2,%1\n"
"0: LR 0,%0\n"
" AR 0,%3\n"
" CS %0,0,0(2)\n"
" JL 0b"
: "=&d" (result), "=m" (*mem)
: "1" (*mem), "d" (val) : "0", "1", "2" );
return result;
}
static inline void
__attribute__ ((unused))
atomic_add (volatile uint32_t *mem, int val)
{
__asm__ __volatile__(
" LA 2,%0\n"
"0: L 0,%1\n"
" LR 1,0\n"
" AR 1,%2\n"
" CS 0,1,0(2)\n"
" JL 0b"
: "=m" (*mem) : "0" (*mem), "d" (val) : "0", "1", "2" );
}
static inline int
__attribute__ ((unused))
compare_and_swap (volatile long int *p, long int oldval, long int newval)
{
int retval;
__asm__ __volatile__(
" la 1,%1\n"
" lr 0,%2\n"
" cs 0,%3,0(1)\n"
" ipm %0\n"
" srl %0,28\n"
"0:"
: "=&r" (retval), "+m" (*p)
: "d" (oldval) , "d" (newval)
: "memory", "0", "1", "cc");
return !retval;
}
#endif /* atomicity.h */

View File

@ -1,76 +0,0 @@
/* Low-level functions for atomic operations. 64 bit S/390 version.
Copyright (C) 2001 Free Software Foundation, Inc.
Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
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 _ATOMICITY_H
#define _ATOMICITY_H 1
#include <inttypes.h>
static inline int
__attribute__ ((unused))
exchange_and_add (volatile uint32_t *mem, int val)
{
int result;
__asm__ __volatile__(
" L %0,%2\n"
" LA 2,%1\n"
"0: LR 0,%0\n"
" AR 0,%3\n"
" CS %0,0,0(2)\n"
" JL 0b"
: "=&d" (result), "=m" (*mem)
: "1" (*mem), "d" (val) : "0", "1", "2" );
return result;
}
static inline void
__attribute__ ((unused))
atomic_add (volatile uint32_t *mem, int val)
{
__asm__ __volatile__(
" LA 2,%0\n"
"0: L 0,%1\n"
" LR 1,0\n"
" AR 1,%2\n"
" CS 0,1,0(2)\n"
" JL 0b"
: "=m" (*mem) : "0" (*mem), "d" (val) : "0", "1", "2" );
}
static inline int
__attribute__ ((unused))
compare_and_swap (volatile long int *p, long int oldval, long int newval)
{
int retval;
__asm__ __volatile__(
" la 1,%1\n"
" lgr 0,%2\n"
" csg 0,%3,0(1)\n"
" ipm %0\n"
" srl %0,28\n"
"0:"
: "=&r" (retval), "+m" (*p)
: "d" (oldval) , "d" (newval)
: "memory", "0", "1", "cc");
return !retval;
}
#endif /* atomicity.h */

View File

@ -1,5 +1,5 @@
/* Determine various system internal values, Linux version.
Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc.
Copyright (C) 1996-2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@ -31,7 +31,7 @@
#include <unistd.h>
#include <sys/sysinfo.h>
#include <atomicity.h>
#include <atomic.h>
/* The default value for the /proc filesystem mount point. */
@ -85,8 +85,7 @@ get_proc_path (char *buffer, size_t bufsize)
/* Now store the copied value. But do it atomically. */
assert (sizeof (long int) == sizeof (void *__unbounded));
if (compare_and_swap ((long int *) &mount_proc, (long int) 0,
(long int) copy_result) == 0)
if (atomic_compare_and_exchange_acq (&mount_proc, copy_result, NULL) == 0)
/* Replacing the value failed. This means another thread was
faster and we don't need the copy anymore. */
free (copy_result);

View File

@ -1,57 +0,0 @@
/* Low-level functions for atomic operations. x86-64 version.
Copyright (C) 1997, 2000, 2001 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 _ATOMICITY_H
#define _ATOMICITY_H 1
#include <inttypes.h>
static inline uint32_t
__attribute__ ((unused))
exchange_and_add (volatile uint32_t *mem, uint32_t val)
{
register uint32_t result;
__asm__ __volatile__ ("lock; xaddl %0,%1"
: "=r" (result), "=m" (*mem) : "0" (val), "1" (*mem));
return result;
}
static inline void
__attribute__ ((unused))
atomic_add (volatile uint32_t *mem, int val)
{
__asm__ __volatile__ ("lock; addl %1,%0"
: "=m" (*mem) : "er" (val), "0" (*mem));
}
static inline char
__attribute__ ((unused))
compare_and_swap (volatile long int *p, long int oldval, long int newval)
{
char ret;
long int readval;
__asm__ __volatile__ ("lock; cmpxchgq %3, %1; sete %0"
: "=q" (ret), "=m" (*p), "=a" (readval)
: "r" (newval), "1" (*p), "a" (oldval));
return ret;
}
#endif /* atomicity.h */