]>
Commit | Line | Data |
---|---|---|
d115c0d8 | 1 | /* Low-level functions for atomic operations. AM33 version. |
d4697bc9 | 2 | Copyright 1999-2014 Free Software Foundation, Inc. |
d115c0d8 AO |
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 | |
ab84e3ff PE |
18 | License along with the GNU C Library. If not, see |
19 | <http://www.gnu.org/licenses/>. */ | |
d115c0d8 AO |
20 | |
21 | #ifndef _ATOMICITY_H | |
22 | #define _ATOMICITY_H 1 | |
23 | ||
24 | #include <inttypes.h> | |
e054f494 | 25 | #include <stdint.h> |
d115c0d8 AO |
26 | |
27 | #define __acquire_lock(lock) \ | |
28 | __asm__ __volatile__("1: bset %1, (%0)\n\t" \ | |
29 | " beq 1b" \ | |
30 | : : "a" (&(lock)), "d" (1) \ | |
31 | : "memory") | |
32 | ||
33 | #define __release_lock(lock) lock = 0 | |
34 | ||
35 | static int | |
36 | __attribute__ ((unused)) | |
37 | exchange_and_add (volatile uint32_t *mem, int val) | |
38 | { | |
39 | static unsigned char lock; | |
40 | int result; | |
41 | ||
42 | __acquire_lock (lock); | |
43 | ||
44 | result = *mem; | |
45 | *mem += val; | |
46 | ||
47 | __release_lock (lock); | |
48 | ||
49 | return result; | |
50 | } | |
51 | ||
52 | static void | |
53 | __attribute__ ((unused)) | |
54 | atomic_add (volatile uint32_t *mem, int val) | |
55 | { | |
56 | static unsigned char lock; | |
57 | ||
58 | __acquire_lock (lock); | |
59 | ||
60 | *mem += val; | |
61 | ||
62 | __release_lock (lock); | |
63 | } | |
64 | ||
65 | static int | |
66 | __attribute__ ((unused)) | |
67 | compare_and_swap (volatile long int *p, long int oldval, long int newval) | |
68 | { | |
69 | static unsigned char lock; | |
70 | int ret; | |
71 | ||
72 | __acquire_lock (lock); | |
73 | ||
74 | if (*p != oldval) | |
75 | ret = 0; | |
76 | else | |
77 | { | |
78 | *p = newval; | |
79 | ret = 1; | |
80 | } | |
81 | ||
82 | __release_lock (lock); | |
83 | ||
84 | return ret; | |
85 | } | |
86 | ||
87 | #endif /* atomicity.h */ |