Update.
[platform/upstream/glibc.git] / sysdeps / i386 / i486 / atomicity.h
1 /* Low-level functions for atomitc operations.  ix86 version, x >= 4.
2    Copyright (C) 1997 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14
15    You should have received a copy of the GNU Library General Public
16    License along with the GNU C Library; see the file COPYING.LIB.  If not,
17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18    Boston, MA 02111-1307, USA.  */
19
20 #ifndef _ATOMICITY_H
21 #define _ATOMICITY_H    1
22
23 #include <inttypes.h>
24
25
26 static inline int
27 __attribute__ ((unused))
28 exchange_and_add (volatile uint32_t *mem, int val)
29 {
30   register int result;
31   __asm__ __volatile__ ("lock; xaddl %0,%1"
32                         : "=r" (result) : "0" (val), "m" (*mem) : "memory");
33   return result;
34 }
35
36 static inline void
37 __attribute__ ((unused))
38 atomic_add (volatile uint32_t *mem, int val)
39 {
40   __asm__ __volatile__ ("lock; addl %0,%1"
41                         : : "ir" (val), "m" (*mem) : "memory");
42 }
43
44 static inline int
45 __attribute__ ((unused))
46 compare_and_swap (volatile long int *p, long int oldval, long int newval)
47 {
48   char ret;
49   long int readval;
50
51   __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
52                         : "=q" (ret), "=m" (*p), "=a" (readval)
53                         : "r" (newval), "m" (*p), "a" (oldval));
54   return ret;
55 }
56
57 #endif /* atomicity.h */