/[svn]/linuxsampler/trunk/src/common/atomic.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/common/atomic.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1791 by persson, Sat Sep 6 16:44:42 2008 UTC revision 1792 by persson, Sun Nov 16 19:19:26 2008 UTC
# Line 2  Line 2 
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
# Line 17  Line 17 
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
# Line 32  Line 32 
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
# Line 42  Line 42 
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;
# Line 67  static __inline__ void atomic_add(int a, Line 67  static __inline__ void atomic_add(int a,
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"
# Line 81  static __inline__ int atomic_add_return( Line 81  static __inline__ int atomic_add_return(
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"
# Line 98  static __inline__ void atomic_sub(int a, Line 98  static __inline__ void atomic_sub(int a,
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"
# Line 112  static __inline__ int atomic_sub_return( Line 112  static __inline__ int atomic_sub_return(
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"
# Line 129  static __inline__ void atomic_inc(atomic Line 129  static __inline__ void atomic_inc(atomic
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"
# Line 143  static __inline__ int atomic_inc_return( Line 143  static __inline__ int atomic_inc_return(
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"
# Line 160  static __inline__ void atomic_dec(atomic Line 160  static __inline__ void atomic_dec(atomic
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"
# Line 174  static __inline__ int atomic_dec_return( Line 174  static __inline__ int atomic_dec_return(
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"
# Line 198  static __inline__ int atomic_dec_if_posi Line 198  static __inline__ int atomic_dec_if_posi
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\
# Line 1238  static __inline__ int atomic_inc_and_tes Line 1238  static __inline__ int atomic_inc_and_tes
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)
# Line 1294  atomic_dec (atomic_t * a) { Line 1280  atomic_dec (atomic_t * a) {
1280  #endif  #endif
1281  }  }
1282    
 #endif /* __APPLE__  */  
1283  #endif /* linux */  #endif /* linux */
1284  #endif /* __linuxsampler_atomic_h__ */  #endif /* __linuxsampler_atomic_h__ */

Legend:
Removed from v.1791  
changed lines
  Added in v.1792

  ViewVC Help
Powered by ViewVC