Updated the atomic API for better use cases
authorSam Lantinga <slouken@libsdl.org>
Sat, 15 Jan 2011 12:41:59 -0800
changeset 50033a95a2b93eb3
parent 5002 c5b9486688ce
child 5004 0c72ae7b7cb2
Updated the atomic API for better use cases
Android.mk
VisualC/SDL/SDL_VS2005.vcproj
VisualC/SDL/SDL_VS2008.vcproj
VisualC/SDL/SDL_VS2010.vcxproj
Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj
Xcode/SDL/SDL.xcodeproj/project.pbxproj
configure.in
include/SDL_atomic.h
src/atomic/SDL_atomic.c
src/atomic/SDL_spinlock.c
src/atomic/dummy/SDL_atomic.c
src/atomic/linux/SDL_atomic.c
src/atomic/macosx/SDL_atomic.c
src/atomic/qnx/SDL_atomic.c
src/atomic/win32/SDL_atomic.c
test/testatomic.c
     1.1 --- a/Android.mk	Sat Jan 15 12:34:43 2011 -0800
     1.2 +++ b/Android.mk	Sat Jan 15 12:41:59 2011 -0800
     1.3 @@ -16,6 +16,8 @@
     1.4  	$(subst $(LOCAL_PATH)/,, \
     1.5  	$(wildcard $(LOCAL_PATH)/src/*.c) \
     1.6  	$(wildcard $(LOCAL_PATH)/src/audio/*.c) \
     1.7 +	$(LOCAL_PATH)/src/atomic/SDL_atomic.c \
     1.8 +	$(LOCAL_PATH)/src/atomic/SDL_spinlock.c.arm \
     1.9  	$(wildcard $(LOCAL_PATH)/src/cpuinfo/*.c) \
    1.10  	$(wildcard $(LOCAL_PATH)/src/events/*.c) \
    1.11  	$(wildcard $(LOCAL_PATH)/src/file/*.c) \
    1.12 @@ -31,7 +33,6 @@
    1.13  	$(wildcard $(LOCAL_PATH)/src/video/android/*.c) \
    1.14  	$(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \
    1.15  	$(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \
    1.16 -	$(wildcard $(LOCAL_PATH)/src/atomic/dummy/*.c) \
    1.17  	$(wildcard $(LOCAL_PATH)/src/thread/pthread/*.c) \
    1.18  	$(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) \
    1.19  	$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c))
     2.1 --- a/VisualC/SDL/SDL_VS2005.vcproj	Sat Jan 15 12:34:43 2011 -0800
     2.2 +++ b/VisualC/SDL/SDL_VS2005.vcproj	Sat Jan 15 12:41:59 2011 -0800
     2.3 @@ -644,7 +644,11 @@
     2.4  			>
     2.5  		</File>
     2.6  		<File
     2.7 -			RelativePath="..\..\src\atomic\win32\SDL_atomic.c"
     2.8 +			RelativePath="..\..\src\atomic\SDL_atomic.c"
     2.9 +			>
    2.10 +		</File>
    2.11 +		<File
    2.12 +			RelativePath="..\..\src\atomic\SDL_spinlock.c"
    2.13  			>
    2.14  		</File>
    2.15  		<File
     3.1 --- a/VisualC/SDL/SDL_VS2008.vcproj	Sat Jan 15 12:34:43 2011 -0800
     3.2 +++ b/VisualC/SDL/SDL_VS2008.vcproj	Sat Jan 15 12:41:59 2011 -0800
     3.3 @@ -631,7 +631,11 @@
     3.4  			>
     3.5  		</File>
     3.6  		<File
     3.7 -			RelativePath="..\..\src\atomic\win32\SDL_atomic.c"
     3.8 +			RelativePath="..\..\src\atomic\SDL_atomic.c"
     3.9 +			>
    3.10 +		</File>
    3.11 +		<File
    3.12 +			RelativePath="..\..\src\atomic\SDL_spinlock.c"
    3.13  			>
    3.14  		</File>
    3.15  		<File
     4.1 --- a/VisualC/SDL/SDL_VS2010.vcxproj	Sat Jan 15 12:34:43 2011 -0800
     4.2 +++ b/VisualC/SDL/SDL_VS2010.vcxproj	Sat Jan 15 12:41:59 2011 -0800
     4.3 @@ -365,7 +365,8 @@
     4.4      <ClCompile Include="..\..\src\SDL.c" />
     4.5      <ClCompile Include="..\..\src\video\SDL_alphamult.c" />
     4.6      <ClCompile Include="..\..\src\SDL_assert.c" />
     4.7 -    <ClCompile Include="..\..\src\atomic\win32\SDL_atomic.c" />
     4.8 +    <ClCompile Include="..\..\src\atomic\SDL_atomic.c" />
     4.9 +    <ClCompile Include="..\..\src\atomic\SDL_spinlock.c" />
    4.10      <ClCompile Include="..\..\src\audio\SDL_audio.c" />
    4.11      <ClCompile Include="..\..\src\audio\SDL_audiocvt.c" />
    4.12      <ClCompile Include="..\..\src\audio\SDL_audiodev.c" />
    4.13 @@ -457,4 +458,4 @@
    4.14    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    4.15    <ImportGroup Label="ExtensionTargets">
    4.16    </ImportGroup>
    4.17 -</Project>
    4.18 \ No newline at end of file
    4.19 +</Project>
     5.1 --- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Sat Jan 15 12:34:43 2011 -0800
     5.2 +++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Sat Jan 15 12:41:59 2011 -0800
     5.3 @@ -93,7 +93,6 @@
     5.4  		04B2ECEC1025CE4800F9BC5F /* SDL_atomic.h in Headers */ = {isa = PBXBuildFile; fileRef = 04B2ECE61025CE4800F9BC5F /* SDL_atomic.h */; settings = {ATTRIBUTES = (Public, ); }; };
     5.5  		04B2ECED1025CE4800F9BC5F /* SDL_power.h in Headers */ = {isa = PBXBuildFile; fileRef = 04B2ECE71025CE4800F9BC5F /* SDL_power.h */; settings = {ATTRIBUTES = (Public, ); }; };
     5.6  		04B2ECEE1025CE4800F9BC5F /* SDL_revision.h in Headers */ = {isa = PBXBuildFile; fileRef = 04B2ECE81025CE4800F9BC5F /* SDL_revision.h */; settings = {ATTRIBUTES = (Public, ); }; };
     5.7 -		04B2ECFF1025CEB900F9BC5F /* SDL_atomic.c in Sources */ = {isa = PBXBuildFile; fileRef = 04B2ECF11025CEB900F9BC5F /* SDL_atomic.c */; };
     5.8  		04B2ED081025CF9E00F9BC5F /* SDL_config.h in Headers */ = {isa = PBXBuildFile; fileRef = 04B2ED061025CF9E00F9BC5F /* SDL_config.h */; settings = {ATTRIBUTES = (Public, ); }; };
     5.9  		04BA9D6311EF474A00B60E01 /* SDL_gesture_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D5F11EF474A00B60E01 /* SDL_gesture_c.h */; };
    5.10  		04BA9D6411EF474A00B60E01 /* SDL_gesture.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BA9D6011EF474A00B60E01 /* SDL_gesture.c */; };
    5.11 @@ -104,6 +103,11 @@
    5.12  		04EC8B521025D12900431D42 /* SDL_config_iphoneos.h in Headers */ = {isa = PBXBuildFile; fileRef = 04EC8B501025D12900431D42 /* SDL_config_iphoneos.h */; };
    5.13  		04F2AF541104ABC300D6DDF7 /* SDL_assert.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F2AF531104ABC300D6DDF7 /* SDL_assert.h */; };
    5.14  		04F2AF561104ABD200D6DDF7 /* SDL_assert.c in Sources */ = {isa = PBXBuildFile; fileRef = 04F2AF551104ABD200D6DDF7 /* SDL_assert.c */; };
    5.15 +		04FFAB8B12E23B8D00BA343D /* SDL_atomic.c in Sources */ = {isa = PBXBuildFile; fileRef = 04FFAB8912E23B8D00BA343D /* SDL_atomic.c */; };
    5.16 +		04FFAB8C12E23B8D00BA343D /* SDL_spinlock.c in Sources */ = {isa = PBXBuildFile; fileRef = 04FFAB8A12E23B8D00BA343D /* SDL_spinlock.c */; };
    5.17 +		04FFAB9612E23BDC00BA343D /* SDL_blendmode.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */; };
    5.18 +		04FFAB9712E23BDC00BA343D /* SDL_scalemode.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9412E23BDC00BA343D /* SDL_scalemode.h */; };
    5.19 +		04FFAB9812E23BDC00BA343D /* SDL_shape.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9512E23BDC00BA343D /* SDL_shape.h */; };
    5.20  		56ED04E1118A8EE200A56AA6 /* SDL_power.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E0118A8EE200A56AA6 /* SDL_power.c */; };
    5.21  		56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */; };
    5.22  		FD24846D0E5655AE0021E198 /* SDL_uikitkeyboard.h in Headers */ = {isa = PBXBuildFile; fileRef = FD24846B0E5655AE0021E198 /* SDL_uikitkeyboard.h */; };
    5.23 @@ -350,7 +354,6 @@
    5.24  		04B2ECE61025CE4800F9BC5F /* SDL_atomic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_atomic.h; path = ../../include/SDL_atomic.h; sourceTree = SOURCE_ROOT; };
    5.25  		04B2ECE71025CE4800F9BC5F /* SDL_power.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_power.h; path = ../../include/SDL_power.h; sourceTree = SOURCE_ROOT; };
    5.26  		04B2ECE81025CE4800F9BC5F /* SDL_revision.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_revision.h; path = ../../include/SDL_revision.h; sourceTree = SOURCE_ROOT; };
    5.27 -		04B2ECF11025CEB900F9BC5F /* SDL_atomic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_atomic.c; sourceTree = "<group>"; };
    5.28  		04B2ED061025CF9E00F9BC5F /* SDL_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_config.h; path = ../../include/SDL_config.h; sourceTree = SOURCE_ROOT; };
    5.29  		04BA9D5F11EF474A00B60E01 /* SDL_gesture_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_gesture_c.h; sourceTree = "<group>"; };
    5.30  		04BA9D6011EF474A00B60E01 /* SDL_gesture.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_gesture.c; sourceTree = "<group>"; };
    5.31 @@ -361,6 +364,11 @@
    5.32  		04EC8B501025D12900431D42 /* SDL_config_iphoneos.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_config_iphoneos.h; path = ../../include/SDL_config_iphoneos.h; sourceTree = SOURCE_ROOT; };
    5.33  		04F2AF531104ABC300D6DDF7 /* SDL_assert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_assert.h; path = ../../include/SDL_assert.h; sourceTree = SOURCE_ROOT; };
    5.34  		04F2AF551104ABD200D6DDF7 /* SDL_assert.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_assert.c; path = ../../src/SDL_assert.c; sourceTree = SOURCE_ROOT; };
    5.35 +		04FFAB8912E23B8D00BA343D /* SDL_atomic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_atomic.c; sourceTree = "<group>"; };
    5.36 +		04FFAB8A12E23B8D00BA343D /* SDL_spinlock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_spinlock.c; sourceTree = "<group>"; };
    5.37 +		04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_blendmode.h; path = ../../include/SDL_blendmode.h; sourceTree = SOURCE_ROOT; };
    5.38 +		04FFAB9412E23BDC00BA343D /* SDL_scalemode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_scalemode.h; path = ../../include/SDL_scalemode.h; sourceTree = SOURCE_ROOT; };
    5.39 +		04FFAB9512E23BDC00BA343D /* SDL_shape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_shape.h; path = ../../include/SDL_shape.h; sourceTree = SOURCE_ROOT; };
    5.40  		56ED04E0118A8EE200A56AA6 /* SDL_power.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_power.c; path = ../../src/power/SDL_power.c; sourceTree = SOURCE_ROOT; };
    5.41  		56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDL_syspower.m; path = ../../src/power/uikit/SDL_syspower.m; sourceTree = SOURCE_ROOT; };
    5.42  		FD0BBFEF0E3933DD00D833B1 /* SDL_uikitview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitview.h; sourceTree = "<group>"; };
    5.43 @@ -690,20 +698,13 @@
    5.44  		04B2ECEF1025CEB900F9BC5F /* atomic */ = {
    5.45  			isa = PBXGroup;
    5.46  			children = (
    5.47 -				04B2ECF01025CEB900F9BC5F /* dummy */,
    5.48 +				04FFAB8912E23B8D00BA343D /* SDL_atomic.c */,
    5.49 +				04FFAB8A12E23B8D00BA343D /* SDL_spinlock.c */,
    5.50  			);
    5.51  			name = atomic;
    5.52  			path = ../../src/atomic;
    5.53  			sourceTree = SOURCE_ROOT;
    5.54  		};
    5.55 -		04B2ECF01025CEB900F9BC5F /* dummy */ = {
    5.56 -			isa = PBXGroup;
    5.57 -			children = (
    5.58 -				04B2ECF11025CEB900F9BC5F /* SDL_atomic.c */,
    5.59 -			);
    5.60 -			path = dummy;
    5.61 -			sourceTree = "<group>";
    5.62 -		};
    5.63  		19C28FACFE9D520D11CA2CBB /* Products */ = {
    5.64  			isa = PBXGroup;
    5.65  			children = (
    5.66 @@ -848,6 +849,9 @@
    5.67  		FD99B8BC0DD52E5C00FB1D6B /* Public Headers */ = {
    5.68  			isa = PBXGroup;
    5.69  			children = (
    5.70 +				04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */,
    5.71 +				04FFAB9412E23BDC00BA343D /* SDL_scalemode.h */,
    5.72 +				04FFAB9512E23BDC00BA343D /* SDL_shape.h */,
    5.73  				FD99B8CC0DD52EB400FB1D6B /* begin_code.h */,
    5.74  				FD99B8CD0DD52EB400FB1D6B /* close_code.h */,
    5.75  				FD99B8F50DD52EB400FB1D6B /* SDL.h */,
    5.76 @@ -1213,6 +1217,9 @@
    5.77  				04BA9D6511EF474A00B60E01 /* SDL_touch_c.h in Headers */,
    5.78  				04BA9D7D11EF497E00B60E01 /* SDL_gesture.h in Headers */,
    5.79  				04BA9D7E11EF497E00B60E01 /* SDL_touch.h in Headers */,
    5.80 +				04FFAB9612E23BDC00BA343D /* SDL_blendmode.h in Headers */,
    5.81 +				04FFAB9712E23BDC00BA343D /* SDL_scalemode.h in Headers */,
    5.82 +				04FFAB9812E23BDC00BA343D /* SDL_shape.h in Headers */,
    5.83  			);
    5.84  			runOnlyForDeploymentPostprocessing = 0;
    5.85  		};
    5.86 @@ -1262,7 +1269,14 @@
    5.87  			isa = PBXProject;
    5.88  			buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SDLiPhoneOS" */;
    5.89  			compatibilityVersion = "Xcode 3.1";
    5.90 +			developmentRegion = English;
    5.91  			hasScannedForEncodings = 1;
    5.92 +			knownRegions = (
    5.93 +				English,
    5.94 +				Japanese,
    5.95 +				French,
    5.96 +				German,
    5.97 +			);
    5.98  			mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */;
    5.99  			projectDirPath = "";
   5.100  			projectRoot = ../..;
   5.101 @@ -1443,7 +1457,6 @@
   5.102  				046387440F0B5B7D0041FD65 /* SDL_drawline.c in Sources */,
   5.103  				046387450F0B5B7D0041FD65 /* SDL_drawpoint.c in Sources */,
   5.104  				046387460F0B5B7D0041FD65 /* SDL_fillrect.c in Sources */,
   5.105 -				04B2ECFF1025CEB900F9BC5F /* SDL_atomic.c in Sources */,
   5.106  				043DD76F10FD8A0000DED673 /* SDL_alphamult.c in Sources */,
   5.107  				043DD77110FD8A0000DED673 /* SDL_blendfillrect.c in Sources */,
   5.108  				043DD77210FD8A0000DED673 /* SDL_drawrect.c in Sources */,
   5.109 @@ -1455,6 +1468,8 @@
   5.110  				0420497111E6F03D007E7EC9 /* SDL_clipboardevents.c in Sources */,
   5.111  				04BA9D6411EF474A00B60E01 /* SDL_gesture.c in Sources */,
   5.112  				04BA9D6611EF474A00B60E01 /* SDL_touch.c in Sources */,
   5.113 +				04FFAB8B12E23B8D00BA343D /* SDL_atomic.c in Sources */,
   5.114 +				04FFAB8C12E23B8D00BA343D /* SDL_spinlock.c in Sources */,
   5.115  			);
   5.116  			runOnlyForDeploymentPostprocessing = 0;
   5.117  		};
     6.1 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj	Sat Jan 15 12:34:43 2011 -0800
     6.2 +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj	Sat Jan 15 12:41:59 2011 -0800
     6.3 @@ -150,8 +150,6 @@
     6.4  		00CFA68F106B44CE00758660 /* SDL_rect.h in Headers */ = {isa = PBXBuildFile; fileRef = 00CFA67F106B44CE00758660 /* SDL_rect.h */; };
     6.5  		00CFA690106B44CE00758660 /* SDL_scancode.h in Headers */ = {isa = PBXBuildFile; fileRef = 00CFA680106B44CE00758660 /* SDL_scancode.h */; };
     6.6  		00CFA691106B44CE00758660 /* SDL_surface.h in Headers */ = {isa = PBXBuildFile; fileRef = 00CFA681106B44CE00758660 /* SDL_surface.h */; };
     6.7 -		00CFA6A8106B467B00758660 /* SDL_atomic.c in Sources */ = {isa = PBXBuildFile; fileRef = 00CFA6A1106B467B00758660 /* SDL_atomic.c */; };
     6.8 -		00CFA6AD106B467B00758660 /* SDL_atomic.c in Sources */ = {isa = PBXBuildFile; fileRef = 00CFA6A1106B467B00758660 /* SDL_atomic.c */; };
     6.9  		00CFA6B6106B46E500758660 /* SDL_audio_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 00CFA6B0106B46E500758660 /* SDL_audio_c.h */; };
    6.10  		00CFA6B7106B46E500758660 /* SDL_audiodev_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 00CFA6B1106B46E500758660 /* SDL_audiodev_c.h */; };
    6.11  		00CFA6B8106B46E500758660 /* SDL_audiomem.h in Headers */ = {isa = PBXBuildFile; fileRef = 00CFA6B2106B46E500758660 /* SDL_audiomem.h */; };
    6.12 @@ -480,6 +478,10 @@
    6.13  		04F2AF671104AC0800D6DDF7 /* SDL_assert.c in Sources */ = {isa = PBXBuildFile; fileRef = 04F2AF651104AC0800D6DDF7 /* SDL_assert.c */; };
    6.14  		04F2AF691104AC4500D6DDF7 /* SDL_assert.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F2AF681104AC4500D6DDF7 /* SDL_assert.h */; settings = {ATTRIBUTES = (Public, ); }; };
    6.15  		04F2AF6A1104AC4500D6DDF7 /* SDL_assert.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F2AF681104AC4500D6DDF7 /* SDL_assert.h */; };
    6.16 +		04FB7D4C12E2350700A522C6 /* SDL_atomic.c in Sources */ = {isa = PBXBuildFile; fileRef = 04FB7D4A12E2350700A522C6 /* SDL_atomic.c */; };
    6.17 +		04FB7D4D12E2350700A522C6 /* SDL_spinlock.c in Sources */ = {isa = PBXBuildFile; fileRef = 04FB7D4B12E2350700A522C6 /* SDL_spinlock.c */; };
    6.18 +		04FB7D4E12E2350700A522C6 /* SDL_atomic.c in Sources */ = {isa = PBXBuildFile; fileRef = 04FB7D4A12E2350700A522C6 /* SDL_atomic.c */; };
    6.19 +		04FB7D4F12E2350700A522C6 /* SDL_spinlock.c in Sources */ = {isa = PBXBuildFile; fileRef = 04FB7D4B12E2350700A522C6 /* SDL_spinlock.c */; };
    6.20  		4537737D1207C4CE002F0F45 /* SDL_shape_internals.h in Headers */ = {isa = PBXBuildFile; fileRef = 4537737B1207C4CE002F0F45 /* SDL_shape_internals.h */; };
    6.21  		4537737E1207C4CE002F0F45 /* SDL_shape.c in Sources */ = {isa = PBXBuildFile; fileRef = 4537737C1207C4CE002F0F45 /* SDL_shape.c */; };
    6.22  		453773821207C518002F0F45 /* SDL_shape.h in Headers */ = {isa = PBXBuildFile; fileRef = 453773811207C518002F0F45 /* SDL_shape.h */; };
    6.23 @@ -656,7 +658,6 @@
    6.24  		00CFA67F106B44CE00758660 /* SDL_rect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_rect.h; path = ../../include/SDL_rect.h; sourceTree = SOURCE_ROOT; };
    6.25  		00CFA680106B44CE00758660 /* SDL_scancode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_scancode.h; path = ../../include/SDL_scancode.h; sourceTree = SOURCE_ROOT; };
    6.26  		00CFA681106B44CE00758660 /* SDL_surface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_surface.h; path = ../../include/SDL_surface.h; sourceTree = SOURCE_ROOT; };
    6.27 -		00CFA6A1106B467B00758660 /* SDL_atomic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_atomic.c; sourceTree = "<group>"; };
    6.28  		00CFA6B0106B46E500758660 /* SDL_audio_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_audio_c.h; sourceTree = "<group>"; };
    6.29  		00CFA6B1106B46E500758660 /* SDL_audiodev_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_audiodev_c.h; sourceTree = "<group>"; };
    6.30  		00CFA6B2106B46E500758660 /* SDL_audiomem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_audiomem.h; sourceTree = "<group>"; };
    6.31 @@ -861,6 +862,8 @@
    6.32  		04DEA57811E600A600386CAC /* SDL_cocoaclipboard.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_cocoaclipboard.m; sourceTree = "<group>"; };
    6.33  		04F2AF651104AC0800D6DDF7 /* SDL_assert.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_assert.c; path = ../../src/SDL_assert.c; sourceTree = SOURCE_ROOT; };
    6.34  		04F2AF681104AC4500D6DDF7 /* SDL_assert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_assert.h; path = ../../include/SDL_assert.h; sourceTree = SOURCE_ROOT; };
    6.35 +		04FB7D4A12E2350700A522C6 /* SDL_atomic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_atomic.c; sourceTree = "<group>"; };
    6.36 +		04FB7D4B12E2350700A522C6 /* SDL_spinlock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_spinlock.c; sourceTree = "<group>"; };
    6.37  		083E489D006D88D97F000001 /* SDL_joystick.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = SDL_joystick.c; sourceTree = "<group>"; };
    6.38  		0C5AF5E501191D2B7F000001 /* begin_code.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = begin_code.h; path = ../../include/begin_code.h; sourceTree = SOURCE_ROOT; };
    6.39  		0C5AF5E601191D2B7F000001 /* close_code.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = close_code.h; path = ../../include/close_code.h; sourceTree = SOURCE_ROOT; };
    6.40 @@ -1073,20 +1076,13 @@
    6.41  		00CFA69B106B467B00758660 /* atomic */ = {
    6.42  			isa = PBXGroup;
    6.43  			children = (
    6.44 -				00CFA6A0106B467B00758660 /* macosx */,
    6.45 +				04FB7D4A12E2350700A522C6 /* SDL_atomic.c */,
    6.46 +				04FB7D4B12E2350700A522C6 /* SDL_spinlock.c */,
    6.47  			);
    6.48  			name = atomic;
    6.49  			path = ../../src/atomic;
    6.50  			sourceTree = SOURCE_ROOT;
    6.51  		};
    6.52 -		00CFA6A0106B467B00758660 /* macosx */ = {
    6.53 -			isa = PBXGroup;
    6.54 -			children = (
    6.55 -				00CFA6A1106B467B00758660 /* SDL_atomic.c */,
    6.56 -			);
    6.57 -			path = macosx;
    6.58 -			sourceTree = "<group>";
    6.59 -		};
    6.60  		00CFA6DF106B48D800758660 /* haptic */ = {
    6.61  			isa = PBXGroup;
    6.62  			children = (
    6.63 @@ -2273,7 +2269,6 @@
    6.64  				002F32E509CA0BF600EBEB88 /* SDL_dummyaudio.c in Sources */,
    6.65  				046B91EC0A11B53500FB151C /* SDL_sysloadso.c in Sources */,
    6.66  				046B92130A11B8AD00FB151C /* SDL_dlcompat.c in Sources */,
    6.67 -				00CFA6A8106B467B00758660 /* SDL_atomic.c in Sources */,
    6.68  				00CFA6B9106B46E500758660 /* SDL_audiotypecvt.c in Sources */,
    6.69  				00CFA6CD106B480800758660 /* SDL_windowevents.c in Sources */,
    6.70  				00CFA6EC106B48D800758660 /* SDL_syshaptic.c in Sources */,
    6.71 @@ -2357,6 +2352,8 @@
    6.72  				4537738A1207C5A2002F0F45 /* SDL_cocoashape.m in Sources */,
    6.73  				453773921207C6E9002F0F45 /* SDL_x11shape.c in Sources */,
    6.74  				046B9B6812D02EE600159CFE /* SDL_x11touch.c in Sources */,
    6.75 +				04FB7D4C12E2350700A522C6 /* SDL_atomic.c in Sources */,
    6.76 +				04FB7D4D12E2350700A522C6 /* SDL_spinlock.c in Sources */,
    6.77  			);
    6.78  			runOnlyForDeploymentPostprocessing = 0;
    6.79  		};
    6.80 @@ -2399,7 +2396,6 @@
    6.81  				002F32E709CA0BF600EBEB88 /* SDL_dummyaudio.c in Sources */,
    6.82  				046B91ED0A11B53500FB151C /* SDL_sysloadso.c in Sources */,
    6.83  				046B92140A11B8AD00FB151C /* SDL_dlcompat.c in Sources */,
    6.84 -				00CFA6AD106B467B00758660 /* SDL_atomic.c in Sources */,
    6.85  				00CFA6BF106B46E500758660 /* SDL_audiotypecvt.c in Sources */,
    6.86  				00CFA6D3106B480800758660 /* SDL_windowevents.c in Sources */,
    6.87  				00CFA6F3106B48D800758660 /* SDL_syshaptic.c in Sources */,
    6.88 @@ -2477,6 +2473,8 @@
    6.89  				04DEA57C11E600A600386CAC /* SDL_cocoaclipboard.m in Sources */,
    6.90  				0420496411E6EFD3007E7EC9 /* SDL_clipboardevents.c in Sources */,
    6.91  				046B9B6A12D02EE600159CFE /* SDL_x11touch.c in Sources */,
    6.92 +				04FB7D4E12E2350700A522C6 /* SDL_atomic.c in Sources */,
    6.93 +				04FB7D4F12E2350700A522C6 /* SDL_spinlock.c in Sources */,
    6.94  			);
    6.95  			runOnlyForDeploymentPostprocessing = 0;
    6.96  		};
     7.1 --- a/configure.in	Sat Jan 15 12:34:43 2011 -0800
     7.2 +++ b/configure.in	Sat Jan 15 12:41:59 2011 -0800
     7.3 @@ -288,6 +288,7 @@
     7.4  # Standard C sources
     7.5  SOURCES="$SOURCES $srcdir/src/*.c"
     7.6  SOURCES="$SOURCES $srcdir/src/audio/*.c"
     7.7 +SOURCES="$SOURCES $srcdir/src/atomic/*.c"
     7.8  SOURCES="$SOURCES $srcdir/src/cpuinfo/*.c"
     7.9  SOURCES="$SOURCES $srcdir/src/events/*.c"
    7.10  SOURCES="$SOURCES $srcdir/src/file/*.c"
    7.11 @@ -2303,16 +2304,6 @@
    7.12              ;;
    7.13            esac
    7.14          fi
    7.15 -        # Set up files for the atomic operations library
    7.16 -        if test x$enable_atomic = xyes; then
    7.17 -          case $ARCH in
    7.18 -            linux)
    7.19 -                AC_DEFINE(SDL_ATOMIC_LINUX)
    7.20 -                SOURCES="$SOURCES $srcdir/src/atomic/linux/*.c"
    7.21 -                have_atomic=yes
    7.22 -            ;;
    7.23 -          esac
    7.24 -        fi
    7.25          # Set up files for the joystick library
    7.26          if test x$enable_joystick = xyes; then
    7.27            case $ARCH in
    7.28 @@ -2395,12 +2386,6 @@
    7.29              SOURCES="$SOURCES $srcdir/src/timer/unix/*.c"
    7.30              have_timers=yes
    7.31          fi
    7.32 -        # Setup files for the atomic operations
    7.33 -        if test x$enable_atomic = xyes; then
    7.34 -                AC_DEFINE(SDL_ATOMIC_QNX)
    7.35 -                SOURCES="$SOURCES $srcdir/src/atomic/qnx/*.c"
    7.36 -                have_atomic=yes
    7.37 -        fi
    7.38          # Set up dummy files for the joystick for now
    7.39          if test x$enable_joystick = xyes; then
    7.40              AC_DEFINE(SDL_JOYSTICK_DUMMY)
    7.41 @@ -2460,12 +2445,6 @@
    7.42              fi
    7.43              have_audio=yes
    7.44          fi
    7.45 -        # Set up files for the atomic operations library
    7.46 -        if test x$enable_atomic = xyes; then
    7.47 -            AC_DEFINE(SDL_ATOMIC_WIN32)
    7.48 -            SOURCES="$SOURCES $srcdir/src/atomic/win32/*.c"
    7.49 -            have_atomic=yes
    7.50 -        fi
    7.51          # Set up dummy files for the joystick for now
    7.52          if test x$enable_joystick = xyes; then
    7.53              AC_DEFINE(SDL_JOYSTICK_DUMMY)
    7.54 @@ -2555,12 +2534,6 @@
    7.55              fi
    7.56              have_audio=yes
    7.57          fi
    7.58 -        # Set up files for the atomic operations library
    7.59 -        if test x$enable_atomic = xyes; then
    7.60 -            AC_DEFINE(SDL_ATOMIC_WIN32)
    7.61 -            SOURCES="$SOURCES $srcdir/src/atomic/win32/*.c"
    7.62 -            have_atomic=yes
    7.63 -        fi
    7.64          # Set up files for the joystick library
    7.65          if test x$enable_joystick = xyes; then
    7.66              if test x$have_dinput = xyes; then
    7.67 @@ -2715,12 +2688,6 @@
    7.68              SOURCES="$SOURCES $srcdir/src/audio/macosx/*.c"
    7.69              have_audio=yes
    7.70          fi
    7.71 -        # Set up files for the atomic operations library
    7.72 -        if test x$enable_atomic = xyes; then
    7.73 -            AC_DEFINE(SDL_ATOMIC_MACOSX)
    7.74 -            SOURCES="$SOURCES $srcdir/src/atomic/macosx/*.c"
    7.75 -            have_atomic=yes
    7.76 -        fi
    7.77          # Set up files for the joystick library
    7.78          if test x$enable_joystick = xyes; then
    7.79              AC_DEFINE(SDL_JOYSTICK_IOKIT)
    7.80 @@ -2826,12 +2793,6 @@
    7.81      fi
    7.82      SOURCES="$SOURCES $srcdir/src/loadso/dummy/*.c"
    7.83  fi
    7.84 -if test x$have_atomic != xyes; then
    7.85 -    if test x$enable_atomic = xyes; then
    7.86 -        AC_DEFINE(SDL_ATOMIC_DISABLED)
    7.87 -    fi
    7.88 -    SOURCES="$SOURCES $srcdir/src/atomic/dummy/*.c"
    7.89 -fi
    7.90  if test x$SDLMAIN_SOURCES = x; then
    7.91      SDLMAIN_SOURCES="$srcdir/src/main/dummy/*.c"
    7.92  fi
     8.1 --- a/include/SDL_atomic.h	Sat Jan 15 12:34:43 2011 -0800
     8.2 +++ b/include/SDL_atomic.h	Sat Jan 15 12:41:59 2011 -0800
     8.3 @@ -18,24 +18,34 @@
     8.4  
     8.5      Sam Lantinga
     8.6      slouken@libsdl.org
     8.7 -
     8.8 -    Contributed by Bob Pendleton, bob@pendleton.com
     8.9   */
    8.10  
    8.11  /**
    8.12 - *  \file SDL_atomic.h
    8.13 - *  
    8.14 - *  Atomic operations.
    8.15 - *  
    8.16 - *  These operations may, or may not, actually be implemented using
    8.17 - *  processor specific atomic operations. When possible they are
    8.18 - *  implemented as true processor specific atomic operations. When that
    8.19 - *  is not possible the are implemented using locks that *do* use the
    8.20 - *  available atomic operations.
    8.21 - *  
    8.22 - *  At the very minimum spin locks must be implemented. Without spin
    8.23 - *  locks it is not possible (AFAICT) to emulate the rest of the atomic
    8.24 - *  operations.
    8.25 + * \file SDL_atomic.h
    8.26 + * 
    8.27 + * Atomic operations.
    8.28 + * 
    8.29 + * IMPORTANT:
    8.30 + * If you are not an expert in concurrent lockless programming, you should
    8.31 + * only be using the atomic lock and reference counting functions in this
    8.32 + * file.  In all other cases you should be protecting your data structures
    8.33 + * with full mutexes.
    8.34 + * 
    8.35 + * The list of "safe" functions to use are:
    8.36 + *  SDL_AtomicLock()
    8.37 + *  SDL_AtomicUnlock()
    8.38 + *  SDL_AtomicIncRef()
    8.39 + *  SDL_AtomicDecRef()
    8.40 + * 
    8.41 + * Seriously, here be dragons!
    8.42 + *
    8.43 + * These operations may, or may not, actually be implemented using
    8.44 + * processor specific atomic operations. When possible they are
    8.45 + * implemented as true processor specific atomic operations. When that
    8.46 + * is not possible the are implemented using locks that *do* use the
    8.47 + * available atomic operations.
    8.48 + *
    8.49 + * All of the atomic operations that modify memory are full memory barriers.
    8.50   */
    8.51  
    8.52  #ifndef _SDL_atomic_h_
    8.53 @@ -53,154 +63,138 @@
    8.54  /* *INDENT-ON* */
    8.55  #endif
    8.56  
    8.57 -/* Function prototypes */
    8.58 -
    8.59  /**
    8.60 - *  \name SDL AtomicLock
    8.61 - *  
    8.62 - *  The spin lock functions and type are required and can not be
    8.63 - *  emulated because they are used in the emulation code.
    8.64 + * \name SDL AtomicLock
    8.65 + * 
    8.66 + * The atomic locks are efficient spinlocks using CPU instructions,
    8.67 + * but are vulnerable to starvation and can spin forever if a thread
    8.68 + * holding a lock has been terminated.  For this reason you should
    8.69 + * minimize the code executed inside an atomic lock and never do
    8.70 + * expensive things like API or system calls while holding them.
    8.71 + *
    8.72 + * The atomic locks are not safe to lock recursively.
    8.73 + *
    8.74 + * Porting Note:
    8.75 + * The spin lock functions and type are required and can not be
    8.76 + * emulated because they are used in the atomic emulation code.
    8.77   */
    8.78  /*@{*/
    8.79  
    8.80 -typedef volatile Uint32 SDL_SpinLock;
    8.81 +typedef int SDL_SpinLock;
    8.82  
    8.83  /**
    8.84 - *  \brief Lock a spin lock by setting it to a none zero value.
    8.85 - *  
    8.86 - *  \param lock Points to the lock.
    8.87 + * \brief Try to lock a spin lock by setting it to a non-zero value.
    8.88 + * 
    8.89 + * \param lock Points to the lock.
    8.90 + *
    8.91 + * \return SDL_TRUE if the lock succeeded, SDL_FALSE if the lock is already held.
    8.92 + */
    8.93 +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTryLock(SDL_SpinLock *lock);
    8.94 +
    8.95 +/**
    8.96 + * \brief Lock a spin lock by setting it to a non-zero value.
    8.97 + * 
    8.98 + * \param lock Points to the lock.
    8.99   */
   8.100  extern DECLSPEC void SDLCALL SDL_AtomicLock(SDL_SpinLock *lock);
   8.101  
   8.102  /**
   8.103 - *  \brief Unlock a spin lock by setting it to 0. Always returns immediately
   8.104 + * \brief Unlock a spin lock by setting it to 0. Always returns immediately
   8.105   *
   8.106 - *  \param lock Points to the lock.
   8.107 + * \param lock Points to the lock.
   8.108   */
   8.109  extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock);
   8.110  
   8.111  /*@}*//*SDL AtomicLock*/
   8.112  
   8.113 -/**
   8.114 - *  \name 32 bit atomic operations
   8.115 - */
   8.116 -/*@{*/
   8.117 +/* Platform specific optimized versions of the atomic functions */
   8.118 +/* None yet... */
   8.119  
   8.120  /**
   8.121 - *  \brief Check to see if \c *ptr == 0 and set it to 1.
   8.122 - *  
   8.123 - *  \return SDL_True if the value pointed to by \c ptr was zero and
   8.124 - *          SDL_False if it was not zero
   8.125 - *  
   8.126 - *  \param ptr Points to the value to be tested and set.
   8.127 + * \brief A type representing an atomic integer value.  It is a struct
   8.128 + *        so people don't accidentally use numeric operations on it.
   8.129   */
   8.130 -extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTestThenSet32(volatile Uint32 * ptr);
   8.131 +#ifndef SDL_atomic_t_defined
   8.132 +typedef struct { int value; } SDL_atomic_t;
   8.133 +#endif
   8.134  
   8.135  /**
   8.136 - *  \brief Set the value pointed to by \c ptr to be zero.
   8.137 - *  
   8.138 - *  \param ptr Address of the value to be set to zero
   8.139 + * \brief Set an atomic variable to a value.
   8.140 + *
   8.141 + * \return The previous value of the atomic variable.
   8.142   */
   8.143 -extern DECLSPEC void SDLCALL SDL_AtomicClear32(volatile Uint32 * ptr);
   8.144 +#ifndef SDL_AtomicSet
   8.145 +extern DECLSPEC int SDLCALL SDL_AtomicSet(SDL_atomic_t *a, int value);
   8.146 +#endif
   8.147  
   8.148  /**
   8.149 - *  \brief Fetch the current value of \c *ptr and then increment that
   8.150 - *         value in place.
   8.151 - *  
   8.152 - *  \return The value before it was incremented.
   8.153 - *  
   8.154 - *  \param ptr Address of the value to fetch and increment
   8.155 + * \brief Get the value of an atomic variable
   8.156   */
   8.157 -extern DECLSPEC Uint32 SDLCALL SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr);
   8.158 +#ifndef SDL_AtomicGet
   8.159 +extern DECLSPEC int SDLCALL SDL_AtomicGet(SDL_atomic_t *a);
   8.160 +#endif
   8.161  
   8.162  /**
   8.163 - *  \brief Fetch \c *ptr and then decrement the value in place.
   8.164 - *  
   8.165 - *  \return The value before it was decremented.
   8.166 - *  
   8.167 - *  \param ptr Address of the value to fetch and decrement
   8.168 + * \brief  Add to an atomic variable.
   8.169 + *
   8.170 + * \return The previous value of the atomic variable.
   8.171   */
   8.172 -extern DECLSPEC Uint32 SDLCALL SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr);
   8.173 +#ifndef SDL_AtomicAdd
   8.174 +extern DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_atomic_t *a, int value);
   8.175 +#endif
   8.176  
   8.177  /**
   8.178 - *  \brief Fetch the current value at \c ptr and then add \c value to \c *ptr.
   8.179 - *  
   8.180 - *  \return \c *ptr before the addition took place.
   8.181 - *  
   8.182 - *  \param ptr The address of data we are changing.
   8.183 - *  \param value The value to add to \c *ptr. 
   8.184 + * \brief Increment an atomic variable used as a reference count.
   8.185   */
   8.186 -extern DECLSPEC Uint32 SDLCALL SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value);
   8.187 +#ifndef SDL_AtomicIncRef
   8.188 +extern DECLSPEC void SDLCALL SDL_AtomicIncRef(SDL_atomic_t *a);
   8.189 +#endif
   8.190  
   8.191  /**
   8.192 - *  \brief Fetch \c *ptr and then subtract \c value from it.
   8.193 - *  
   8.194 - *  \return \c *ptr before the subtraction took place.
   8.195 - *  
   8.196 - *  \param ptr The address of the data being changed.
   8.197 - *  \param value The value to subtract from \c *ptr.
   8.198 + * \brief Decrement an atomic variable used as a reference count.
   8.199 + *
   8.200 + * \return SDL_TRUE if the variable has reached zero after decrementing,
   8.201 + *         SDL_FALSE otherwise
   8.202   */
   8.203 -extern DECLSPEC Uint32 SDLCALL SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value);
   8.204 +#ifndef SDL_AtomicDecRef
   8.205 +extern DECLSPEC SDL_bool SDLCALL SDL_AtomicDecRef(SDL_atomic_t *a);
   8.206 +#endif
   8.207  
   8.208  /**
   8.209 - *  \brief Add one to the data pointed to by \c ptr and return that value.
   8.210 - *  
   8.211 - *  \return The incremented value.
   8.212 - *  
   8.213 - *  \param ptr The address of the data to increment.
   8.214 - */
   8.215 -extern DECLSPEC Uint32 SDLCALL SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr);
   8.216 + * \brief Set an atomic variable to a new value if it is currently an old value.
   8.217 + *
   8.218 + * \return The previous value of the atomic variable
   8.219 + *
   8.220 + * \note If you don't know what this function is for, you shouldn't use it!
   8.221 +*/
   8.222 +#ifndef SDL_AtomicCAS
   8.223 +extern DECLSPEC int SDLCALL SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval);
   8.224 +#endif
   8.225  
   8.226  /**
   8.227 - *  \brief Subtract one from data pointed to by \c ptr and return the new value.
   8.228 - *  
   8.229 - *  \return The decremented value.
   8.230 - *  
   8.231 - *  \param ptr The address of the data to decrement.
   8.232 + * \brief Set a pointer to a value atomically.
   8.233   */
   8.234 -extern DECLSPEC Uint32 SDLCALL SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr);
   8.235 +#ifndef SDL_AtomicSetPtr
   8.236 +extern DECLSPEC void SDLCALL SDL_AtomicSetPtr(void** a, void* value);
   8.237 +#endif
   8.238  
   8.239  /**
   8.240 - *  \brief Add \c value to the data pointed to by \c ptr and return result.
   8.241 - *  
   8.242 - *  \return The sum of \c *ptr and \c value.
   8.243 - *  
   8.244 - *  \param ptr The address of the data to be modified.
   8.245 - *  \param value The value to be added.
   8.246 + * \brief Get the value of a pointer atomically.
   8.247   */
   8.248 -extern DECLSPEC Uint32 SDLCALL SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value);
   8.249 +#ifndef SDL_AtomicGetPtr
   8.250 +extern DECLSPEC void* SDLCALL SDL_AtomicGetPtr(void** a);
   8.251 +#endif
   8.252  
   8.253  /**
   8.254 - *  \brief Subtract \c value from the data pointed to by \c ptr and return the result.
   8.255 - *  
   8.256 - *  \return The difference between \c *ptr and \c value.
   8.257 - *  
   8.258 - *  \param ptr The address of the data to be modified.
   8.259 - *  \param value The value to be subtracted.
   8.260 - */
   8.261 -extern DECLSPEC Uint32 SDLCALL SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value);
   8.262 -
   8.263 -/*@}*//*32 bit atomic operations*/
   8.264 -
   8.265 -/**
   8.266 - *  \name 64 bit atomic operations
   8.267 - */
   8.268 -/*@{*/
   8.269 -#ifdef SDL_HAS_64BIT_TYPE
   8.270 -
   8.271 -extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTestThenSet64(volatile Uint64 * ptr);
   8.272 -extern DECLSPEC void SDLCALL SDL_AtomicClear64(volatile Uint64 * ptr);
   8.273 -extern DECLSPEC Uint64 SDLCALL SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr);
   8.274 -extern DECLSPEC Uint64 SDLCALL SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr);
   8.275 -extern DECLSPEC Uint64 SDLCALL SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value);
   8.276 -extern DECLSPEC Uint64 SDLCALL SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value);
   8.277 -extern DECLSPEC Uint64 SDLCALL SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr);
   8.278 -extern DECLSPEC Uint64 SDLCALL SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr);
   8.279 -extern DECLSPEC Uint64 SDLCALL SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value);
   8.280 -extern DECLSPEC Uint64 SDLCALL SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value);
   8.281 -#endif /*  SDL_HAS_64BIT_TYPE */
   8.282 -
   8.283 -/*@}*//*64 bit atomic operations*/
   8.284 + * \brief Set a pointer to a new value if it is currently an old value.
   8.285 + *
   8.286 + * \return The previous value of the pointer
   8.287 + *
   8.288 + * \note If you don't know what this function is for, you shouldn't use it!
   8.289 +*/
   8.290 +#ifndef SDL_AtomicCASPtr
   8.291 +extern DECLSPEC void* SDLCALL SDL_AtomicCASPtr(void **a, void *oldval, void *newval);
   8.292 +#endif
   8.293  
   8.294  /* Ends C function definitions when using C++ */
   8.295  #ifdef __cplusplus
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/atomic/SDL_atomic.c	Sat Jan 15 12:41:59 2011 -0800
     9.3 @@ -0,0 +1,179 @@
     9.4 +/*
     9.5 +  SDL - Simple DirectMedia Layer
     9.6 +  Copyright (C) 1997-2010 Sam Lantinga
     9.7 +
     9.8 +  This library is free software; you can redistribute it and/or
     9.9 +  modify it under the terms of the GNU Lesser General Public
    9.10 +  License as published by the Free Software Foundation; either
    9.11 +  version 2.1 of the License, or (at your option) any later version.
    9.12 +
    9.13 +  This library is distributed in the hope that it will be useful,
    9.14 +  but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +  Lesser General Public License for more details.
    9.17 +
    9.18 +  You should have received a copy of the GNU Lesser General Public
    9.19 +  License along with this library; if not, write to the Free Software
    9.20 +  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    9.21 +
    9.22 +  Sam Lantinga
    9.23 +  slouken@libsdl.org
    9.24 +*/
    9.25 +#include "SDL_stdinc.h"
    9.26 +
    9.27 +#include "SDL_atomic.h"
    9.28 +
    9.29 +/* 
    9.30 +  If any of the operations are not provided then we must emulate some
    9.31 +  of them. That means we need a nice implementation of spin locks
    9.32 +  that avoids the "one big lock" problem. We use a vector of spin
    9.33 +  locks and pick which one to use based on the address of the operand
    9.34 +  of the function.
    9.35 +
    9.36 +  To generate the index of the lock we first shift by 3 bits to get
    9.37 +  rid on the zero bits that result from 32 and 64 bit allignment of
    9.38 +  data. We then mask off all but 5 bits and use those 5 bits as an
    9.39 +  index into the table. 
    9.40 +
    9.41 +  Picking the lock this way insures that accesses to the same data at
    9.42 +  the same time will go to the same lock. OTOH, accesses to different
    9.43 +  data have only a 1/32 chance of hitting the same lock. That should
    9.44 +  pretty much eliminate the chances of several atomic operations on
    9.45 +  different data from waiting on the same "big lock". If it isn't
    9.46 +  then the table of locks can be expanded to a new size so long as
    9.47 +  the new size is a power of two.
    9.48 +
    9.49 +  Contributed by Bob Pendleton, bob@pendleton.com
    9.50 +*/
    9.51 +
    9.52 +static SDL_SpinLock locks[32];
    9.53 +
    9.54 +static __inline__ void
    9.55 +enterLock(void *a)
    9.56 +{
    9.57 +   uintptr_t index = ((((uintptr_t)a) >> 3) & 0x1f);
    9.58 +
    9.59 +   SDL_AtomicLock(&locks[index]);
    9.60 +}
    9.61 +
    9.62 +static __inline__ void
    9.63 +leaveLock(void *a)
    9.64 +{
    9.65 +   uintptr_t index = ((((uintptr_t)a) >> 3) & 0x1f);
    9.66 +
    9.67 +   SDL_AtomicUnlock(&locks[index]);
    9.68 +}
    9.69 +
    9.70 +#ifndef SDL_AtomicSet
    9.71 +int
    9.72 +SDL_AtomicSet(SDL_atomic_t *a, int value)
    9.73 +{
    9.74 +    int oldvalue;
    9.75 +
    9.76 +    enterLock(a);
    9.77 +    oldvalue = a->value;
    9.78 +    a->value = value;
    9.79 +    leaveLock(a);
    9.80 +
    9.81 +    return oldvalue;
    9.82 +}
    9.83 +#endif
    9.84 +
    9.85 +#ifndef SDL_AtomicGet
    9.86 +int
    9.87 +SDL_AtomicGet(SDL_atomic_t *a)
    9.88 +{
    9.89 +    /* Assuming integral reads on this platform, we're safe here since the
    9.90 +       functions that set the variable have the necessary memory barriers.
    9.91 +    */
    9.92 +    return a->value;
    9.93 +}
    9.94 +#endif
    9.95 +
    9.96 +#ifndef SDL_AtomicAdd
    9.97 +int
    9.98 +SDL_AtomicAdd(SDL_atomic_t *a, int value)
    9.99 +{
   9.100 +    int oldvalue;
   9.101 +
   9.102 +    enterLock(a);
   9.103 +    oldvalue = a->value;
   9.104 +    a->value += value;
   9.105 +    leaveLock(a);
   9.106 +
   9.107 +    return oldvalue;
   9.108 +}
   9.109 +#endif
   9.110 +
   9.111 +#ifndef SDL_AtomicIncRef
   9.112 +void
   9.113 +SDL_AtomicIncRef(SDL_atomic_t *a)
   9.114 +{
   9.115 +    SDL_AtomicAdd(a, 1);
   9.116 +}
   9.117 +#endif
   9.118 +
   9.119 +#ifndef SDL_AtomicDecRef
   9.120 +SDL_bool
   9.121 +SDL_AtomicDecRef(SDL_atomic_t *a)
   9.122 +{
   9.123 +    return SDL_AtomicAdd(a, -1) == 1;
   9.124 +}
   9.125 +#endif
   9.126 +
   9.127 +#ifndef SDL_AtomicCAS
   9.128 +int
   9.129 +SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
   9.130 +{
   9.131 +    int prevval;
   9.132 +
   9.133 +    enterLock(a);
   9.134 +    prevval = a->value;
   9.135 +    if (prevval == oldval) {
   9.136 +        a->value = newval;
   9.137 +    }
   9.138 +    leaveLock(a);
   9.139 +
   9.140 +    return prevval;
   9.141 +}
   9.142 +#endif
   9.143 +
   9.144 +#ifndef SDL_AtomicSetPtr
   9.145 +void
   9.146 +SDL_AtomicSetPtr(void** a, void* value)
   9.147 +{
   9.148 +    void *prevval;
   9.149 +    do {
   9.150 +        prevval = *a;
   9.151 +    } while (SDL_AtomicCASPtr(a, prevval, value) != prevval);
   9.152 +}
   9.153 +#endif
   9.154 +
   9.155 +#ifndef SDL_AtomicGetPtr
   9.156 +void*
   9.157 +SDL_AtomicGetPtr(void** a)
   9.158 +{
   9.159 +    /* Assuming integral reads on this platform, we're safe here since the
   9.160 +       functions that set the pointer have the necessary memory barriers.
   9.161 +    */
   9.162 +    return *a;
   9.163 +}
   9.164 +#endif
   9.165 +
   9.166 +#ifndef SDL_AtomicCASPtr
   9.167 +void* SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
   9.168 +{
   9.169 +    void *prevval;
   9.170 +
   9.171 +    enterLock(a);
   9.172 +    prevval = *a;
   9.173 +    if (*a == oldval) {
   9.174 +        *a = newval;
   9.175 +    }
   9.176 +    leaveLock(a);
   9.177 +
   9.178 +    return prevval;
   9.179 +}
   9.180 +#endif
   9.181 +
   9.182 +/* vi: set ts=4 sw=4 expandtab: */
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/atomic/SDL_spinlock.c	Sat Jan 15 12:41:59 2011 -0800
    10.3 @@ -0,0 +1,99 @@
    10.4 +/*
    10.5 +  SDL - Simple DirectMedia Layer
    10.6 +  Copyright (C) 1997-2010 Sam Lantinga
    10.7 +
    10.8 +  This library is free software; you can redistribute it and/or
    10.9 +  modify it under the terms of the GNU Lesser General Public
   10.10 +  License as published by the Free Software Foundation; either
   10.11 +  version 2.1 of the License, or (at your option) any later version.
   10.12 +
   10.13 +  This library is distributed in the hope that it will be useful,
   10.14 +  but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   10.16 +  Lesser General Public License for more details.
   10.17 +
   10.18 +  You should have received a copy of the GNU Lesser General Public
   10.19 +  License along with this library; if not, write to the Free Software
   10.20 +  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   10.21 +
   10.22 +  Sam Lantinga
   10.23 +  slouken@libsdl.org
   10.24 +*/
   10.25 +#include "SDL_stdinc.h"
   10.26 +
   10.27 +#include "SDL_atomic.h"
   10.28 +#include "SDL_timer.h"
   10.29 +
   10.30 +#if defined(__WIN32__)
   10.31 +#define WIN32_LEAN_AND_MEAN
   10.32 +#include <windows.h>
   10.33 +
   10.34 +#elif defined(__MACOSX__)
   10.35 +#include <libkern/OSAtomic.h>
   10.36 +
   10.37 +#endif
   10.38 +
   10.39 +
   10.40 +/* This function is where all the magic happens... */
   10.41 +SDL_bool
   10.42 +SDL_AtomicTryLock(SDL_SpinLock *lock)
   10.43 +{
   10.44 +#if defined(__WIN32__)
   10.45 +    return (InterlockedExchange(lock, 1) == 0);
   10.46 +
   10.47 +#elif defined(__MACOSX__)
   10.48 +    return OSAtomicCompareAndSwap32Barrier(0, 1, lock);
   10.49 +
   10.50 +#elif defined(__GNUC__)
   10.51 +#if defined(__arm__)
   10.52 +#ifdef __ARM_ARCH_5__
   10.53 +    int result;
   10.54 +    __asm__ __volatile__ (
   10.55 +        "swp %0, %1, [%2]\n"
   10.56 +        : "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory");
   10.57 +    return (result == 0);
   10.58 +#else
   10.59 +    int result;
   10.60 +    __asm__ __volatile__ (
   10.61 +        "ldrex %0, [%2]\nteq   %0, #0\nstrexeq %0, %1, [%2]"
   10.62 +        : "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
   10.63 +    return (result == 0);
   10.64 +#endif
   10.65 +#else
   10.66 +    return (__sync_lock_test_and_set(lock, 1) == 0);
   10.67 +#endif
   10.68 +
   10.69 +#else
   10.70 +    /* Need CPU instructions for spinlock here! */
   10.71 +    __need_spinlock_implementation__
   10.72 +#endif
   10.73 +}
   10.74 +
   10.75 +void
   10.76 +SDL_AtomicLock(SDL_SpinLock *lock)
   10.77 +{
   10.78 +    /* FIXME: Should we have an eventual timeout? */
   10.79 +    while (!SDL_AtomicTryLock(lock)) {
   10.80 +        SDL_Delay(0);
   10.81 +    }
   10.82 +}
   10.83 +
   10.84 +void
   10.85 +SDL_AtomicUnlock(SDL_SpinLock *lock)
   10.86 +{
   10.87 +#if defined(__WIN32__)
   10.88 +    *lock = 0;
   10.89 +
   10.90 +#elif defined(__MACOSX__)
   10.91 +    *lock = 0;
   10.92 +
   10.93 +#elif defined(__GNUC__) && !defined(__arm__)
   10.94 +    __sync_lock_release(lock);
   10.95 +
   10.96 +#else
   10.97 +    /* Assuming memory barrier in lock and integral assignment operation */
   10.98 +    *lock = 0;
   10.99 +#endif
  10.100 +}
  10.101 +
  10.102 +/* vi: set ts=4 sw=4 expandtab: */
    11.1 --- a/src/atomic/dummy/SDL_atomic.c	Sat Jan 15 12:34:43 2011 -0800
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,469 +0,0 @@
    11.4 -/*
    11.5 -  SDL - Simple DirectMedia Layer
    11.6 -  Copyright (C) 1997-2010 Sam Lantinga
    11.7 -
    11.8 -  This library is free software; you can redistribute it and/or
    11.9 -  modify it under the terms of the GNU Lesser General Public
   11.10 -  License as published by the Free Software Foundation; either
   11.11 -  version 2.1 of the License, or (at your option) any later version.
   11.12 -
   11.13 -  This library is distributed in the hope that it will be useful,
   11.14 -  but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11.16 -  Lesser General Public License for more details.
   11.17 -
   11.18 -  You should have received a copy of the GNU Lesser General Public
   11.19 -  License along with this library; if not, write to the Free Software
   11.20 -  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   11.21 -
   11.22 -  Sam Lantinga
   11.23 -  slouken@libsdl.org
   11.24 -
   11.25 -  Contributed by Bob Pendleton, bob@pendleton.com
   11.26 -*/
   11.27 -
   11.28 -#include "SDL_stdinc.h"
   11.29 -#include "SDL_atomic.h"
   11.30 -
   11.31 -#include "SDL_error.h"
   11.32 -
   11.33 -/*
   11.34 -  This file provides 32, and 64 bit atomic operations. If the
   11.35 -  operations are provided by the native hardware and operating system
   11.36 -  they are used. If they are not then the operations are emulated
   11.37 -  using the SDL spin lock operations. If spin lock can not be
   11.38 -  implemented then these functions must fail.
   11.39 -*/
   11.40 -
   11.41 -/* 
   11.42 -  DUMMY VERSION.
   11.43 -
   11.44 -  This version of the code assumes there is no support for atomic
   11.45 -  operations. Therefore, every function sets the SDL error
   11.46 -  message. Oddly enough, if you only have one thread then this
   11.47 -  version actuallys works.
   11.48 -*/
   11.49 -
   11.50 -/*
   11.51 -  Native spinlock routines. Because this is the dummy implementation
   11.52 -  these will always call SDL_SetError() and do nothing.
   11.53 -*/
   11.54 -
   11.55 -void 
   11.56 -SDL_AtomicLock(SDL_SpinLock *lock)
   11.57 -{
   11.58 -   SDL_SetError("SDL_atomic.c: is not implemented on this platform");
   11.59 -}
   11.60 -
   11.61 -void 
   11.62 -SDL_AtomicUnlock(SDL_SpinLock *lock)
   11.63 -{
   11.64 -   SDL_SetError("SDL_atomic.c: is not implemented on this platform");
   11.65 -}
   11.66 -
   11.67 -/*
   11.68 -  Note that platform specific versions can be built from this version
   11.69 -  by changing the #undefs to #defines and adding platform specific
   11.70 -  code.
   11.71 -*/
   11.72 -
   11.73 -#undef  nativeTestThenSet32
   11.74 -#undef  nativeClear32
   11.75 -#undef  nativeFetchThenIncrement32
   11.76 -#undef  nativeFetchThenDecrement32
   11.77 -#undef  nativeFetchThenAdd32
   11.78 -#undef  nativeFetchThenSubtract32
   11.79 -#undef  nativeIncrementThenFetch32
   11.80 -#undef  nativeDecrementThenFetch32
   11.81 -#undef  nativeAddThenFetch32
   11.82 -#undef  nativeSubtractThenFetch32
   11.83 -
   11.84 -#undef  nativeTestThenSet64
   11.85 -#undef  nativeClear64
   11.86 -#undef  nativeFetchThenIncrement64
   11.87 -#undef  nativeFetchThenDecrement64
   11.88 -#undef  nativeFetchThenAdd64
   11.89 -#undef  nativeFetchThenSubtract64
   11.90 -#undef  nativeIncrementThenFetch64
   11.91 -#undef  nativeDecrementThenFetch64
   11.92 -#undef  nativeAddThenFetch64
   11.93 -#undef  nativeSubtractThenFetch64
   11.94 -
   11.95 -/* 
   11.96 -  If any of the operations are not provided then we must emulate some
   11.97 -  of them. That means we need a nice implementation of spin locks
   11.98 -  that avoids the "one big lock" problem. We use a vector of spin
   11.99 -  locks and pick which one to use based on the address of the operand
  11.100 -  of the function.
  11.101 -
  11.102 -  To generate the index of the lock we first shift by 3 bits to get
  11.103 -  rid on the zero bits that result from 32 and 64 bit allignment of
  11.104 -  data. We then mask off all but 5 bits and use those 5 bits as an
  11.105 -  index into the table. 
  11.106 -
  11.107 -  Picking the lock this way insures that accesses to the same data at
  11.108 -  the same time will go to the same lock. OTOH, accesses to different
  11.109 -  data have only a 1/32 chance of hitting the same lock. That should
  11.110 -  pretty much eliminate the chances of several atomic operations on
  11.111 -  different data from waiting on the same "big lock". If it isn't
  11.112 -  then the table of locks can be expanded to a new size so long as
  11.113 -  the new size is a power of two.
  11.114 -*/
  11.115 -
  11.116 -static SDL_SpinLock locks[32] = {
  11.117 -   0, 0, 0, 0, 0, 0, 0, 0,
  11.118 -   0, 0, 0, 0, 0, 0, 0, 0,
  11.119 -   0, 0, 0, 0, 0, 0, 0, 0,
  11.120 -   0, 0, 0, 0, 0, 0, 0, 0,
  11.121 -};
  11.122 -
  11.123 -static __inline__ void
  11.124 -privateWaitLock(volatile void *ptr)
  11.125 -{
  11.126 -#if SIZEOF_VOIDP == 4
  11.127 -   Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
  11.128 -#elif SIZEOF_VOIDP == 8
  11.129 -   Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
  11.130 -#endif
  11.131 -
  11.132 -   SDL_AtomicLock(&locks[index]);
  11.133 -}
  11.134 -
  11.135 -static __inline__ void
  11.136 -privateUnlock(volatile void *ptr)
  11.137 -{
  11.138 -#if SIZEOF_VOIDP == 4
  11.139 -   Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
  11.140 -#elif SIZEOF_VOIDP == 8
  11.141 -   Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
  11.142 -#endif
  11.143 -
  11.144 -   SDL_AtomicUnlock(&locks[index]);
  11.145 -}
  11.146 -
  11.147 -/* 32 bit atomic operations */
  11.148 -
  11.149 -SDL_bool
  11.150 -SDL_AtomicTestThenSet32(volatile Uint32 * ptr)
  11.151 -{
  11.152 -#ifdef nativeTestThenSet32
  11.153 -#else
  11.154 -   SDL_bool result = SDL_FALSE;
  11.155 -
  11.156 -   privateWaitLock(ptr);
  11.157 -   result = (*ptr == 0);
  11.158 -   if (result)
  11.159 -   {
  11.160 -      *ptr = 1;
  11.161 -   }
  11.162 -   privateUnlock(ptr);
  11.163 -
  11.164 -   return result;
  11.165 -#endif
  11.166 -}
  11.167 -
  11.168 -void
  11.169 -SDL_AtomicClear32(volatile Uint32 * ptr)
  11.170 -{
  11.171 -#ifdef nativeClear32
  11.172 -#else
  11.173 -   privateWaitLock(ptr);
  11.174 -   *ptr = 0;
  11.175 -   privateUnlock(ptr);
  11.176 -
  11.177 -   return;
  11.178 -#endif
  11.179 -}
  11.180 -
  11.181 -Uint32
  11.182 -SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr)
  11.183 -{
  11.184 -#ifdef nativeFetchThenIncrement32
  11.185 -#else
  11.186 -   Uint32 tmp = 0;
  11.187 -
  11.188 -   privateWaitLock(ptr);
  11.189 -   tmp = *ptr;
  11.190 -   (*ptr)+= 1;
  11.191 -   privateUnlock(ptr);
  11.192 -
  11.193 -   return tmp;
  11.194 -#endif
  11.195 -}
  11.196 -
  11.197 -Uint32
  11.198 -SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr)
  11.199 -{
  11.200 -#ifdef nativeFetchThenDecrement32
  11.201 -#else
  11.202 -   Uint32 tmp = 0;
  11.203 -
  11.204 -   privateWaitLock(ptr);
  11.205 -   tmp = *ptr;
  11.206 -   (*ptr) -= 1;
  11.207 -   privateUnlock(ptr);
  11.208 -
  11.209 -   return tmp;
  11.210 -#endif
  11.211 -}
  11.212 -
  11.213 -Uint32
  11.214 -SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value)
  11.215 -{
  11.216 -#ifdef nativeFetchThenAdd32
  11.217 -#else
  11.218 -   Uint32 tmp = 0;
  11.219 -
  11.220 -   privateWaitLock(ptr);
  11.221 -   tmp = *ptr;
  11.222 -   (*ptr)+= value;
  11.223 -   privateUnlock(ptr);
  11.224 -
  11.225 -   return tmp;
  11.226 -#endif
  11.227 -}
  11.228 -
  11.229 -Uint32
  11.230 -SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value)
  11.231 -{
  11.232 -#ifdef nativeFetchThenSubtract32
  11.233 -#else
  11.234 -   Uint32 tmp = 0;
  11.235 -
  11.236 -   privateWaitLock(ptr);
  11.237 -   tmp = *ptr;
  11.238 -   (*ptr)-= value;
  11.239 -   privateUnlock(ptr);
  11.240 -
  11.241 -   return tmp;
  11.242 -#endif
  11.243 -}
  11.244 -
  11.245 -Uint32
  11.246 -SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr)
  11.247 -{
  11.248 -#ifdef nativeIncrementThenFetch32
  11.249 -#else
  11.250 -   Uint32 tmp = 0;
  11.251 -
  11.252 -   privateWaitLock(ptr);
  11.253 -   (*ptr)+= 1;
  11.254 -   tmp = *ptr;
  11.255 -   privateUnlock(ptr);
  11.256 -
  11.257 -   return tmp;
  11.258 -#endif
  11.259 -}
  11.260 -
  11.261 -Uint32
  11.262 -SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr)
  11.263 -{
  11.264 -#ifdef nativeDecrementThenFetch32
  11.265 -#else
  11.266 -   Uint32 tmp = 0;
  11.267 -
  11.268 -   privateWaitLock(ptr);
  11.269 -   (*ptr)-= 1;
  11.270 -   tmp = *ptr;
  11.271 -   privateUnlock(ptr);
  11.272 -
  11.273 -   return tmp;
  11.274 -#endif
  11.275 -}
  11.276 -
  11.277 -Uint32
  11.278 -SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value)
  11.279 -{
  11.280 -#ifdef nativeAddThenFetch32
  11.281 -#else
  11.282 -   Uint32 tmp = 0;
  11.283 -
  11.284 -   privateWaitLock(ptr);
  11.285 -   (*ptr)+= value;
  11.286 -   tmp = *ptr;
  11.287 -   privateUnlock(ptr);
  11.288 -
  11.289 -   return tmp;
  11.290 -#endif
  11.291 -}
  11.292 -
  11.293 -Uint32
  11.294 -SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value)
  11.295 -{
  11.296 -#ifdef nativeSubtractThenFetch32
  11.297 -#else
  11.298 -   Uint32 tmp = 0;
  11.299 -
  11.300 -   privateWaitLock(ptr);
  11.301 -   (*ptr)-= value;
  11.302 -   tmp = *ptr;
  11.303 -   privateUnlock(ptr);
  11.304 -
  11.305 -   return tmp;
  11.306 -#endif
  11.307 -}
  11.308 -
  11.309 -/* 64 bit atomic operations */
  11.310 -#ifdef SDL_HAS_64BIT_TYPE
  11.311 -
  11.312 -SDL_bool
  11.313 -SDL_AtomicTestThenSet64(volatile Uint64 * ptr)
  11.314 -{
  11.315 -#ifdef nativeTestThenSet64
  11.316 -#else
  11.317 -   SDL_bool result = SDL_FALSE;
  11.318 -
  11.319 -   privateWaitLock(ptr);
  11.320 -   result = (*ptr == 0);
  11.321 -   if (result)
  11.322 -   {
  11.323 -      *ptr = 1;
  11.324 -   }
  11.325 -   privateUnlock(ptr);
  11.326 -
  11.327 -   return result;
  11.328 -#endif
  11.329 -}
  11.330 -
  11.331 -void
  11.332 -SDL_AtomicClear64(volatile Uint64 * ptr)
  11.333 -{
  11.334 -#ifdef nativeClear64
  11.335 -#else
  11.336 -   privateWaitLock(ptr);
  11.337 -   *ptr = 0;
  11.338 -   privateUnlock(ptr);
  11.339 -
  11.340 -   return;
  11.341 -#endif
  11.342 -}
  11.343 -
  11.344 -Uint64
  11.345 -SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr)
  11.346 -{
  11.347 -#ifdef nativeFetchThenIncrement64
  11.348 -#else
  11.349 -   Uint64 tmp = 0;
  11.350 -
  11.351 -   privateWaitLock(ptr);
  11.352 -   tmp = *ptr;
  11.353 -   (*ptr)+= 1;
  11.354 -   privateUnlock(ptr);
  11.355 -
  11.356 -   return tmp;
  11.357 -#endif
  11.358 -}
  11.359 -
  11.360 -Uint64
  11.361 -SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr)
  11.362 -{
  11.363 -#ifdef nativeFetchThenDecrement64
  11.364 -#else
  11.365 -   Uint64 tmp = 0;
  11.366 -
  11.367 -   privateWaitLock(ptr);
  11.368 -   tmp = *ptr;
  11.369 -   (*ptr) -= 1;
  11.370 -   privateUnlock(ptr);
  11.371 -
  11.372 -   return tmp;
  11.373 -#endif
  11.374 -}
  11.375 -
  11.376 -Uint64
  11.377 -SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value)
  11.378 -{
  11.379 -#ifdef nativeFetchThenAdd64
  11.380 -#else
  11.381 -   Uint64 tmp = 0;
  11.382 -
  11.383 -   privateWaitLock(ptr);
  11.384 -   tmp = *ptr;
  11.385 -   (*ptr)+= value;
  11.386 -   privateUnlock(ptr);
  11.387 -
  11.388 -   return tmp;
  11.389 -#endif
  11.390 -}
  11.391 -
  11.392 -Uint64
  11.393 -SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value)
  11.394 -{
  11.395 -#ifdef nativeFetchThenSubtract64
  11.396 -#else
  11.397 -   Uint64 tmp = 0;
  11.398 -
  11.399 -   privateWaitLock(ptr);
  11.400 -   tmp = *ptr;
  11.401 -   (*ptr)-= value;
  11.402 -   privateUnlock(ptr);
  11.403 -
  11.404 -   return tmp;
  11.405 -#endif
  11.406 -}
  11.407 -
  11.408 -Uint64
  11.409 -SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr)
  11.410 -{
  11.411 -#ifdef nativeIncrementThenFetch64
  11.412 -#else
  11.413 -   Uint64 tmp = 0;
  11.414 -
  11.415 -   privateWaitLock(ptr);
  11.416 -   (*ptr)+= 1;
  11.417 -   tmp = *ptr;
  11.418 -   privateUnlock(ptr);
  11.419 -
  11.420 -   return tmp;
  11.421 -#endif
  11.422 -}
  11.423 -
  11.424 -Uint64
  11.425 -SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr)
  11.426 -{
  11.427 -#ifdef nativeDecrementThenFetch64
  11.428 -#else
  11.429 -   Uint64 tmp = 0;
  11.430 -
  11.431 -   privateWaitLock(ptr);
  11.432 -   (*ptr)-= 1;
  11.433 -   tmp = *ptr;
  11.434 -   privateUnlock(ptr);
  11.435 -
  11.436 -   return tmp;
  11.437 -#endif
  11.438 -}
  11.439 -
  11.440 -Uint64
  11.441 -SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value)
  11.442 -{
  11.443 -#ifdef nativeAddThenFetch64
  11.444 -#else
  11.445 -   Uint64 tmp = 0;
  11.446 -
  11.447 -   privateWaitLock(ptr);
  11.448 -   (*ptr)+= value;
  11.449 -   tmp = *ptr;
  11.450 -   privateUnlock(ptr);
  11.451 -
  11.452 -   return tmp;
  11.453 -#endif
  11.454 -}
  11.455 -
  11.456 -Uint64
  11.457 -SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value)
  11.458 -{
  11.459 -#ifdef nativeSubtractThenFetch64
  11.460 -#else
  11.461 -   Uint64 tmp = 0;
  11.462 -
  11.463 -   privateWaitLock(ptr);
  11.464 -   (*ptr)-= value;
  11.465 -   tmp = *ptr;
  11.466 -   privateUnlock(ptr);
  11.467 -
  11.468 -   return tmp;
  11.469 -#endif
  11.470 -}
  11.471 -#endif
  11.472 -
    12.1 --- a/src/atomic/linux/SDL_atomic.c	Sat Jan 15 12:34:43 2011 -0800
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,510 +0,0 @@
    12.4 -/*
    12.5 -  SDL - Simple DirectMedia Layer
    12.6 -  Copyright (C) 1997-2010 Sam Lantinga
    12.7 -
    12.8 -  This library is free software; you can redistribute it and/or
    12.9 -  modify it under the terms of the GNU Lesser General Public
   12.10 -  License as published by the Free Software Foundation; either
   12.11 -  version 2.1 of the License, or (at your option) any later version.
   12.12 -
   12.13 -  This library is distributed in the hope that it will be useful,
   12.14 -  but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.16 -  Lesser General Public License for more details.
   12.17 -
   12.18 -  You should have received a copy of the GNU Lesser General Public
   12.19 -  License along with this library; if not, write to the Free Software
   12.20 -  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   12.21 -
   12.22 -  Sam Lantinga
   12.23 -  slouken@libsdl.org
   12.24 -
   12.25 -  Contributed by Bob Pendleton, bob@pendleton.com
   12.26 -*/
   12.27 -
   12.28 -#include "SDL_stdinc.h"
   12.29 -#include "SDL_atomic.h"
   12.30 -
   12.31 -#include "SDL_error.h"
   12.32 -
   12.33 -/*
   12.34 -  This file provides 32, and 64 bit atomic operations. If the
   12.35 -  operations are provided by the native hardware and operating system
   12.36 -  they are used. If they are not then the operations are emulated
   12.37 -  using the SDL spin lock operations. If spin lock can not be
   12.38 -  implemented then these functions must fail.
   12.39 -*/
   12.40 -
   12.41 -/* 
   12.42 -  LINUX/GCC VERSION.
   12.43 -
   12.44 -  This version of the code assumes support of the atomic builtins as
   12.45 -  documented at gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html This
   12.46 -  code should work on any modern x86 or other processor supported by
   12.47 -  GCC. 
   12.48 -
   12.49 -  Some processors will only support some of these operations so
   12.50 -  #ifdefs will have to be added as incompatibilities are discovered
   12.51 -*/
   12.52 -
   12.53 -/*
   12.54 -  Native spinlock routines.
   12.55 -*/
   12.56 -
   12.57 -void 
   12.58 -SDL_AtomicLock(SDL_SpinLock *lock)
   12.59 -{
   12.60 -   while (0 != __sync_lock_test_and_set(lock, 1))
   12.61 -   {
   12.62 -   }
   12.63 -}
   12.64 -
   12.65 -void 
   12.66 -SDL_AtomicUnlock(SDL_SpinLock *lock)
   12.67 -{
   12.68 -   __sync_lock_test_and_set(lock, 0);
   12.69 -}
   12.70 -
   12.71 -/*
   12.72 -  Note that platform specific versions can be built from this version
   12.73 -  by changing the #undefs to #defines and adding platform specific
   12.74 -  code.
   12.75 -*/
   12.76 -
   12.77 -#define nativeTestThenSet32
   12.78 -#define nativeClear32
   12.79 -#define nativeFetchThenIncrement32
   12.80 -#define nativeFetchThenDecrement32
   12.81 -#define nativeFetchThenAdd32
   12.82 -#define nativeFetchThenSubtract32
   12.83 -#define nativeIncrementThenFetch32
   12.84 -#define nativeDecrementThenFetch32
   12.85 -#define nativeAddThenFetch32
   12.86 -#define nativeSubtractThenFetch32
   12.87 -
   12.88 -#ifdef SDL_HAS_64BIT_TYPE
   12.89 -  #ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
   12.90 -    #define nativeTestThenSet64
   12.91 -    #define nativeClear64
   12.92 -    #define nativeFetchThenIncrement64
   12.93 -    #define nativeFetchThenDecrement64
   12.94 -    #define nativeFetchThenAdd64
   12.95 -    #define nativeFetchThenSubtract64
   12.96 -    #define nativeIncrementThenFetch64
   12.97 -    #define nativeDecrementThenFetch64
   12.98 -    #define nativeAddThenFetch64
   12.99 -    #define nativeSubtractThenFetch64
  12.100 -  #else
  12.101 -    #undef  nativeTestThenSet64
  12.102 -    #undef  nativeClear64
  12.103 -    #undef  nativeFetchThenIncrement64
  12.104 -    #undef  nativeFetchThenDecrement64
  12.105 -    #undef  nativeFetchThenAdd64
  12.106 -    #undef  nativeFetchThenSubtract64
  12.107 -    #undef  nativeIncrementThenFetch64
  12.108 -    #undef  nativeDecrementThenFetch64
  12.109 -    #undef  nativeAddThenFetch64
  12.110 -    #undef  nativeSubtractThenFetch64
  12.111 -  #endif /* __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 */
  12.112 -#endif /* SDL_HAS_64BIT_TYPE */
  12.113 -
  12.114 -/* 
  12.115 -  If any of the operations are not provided then we must emulate some
  12.116 -  of them. That means we need a nice implementation of spin locks
  12.117 -  that avoids the "one big lock" problem. We use a vector of spin
  12.118 -  locks and pick which one to use based on the address of the operand
  12.119 -  of the function.
  12.120 -
  12.121 -  To generate the index of the lock we first shift by 3 bits to get
  12.122 -  rid on the zero bits that result from 32 and 64 bit allignment of
  12.123 -  data. We then mask off all but 5 bits and use those 5 bits as an
  12.124 -  index into the table. 
  12.125 -
  12.126 -  Picking the lock this way insures that accesses to the same data at
  12.127 -  the same time will go to the same lock. OTOH, accesses to different
  12.128 -  data have only a 1/32 chance of hitting the same lock. That should
  12.129 -  pretty much eliminate the chances of several atomic operations on
  12.130 -  different data from waiting on the same "big lock". If it isn't
  12.131 -  then the table of locks can be expanded to a new size so long as
  12.132 -  the new size is a power of two.
  12.133 -*/
  12.134 -
  12.135 -static SDL_SpinLock locks[32] = {
  12.136 -   0, 0, 0, 0, 0, 0, 0, 0,
  12.137 -   0, 0, 0, 0, 0, 0, 0, 0,
  12.138 -   0, 0, 0, 0, 0, 0, 0, 0,
  12.139 -   0, 0, 0, 0, 0, 0, 0, 0,
  12.140 -};
  12.141 -
  12.142 -static __inline__ void
  12.143 -privateWaitLock(volatile void *ptr)
  12.144 -{
  12.145 -#if SIZEOF_VOIDP == 4
  12.146 -   Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
  12.147 -#elif SIZEOF_VOIDP == 8
  12.148 -   Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
  12.149 -#endif
  12.150 -
  12.151 -   SDL_AtomicLock(&locks[index]);
  12.152 -}
  12.153 -
  12.154 -static __inline__ void
  12.155 -privateUnlock(volatile void *ptr)
  12.156 -{
  12.157 -#if SIZEOF_VOIDP == 4
  12.158 -   Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
  12.159 -#elif SIZEOF_VOIDP == 8
  12.160 -   Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
  12.161 -#endif
  12.162 -
  12.163 -   SDL_AtomicUnlock(&locks[index]);
  12.164 -}
  12.165 -
  12.166 -/* 32 bit atomic operations */
  12.167 -
  12.168 -SDL_bool
  12.169 -SDL_AtomicTestThenSet32(volatile Uint32 * ptr)
  12.170 -{
  12.171 -#ifdef nativeTestThenSet32
  12.172 -   return 0 == __sync_lock_test_and_set(ptr, 1);
  12.173 -#else
  12.174 -   SDL_bool result = SDL_FALSE;
  12.175 -
  12.176 -   privateWaitLock(ptr);
  12.177 -   result = (*ptr == 0);
  12.178 -   if (result)
  12.179 -   {
  12.180 -      *ptr = 1;
  12.181 -   }
  12.182 -   privateUnlock(ptr);
  12.183 -
  12.184 -   return result;
  12.185 -#endif
  12.186 -}
  12.187 -
  12.188 -void
  12.189 -SDL_AtomicClear32(volatile Uint32 * ptr)
  12.190 -{
  12.191 -#ifdef nativeClear32
  12.192 -   __sync_lock_test_and_set(ptr, 0);
  12.193 -   return;
  12.194 -#else
  12.195 -   privateWaitLock(ptr);
  12.196 -   *ptr = 0;
  12.197 -   privateUnlock(ptr);
  12.198 -
  12.199 -   return;
  12.200 -#endif
  12.201 -}
  12.202 -
  12.203 -Uint32
  12.204 -SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr)
  12.205 -{
  12.206 -#ifdef nativeFetchThenIncrement32
  12.207 -   return __sync_fetch_and_add(ptr, 1);
  12.208 -#else
  12.209 -   Uint32 tmp = 0;
  12.210 -
  12.211 -   privateWaitLock(ptr);
  12.212 -   tmp = *ptr;
  12.213 -   (*ptr)+= 1;
  12.214 -   privateUnlock(ptr);
  12.215 -
  12.216 -   return tmp;
  12.217 -#endif
  12.218 -}
  12.219 -
  12.220 -Uint32
  12.221 -SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr)
  12.222 -{
  12.223 -#ifdef nativeFetchThenDecrement32
  12.224 -   return __sync_fetch_and_sub(ptr, 1);
  12.225 -#else
  12.226 -   Uint32 tmp = 0;
  12.227 -
  12.228 -   privateWaitLock(ptr);
  12.229 -   tmp = *ptr;
  12.230 -   (*ptr) -= 1;
  12.231 -   privateUnlock(ptr);
  12.232 -
  12.233 -   return tmp;
  12.234 -#endif
  12.235 -}
  12.236 -
  12.237 -Uint32
  12.238 -SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value)
  12.239 -{
  12.240 -#ifdef nativeFetchThenAdd32
  12.241 -   return __sync_fetch_and_add(ptr, value);
  12.242 -#else
  12.243 -   Uint32 tmp = 0;
  12.244 -
  12.245 -   privateWaitLock(ptr);
  12.246 -   tmp = *ptr;
  12.247 -   (*ptr)+= value;
  12.248 -   privateUnlock(ptr);
  12.249 -
  12.250 -   return tmp;
  12.251 -#endif
  12.252 -}
  12.253 -
  12.254 -Uint32
  12.255 -SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value)
  12.256 -{
  12.257 -#ifdef nativeFetchThenSubtract32
  12.258 -   return __sync_fetch_and_sub(ptr, value);
  12.259 -#else
  12.260 -   Uint32 tmp = 0;
  12.261 -
  12.262 -   privateWaitLock(ptr);
  12.263 -   tmp = *ptr;
  12.264 -   (*ptr)-= value;
  12.265 -   privateUnlock(ptr);
  12.266 -
  12.267 -   return tmp;
  12.268 -#endif
  12.269 -}
  12.270 -
  12.271 -Uint32
  12.272 -SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr)
  12.273 -{
  12.274 -#ifdef nativeIncrementThenFetch32
  12.275 -   return __sync_add_and_fetch(ptr, 1);
  12.276 -#else
  12.277 -   Uint32 tmp = 0;
  12.278 -
  12.279 -   privateWaitLock(ptr);
  12.280 -   (*ptr)+= 1;
  12.281 -   tmp = *ptr;
  12.282 -   privateUnlock(ptr);
  12.283 -
  12.284 -   return tmp;
  12.285 -#endif
  12.286 -}
  12.287 -
  12.288 -Uint32
  12.289 -SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr)
  12.290 -{
  12.291 -#ifdef nativeDecrementThenFetch32
  12.292 -   return __sync_sub_and_fetch(ptr, 1);
  12.293 -#else
  12.294 -   Uint32 tmp = 0;
  12.295 -
  12.296 -   privateWaitLock(ptr);
  12.297 -   (*ptr)-= 1;
  12.298 -   tmp = *ptr;
  12.299 -   privateUnlock(ptr);
  12.300 -
  12.301 -   return tmp;
  12.302 -#endif
  12.303 -}
  12.304 -
  12.305 -Uint32
  12.306 -SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value)
  12.307 -{
  12.308 -#ifdef nativeAddThenFetch32
  12.309 -   return __sync_add_and_fetch(ptr, value);
  12.310 -#else
  12.311 -   Uint32 tmp = 0;
  12.312 -
  12.313 -   privateWaitLock(ptr);
  12.314 -   (*ptr)+= value;
  12.315 -   tmp = *ptr;
  12.316 -   privateUnlock(ptr);
  12.317 -
  12.318 -   return tmp;
  12.319 -#endif
  12.320 -}
  12.321 -
  12.322 -Uint32
  12.323 -SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value)
  12.324 -{
  12.325 -#ifdef nativeSubtractThenFetch32
  12.326 -   return __sync_sub_and_fetch(ptr, value);
  12.327 -#else
  12.328 -   Uint32 tmp = 0;
  12.329 -
  12.330 -   privateWaitLock(ptr);
  12.331 -   (*ptr)-= value;
  12.332 -   tmp = *ptr;
  12.333 -   privateUnlock(ptr);
  12.334 -
  12.335 -   return tmp;
  12.336 -#endif
  12.337 -}
  12.338 -
  12.339 -/* 64 bit atomic operations */
  12.340 -#ifdef SDL_HAS_64BIT_TYPE
  12.341 -
  12.342 -SDL_bool
  12.343 -SDL_AtomicTestThenSet64(volatile Uint64 * ptr)
  12.344 -{
  12.345 -#ifdef nativeTestThenSet64
  12.346 -   return 0 == __sync_lock_test_and_set(ptr, 1);
  12.347 -#else
  12.348 -   SDL_bool result = SDL_FALSE;
  12.349 -
  12.350 -   privateWaitLock(ptr);
  12.351 -   result = (*ptr == 0);
  12.352 -   if (result)
  12.353 -   {
  12.354 -      *ptr = 1;
  12.355 -   }
  12.356 -   privateUnlock(ptr);
  12.357 -
  12.358 -   return result;
  12.359 -#endif
  12.360 -}
  12.361 -
  12.362 -void
  12.363 -SDL_AtomicClear64(volatile Uint64 * ptr)
  12.364 -{
  12.365 -#ifdef nativeClear64
  12.366 -   __sync_lock_test_and_set(ptr, 0);
  12.367 -   return;
  12.368 -#else
  12.369 -   privateWaitLock(ptr);
  12.370 -   *ptr = 0;
  12.371 -   privateUnlock(ptr);
  12.372 -
  12.373 -   return;
  12.374 -#endif
  12.375 -}
  12.376 -
  12.377 -Uint64
  12.378 -SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr)
  12.379 -{
  12.380 -#ifdef nativeFetchThenIncrement64
  12.381 -   return __sync_fetch_and_add(ptr, 1);
  12.382 -#else
  12.383 -   Uint64 tmp = 0;
  12.384 -
  12.385 -   privateWaitLock(ptr);
  12.386 -   tmp = *ptr;
  12.387 -   (*ptr)+= 1;
  12.388 -   privateUnlock(ptr);
  12.389 -
  12.390 -   return tmp;
  12.391 -#endif
  12.392 -}
  12.393 -
  12.394 -Uint64
  12.395 -SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr)
  12.396 -{
  12.397 -#ifdef nativeFetchThenDecrement64
  12.398 -   return __sync_fetch_and_sub(ptr, 1);
  12.399 -#else
  12.400 -   Uint64 tmp = 0;
  12.401 -
  12.402 -   privateWaitLock(ptr);
  12.403 -   tmp = *ptr;
  12.404 -   (*ptr) -= 1;
  12.405 -   privateUnlock(ptr);
  12.406 -
  12.407 -   return tmp;
  12.408 -#endif
  12.409 -}
  12.410 -
  12.411 -Uint64
  12.412 -SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value)
  12.413 -{
  12.414 -#ifdef nativeFetchThenAdd64
  12.415 -   return __sync_fetch_and_add(ptr, value);
  12.416 -#else
  12.417 -   Uint64 tmp = 0;
  12.418 -
  12.419 -   privateWaitLock(ptr);
  12.420 -   tmp = *ptr;
  12.421 -   (*ptr)+= value;
  12.422 -   privateUnlock(ptr);
  12.423 -
  12.424 -   return tmp;
  12.425 -#endif
  12.426 -}
  12.427 -
  12.428 -Uint64
  12.429 -SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value)
  12.430 -{
  12.431 -#ifdef nativeFetchThenSubtract64
  12.432 -   return __sync_fetch_and_sub(ptr, value);
  12.433 -#else
  12.434 -   Uint64 tmp = 0;
  12.435 -
  12.436 -   privateWaitLock(ptr);
  12.437 -   tmp = *ptr;
  12.438 -   (*ptr)-= value;
  12.439 -   privateUnlock(ptr);
  12.440 -
  12.441 -   return tmp;
  12.442 -#endif
  12.443 -}
  12.444 -
  12.445 -Uint64
  12.446 -SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr)
  12.447 -{
  12.448 -#ifdef nativeIncrementThenFetch64
  12.449 -   return __sync_add_and_fetch(ptr, 1);
  12.450 -#else
  12.451 -   Uint64 tmp = 0;
  12.452 -
  12.453 -   privateWaitLock(ptr);
  12.454 -   (*ptr)+= 1;
  12.455 -   tmp = *ptr;
  12.456 -   privateUnlock(ptr);
  12.457 -
  12.458 -   return tmp;
  12.459 -#endif
  12.460 -}
  12.461 -
  12.462 -Uint64
  12.463 -SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr)
  12.464 -{
  12.465 -#ifdef nativeDecrementThenFetch64
  12.466 -   return __sync_sub_and_fetch(ptr, 1);
  12.467 -#else
  12.468 -   Uint64 tmp = 0;
  12.469 -
  12.470 -   privateWaitLock(ptr);
  12.471 -   (*ptr)-= 1;
  12.472 -   tmp = *ptr;
  12.473 -   privateUnlock(ptr);
  12.474 -
  12.475 -   return tmp;
  12.476 -#endif
  12.477 -}
  12.478 -
  12.479 -Uint64
  12.480 -SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value)
  12.481 -{
  12.482 -#ifdef nativeAddThenFetch64
  12.483 -   return __sync_add_and_fetch(ptr, value);
  12.484 -#else
  12.485 -   Uint64 tmp = 0;
  12.486 -
  12.487 -   privateWaitLock(ptr);
  12.488 -   (*ptr)+= value;
  12.489 -   tmp = *ptr;
  12.490 -   privateUnlock(ptr);
  12.491 -
  12.492 -   return tmp;
  12.493 -#endif
  12.494 -}
  12.495 -
  12.496 -Uint64
  12.497 -SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value)
  12.498 -{
  12.499 -#ifdef nativeSubtractThenFetch64
  12.500 -   return __sync_sub_and_fetch(ptr, value);
  12.501 -#else
  12.502 -   Uint64 tmp = 0;
  12.503 -
  12.504 -   privateWaitLock(ptr);
  12.505 -   (*ptr)-= value;
  12.506 -   tmp = *ptr;
  12.507 -   privateUnlock(ptr);
  12.508 -
  12.509 -   return tmp;
  12.510 -#endif
  12.511 -}
  12.512 -
  12.513 -#endif /* SDL_HAS_64BIT_TYPE */
    13.1 --- a/src/atomic/macosx/SDL_atomic.c	Sat Jan 15 12:34:43 2011 -0800
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,469 +0,0 @@
    13.4 -/*
    13.5 -  SDL - Simple DirectMedia Layer
    13.6 -  Copyright (C) 1997-2010 Sam Lantinga
    13.7 -
    13.8 -  This library is free software; you can redistribute it and/or
    13.9 -  modify it under the terms of the GNU Lesser General Public
   13.10 -  License as published by the Free Software Foundation; either
   13.11 -  version 2.1 of the License, or (at your option) any later version.
   13.12 -
   13.13 -  This library is distributed in the hope that it will be useful,
   13.14 -  but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.15 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13.16 -  Lesser General Public License for more details.
   13.17 -
   13.18 -  You should have received a copy of the GNU Lesser General Public
   13.19 -  License along with this library; if not, write to the Free Software
   13.20 -  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   13.21 -
   13.22 -  Sam Lantinga
   13.23 -  slouken@libsdl.org
   13.24 -
   13.25 -  Contributed by Bob Pendleton, bob@pendleton.com
   13.26 -*/
   13.27 -
   13.28 -#include "SDL_stdinc.h"
   13.29 -#include "SDL_atomic.h"
   13.30 -
   13.31 -#include "SDL_error.h"
   13.32 -
   13.33 -/*
   13.34 -  This file provides 32, and 64 bit atomic operations. If the
   13.35 -  operations are provided by the native hardware and operating system
   13.36 -  they are used. If they are not then the operations are emulated
   13.37 -  using the SDL spin lock operations. If spin lock can not be
   13.38 -  implemented then these functions must fail.
   13.39 -*/
   13.40 -
   13.41 -/* 
   13.42 -  DUMMY VERSION.
   13.43 -
   13.44 -  This version of the code assumes there is no support for atomic
   13.45 -  operations. Therefore, every function sets the SDL error
   13.46 -  message. Oddly enough, if you only have one thread then this
   13.47 -  version actuallys works.
   13.48 -*/
   13.49 -
   13.50 -/*
   13.51 -  Native spinlock routines. Because this is the dummy implementation
   13.52 -  these will always call SDL_SetError() and do nothing.
   13.53 -*/
   13.54 -
   13.55 -void 
   13.56 -SDL_AtomicLock(SDL_SpinLock *lock)
   13.57 -{
   13.58 -   SDL_SetError("SDL_atomic.c: is not implemented on this platform");
   13.59 -}
   13.60 -
   13.61 -void 
   13.62 -SDL_AtomicUnlock(SDL_SpinLock *lock)
   13.63 -{
   13.64 -   SDL_SetError("SDL_atomic.c: is not implemented on this platform");
   13.65 -}
   13.66 -
   13.67 -/*
   13.68 -  Note that platform specific versions can be built from this version
   13.69 -  by changing the #undefs to #defines and adding platform specific
   13.70 -  code.
   13.71 -*/
   13.72 -
   13.73 -#undef  nativeTestThenSet32
   13.74 -#undef  nativeClear32
   13.75 -#undef  nativeFetchThenIncrement32
   13.76 -#undef  nativeFetchThenDecrement32
   13.77 -#undef  nativeFetchThenAdd32
   13.78 -#undef  nativeFetchThenSubtract32
   13.79 -#undef  nativeIncrementThenFetch32
   13.80 -#undef  nativeDecrementThenFetch32
   13.81 -#undef  nativeAddThenFetch32
   13.82 -#undef  nativeSubtractThenFetch32
   13.83 -
   13.84 -#undef  nativeTestThenSet64
   13.85 -#undef  nativeClear64
   13.86 -#undef  nativeFetchThenIncrement64
   13.87 -#undef  nativeFetchThenDecrement64
   13.88 -#undef  nativeFetchThenAdd64
   13.89 -#undef  nativeFetchThenSubtract64
   13.90 -#undef  nativeIncrementThenFetch64
   13.91 -#undef  nativeDecrementThenFetch64
   13.92 -#undef  nativeAddThenFetch64
   13.93 -#undef  nativeSubtractThenFetch64
   13.94 -
   13.95 -/* 
   13.96 -  If any of the operations are not provided then we must emulate some
   13.97 -  of them. That means we need a nice implementation of spin locks
   13.98 -  that avoids the "one big lock" problem. We use a vector of spin
   13.99 -  locks and pick which one to use based on the address of the operand
  13.100 -  of the function.
  13.101 -
  13.102 -  To generate the index of the lock we first shift by 3 bits to get
  13.103 -  rid on the zero bits that result from 32 and 64 bit allignment of
  13.104 -  data. We then mask off all but 5 bits and use those 5 bits as an
  13.105 -  index into the table. 
  13.106 -
  13.107 -  Picking the lock this way insures that accesses to the same data at
  13.108 -  the same time will go to the same lock. OTOH, accesses to different
  13.109 -  data have only a 1/32 chance of hitting the same lock. That should
  13.110 -  pretty much eliminate the chances of several atomic operations on
  13.111 -  different data from waiting on the same "big lock". If it isn't
  13.112 -  then the table of locks can be expanded to a new size so long as
  13.113 -  the new size is a power of two.
  13.114 -*/
  13.115 -
  13.116 -static SDL_SpinLock locks[32] = {
  13.117 -   0, 0, 0, 0, 0, 0, 0, 0,
  13.118 -   0, 0, 0, 0, 0, 0, 0, 0,
  13.119 -   0, 0, 0, 0, 0, 0, 0, 0,
  13.120 -   0, 0, 0, 0, 0, 0, 0, 0,
  13.121 -};
  13.122 -
  13.123 -static __inline__ void
  13.124 -privateWaitLock(volatile void *ptr)
  13.125 -{
  13.126 -#if SIZEOF_VOIDP == 4
  13.127 -   Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
  13.128 -#elif SIZEOF_VOIDP == 8
  13.129 -   Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
  13.130 -#endif
  13.131 -
  13.132 -   SDL_AtomicLock(&locks[index]);
  13.133 -}
  13.134 -
  13.135 -static __inline__ void
  13.136 -privateUnlock(volatile void *ptr)
  13.137 -{
  13.138 -#if SIZEOF_VOIDP == 4
  13.139 -   Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
  13.140 -#elif SIZEOF_VOIDP == 8
  13.141 -   Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
  13.142 -#endif
  13.143 -
  13.144 -   SDL_AtomicUnlock(&locks[index]);
  13.145 -}
  13.146 -
  13.147 -/* 32 bit atomic operations */
  13.148 -
  13.149 -SDL_bool
  13.150 -SDL_AtomicTestThenSet32(volatile Uint32 * ptr)
  13.151 -{
  13.152 -#ifdef nativeTestThenSet32
  13.153 -#else
  13.154 -   SDL_bool result = SDL_FALSE;
  13.155 -
  13.156 -   privateWaitLock(ptr);
  13.157 -   result = (*ptr == 0);
  13.158 -   if (result)
  13.159 -   {
  13.160 -      *ptr = 1;
  13.161 -   }
  13.162 -   privateUnlock(ptr);
  13.163 -
  13.164 -   return result;
  13.165 -#endif
  13.166 -}
  13.167 -
  13.168 -void
  13.169 -SDL_AtomicClear32(volatile Uint32 * ptr)
  13.170 -{
  13.171 -#ifdef nativeClear32
  13.172 -#else
  13.173 -   privateWaitLock(ptr);
  13.174 -   *ptr = 0;
  13.175 -   privateUnlock(ptr);
  13.176 -
  13.177 -   return;
  13.178 -#endif
  13.179 -}
  13.180 -
  13.181 -Uint32
  13.182 -SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr)
  13.183 -{
  13.184 -#ifdef nativeFetchThenIncrement32
  13.185 -#else
  13.186 -   Uint32 tmp = 0;
  13.187 -
  13.188 -   privateWaitLock(ptr);
  13.189 -   tmp = *ptr;
  13.190 -   (*ptr)+= 1;
  13.191 -   privateUnlock(ptr);
  13.192 -
  13.193 -   return tmp;
  13.194 -#endif
  13.195 -}
  13.196 -
  13.197 -Uint32
  13.198 -SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr)
  13.199 -{
  13.200 -#ifdef nativeFetchThenDecrement32
  13.201 -#else
  13.202 -   Uint32 tmp = 0;
  13.203 -
  13.204 -   privateWaitLock(ptr);
  13.205 -   tmp = *ptr;
  13.206 -   (*ptr) -= 1;
  13.207 -   privateUnlock(ptr);
  13.208 -
  13.209 -   return tmp;
  13.210 -#endif
  13.211 -}
  13.212 -
  13.213 -Uint32
  13.214 -SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value)
  13.215 -{
  13.216 -#ifdef nativeFetchThenAdd32
  13.217 -#else
  13.218 -   Uint32 tmp = 0;
  13.219 -
  13.220 -   privateWaitLock(ptr);
  13.221 -   tmp = *ptr;
  13.222 -   (*ptr)+= value;
  13.223 -   privateUnlock(ptr);
  13.224 -
  13.225 -   return tmp;
  13.226 -#endif
  13.227 -}
  13.228 -
  13.229 -Uint32
  13.230 -SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value)
  13.231 -{
  13.232 -#ifdef nativeFetchThenSubtract32
  13.233 -#else
  13.234 -   Uint32 tmp = 0;
  13.235 -
  13.236 -   privateWaitLock(ptr);
  13.237 -   tmp = *ptr;
  13.238 -   (*ptr)-= value;
  13.239 -   privateUnlock(ptr);
  13.240 -
  13.241 -   return tmp;
  13.242 -#endif
  13.243 -}
  13.244 -
  13.245 -Uint32
  13.246 -SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr)
  13.247 -{
  13.248 -#ifdef nativeIncrementThenFetch32
  13.249 -#else
  13.250 -   Uint32 tmp = 0;
  13.251 -
  13.252 -   privateWaitLock(ptr);
  13.253 -   (*ptr)+= 1;
  13.254 -   tmp = *ptr;
  13.255 -   privateUnlock(ptr);
  13.256 -
  13.257 -   return tmp;
  13.258 -#endif
  13.259 -}
  13.260 -
  13.261 -Uint32
  13.262 -SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr)
  13.263 -{
  13.264 -#ifdef nativeDecrementThenFetch32
  13.265 -#else
  13.266 -   Uint32 tmp = 0;
  13.267 -
  13.268 -   privateWaitLock(ptr);
  13.269 -   (*ptr)-= 1;
  13.270 -   tmp = *ptr;
  13.271 -   privateUnlock(ptr);
  13.272 -
  13.273 -   return tmp;
  13.274 -#endif
  13.275 -}
  13.276 -
  13.277 -Uint32
  13.278 -SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value)
  13.279 -{
  13.280 -#ifdef nativeAddThenFetch32
  13.281 -#else
  13.282 -   Uint32 tmp = 0;
  13.283 -
  13.284 -   privateWaitLock(ptr);
  13.285 -   (*ptr)+= value;
  13.286 -   tmp = *ptr;
  13.287 -   privateUnlock(ptr);
  13.288 -
  13.289 -   return tmp;
  13.290 -#endif
  13.291 -}
  13.292 -
  13.293 -Uint32
  13.294 -SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value)
  13.295 -{
  13.296 -#ifdef nativeSubtractThenFetch32
  13.297 -#else
  13.298 -   Uint32 tmp = 0;
  13.299 -
  13.300 -   privateWaitLock(ptr);
  13.301 -   (*ptr)-= value;
  13.302 -   tmp = *ptr;
  13.303 -   privateUnlock(ptr);
  13.304 -
  13.305 -   return tmp;
  13.306 -#endif
  13.307 -}
  13.308 -
  13.309 -/* 64 bit atomic operations */
  13.310 -#ifdef SDL_HAS_64BIT_TYPE
  13.311 -
  13.312 -SDL_bool
  13.313 -SDL_AtomicTestThenSet64(volatile Uint64 * ptr)
  13.314 -{
  13.315 -#ifdef nativeTestThenSet64
  13.316 -#else
  13.317 -   SDL_bool result = SDL_FALSE;
  13.318 -
  13.319 -   privateWaitLock(ptr);
  13.320 -   result = (*ptr == 0);
  13.321 -   if (result)
  13.322 -   {
  13.323 -      *ptr = 1;
  13.324 -   }
  13.325 -   privateUnlock(ptr);
  13.326 -
  13.327 -   return result;
  13.328 -#endif
  13.329 -}
  13.330 -
  13.331 -void
  13.332 -SDL_AtomicClear64(volatile Uint64 * ptr)
  13.333 -{
  13.334 -#ifdef nativeClear64
  13.335 -#else
  13.336 -   privateWaitLock(ptr);
  13.337 -   *ptr = 0;
  13.338 -   privateUnlock(ptr);
  13.339 -
  13.340 -   return;
  13.341 -#endif
  13.342 -}
  13.343 -
  13.344 -Uint64
  13.345 -SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr)
  13.346 -{
  13.347 -#ifdef nativeFetchThenIncrement64
  13.348 -#else
  13.349 -   Uint64 tmp = 0;
  13.350 -
  13.351 -   privateWaitLock(ptr);
  13.352 -   tmp = *ptr;
  13.353 -   (*ptr)+= 1;
  13.354 -   privateUnlock(ptr);
  13.355 -
  13.356 -   return tmp;
  13.357 -#endif
  13.358 -}
  13.359 -
  13.360 -Uint64
  13.361 -SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr)
  13.362 -{
  13.363 -#ifdef nativeFetchThenDecrement64
  13.364 -#else
  13.365 -   Uint64 tmp = 0;
  13.366 -
  13.367 -   privateWaitLock(ptr);
  13.368 -   tmp = *ptr;
  13.369 -   (*ptr) -= 1;
  13.370 -   privateUnlock(ptr);
  13.371 -
  13.372 -   return tmp;
  13.373 -#endif
  13.374 -}
  13.375 -
  13.376 -Uint64
  13.377 -SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value)
  13.378 -{
  13.379 -#ifdef nativeFetchThenAdd64
  13.380 -#else
  13.381 -   Uint64 tmp = 0;
  13.382 -
  13.383 -   privateWaitLock(ptr);
  13.384 -   tmp = *ptr;
  13.385 -   (*ptr)+= value;
  13.386 -   privateUnlock(ptr);
  13.387 -
  13.388 -   return tmp;
  13.389 -#endif
  13.390 -}
  13.391 -
  13.392 -Uint64
  13.393 -SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value)
  13.394 -{
  13.395 -#ifdef nativeFetchThenSubtract64
  13.396 -#else
  13.397 -   Uint64 tmp = 0;
  13.398 -
  13.399 -   privateWaitLock(ptr);
  13.400 -   tmp = *ptr;
  13.401 -   (*ptr)-= value;
  13.402 -   privateUnlock(ptr);
  13.403 -
  13.404 -   return tmp;
  13.405 -#endif
  13.406 -}
  13.407 -
  13.408 -Uint64
  13.409 -SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr)
  13.410 -{
  13.411 -#ifdef nativeIncrementThenFetch64
  13.412 -#else
  13.413 -   Uint64 tmp = 0;
  13.414 -
  13.415 -   privateWaitLock(ptr);
  13.416 -   (*ptr)+= 1;
  13.417 -   tmp = *ptr;
  13.418 -   privateUnlock(ptr);
  13.419 -
  13.420 -   return tmp;
  13.421 -#endif
  13.422 -}
  13.423 -
  13.424 -Uint64
  13.425 -SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr)
  13.426 -{
  13.427 -#ifdef nativeDecrementThenFetch64
  13.428 -#else
  13.429 -   Uint64 tmp = 0;
  13.430 -
  13.431 -   privateWaitLock(ptr);
  13.432 -   (*ptr)-= 1;
  13.433 -   tmp = *ptr;
  13.434 -   privateUnlock(ptr);
  13.435 -
  13.436 -   return tmp;
  13.437 -#endif
  13.438 -}
  13.439 -
  13.440 -Uint64
  13.441 -SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value)
  13.442 -{
  13.443 -#ifdef nativeAddThenFetch64
  13.444 -#else
  13.445 -   Uint64 tmp = 0;
  13.446 -
  13.447 -   privateWaitLock(ptr);
  13.448 -   (*ptr)+= value;
  13.449 -   tmp = *ptr;
  13.450 -   privateUnlock(ptr);
  13.451 -
  13.452 -   return tmp;
  13.453 -#endif
  13.454 -}
  13.455 -
  13.456 -Uint64
  13.457 -SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value)
  13.458 -{
  13.459 -#ifdef nativeSubtractThenFetch64
  13.460 -#else
  13.461 -   Uint64 tmp = 0;
  13.462 -
  13.463 -   privateWaitLock(ptr);
  13.464 -   (*ptr)-= value;
  13.465 -   tmp = *ptr;
  13.466 -   privateUnlock(ptr);
  13.467 -
  13.468 -   return tmp;
  13.469 -#endif
  13.470 -}
  13.471 -#endif
  13.472 -
    14.1 --- a/src/atomic/qnx/SDL_atomic.c	Sat Jan 15 12:34:43 2011 -0800
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,505 +0,0 @@
    14.4 -/*
    14.5 -    SDL - Simple DirectMedia Layer
    14.6 -    Copyright (C) 1997-2010 Sam Lantinga
    14.7 -
    14.8 -    This library is free software; you can redistribute it and/or
    14.9 -    modify it under the terms of the GNU Lesser General Public
   14.10 -    License as published by the Free Software Foundation; either
   14.11 -    version 2.1 of the License, or (at your option) any later version.
   14.12 -
   14.13 -    This library is distributed in the hope that it will be useful,
   14.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   14.16 -    Lesser General Public License for more details.
   14.17 -
   14.18 -    You should have received a copy of the GNU Lesser General Public
   14.19 -    License along with this library; if not, write to the Free Software
   14.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   14.21 -
   14.22 -    Sam Lantinga
   14.23 -    slouken@libsdl.org
   14.24 -
   14.25 -    QNX native atomic operations
   14.26 -    Copyright (C) 2009 Mike Gorchak
   14.27 -    (mike@malva.ua, lestat@i.com.ua)
   14.28 -*/
   14.29 -
   14.30 -#include "SDL_stdinc.h"
   14.31 -#include "SDL_atomic.h"
   14.32 -#include "SDL_error.h"
   14.33 -
   14.34 -#include <atomic.h>
   14.35 -
   14.36 -/* SMP Exchange for PPC platform */
   14.37 -#ifdef __PPC__
   14.38 -#include <ppc/smpxchg.h>
   14.39 -#endif /* __PPC__ */
   14.40 -
   14.41 -/* SMP Exchange for ARM platform */
   14.42 -#ifdef __ARM__
   14.43 -#include <arm/smpxchg.h>
   14.44 -#endif /* __ARM__ */
   14.45 -
   14.46 -/* SMP Exchange for MIPS platform */
   14.47 -#if defined (__MIPSEB__) || defined(__MIPSEL__)
   14.48 -#include <mips/smpxchg.h>
   14.49 -#endif /* __MIPSEB__ || __MIPSEL__ */
   14.50 -
   14.51 -/* SMP Exchange for SH platform */
   14.52 -#ifdef __SH__
   14.53 -#include <sh/smpxchg.h>
   14.54 -#endif /* __SH__ */
   14.55 -
   14.56 -/* SMP Exchange for x86 platform */
   14.57 -#ifdef __X86__
   14.58 -#include <x86/smpxchg.h>
   14.59 -#endif /* __X86__ */
   14.60 -
   14.61 -/*
   14.62 -  This file provides 32, and 64 bit atomic operations. If the
   14.63 -  operations are provided by the native hardware and operating system
   14.64 -  they are used. If they are not then the operations are emulated
   14.65 -  using the SDL spin lock operations. If spin lock can not be
   14.66 -  implemented then these functions must fail.
   14.67 -*/
   14.68 -
   14.69 -void 
   14.70 -SDL_AtomicLock(SDL_SpinLock *lock)
   14.71 -{
   14.72 -   unsigned volatile* l = (unsigned volatile*)lock;
   14.73 -   Uint32 oldval = 0;
   14.74 -   Uint32 newval = 1;
   14.75 -
   14.76 -   oldval = _smp_xchg(l, newval);
   14.77 -   while(1 == oldval)
   14.78 -   {
   14.79 -      oldval = _smp_xchg(l, newval);
   14.80 -   }
   14.81 -}
   14.82 -
   14.83 -void 
   14.84 -SDL_AtomicUnlock(SDL_SpinLock *lock)
   14.85 -{
   14.86 -   unsigned volatile* l = (unsigned volatile*)lock;
   14.87 -   Uint32 newval = 0;
   14.88 -
   14.89 -   _smp_xchg(l, newval);
   14.90 -}
   14.91 -
   14.92 -/*
   14.93 -   QNX 6.4.1 supports only 32 bit atomic access
   14.94 -*/
   14.95 -
   14.96 -#undef   nativeTestThenSet32
   14.97 -#define  nativeClear32
   14.98 -#define  nativeFetchThenIncrement32
   14.99 -#define  nativeFetchThenDecrement32
  14.100 -#define  nativeFetchThenAdd32
  14.101 -#define  nativeFetchThenSubtract32
  14.102 -#define  nativeIncrementThenFetch32
  14.103 -#define  nativeDecrementThenFetch32
  14.104 -#define  nativeAddThenFetch32
  14.105 -#define  nativeSubtractThenFetch32
  14.106 -
  14.107 -#undef  nativeTestThenSet64
  14.108 -#undef  nativeClear64
  14.109 -#undef  nativeFetchThenIncrement64
  14.110 -#undef  nativeFetchThenDecrement64
  14.111 -#undef  nativeFetchThenAdd64
  14.112 -#undef  nativeFetchThenSubtract64
  14.113 -#undef  nativeIncrementThenFetch64
  14.114 -#undef  nativeDecrementThenFetch64
  14.115 -#undef  nativeAddThenFetch64
  14.116 -#undef  nativeSubtractThenFetch64
  14.117 -
  14.118 -/*
  14.119 -  If any of the operations are not provided then we must emulate some
  14.120 -  of them. That means we need a nice implementation of spin locks
  14.121 -  that avoids the "one big lock" problem. We use a vector of spin
  14.122 -  locks and pick which one to use based on the address of the operand
  14.123 -  of the function.
  14.124 -
  14.125 -  To generate the index of the lock we first shift by 3 bits to get
  14.126 -  rid on the zero bits that result from 32 and 64 bit allignment of
  14.127 -  data. We then mask off all but 5 bits and use those 5 bits as an
  14.128 -  index into the table.
  14.129 -
  14.130 -  Picking the lock this way insures that accesses to the same data at
  14.131 -  the same time will go to the same lock. OTOH, accesses to different
  14.132 -  data have only a 1/32 chance of hitting the same lock. That should
  14.133 -  pretty much eliminate the chances of several atomic operations on
  14.134 -  different data from waiting on the same "big lock". If it isn't
  14.135 -  then the table of locks can be expanded to a new size so long as
  14.136 -  the new size is a power of two.
  14.137 -*/
  14.138 -
  14.139 -static SDL_SpinLock locks[32] = {
  14.140 -   0, 0, 0, 0, 0, 0, 0, 0,
  14.141 -   0, 0, 0, 0, 0, 0, 0, 0,
  14.142 -   0, 0, 0, 0, 0, 0, 0, 0,
  14.143 -   0, 0, 0, 0, 0, 0, 0, 0,
  14.144 -};
  14.145 -
  14.146 -static __inline__ void
  14.147 -privateWaitLock(volatile void *ptr)
  14.148 -{
  14.149 -#if SIZEOF_VOIDP == 4
  14.150 -   Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
  14.151 -#elif SIZEOF_VOIDP == 8
  14.152 -   Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
  14.153 -#endif /* SIZEOF_VOIDP */
  14.154 -
  14.155 -   SDL_AtomicLock(&locks[index]);
  14.156 -}
  14.157 -
  14.158 -static __inline__ void
  14.159 -privateUnlock(volatile void *ptr)
  14.160 -{
  14.161 -#if SIZEOF_VOIDP == 4
  14.162 -   Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
  14.163 -#elif SIZEOF_VOIDP == 8
  14.164 -   Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
  14.165 -#endif /* SIZEOF_VOIDP */
  14.166 -
  14.167 -   SDL_AtomicUnlock(&locks[index]);
  14.168 -}
  14.169 -
  14.170 -/* 32 bit atomic operations */
  14.171 -
  14.172 -SDL_bool
  14.173 -SDL_AtomicTestThenSet32(volatile Uint32 * ptr)
  14.174 -{
  14.175 -#ifdef nativeTestThenSet32
  14.176 -#else
  14.177 -   SDL_bool result = SDL_FALSE;
  14.178 -
  14.179 -   privateWaitLock(ptr);
  14.180 -   result = (*ptr == 0);
  14.181 -   if (result)
  14.182 -   {
  14.183 -      *ptr = 1;
  14.184 -   }
  14.185 -   privateUnlock(ptr);
  14.186 -
  14.187 -   return result;
  14.188 -#endif /* nativeTestThenSet32 */
  14.189 -}
  14.190 -
  14.191 -void
  14.192 -SDL_AtomicClear32(volatile Uint32 * ptr)
  14.193 -{
  14.194 -#ifdef nativeClear32
  14.195 -   atomic_clr(ptr, 0xFFFFFFFF);
  14.196 -#else
  14.197 -   privateWaitLock(ptr);
  14.198 -   *ptr = 0;
  14.199 -   privateUnlock(ptr);
  14.200 -
  14.201 -   return;
  14.202 -#endif /* nativeClear32 */
  14.203 -}
  14.204 -
  14.205 -Uint32
  14.206 -SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr)
  14.207 -{
  14.208 -#ifdef nativeFetchThenIncrement32
  14.209 -   return atomic_add_value(ptr, 0x00000001);
  14.210 -#else
  14.211 -   Uint32 tmp = 0;
  14.212 -
  14.213 -   privateWaitLock(ptr);
  14.214 -   tmp = *ptr;
  14.215 -   (*ptr)+= 1;
  14.216 -   privateUnlock(ptr);
  14.217 -
  14.218 -   return tmp;
  14.219 -#endif /* nativeFetchThenIncrement32 */
  14.220 -}
  14.221 -
  14.222 -Uint32
  14.223 -SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr)
  14.224 -{
  14.225 -#ifdef nativeFetchThenDecrement32
  14.226 -   return atomic_sub_value(ptr, 0x00000001);
  14.227 -#else
  14.228 -   Uint32 tmp = 0;
  14.229 -
  14.230 -   privateWaitLock(ptr);
  14.231 -   tmp = *ptr;
  14.232 -   (*ptr) -= 1;
  14.233 -   privateUnlock(ptr);
  14.234 -
  14.235 -   return tmp;
  14.236 -#endif /* nativeFetchThenDecrement32 */
  14.237 -}
  14.238 -
  14.239 -Uint32
  14.240 -SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value)
  14.241 -{
  14.242 -#ifdef nativeFetchThenAdd32
  14.243 -   return atomic_add_value(ptr, value);
  14.244 -#else
  14.245 -   Uint32 tmp = 0;
  14.246 -
  14.247 -   privateWaitLock(ptr);
  14.248 -   tmp = *ptr;
  14.249 -   (*ptr)+= value;
  14.250 -   privateUnlock(ptr);
  14.251 -
  14.252 -   return tmp;
  14.253 -#endif /* nativeFetchThenAdd32 */
  14.254 -}
  14.255 -
  14.256 -Uint32
  14.257 -SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value)
  14.258 -{
  14.259 -#ifdef nativeFetchThenSubtract32
  14.260 -   return atomic_sub_value(ptr, value);
  14.261 -#else
  14.262 -   Uint32 tmp = 0;
  14.263 -
  14.264 -   privateWaitLock(ptr);
  14.265 -   tmp = *ptr;
  14.266 -   (*ptr)-= value;
  14.267 -   privateUnlock(ptr);
  14.268 -
  14.269 -   return tmp;
  14.270 -#endif /* nativeFetchThenSubtract32 */
  14.271 -}
  14.272 -
  14.273 -Uint32
  14.274 -SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr)
  14.275 -{
  14.276 -#ifdef nativeIncrementThenFetch32
  14.277 -   atomic_add(ptr, 0x00000001);
  14.278 -   return atomic_add_value(ptr, 0x00000000);
  14.279 -#else
  14.280 -   Uint32 tmp = 0;
  14.281 -
  14.282 -   privateWaitLock(ptr);
  14.283 -   (*ptr)+= 1;
  14.284 -   tmp = *ptr;
  14.285 -   privateUnlock(ptr);
  14.286 -
  14.287 -   return tmp;
  14.288 -#endif /* nativeIncrementThenFetch32 */
  14.289 -}
  14.290 -
  14.291 -Uint32
  14.292 -SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr)
  14.293 -{
  14.294 -#ifdef nativeDecrementThenFetch32
  14.295 -   atomic_sub(ptr, 0x00000001);
  14.296 -   return atomic_sub_value(ptr, 0x00000000);
  14.297 -#else
  14.298 -   Uint32 tmp = 0;
  14.299 -
  14.300 -   privateWaitLock(ptr);
  14.301 -   (*ptr)-= 1;
  14.302 -   tmp = *ptr;
  14.303 -   privateUnlock(ptr);
  14.304 -
  14.305 -   return tmp;
  14.306 -#endif /* nativeDecrementThenFetch32 */
  14.307 -}
  14.308 -
  14.309 -Uint32
  14.310 -SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value)
  14.311 -{
  14.312 -#ifdef nativeAddThenFetch32
  14.313 -   atomic_add(ptr, value);
  14.314 -   return atomic_add_value(ptr, 0x00000000);
  14.315 -#else
  14.316 -   Uint32 tmp = 0;
  14.317 -
  14.318 -   privateWaitLock(ptr);
  14.319 -   (*ptr)+= value;
  14.320 -   tmp = *ptr;
  14.321 -   privateUnlock(ptr);
  14.322 -
  14.323 -   return tmp;
  14.324 -#endif /* nativeAddThenFetch32 */
  14.325 -}
  14.326 -
  14.327 -Uint32
  14.328 -SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value)
  14.329 -{
  14.330 -#ifdef nativeSubtractThenFetch32
  14.331 -   atomic_sub(ptr, value);
  14.332 -   return atomic_sub_value(ptr, 0x00000000);
  14.333 -#else
  14.334 -   Uint32 tmp = 0;
  14.335 -
  14.336 -   privateWaitLock(ptr);
  14.337 -   (*ptr)-= value;
  14.338 -   tmp = *ptr;
  14.339 -   privateUnlock(ptr);
  14.340 -
  14.341 -   return tmp;
  14.342 -#endif /* nativeSubtractThenFetch32 */
  14.343 -}
  14.344 -
  14.345 -/* 64 bit atomic operations */
  14.346 -#ifdef SDL_HAS_64BIT_TYPE
  14.347 -
  14.348 -SDL_bool
  14.349 -SDL_AtomicTestThenSet64(volatile Uint64 * ptr)
  14.350 -{
  14.351 -#ifdef nativeTestThenSet64
  14.352 -#else
  14.353 -   SDL_bool result = SDL_FALSE;
  14.354 -
  14.355 -   privateWaitLock(ptr);
  14.356 -   result = (*ptr == 0);
  14.357 -   if (result)
  14.358 -   {
  14.359 -      *ptr = 1;
  14.360 -   }
  14.361 -   privateUnlock(ptr);
  14.362 -
  14.363 -   return result;
  14.364 -#endif /* nativeTestThenSet64 */
  14.365 -}
  14.366 -
  14.367 -void
  14.368 -SDL_AtomicClear64(volatile Uint64 * ptr)
  14.369 -{
  14.370 -#ifdef nativeClear64
  14.371 -#else
  14.372 -   privateWaitLock(ptr);
  14.373 -   *ptr = 0;
  14.374 -   privateUnlock(ptr);
  14.375 -
  14.376 -   return;
  14.377 -#endif /* nativeClear64 */
  14.378 -}
  14.379 -
  14.380 -Uint64
  14.381 -SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr)
  14.382 -{
  14.383 -#ifdef nativeFetchThenIncrement64
  14.384 -#else
  14.385 -   Uint64 tmp = 0;
  14.386 -
  14.387 -   privateWaitLock(ptr);
  14.388 -   tmp = *ptr;
  14.389 -   (*ptr)+= 1;
  14.390 -   privateUnlock(ptr);
  14.391 -
  14.392 -   return tmp;
  14.393 -#endif /* nativeFetchThenIncrement64 */
  14.394 -}
  14.395 -
  14.396 -Uint64
  14.397 -SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr)
  14.398 -{
  14.399 -#ifdef nativeFetchThenDecrement64
  14.400 -#else
  14.401 -   Uint64 tmp = 0;
  14.402 -
  14.403 -   privateWaitLock(ptr);
  14.404 -   tmp = *ptr;
  14.405 -   (*ptr) -= 1;
  14.406 -   privateUnlock(ptr);
  14.407 -
  14.408 -   return tmp;
  14.409 -#endif /* nativeFetchThenDecrement64 */
  14.410 -}
  14.411 -
  14.412 -Uint64
  14.413 -SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value)
  14.414 -{
  14.415 -#ifdef nativeFetchThenAdd64
  14.416 -#else
  14.417 -   Uint64 tmp = 0;
  14.418 -
  14.419 -   privateWaitLock(ptr);
  14.420 -   tmp = *ptr;
  14.421 -   (*ptr)+= value;
  14.422 -   privateUnlock(ptr);
  14.423 -
  14.424 -   return tmp;
  14.425 -#endif /* nativeFetchThenAdd64 */
  14.426 -}
  14.427 -
  14.428 -Uint64
  14.429 -SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value)
  14.430 -{
  14.431 -#ifdef nativeFetchThenSubtract64
  14.432 -#else
  14.433 -   Uint64 tmp = 0;
  14.434 -
  14.435 -   privateWaitLock(ptr);
  14.436 -   tmp = *ptr;
  14.437 -   (*ptr)-= value;
  14.438 -   privateUnlock(ptr);
  14.439 -
  14.440 -   return tmp;
  14.441 -#endif /* nativeFetchThenSubtract64 */
  14.442 -}
  14.443 -
  14.444 -Uint64
  14.445 -SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr)
  14.446 -{
  14.447 -#ifdef nativeIncrementThenFetch64
  14.448 -#else
  14.449 -   Uint64 tmp = 0;
  14.450 -
  14.451 -   privateWaitLock(ptr);
  14.452 -   (*ptr)+= 1;
  14.453 -   tmp = *ptr;
  14.454 -   privateUnlock(ptr);
  14.455 -
  14.456 -   return tmp;
  14.457 -#endif /* nativeIncrementThenFetch64 */
  14.458 -}
  14.459 -
  14.460 -Uint64
  14.461 -SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr)
  14.462 -{
  14.463 -#ifdef nativeDecrementThenFetch64
  14.464 -#else
  14.465 -   Uint64 tmp = 0;
  14.466 -
  14.467 -   privateWaitLock(ptr);
  14.468 -   (*ptr)-= 1;
  14.469 -   tmp = *ptr;
  14.470 -   privateUnlock(ptr);
  14.471 -
  14.472 -   return tmp;
  14.473 -#endif /* nativeDecrementThenFetch64 */
  14.474 -}
  14.475 -
  14.476 -Uint64
  14.477 -SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value)
  14.478 -{
  14.479 -#ifdef nativeAddThenFetch64
  14.480 -#else
  14.481 -   Uint64 tmp = 0;
  14.482 -
  14.483 -   privateWaitLock(ptr);
  14.484 -   (*ptr)+= value;
  14.485 -   tmp = *ptr;
  14.486 -   privateUnlock(ptr);
  14.487 -
  14.488 -   return tmp;
  14.489 -#endif /* nativeAddThenFetch64 */
  14.490 -}
  14.491 -
  14.492 -Uint64
  14.493 -SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value)
  14.494 -{
  14.495 -#ifdef nativeSubtractThenFetch64
  14.496 -#else
  14.497 -   Uint64 tmp = 0;
  14.498 -
  14.499 -   privateWaitLock(ptr);
  14.500 -   (*ptr)-= value;
  14.501 -   tmp = *ptr;
  14.502 -   privateUnlock(ptr);
  14.503 -
  14.504 -   return tmp;
  14.505 -#endif /* nativeSubtractThenFetch64 */
  14.506 -}
  14.507 -
  14.508 -#endif /* SDL_HAS_64BIT_TYPE */
    15.1 --- a/src/atomic/win32/SDL_atomic.c	Sat Jan 15 12:34:43 2011 -0800
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,512 +0,0 @@
    15.4 -/*
    15.5 -  SDL - Simple DirectMedia Layer
    15.6 -  Copyright (C) 1997-2010 Sam Lantinga
    15.7 -
    15.8 -  This library is free software; you can redistribute it and/or
    15.9 -  modify it under the terms of the GNU Lesser General Public
   15.10 -  License as published by the Free Software Foundation; either
   15.11 -  version 2.1 of the License, or (at your option) any later version.
   15.12 -
   15.13 -  This library is distributed in the hope that it will be useful,
   15.14 -  but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.15 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15.16 -  Lesser General Public License for more details.
   15.17 -
   15.18 -  You should have received a copy of the GNU Lesser General Public
   15.19 -  License along with this library; if not, write to the Free Software
   15.20 -  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   15.21 -
   15.22 -  Sam Lantinga
   15.23 -  slouken@libsdl.org
   15.24 -
   15.25 -  Contributed by Bob Pendleton, bob@pendleton.com
   15.26 -*/
   15.27 -
   15.28 -#include "SDL_stdinc.h"
   15.29 -#include "SDL_atomic.h"
   15.30 -
   15.31 -#define WIN32_LEAN_AND_MEAN
   15.32 -#include <windows.h>
   15.33 -
   15.34 -#include "SDL_error.h"
   15.35 -
   15.36 -/*
   15.37 -  This file provides 32, and 64 bit atomic operations. If the
   15.38 -  operations are provided by the native hardware and operating system
   15.39 -  they are used. If they are not then the operations are emulated
   15.40 -  using the SDL spin lock operations. If spin lock can not be
   15.41 -  implemented then these functions must fail.
   15.42 -*/
   15.43 -
   15.44 -/* 
   15.45 -  WIN32 VERSION.
   15.46 -
   15.47 -  This makes use of native Windows atomic operations.
   15.48 -*/
   15.49 -
   15.50 -/*
   15.51 -  Native spinlock routines. Because this is the dummy implementation
   15.52 -  these will always call SDL_SetError() and do nothing.
   15.53 -*/
   15.54 -
   15.55 -void 
   15.56 -SDL_AtomicLock(SDL_SpinLock *lock)
   15.57 -{
   15.58 -  long volatile * l = (long volatile *)lock;
   15.59 -  Uint32 old = 0;
   15.60 -  Uint32 new = 1;
   15.61 -
   15.62 -  old = InterlockedExchange(l, new);
   15.63 -  while(1 == old)
   15.64 -    {
   15.65 -      old = InterlockedExchange(l, new);
   15.66 -    }
   15.67 -}
   15.68 -
   15.69 -void 
   15.70 -SDL_AtomicUnlock(SDL_SpinLock *lock)
   15.71 -{
   15.72 -  long volatile * l = (long volatile *)lock;
   15.73 -  Uint32 new = 0;
   15.74 -
   15.75 -  InterlockedExchange(l, new);
   15.76 -}
   15.77 -
   15.78 -/*
   15.79 -  Note that platform specific versions can be built from this version
   15.80 -  by changing the #undefs to #defines and adding platform specific
   15.81 -  code.
   15.82 -*/
   15.83 -
   15.84 -#define nativeTestThenSet32
   15.85 -#define nativeClear32
   15.86 -#define nativeFetchThenIncrement32
   15.87 -#define nativeFetchThenDecrement32
   15.88 -#define nativeFetchThenAdd32
   15.89 -#define nativeFetchThenSubtract32
   15.90 -#define nativeIncrementThenFetch32
   15.91 -#define nativeDecrementThenFetch32
   15.92 -#define nativeAddThenFetch32
   15.93 -#define nativeSubtractThenFetch32
   15.94 -
   15.95 -#undef  nativeTestThenSet64
   15.96 -#undef  nativeClear64
   15.97 -#undef  nativeFetchThenIncrement64
   15.98 -#undef  nativeFetchThenDecrement64
   15.99 -#undef  nativeFetchThenAdd64
  15.100 -#undef  nativeFetchThenSubtract64
  15.101 -#undef  nativeIncrementThenFetch64
  15.102 -#undef  nativeDecrementThenFetch64
  15.103 -#undef  nativeAddThenFetch64
  15.104 -#undef  nativeSubtractThenFetch64
  15.105 -
  15.106 -/* 
  15.107 -  If any of the operations are not provided then we must emulate some
  15.108 -  of them. That means we need a nice implementation of spin locks
  15.109 -  that avoids the "one big lock" problem. We use a vector of spin
  15.110 -  locks and pick which one to use based on the address of the operand
  15.111 -  of the function.
  15.112 -
  15.113 -  To generate the index of the lock we first shift by 3 bits to get
  15.114 -  rid on the zero bits that result from 32 and 64 bit allignment of
  15.115 -  data. We then mask off all but 5 bits and use those 5 bits as an
  15.116 -  index into the table. 
  15.117 -
  15.118 -  Picking the lock this way insures that accesses to the same data at
  15.119 -  the same time will go to the same lock. OTOH, accesses to different
  15.120 -  data have only a 1/32 chance of hitting the same lock. That should
  15.121 -  pretty much eliminate the chances of several atomic operations on
  15.122 -  different data from waiting on the same "big lock". If it isn't
  15.123 -  then the table of locks can be expanded to a new size so long as
  15.124 -  the new size is a power of two.
  15.125 -*/
  15.126 -
  15.127 -static SDL_SpinLock locks[32] = {
  15.128 -   0, 0, 0, 0, 0, 0, 0, 0,
  15.129 -   0, 0, 0, 0, 0, 0, 0, 0,
  15.130 -   0, 0, 0, 0, 0, 0, 0, 0,
  15.131 -   0, 0, 0, 0, 0, 0, 0, 0,
  15.132 -};
  15.133 -
  15.134 -static __inline__ void
  15.135 -privateWaitLock(volatile void *ptr)
  15.136 -{
  15.137 -#if SIZEOF_VOIDP == 4
  15.138 -   Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
  15.139 -#elif SIZEOF_VOIDP == 8
  15.140 -   Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
  15.141 -#endif
  15.142 -
  15.143 -   SDL_AtomicLock(&locks[index]);
  15.144 -}
  15.145 -
  15.146 -static __inline__ void
  15.147 -privateUnlock(volatile void *ptr)
  15.148 -{
  15.149 -#if SIZEOF_VOIDP == 4
  15.150 -   Uint32 index = ((((Uint32)ptr) >> 3) & 0x1f);
  15.151 -#elif SIZEOF_VOIDP == 8
  15.152 -   Uint64 index = ((((Uint64)ptr) >> 3) & 0x1f);
  15.153 -#endif
  15.154 -
  15.155 -   SDL_AtomicUnlock(&locks[index]);
  15.156 -}
  15.157 -
  15.158 -/* 32 bit atomic operations */
  15.159 -
  15.160 -SDL_bool
  15.161 -SDL_AtomicTestThenSet32(volatile Uint32 * ptr)
  15.162 -{
  15.163 -#ifdef nativeTestThenSet32
  15.164 -  long volatile * p = (long volatile *)ptr;
  15.165 -  Uint32 new = 1;
  15.166 -
  15.167 -  return 0 == InterlockedExchange(p, new);
  15.168 -#else
  15.169 -   SDL_bool result = SDL_FALSE;
  15.170 -
  15.171 -   privateWaitLock(ptr);
  15.172 -   result = (*ptr == 0);
  15.173 -   if (result)
  15.174 -   {
  15.175 -      *ptr = 1;
  15.176 -   }
  15.177 -   privateUnlock(ptr);
  15.178 -
  15.179 -   return result;
  15.180 -#endif
  15.181 -}
  15.182 -
  15.183 -void
  15.184 -SDL_AtomicClear32(volatile Uint32 * ptr)
  15.185 -{
  15.186 -#ifdef nativeClear32
  15.187 -  long volatile * p = (long volatile *)ptr;
  15.188 -  Uint32 new = 0;
  15.189 -
  15.190 -  InterlockedExchange(p, new);
  15.191 -#else
  15.192 -   privateWaitLock(ptr);
  15.193 -   *ptr = 0;
  15.194 -   privateUnlock(ptr);
  15.195 -
  15.196 -   return;
  15.197 -#endif
  15.198 -}
  15.199 -
  15.200 -Uint32
  15.201 -SDL_AtomicFetchThenIncrement32(volatile Uint32 * ptr)
  15.202 -{
  15.203 -#ifdef nativeFetchThenIncrement32
  15.204 -  long volatile * p = (long volatile *)ptr;
  15.205 -
  15.206 -  return InterlockedExchangeAdd(p, 1);
  15.207 -#else
  15.208 -   Uint32 tmp = 0;
  15.209 -
  15.210 -   privateWaitLock(ptr);
  15.211 -   tmp = *ptr;
  15.212 -   (*ptr)+= 1;
  15.213 -   privateUnlock(ptr);
  15.214 -
  15.215 -   return tmp;
  15.216 -#endif
  15.217 -}
  15.218 -
  15.219 -Uint32
  15.220 -SDL_AtomicFetchThenDecrement32(volatile Uint32 * ptr)
  15.221 -{
  15.222 -#ifdef nativeFetchThenDecrement32
  15.223 -  long volatile * p = (long volatile *)ptr;
  15.224 -
  15.225 -  return InterlockedExchangeAdd(p, -1);
  15.226 -#else
  15.227 -   Uint32 tmp = 0;
  15.228 -
  15.229 -   privateWaitLock(ptr);
  15.230 -   tmp = *ptr;
  15.231 -   (*ptr) -= 1;
  15.232 -   privateUnlock(ptr);
  15.233 -
  15.234 -   return tmp;
  15.235 -#endif
  15.236 -}
  15.237 -
  15.238 -Uint32
  15.239 -SDL_AtomicFetchThenAdd32(volatile Uint32 * ptr, Uint32 value)
  15.240 -{
  15.241 -#ifdef nativeFetchThenAdd32
  15.242 -  long volatile * p = (long volatile *)ptr;
  15.243 -
  15.244 -  return InterlockedExchangeAdd(p, value);
  15.245 -#else
  15.246 -   Uint32 tmp = 0;
  15.247 -
  15.248 -   privateWaitLock(ptr);
  15.249 -   tmp = *ptr;
  15.250 -   (*ptr)+= value;
  15.251 -   privateUnlock(ptr);
  15.252 -
  15.253 -   return tmp;
  15.254 -#endif
  15.255 -}
  15.256 -
  15.257 -Uint32
  15.258 -SDL_AtomicFetchThenSubtract32(volatile Uint32 * ptr, Uint32 value)
  15.259 -{
  15.260 -#ifdef nativeFetchThenSubtract32
  15.261 -  long volatile * p = (long volatile *)ptr;
  15.262 -
  15.263 -  return InterlockedExchangeAdd(p, (0 - value));
  15.264 -#else
  15.265 -   Uint32 tmp = 0;
  15.266 -
  15.267 -   privateWaitLock(ptr);
  15.268 -   tmp = *ptr;
  15.269 -   (*ptr)-= value;
  15.270 -   privateUnlock(ptr);
  15.271 -
  15.272 -   return tmp;
  15.273 -#endif
  15.274 -}
  15.275 -
  15.276 -Uint32
  15.277 -SDL_AtomicIncrementThenFetch32(volatile Uint32 * ptr)
  15.278 -{
  15.279 -#ifdef nativeIncrementThenFetch32
  15.280 -  long volatile * p = (LONG volatile *)ptr;
  15.281 -
  15.282 -  return InterlockedIncrement(p);
  15.283 -#else
  15.284 -   Uint32 tmp = 0;
  15.285 -
  15.286 -   privateWaitLock(ptr);
  15.287 -   (*ptr)+= 1;
  15.288 -   tmp = *ptr;
  15.289 -   privateUnlock(ptr);
  15.290 -
  15.291 -   return tmp;
  15.292 -#endif
  15.293 -}
  15.294 -
  15.295 -Uint32
  15.296 -SDL_AtomicDecrementThenFetch32(volatile Uint32 * ptr)
  15.297 -{
  15.298 -#ifdef nativeDecrementThenFetch32
  15.299 -  long volatile * p = (LONG volatile *)ptr;
  15.300 -
  15.301 -  return InterlockedDecrement(p);
  15.302 -#else
  15.303 -   Uint32 tmp = 0;
  15.304 -
  15.305 -   privateWaitLock(ptr);
  15.306 -   (*ptr)-= 1;
  15.307 -   tmp = *ptr;
  15.308 -   privateUnlock(ptr);
  15.309 -
  15.310 -   return tmp;
  15.311 -#endif
  15.312 -}
  15.313 -
  15.314 -Uint32
  15.315 -SDL_AtomicAddThenFetch32(volatile Uint32 * ptr, Uint32 value)
  15.316 -{
  15.317 -#ifdef nativeAddThenFetch32
  15.318 -  long volatile * p = (long volatile *)ptr;
  15.319 -
  15.320 -  return InterlockedExchangeAdd(p, value) + value;
  15.321 -#else
  15.322 -   Uint32 tmp = 0;
  15.323 -
  15.324 -   privateWaitLock(ptr);
  15.325 -   (*ptr)+= value;
  15.326 -   tmp = *ptr;
  15.327 -   privateUnlock(ptr);
  15.328 -
  15.329 -   return tmp;
  15.330 -#endif
  15.331 -}
  15.332 -
  15.333 -Uint32
  15.334 -SDL_AtomicSubtractThenFetch32(volatile Uint32 * ptr, Uint32 value)
  15.335 -{
  15.336 -#ifdef nativeSubtractThenFetch32
  15.337 -  long volatile * p = (long volatile *)ptr;
  15.338 -
  15.339 -  return InterlockedExchangeAdd(p, (0 - value)) - value;
  15.340 -#else
  15.341 -   Uint32 tmp = 0;
  15.342 -
  15.343 -   privateWaitLock(ptr);
  15.344 -   (*ptr)-= value;
  15.345 -   tmp = *ptr;
  15.346 -   privateUnlock(ptr);
  15.347 -
  15.348 -   return tmp;
  15.349 -#endif
  15.350 -}
  15.351 -
  15.352 -/* 64 bit atomic operations */
  15.353 -#ifdef SDL_HAS_64BIT_TYPE
  15.354 -
  15.355 -SDL_bool
  15.356 -SDL_AtomicTestThenSet64(volatile Uint64 * ptr)
  15.357 -{
  15.358 -#ifdef nativeTestThenSet64
  15.359 -#else
  15.360 -   SDL_bool result = SDL_FALSE;
  15.361 -
  15.362 -   privateWaitLock(ptr);
  15.363 -   result = (*ptr == 0);
  15.364 -   if (result)
  15.365 -   {
  15.366 -      *ptr = 1;
  15.367 -   }
  15.368 -   privateUnlock(ptr);
  15.369 -
  15.370 -   return result;
  15.371 -#endif
  15.372 -}
  15.373 -
  15.374 -void
  15.375 -SDL_AtomicClear64(volatile Uint64 * ptr)
  15.376 -{
  15.377 -#ifdef nativeClear64
  15.378 -#else
  15.379 -   privateWaitLock(ptr);
  15.380 -   *ptr = 0;
  15.381 -   privateUnlock(ptr);
  15.382 -
  15.383 -   return;
  15.384 -#endif
  15.385 -}
  15.386 -
  15.387 -Uint64
  15.388 -SDL_AtomicFetchThenIncrement64(volatile Uint64 * ptr)
  15.389 -{
  15.390 -#ifdef nativeFetchThenIncrement64
  15.391 -#else
  15.392 -   Uint64 tmp = 0;
  15.393 -
  15.394 -   privateWaitLock(ptr);
  15.395 -   tmp = *ptr;
  15.396 -   (*ptr)+= 1;
  15.397 -   privateUnlock(ptr);
  15.398 -
  15.399 -   return tmp;
  15.400 -#endif
  15.401 -}
  15.402 -
  15.403 -Uint64
  15.404 -SDL_AtomicFetchThenDecrement64(volatile Uint64 * ptr)
  15.405 -{
  15.406 -#ifdef nativeFetchThenDecrement64
  15.407 -#else
  15.408 -   Uint64 tmp = 0;
  15.409 -
  15.410 -   privateWaitLock(ptr);
  15.411 -   tmp = *ptr;
  15.412 -   (*ptr) -= 1;
  15.413 -   privateUnlock(ptr);
  15.414 -
  15.415 -   return tmp;
  15.416 -#endif
  15.417 -}
  15.418 -
  15.419 -Uint64
  15.420 -SDL_AtomicFetchThenAdd64(volatile Uint64 * ptr, Uint64 value)
  15.421 -{
  15.422 -#ifdef nativeFetchThenAdd64
  15.423 -#else
  15.424 -   Uint64 tmp = 0;
  15.425 -
  15.426 -   privateWaitLock(ptr);
  15.427 -   tmp = *ptr;
  15.428 -   (*ptr)+= value;
  15.429 -   privateUnlock(ptr);
  15.430 -
  15.431 -   return tmp;
  15.432 -#endif
  15.433 -}
  15.434 -
  15.435 -Uint64
  15.436 -SDL_AtomicFetchThenSubtract64(volatile Uint64 * ptr, Uint64 value)
  15.437 -{
  15.438 -#ifdef nativeFetchThenSubtract64
  15.439 -#else
  15.440 -   Uint64 tmp = 0;
  15.441 -
  15.442 -   privateWaitLock(ptr);
  15.443 -   tmp = *ptr;
  15.444 -   (*ptr)-= value;
  15.445 -   privateUnlock(ptr);
  15.446 -
  15.447 -   return tmp;
  15.448 -#endif
  15.449 -}
  15.450 -
  15.451 -Uint64
  15.452 -SDL_AtomicIncrementThenFetch64(volatile Uint64 * ptr)
  15.453 -{
  15.454 -#ifdef nativeIncrementThenFetch64
  15.455 -#else
  15.456 -   Uint64 tmp = 0;
  15.457 -
  15.458 -   privateWaitLock(ptr);
  15.459 -   (*ptr)+= 1;
  15.460 -   tmp = *ptr;
  15.461 -   privateUnlock(ptr);
  15.462 -
  15.463 -   return tmp;
  15.464 -#endif
  15.465 -}
  15.466 -
  15.467 -Uint64
  15.468 -SDL_AtomicDecrementThenFetch64(volatile Uint64 * ptr)
  15.469 -{
  15.470 -#ifdef nativeDecrementThenFetch64
  15.471 -#else
  15.472 -   Uint64 tmp = 0;
  15.473 -
  15.474 -   privateWaitLock(ptr);
  15.475 -   (*ptr)-= 1;
  15.476 -   tmp = *ptr;
  15.477 -   privateUnlock(ptr);
  15.478 -
  15.479 -   return tmp;
  15.480 -#endif
  15.481 -}
  15.482 -
  15.483 -Uint64
  15.484 -SDL_AtomicAddThenFetch64(volatile Uint64 * ptr, Uint64 value)
  15.485 -{
  15.486 -#ifdef nativeAddThenFetch64
  15.487 -#else
  15.488 -   Uint64 tmp = 0;
  15.489 -
  15.490 -   privateWaitLock(ptr);
  15.491 -   (*ptr)+= value;
  15.492 -   tmp = *ptr;
  15.493 -   privateUnlock(ptr);
  15.494 -
  15.495 -   return tmp;
  15.496 -#endif
  15.497 -}
  15.498 -
  15.499 -Uint64
  15.500 -SDL_AtomicSubtractThenFetch64(volatile Uint64 * ptr, Uint64 value)
  15.501 -{
  15.502 -#ifdef nativeSubtractThenFetch64
  15.503 -#else
  15.504 -   Uint64 tmp = 0;
  15.505 -
  15.506 -   privateWaitLock(ptr);
  15.507 -   (*ptr)-= value;
  15.508 -   tmp = *ptr;
  15.509 -   privateUnlock(ptr);
  15.510 -
  15.511 -   return tmp;
  15.512 -#endif
  15.513 -}
  15.514 -#endif
  15.515 -
    16.1 --- a/test/testatomic.c	Sat Jan 15 12:34:43 2011 -0800
    16.2 +++ b/test/testatomic.c	Sat Jan 15 12:41:59 2011 -0800
    16.3 @@ -1,18 +1,6 @@
    16.4  #include <stdio.h>
    16.5  #include "SDL.h"
    16.6  
    16.7 -/* Make sure we have good macros for printing 32 and 64 bit values */
    16.8 -#ifndef PRIu32
    16.9 -#define PRIu32 "u"
   16.10 -#endif
   16.11 -#ifndef PRIu64
   16.12 -#ifdef __WIN32__
   16.13 -#define PRIu64 "I64u"
   16.14 -#else
   16.15 -#define PRIu64 "llu"
   16.16 -#endif
   16.17 -#endif
   16.18 -
   16.19  /*
   16.20    Absolutely basic tests just to see if we get the expected value
   16.21    after calling each function.
   16.22 @@ -21,109 +9,60 @@
   16.23  char *
   16.24  tf(SDL_bool tf)
   16.25  {
   16.26 -   static char *t = "true";
   16.27 -   static char *f = "false";
   16.28 +    static char *t = "TRUE";
   16.29 +    static char *f = "FALSE";
   16.30  
   16.31 -   if (tf)
   16.32 -   {
   16.33 -      return t;
   16.34 -   }
   16.35 +    if (tf)
   16.36 +    {
   16.37 +       return t;
   16.38 +    }
   16.39  
   16.40 -   return f;
   16.41 +    return f;
   16.42  }
   16.43  
   16.44  int
   16.45  main(int argc, char *argv[])
   16.46  {
   16.47 +    int value;
   16.48 +    SDL_SpinLock lock = 0;
   16.49  
   16.50 -   volatile Uint32 val32 = 0;
   16.51 -   Uint32 ret32 = 0;
   16.52 +    SDL_bool tfret = SDL_FALSE;
   16.53  
   16.54 -   volatile Uint64 val64 = 0;
   16.55 -   Uint64 ret64 = 0;
   16.56 +    printf("\nspin lock---------------------------------------\n\n");
   16.57  
   16.58 -   SDL_SpinLock lock = 0;
   16.59 +    SDL_AtomicLock(&lock);
   16.60 +    printf("AtomicLock                   lock=%d\n", lock);
   16.61 +    SDL_AtomicUnlock(&lock);
   16.62 +    printf("AtomicUnlock                 lock=%d\n", lock);
   16.63  
   16.64 -   SDL_bool tfret = SDL_FALSE;
   16.65 +    printf("\natomic -----------------------------------------\n\n");
   16.66  
   16.67 -   printf("\nspin lock---------------------------------------\n\n");
   16.68 +    SDL_atomic_t v;
   16.69 +     
   16.70 +    SDL_AtomicSet(&v, 0);
   16.71 +    tfret = SDL_AtomicSet(&v, 10) == 0;
   16.72 +    printf("AtomicSet(10)        tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v));
   16.73 +    tfret = SDL_AtomicAdd(&v, 10) == 10;
   16.74 +    printf("AtomicAdd(10)        tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v));
   16.75  
   16.76 -   SDL_AtomicLock(&lock);
   16.77 -   printf("AtomicLock                   lock=%d\n", lock);
   16.78 -   SDL_AtomicUnlock(&lock);
   16.79 -   printf("AtomicUnlock                 lock=%d\n", lock);
   16.80 +    SDL_AtomicSet(&v, 0);
   16.81 +    SDL_AtomicIncRef(&v);
   16.82 +    tfret = (SDL_AtomicGet(&v) == 1);
   16.83 +    printf("AtomicIncRef()       tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v));
   16.84 +    SDL_AtomicIncRef(&v);
   16.85 +    tfret = (SDL_AtomicGet(&v) == 2);
   16.86 +    printf("AtomicIncRef()       tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v));
   16.87 +    tfret = (SDL_AtomicDecRef(&v) == SDL_FALSE);
   16.88 +    printf("AtomicDecRef()       tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v));
   16.89 +    tfret = (SDL_AtomicDecRef(&v) == SDL_TRUE);
   16.90 +    printf("AtomicDecRef()       tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v));
   16.91  
   16.92 -   printf("\n32 bit -----------------------------------------\n\n");
   16.93 +    SDL_AtomicSet(&v, 10);
   16.94 +    tfret = (SDL_AtomicCAS(&v, 0, 20) != 0);
   16.95 +    printf("AtomicCAS()          tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v));
   16.96 +    value = SDL_AtomicGet(&v);
   16.97 +    tfret = (SDL_AtomicCAS(&v, value, 20) == value);
   16.98 +    printf("AtomicCAS()          tfret=%s val=%"PRIu32"\n", tf(tfret), SDL_AtomicGet(&v));
   16.99  
  16.100 -   val32 = 0;
  16.101 -   tfret = SDL_AtomicTestThenSet32(&val32);
  16.102 -   printf("TestThenSet32        tfret=%s val=%"PRIu32"\n", tf(tfret), val32);
  16.103 -   tfret = SDL_AtomicTestThenSet32(&val32);
  16.104 -   printf("TestThenSet32        tfret=%s val=%"PRIu32"\n", tf(tfret), val32);
  16.105 -
  16.106 -   SDL_AtomicClear32(&val32);
  16.107 -   printf("Clear32              val=%"PRIu32"\n", val32);
  16.108 -
  16.109 -   ret32 = SDL_AtomicFetchThenIncrement32(&val32);
  16.110 -   printf("FetchThenIncrement32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
  16.111 -
  16.112 -   ret32 = SDL_AtomicFetchThenDecrement32(&val32);
  16.113 -   printf("FetchThenDecrement32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
  16.114 -
  16.115 -   ret32 = SDL_AtomicFetchThenAdd32(&val32, 10);
  16.116 -   printf("FetchThenAdd32       ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
  16.117 -
  16.118 -   ret32 = SDL_AtomicFetchThenSubtract32(&val32, 10);
  16.119 -   printf("FetchThenSubtract32  ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
  16.120 -
  16.121 -   ret32 = SDL_AtomicIncrementThenFetch32(&val32);
  16.122 -   printf("IncrementThenFetch32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
  16.123 -
  16.124 -   ret32 = SDL_AtomicDecrementThenFetch32(&val32);
  16.125 -   printf("DecrementThenFetch32 ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
  16.126 -
  16.127 -   ret32 = SDL_AtomicAddThenFetch32(&val32, 10);
  16.128 -   printf("AddThenFetch32       ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
  16.129 -
  16.130 -   ret32 = SDL_AtomicSubtractThenFetch32(&val32, 10);
  16.131 -   printf("SubtractThenFetch32  ret=%"PRIu32" val=%"PRIu32"\n", ret32, val32);
  16.132 -
  16.133 -#ifdef SDL_HAS_64BIT_TYPE
  16.134 -   printf("\n64 bit -----------------------------------------\n\n");
  16.135 -
  16.136 -   val64 = 0;
  16.137 -   tfret = SDL_AtomicTestThenSet64(&val64);
  16.138 -   printf("TestThenSet64        tfret=%s val=%"PRIu64"\n", tf(tfret), val64);
  16.139 -   tfret = SDL_AtomicTestThenSet64(&val64);
  16.140 -   printf("TestThenSet64        tfret=%s val=%"PRIu64"\n", tf(tfret), val64);
  16.141 -
  16.142 -   SDL_AtomicClear64(&val64);
  16.143 -   printf("Clear64              val=%"PRIu64"\n", val64);
  16.144 -
  16.145 -   ret64 = SDL_AtomicFetchThenIncrement64(&val64);
  16.146 -   printf("FetchThenIncrement64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
  16.147 -
  16.148 -   ret64 = SDL_AtomicFetchThenDecrement64(&val64);
  16.149 -   printf("FetchThenDecrement64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
  16.150 -
  16.151 -   ret64 = SDL_AtomicFetchThenAdd64(&val64, 10);
  16.152 -   printf("FetchThenAdd64       ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
  16.153 -
  16.154 -   ret64 = SDL_AtomicFetchThenSubtract64(&val64, 10);
  16.155 -   printf("FetchThenSubtract64  ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
  16.156 -
  16.157 -   ret64 = SDL_AtomicIncrementThenFetch64(&val64);
  16.158 -   printf("IncrementThenFetch64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
  16.159 -
  16.160 -   ret64 = SDL_AtomicDecrementThenFetch64(&val64);
  16.161 -   printf("DecrementThenFetch64 ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
  16.162 -
  16.163 -   ret64 = SDL_AtomicAddThenFetch64(&val64, 10);
  16.164 -   printf("AddThenFetch64       ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
  16.165 -
  16.166 -   ret64 = SDL_AtomicSubtractThenFetch64(&val64, 10);
  16.167 -   printf("SubtractThenFetch64  ret=%"PRIu64" val=%"PRIu64"\n", ret64, val64);
  16.168 -#endif
  16.169 -
  16.170 -   return 0;
  16.171 -   }
  16.172 +    return 0;
  16.173 +}