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_WIN32__ 00021 #define __JackAtomic_WIN32__ 00022 00023 #include "JackTypes.h" 00024 00025 #ifndef __MINGW32__ 00026 #ifdef __SMP__ 00027 # define LOCK lock 00028 #else 00029 # define LOCK 00030 #endif 00031 00032 #ifndef inline 00033 #define inline __inline 00034 #endif 00035 00036 //---------------------------------------------------------------- 00037 // CAS functions 00038 //---------------------------------------------------------------- 00039 inline char CAS(volatile UInt32 value, UInt32 newvalue, volatile void * addr) 00040 { 00041 register char c; 00042 __asm { 00043 push ebx 00044 push esi 00045 mov esi, addr 00046 mov eax, value 00047 mov ebx, newvalue 00048 LOCK cmpxchg dword ptr [esi], ebx 00049 sete c 00050 pop esi 00051 pop ebx 00052 } 00053 return c; 00054 } 00055 00056 #else 00057 00058 #define LOCK "lock ; " 00059 00060 static inline char CAS(volatile UInt32 value, UInt32 newvalue, volatile void* addr) 00061 { 00062 register char ret; 00063 __asm__ __volatile__ ( 00064 "# CAS \n\t" 00065 LOCK "cmpxchg %2, (%1) \n\t" 00066 "sete %0 \n\t" 00067 : "=a" (ret) 00068 : "c" (addr), "d" (newvalue), "a" (value) 00069 ); 00070 return ret; 00071 } 00072 00073 #endif 00074 00075 #endif 00076