2 |
Copyright (C) 2001 Paul Davis and others (see below) |
Copyright (C) 2001 Paul Davis and others (see below) |
3 |
Code derived from various headers from the Linux kernel. |
Code derived from various headers from the Linux kernel. |
4 |
Copyright attributions maintained where present. |
Copyright attributions maintained where present. |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
7 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
8 |
the Free Software Foundation; either version 2 of the License, or |
the Free Software Foundation; either version 2 of the License, or |
17 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
18 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
|
|
20 |
$Id: atomic.h,v 1.6 2008-09-06 16:44:42 persson Exp $ |
$Id: atomic.h,v 1.7 2008-11-16 19:19:26 persson Exp $ |
21 |
*/ |
*/ |
22 |
|
|
23 |
//TODO: should we put this into namespace? it might clash with system installed atomic.h, because we need to install atomic.h for the LS API |
//TODO: should we put this into namespace? it might clash with system installed atomic.h, because we need to install atomic.h for the LS API |
32 |
#define CONFIG_SMP /* ... the macro the kernel headers use */ |
#define CONFIG_SMP /* ... the macro the kernel headers use */ |
33 |
#endif |
#endif |
34 |
|
|
35 |
#if defined(linux) || defined(WIN32) |
#if defined(__linux__) || defined(WIN32) || defined(__APPLE__) |
36 |
#ifdef __powerpc__ |
#ifdef _ARCH_PPC |
37 |
|
|
38 |
/* |
/* |
39 |
* BK Id: SCCS/s.atomic.h 1.15 10/28/01 10:37:22 trini |
* BK Id: SCCS/s.atomic.h 1.15 10/28/01 10:37:22 trini |
42 |
* PowerPC atomic operations |
* PowerPC atomic operations |
43 |
*/ |
*/ |
44 |
|
|
45 |
#ifndef _ASM_PPC_ATOMIC_H_ |
#ifndef _ASM_PPC_ATOMIC_H_ |
46 |
#define _ASM_PPC_ATOMIC_H_ |
#define _ASM_PPC_ATOMIC_H_ |
47 |
|
|
48 |
typedef struct { volatile int counter; } atomic_t; |
typedef struct { volatile int counter; } atomic_t; |
67 |
int t; |
int t; |
68 |
|
|
69 |
__asm__ __volatile__( |
__asm__ __volatile__( |
70 |
"1: lwarx %0,0,%3 # atomic_add\n\ |
"1: lwarx %0,0,%3\n\ |
71 |
add %0,%2,%0\n\ |
add %0,%2,%0\n\ |
72 |
stwcx. %0,0,%3\n\ |
stwcx. %0,0,%3\n\ |
73 |
bne- 1b" |
bne- 1b" |
81 |
int t; |
int t; |
82 |
|
|
83 |
__asm__ __volatile__( |
__asm__ __volatile__( |
84 |
"1: lwarx %0,0,%2 # atomic_add_return\n\ |
"1: lwarx %0,0,%2\n\ |
85 |
add %0,%1,%0\n\ |
add %0,%1,%0\n\ |
86 |
stwcx. %0,0,%2\n\ |
stwcx. %0,0,%2\n\ |
87 |
bne- 1b" |
bne- 1b" |
98 |
int t; |
int t; |
99 |
|
|
100 |
__asm__ __volatile__( |
__asm__ __volatile__( |
101 |
"1: lwarx %0,0,%3 # atomic_sub\n\ |
"1: lwarx %0,0,%3\n\ |
102 |
subf %0,%2,%0\n\ |
subf %0,%2,%0\n\ |
103 |
stwcx. %0,0,%3\n\ |
stwcx. %0,0,%3\n\ |
104 |
bne- 1b" |
bne- 1b" |
112 |
int t; |
int t; |
113 |
|
|
114 |
__asm__ __volatile__( |
__asm__ __volatile__( |
115 |
"1: lwarx %0,0,%2 # atomic_sub_return\n\ |
"1: lwarx %0,0,%2\n\ |
116 |
subf %0,%1,%0\n\ |
subf %0,%1,%0\n\ |
117 |
stwcx. %0,0,%2\n\ |
stwcx. %0,0,%2\n\ |
118 |
bne- 1b" |
bne- 1b" |
129 |
int t; |
int t; |
130 |
|
|
131 |
__asm__ __volatile__( |
__asm__ __volatile__( |
132 |
"1: lwarx %0,0,%2 # atomic_inc\n\ |
"1: lwarx %0,0,%2\n\ |
133 |
addic %0,%0,1\n\ |
addic %0,%0,1\n\ |
134 |
stwcx. %0,0,%2\n\ |
stwcx. %0,0,%2\n\ |
135 |
bne- 1b" |
bne- 1b" |
143 |
int t; |
int t; |
144 |
|
|
145 |
__asm__ __volatile__( |
__asm__ __volatile__( |
146 |
"1: lwarx %0,0,%1 # atomic_inc_return\n\ |
"1: lwarx %0,0,%1\n\ |
147 |
addic %0,%0,1\n\ |
addic %0,%0,1\n\ |
148 |
stwcx. %0,0,%1\n\ |
stwcx. %0,0,%1\n\ |
149 |
bne- 1b" |
bne- 1b" |
160 |
int t; |
int t; |
161 |
|
|
162 |
__asm__ __volatile__( |
__asm__ __volatile__( |
163 |
"1: lwarx %0,0,%2 # atomic_dec\n\ |
"1: lwarx %0,0,%2\n\ |
164 |
addic %0,%0,-1\n\ |
addic %0,%0,-1\n\ |
165 |
stwcx. %0,0,%2\n\ |
stwcx. %0,0,%2\n\ |
166 |
bne- 1b" |
bne- 1b" |
174 |
int t; |
int t; |
175 |
|
|
176 |
__asm__ __volatile__( |
__asm__ __volatile__( |
177 |
"1: lwarx %0,0,%1 # atomic_dec_return\n\ |
"1: lwarx %0,0,%1\n\ |
178 |
addic %0,%0,-1\n\ |
addic %0,%0,-1\n\ |
179 |
stwcx. %0,0,%1\n\ |
stwcx. %0,0,%1\n\ |
180 |
bne- 1b" |
bne- 1b" |
198 |
int t; |
int t; |
199 |
|
|
200 |
__asm__ __volatile__( |
__asm__ __volatile__( |
201 |
"1: lwarx %0,0,%1 # atomic_dec_if_positive\n\ |
"1: lwarx %0,0,%1\n\ |
202 |
addic. %0,%0,-1\n\ |
addic. %0,%0,-1\n\ |
203 |
blt- 2f\n\ |
blt- 2f\n\ |
204 |
stwcx. %0,0,%1\n\ |
stwcx. %0,0,%1\n\ |
1238 |
|
|
1239 |
#else /* !linux */ |
#else /* !linux */ |
1240 |
|
|
|
#if defined(__APPLE__) |
|
|
|
|
|
typedef unsigned long atomic_t; |
|
|
|
|
|
#define ATOMIC_INIT(i) { (i) } |
|
|
#define atomic_set(a, v) (*(a) = (v)) |
|
|
#define atomic_read(a) (*(a)) |
|
|
|
|
|
/* TODO: should use atomic routines in CoreServices.framework */ |
|
|
#define atomic_inc(a) (++(*a)) |
|
|
#define atomic_dec(a) (--(*a)) |
|
|
|
|
|
#else |
|
|
|
|
1241 |
typedef unsigned long atomic_t; |
typedef unsigned long atomic_t; |
1242 |
|
|
1243 |
#if defined(__sgi) |
#if defined(__sgi) |
1280 |
#endif |
#endif |
1281 |
} |
} |
1282 |
|
|
|
#endif /* __APPLE__ */ |
|
1283 |
#endif /* linux */ |
#endif /* linux */ |
1284 |
#endif /* __linuxsampler_atomic_h__ */ |
#endif /* __linuxsampler_atomic_h__ */ |