Move all files into ports/ subdirectory in preparation for merge with glibc
[jlayton/glibc.git] / ports / sysdeps / am33 / atomicity.h
1 /* Low-level functions for atomic operations.  AM33 version.
2    Copyright 1999, 2001 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Alexandre Oliva <aoliva@redhat.com>.
5    Based on ../sparc/sparc32/atomicity.h
6
7    The GNU C Library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Library General Public License as
9    published by the Free Software Foundation; either version 2 of the
10    License, or (at your option) any later version.
11
12    The GNU C Library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Library General Public License for more details.
16
17    You should have received a copy of the GNU Library General Public
18    License along with the GNU C Library.  If not, see
19    <http://www.gnu.org/licenses/>.  */
20
21 #ifndef _ATOMICITY_H
22 #define _ATOMICITY_H    1
23
24 #include <inttypes.h>
25
26 #define __acquire_lock(lock) \
27   __asm__ __volatile__("1:      bset    %1, (%0)\n\t"           \
28                        "        beq     1b"                     \
29                        : : "a" (&(lock)), "d" (1)               \
30                        : "memory")
31
32 #define __release_lock(lock) lock = 0
33
34 static int
35 __attribute__ ((unused))
36 exchange_and_add (volatile uint32_t *mem, int val)
37 {
38   static unsigned char lock;
39   int result;
40
41   __acquire_lock (lock);
42
43   result = *mem;
44   *mem += val;
45
46   __release_lock (lock);
47
48   return result;
49 }
50
51 static void
52 __attribute__ ((unused))
53 atomic_add (volatile uint32_t *mem, int val)
54 {
55   static unsigned char lock;
56
57   __acquire_lock (lock);
58
59   *mem += val;
60
61   __release_lock (lock);
62 }
63
64 static int
65 __attribute__ ((unused))
66 compare_and_swap (volatile long int *p, long int oldval, long int newval)
67 {
68   static unsigned char lock;
69   int ret;
70
71   __acquire_lock (lock);
72
73   if (*p != oldval)
74     ret = 0;
75   else
76     {
77       *p = newval;
78       ret = 1;
79     }
80
81   __release_lock (lock);
82
83   return ret;
84 }
85
86 #endif /* atomicity.h */