Jack2 1.9.6
|
00001 /* 00002 Copyright (C) 2004-2008 Grame 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU Lesser General Public License as published by 00006 the Free Software Foundation; either version 2.1 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 */ 00019 00020 #ifndef __JackAtomic_linux__ 00021 #define __JackAtomic_linux__ 00022 00023 #include "JackTypes.h" 00024 00025 #ifdef __PPC__ 00026 00027 static inline int CAS(register UInt32 value, register UInt32 newvalue, register volatile void* addr) 00028 { 00029 register int result; 00030 register UInt32 tmp; 00031 asm volatile ( 00032 "# CAS \n" 00033 " lwarx %4, 0, %1 \n" // creates a reservation on addr 00034 " cmpw %4, %2 \n" // test value at addr 00035 " bne- 1f \n" 00036 " sync \n" // synchronize instructions 00037 " stwcx. %3, 0, %1 \n" // if the reservation is not altered 00038 // stores the new value at addr 00039 " bne- 1f \n" 00040 " li %0, 1 \n" 00041 " b 2f \n" 00042 "1: \n" 00043 " li %0, 0 \n" 00044 "2: \n" 00045 : "=r" (result) 00046 : "r" (addr), "r" (value), "r" (newvalue), "r" (tmp) 00047 ); 00048 return result; 00049 } 00050 00051 #endif 00052 00053 #if defined(__i386__) || defined(__x86_64__) 00054 00055 #define LOCK "lock ; " 00056 00057 static inline char CAS(volatile UInt32 value, UInt32 newvalue, volatile void* addr) 00058 { 00059 register char ret; 00060 __asm__ __volatile__ ( 00061 "# CAS \n\t" 00062 LOCK "cmpxchg %2, (%1) \n\t" 00063 "sete %0 \n\t" 00064 : "=a" (ret) 00065 : "c" (addr), "d" (newvalue), "a" (value) 00066 ); 00067 return ret; 00068 } 00069 00070 #endif 00071 00072 #if !defined(__i386__) && !defined(__x86_64__) && !defined(__PPC__) 00073 #warning using builtin gcc (version > 4.1) atomic 00074 00075 static inline char CAS(volatile UInt32 value, UInt32 newvalue, volatile void* addr) 00076 { 00077 return __sync_bool_compare_and_swap (&addr, value, newvalue); 00078 } 00079 #endif 00080 00081 00082 #endif 00083