5
* $Id: atomic_x86.h,v 1.8 2001/04/11 08:39:53 richi Exp $
7
* This code was taken from linux/include/asm-i386/atomic.h from the
8
* Linux kernel source code and adapted to the need of GLAME.
10
* Copyright (C) by Linus Torvalds and others
12
* This program is free software; you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation; either version 2 of the License, or
15
* (at your option) any later version.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
* Atomic operations that C can't guarantee us. Useful for
30
* resource counting etc..
34
* Make sure gcc doesn't try to be clever and move things around
35
* on us. We need to use _exactly_ the address the user gave us,
36
* not some alias that contains the same information.
38
typedef struct { volatile int counter; } glame_atomic_t;
40
#define ATOMIC_INIT(a, val) do { (a).counter = (val); } while(0)
42
#define ATOMIC_RELEASE(a)
44
#define ATOMIC_VAL(a) ((a).counter)
46
#define atomic_read(v) ((v)->counter)
47
#define atomic_set(v,i) (((v)->counter) = (i))
49
static inline void atomic_add(int i, volatile glame_atomic_t *v)
54
:"ir" (i), "m" (v->counter));
57
static inline void atomic_sub(int i, volatile glame_atomic_t *v)
62
:"ir" (i), "m" (v->counter));
65
static inline void atomic_inc(volatile glame_atomic_t *v)
73
static inline void atomic_dec(volatile glame_atomic_t *v)
81
static inline int atomic_dec_and_test(volatile glame_atomic_t *v)
86
"lock ; decl %0; sete %1"
87
:"=m" (v->counter), "=qm" (c)
88
:"m" (v->counter) : "memory");