gosu 0.15.2 → 1.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dependencies/SDL/include/SDL.h +138 -0
- data/dependencies/SDL/include/SDL_assert.h +293 -0
- data/dependencies/SDL/include/SDL_atomic.h +295 -0
- data/dependencies/SDL/include/SDL_audio.h +859 -0
- data/dependencies/SDL/include/SDL_bits.h +121 -0
- data/dependencies/SDL/include/SDL_blendmode.h +123 -0
- data/dependencies/SDL/include/SDL_clipboard.h +71 -0
- data/dependencies/SDL/include/SDL_config.h +55 -0
- data/dependencies/SDL/include/SDL_config_android.h +182 -0
- data/dependencies/SDL/include/SDL_config_iphoneos.h +207 -0
- data/dependencies/SDL/include/SDL_config_macosx.h +266 -0
- data/dependencies/SDL/include/SDL_config_minimal.h +85 -0
- data/dependencies/SDL/include/SDL_config_os2.h +188 -0
- data/dependencies/SDL/include/SDL_config_pandora.h +135 -0
- data/dependencies/SDL/include/SDL_config_psp.h +165 -0
- data/dependencies/SDL/include/SDL_config_windows.h +288 -0
- data/dependencies/SDL/include/SDL_config_winrt.h +243 -0
- data/dependencies/SDL/include/SDL_config_wiz.h +149 -0
- data/dependencies/SDL/include/SDL_copying.h +20 -0
- data/dependencies/SDL/include/SDL_cpuinfo.h +299 -0
- data/dependencies/SDL/include/SDL_egl.h +1676 -0
- data/dependencies/SDL/include/SDL_endian.h +263 -0
- data/dependencies/SDL/include/SDL_error.h +112 -0
- data/dependencies/SDL/include/SDL_events.h +827 -0
- data/dependencies/SDL/include/SDL_filesystem.h +136 -0
- data/dependencies/SDL/include/SDL_gamecontroller.h +541 -0
- data/dependencies/SDL/include/SDL_gesture.h +87 -0
- data/dependencies/SDL/include/SDL_haptic.h +1247 -0
- data/dependencies/SDL/include/SDL_hints.h +1578 -0
- data/dependencies/SDL/include/SDL_joystick.h +499 -0
- data/dependencies/SDL/include/SDL_keyboard.h +217 -0
- data/dependencies/SDL/include/SDL_keycode.h +351 -0
- data/dependencies/SDL/include/SDL_loadso.h +81 -0
- data/dependencies/SDL/include/SDL_locale.h +101 -0
- data/dependencies/SDL/include/SDL_log.h +211 -0
- data/dependencies/SDL/include/SDL_main.h +180 -0
- data/dependencies/SDL/include/SDL_messagebox.h +146 -0
- data/dependencies/SDL/include/SDL_metal.h +117 -0
- data/dependencies/SDL/include/SDL_misc.h +75 -0
- data/dependencies/SDL/include/SDL_mouse.h +302 -0
- data/dependencies/SDL/include/SDL_mutex.h +251 -0
- data/dependencies/SDL/include/SDL_name.h +33 -0
- data/dependencies/SDL/include/SDL_opengl.h +2183 -0
- data/dependencies/SDL/include/SDL_opengl_glext.h +11180 -0
- data/dependencies/SDL/include/SDL_opengles.h +39 -0
- data/dependencies/SDL/include/SDL_opengles2.h +52 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2.h +621 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2ext.h +2050 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2platform.h +30 -0
- data/dependencies/SDL/include/SDL_opengles2_khrplatform.h +282 -0
- data/dependencies/SDL/include/SDL_pixels.h +479 -0
- data/dependencies/SDL/include/SDL_platform.h +198 -0
- data/dependencies/SDL/include/SDL_power.h +75 -0
- data/dependencies/SDL/include/SDL_quit.h +58 -0
- data/dependencies/SDL/include/SDL_rect.h +174 -0
- data/dependencies/SDL/include/SDL_render.h +1158 -0
- data/dependencies/SDL/include/SDL_revision.h +2 -0
- data/dependencies/SDL/include/SDL_rwops.h +283 -0
- data/dependencies/SDL/include/SDL_scancode.h +413 -0
- data/dependencies/SDL/include/SDL_sensor.h +267 -0
- data/dependencies/SDL/include/SDL_shape.h +144 -0
- data/dependencies/SDL/include/SDL_stdinc.h +647 -0
- data/dependencies/SDL/include/SDL_surface.h +563 -0
- data/dependencies/SDL/include/SDL_system.h +325 -0
- data/dependencies/SDL/include/SDL_syswm.h +354 -0
- data/dependencies/SDL/include/SDL_test.h +69 -0
- data/dependencies/SDL/include/SDL_test_assert.h +105 -0
- data/dependencies/SDL/include/SDL_test_common.h +218 -0
- data/dependencies/SDL/include/SDL_test_compare.h +69 -0
- data/dependencies/SDL/include/SDL_test_crc32.h +124 -0
- data/dependencies/SDL/include/SDL_test_font.h +81 -0
- data/dependencies/SDL/include/SDL_test_fuzzer.h +384 -0
- data/dependencies/SDL/include/SDL_test_harness.h +134 -0
- data/dependencies/SDL/include/SDL_test_images.h +78 -0
- data/dependencies/SDL/include/SDL_test_log.h +67 -0
- data/dependencies/SDL/include/SDL_test_md5.h +129 -0
- data/dependencies/SDL/include/SDL_test_memory.h +63 -0
- data/dependencies/SDL/include/SDL_test_random.h +115 -0
- data/dependencies/SDL/include/SDL_thread.h +366 -0
- data/dependencies/SDL/include/SDL_timer.h +115 -0
- data/dependencies/SDL/include/SDL_touch.h +102 -0
- data/dependencies/SDL/include/SDL_types.h +29 -0
- data/dependencies/SDL/include/SDL_version.h +162 -0
- data/dependencies/SDL/include/SDL_video.h +1282 -0
- data/dependencies/SDL/include/SDL_vulkan.h +276 -0
- data/dependencies/SDL/include/begin_code.h +166 -0
- data/dependencies/SDL/include/close_code.h +40 -0
- data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
- data/dependencies/SDL_sound/SDL_sound.c +795 -0
- data/dependencies/SDL_sound/SDL_sound.h +725 -0
- data/dependencies/SDL_sound/SDL_sound_aiff.c +537 -0
- data/dependencies/SDL_sound/SDL_sound_au.c +352 -0
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +747 -0
- data/dependencies/SDL_sound/SDL_sound_flac.c +182 -0
- data/dependencies/SDL_sound/SDL_sound_internal.h +304 -0
- data/dependencies/SDL_sound/SDL_sound_modplug.c +228 -0
- data/dependencies/SDL_sound/SDL_sound_mp3.c +184 -0
- data/dependencies/SDL_sound/SDL_sound_raw.c +164 -0
- data/dependencies/SDL_sound/SDL_sound_shn.c +1309 -0
- data/dependencies/SDL_sound/SDL_sound_voc.c +550 -0
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +223 -0
- data/dependencies/SDL_sound/SDL_sound_wav.c +783 -0
- data/dependencies/SDL_sound/dr_flac.h +5906 -0
- data/dependencies/SDL_sound/dr_mp3.h +2832 -0
- data/dependencies/SDL_sound/libmodplug/fastmix.c +1748 -0
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +1001 -0
- data/dependencies/SDL_sound/libmodplug/load_669.c +188 -0
- data/dependencies/SDL_sound/libmodplug/load_abc.c +4725 -0
- data/dependencies/SDL_sound/libmodplug/load_amf.c +403 -0
- data/dependencies/SDL_sound/libmodplug/load_ams.c +587 -0
- data/dependencies/SDL_sound/libmodplug/load_dbm.c +357 -0
- data/dependencies/SDL_sound/libmodplug/load_dmf.c +531 -0
- data/dependencies/SDL_sound/libmodplug/load_dsm.c +232 -0
- data/dependencies/SDL_sound/libmodplug/load_far.c +253 -0
- data/dependencies/SDL_sound/libmodplug/load_it.c +796 -0
- data/dependencies/SDL_sound/libmodplug/load_mdl.c +488 -0
- data/dependencies/SDL_sound/libmodplug/load_med.c +757 -0
- data/dependencies/SDL_sound/libmodplug/load_mid.c +1405 -0
- data/dependencies/SDL_sound/libmodplug/load_mod.c +269 -0
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +546 -0
- data/dependencies/SDL_sound/libmodplug/load_mtm.c +142 -0
- data/dependencies/SDL_sound/libmodplug/load_okt.c +192 -0
- data/dependencies/SDL_sound/libmodplug/load_pat.c +1143 -0
- data/dependencies/SDL_sound/libmodplug/load_pat.h +25 -0
- data/dependencies/SDL_sound/libmodplug/load_psm.c +350 -0
- data/dependencies/SDL_sound/libmodplug/load_ptm.c +204 -0
- data/dependencies/SDL_sound/libmodplug/load_s3m.c +325 -0
- data/dependencies/SDL_sound/libmodplug/load_stm.c +180 -0
- data/dependencies/SDL_sound/libmodplug/load_ult.c +206 -0
- data/dependencies/SDL_sound/libmodplug/load_umx.c +51 -0
- data/dependencies/SDL_sound/libmodplug/load_xm.c +554 -0
- data/dependencies/SDL_sound/libmodplug/mmcmp.c +382 -0
- data/dependencies/SDL_sound/libmodplug/modplug.c +170 -0
- data/dependencies/SDL_sound/libmodplug/modplug.h +90 -0
- data/dependencies/SDL_sound/libmodplug/snd_dsp.c +301 -0
- data/dependencies/SDL_sound/libmodplug/snd_flt.c +63 -0
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +2350 -0
- data/dependencies/SDL_sound/libmodplug/sndfile.c +1169 -0
- data/dependencies/SDL_sound/libmodplug/sndmix.c +1034 -0
- data/dependencies/SDL_sound/libmodplug/tables.h +371 -0
- data/{src/stb_vorbis.c → dependencies/SDL_sound/stb_vorbis.h} +143 -78
- data/dependencies/al_soft/AL/al.h +655 -0
- data/dependencies/al_soft/AL/alc.h +270 -0
- data/dependencies/al_soft/AL/alext.h +585 -0
- data/dependencies/al_soft/AL/efx-creative.h +3 -0
- data/dependencies/al_soft/AL/efx-presets.h +402 -0
- data/dependencies/al_soft/AL/efx.h +762 -0
- data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
- data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
- data/{src → dependencies/stb}/stb_image.h +330 -127
- data/{src → dependencies/stb}/stb_image_write.h +156 -85
- data/{src → dependencies/stb}/stb_truetype.h +192 -69
- data/{src → dependencies/utf8proc}/utf8proc.c +0 -0
- data/{src → dependencies/utf8proc}/utf8proc.h +0 -0
- data/{src → dependencies/utf8proc}/utf8proc_data.h +0 -0
- data/ext/gosu/extconf.rb +56 -22
- data/{Gosu → include/Gosu}/Audio.hpp +6 -8
- data/{Gosu → include/Gosu}/AutoLink.hpp +0 -0
- data/include/Gosu/Bitmap.hpp +100 -0
- data/{Gosu → include/Gosu}/Buttons.hpp +94 -35
- data/{Gosu → include/Gosu}/Channel.h +0 -0
- data/{Gosu → include/Gosu}/Color.h +0 -0
- data/{Gosu → include/Gosu}/Color.hpp +0 -0
- data/{Gosu → include/Gosu}/Directories.hpp +0 -0
- data/{Gosu → include/Gosu}/Font.h +0 -0
- data/{Gosu → include/Gosu}/Font.hpp +0 -0
- data/{Gosu → include/Gosu}/Fwd.hpp +0 -0
- data/{Gosu → include/Gosu}/Gosu.h +3 -0
- data/{Gosu → include/Gosu}/Gosu.hpp +0 -0
- data/{Gosu → include/Gosu}/Graphics.hpp +0 -0
- data/{Gosu → include/Gosu}/GraphicsBase.hpp +0 -0
- data/{Gosu → include/Gosu}/IO.hpp +0 -0
- data/{Gosu → include/Gosu}/Image.h +0 -0
- data/{Gosu → include/Gosu}/Image.hpp +7 -6
- data/{Gosu → include/Gosu}/ImageData.hpp +0 -0
- data/{Gosu → include/Gosu}/Input.hpp +30 -15
- data/{Gosu → include/Gosu}/Inspection.hpp +0 -0
- data/{Gosu → include/Gosu}/Math.hpp +0 -0
- data/{Gosu → include/Gosu}/Platform.hpp +0 -0
- data/{Gosu → include/Gosu}/Sample.h +0 -0
- data/{Gosu → include/Gosu}/Song.h +0 -0
- data/{Gosu → include/Gosu}/Text.hpp +0 -0
- data/{Gosu → include/Gosu}/TextInput.h +0 -0
- data/{Gosu → include/Gosu}/TextInput.hpp +0 -0
- data/{Gosu → include/Gosu}/Timing.hpp +0 -0
- data/{Gosu → include/Gosu}/Utility.hpp +1 -1
- data/{Gosu → include/Gosu}/Version.hpp +0 -0
- data/{Gosu → include/Gosu}/Window.h +2 -0
- data/{Gosu → include/Gosu}/Window.hpp +21 -13
- data/lib/OpenAL32.dll +0 -0
- data/lib/SDL2.dll +0 -0
- data/lib/gosu.rb +0 -3
- data/lib/gosu/patches.rb +0 -9
- data/lib/gosu/swig_patches.rb +3 -2
- data/lib/libmpg123.dll +0 -0
- data/lib/libsndfile.dll +0 -0
- data/lib64/OpenAL32.dll +0 -0
- data/lib64/SDL2.dll +0 -0
- data/lib64/libmpg123.dll +0 -0
- data/lib64/libsndfile.dll +0 -0
- data/rdoc/gosu.rb +95 -20
- data/src/Audio.cpp +50 -224
- data/src/AudioFile.hpp +17 -37
- data/src/AudioFileAudioToolbox.cpp +237 -0
- data/src/AudioFileSDLSound.cpp +147 -0
- data/src/AudioImpl.cpp +3 -12
- data/src/AudioImpl.hpp +3 -1
- data/src/Bitmap.cpp +85 -83
- data/src/BitmapIO.cpp +52 -58
- data/src/Constants.cpp +80 -33
- data/src/Font.cpp +3 -1
- data/src/GosuWrapper.cpp +19 -0
- data/src/Graphics.cpp +7 -4
- data/src/Image.cpp +13 -16
- data/src/Input.cpp +408 -159
- data/src/LargeImageData.cpp +1 -1
- data/src/MarkupParser.cpp +2 -1
- data/src/RubyGosu.cxx +349 -83
- data/src/RubyGosu.h +4 -2
- data/src/TexChunk.cpp +1 -1
- data/src/TextBuilder.cpp +3 -1
- data/src/Texture.cpp +1 -1
- data/src/TrueTypeFont.cpp +1 -1
- data/src/Utility.cpp +11 -7
- data/src/Window.cpp +30 -39
- data/src/WindowWrapper.cpp +28 -0
- metadata +207 -52
- data/Gosu/Bitmap.hpp +0 -113
- data/src/AudioToolboxFile.hpp +0 -210
- data/src/OggFile.hpp +0 -92
- data/src/SndFile.hpp +0 -174
- data/src/WinMain.cpp +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd0fd86f4301c36a1537d5adaa45e6bc7fd918e47191909bb1bc238624d01f48
|
4
|
+
data.tar.gz: 0d79c98a88fc7c433a8eaf3b5a432da6a9c24c86d6388d6e853c6d6c4a44f4a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3393dda33deff7db00d4fda1f40faac895243f6dc8c0d6c776eaf905bc44e64235ac0e3e2ff9067bac7a971d6794c02e526755e7602b98f4fc58b2053c1441a
|
7
|
+
data.tar.gz: 1fce5bf10d01a9e2ab6df0d30d62a3105bb98050c8efe94701eb09d8cbc64fa19a9a7fac02bc1d7a2ab62d74bb591b5bce1fdc1ae5a49ccdc57d8d6911ec9757
|
@@ -0,0 +1,138 @@
|
|
1
|
+
/*
|
2
|
+
Simple DirectMedia Layer
|
3
|
+
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
4
|
+
|
5
|
+
This software is provided 'as-is', without any express or implied
|
6
|
+
warranty. In no event will the authors be held liable for any damages
|
7
|
+
arising from the use of this software.
|
8
|
+
|
9
|
+
Permission is granted to anyone to use this software for any purpose,
|
10
|
+
including commercial applications, and to alter it and redistribute it
|
11
|
+
freely, subject to the following restrictions:
|
12
|
+
|
13
|
+
1. The origin of this software must not be misrepresented; you must not
|
14
|
+
claim that you wrote the original software. If you use this software
|
15
|
+
in a product, an acknowledgment in the product documentation would be
|
16
|
+
appreciated but is not required.
|
17
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
18
|
+
misrepresented as being the original software.
|
19
|
+
3. This notice may not be removed or altered from any source distribution.
|
20
|
+
*/
|
21
|
+
|
22
|
+
/**
|
23
|
+
* \file SDL.h
|
24
|
+
*
|
25
|
+
* Main include header for the SDL library
|
26
|
+
*/
|
27
|
+
|
28
|
+
|
29
|
+
#ifndef SDL_h_
|
30
|
+
#define SDL_h_
|
31
|
+
|
32
|
+
#include "SDL_main.h"
|
33
|
+
#include "SDL_stdinc.h"
|
34
|
+
#include "SDL_assert.h"
|
35
|
+
#include "SDL_atomic.h"
|
36
|
+
#include "SDL_audio.h"
|
37
|
+
#include "SDL_clipboard.h"
|
38
|
+
#include "SDL_cpuinfo.h"
|
39
|
+
#include "SDL_endian.h"
|
40
|
+
#include "SDL_error.h"
|
41
|
+
#include "SDL_events.h"
|
42
|
+
#include "SDL_filesystem.h"
|
43
|
+
#include "SDL_gamecontroller.h"
|
44
|
+
#include "SDL_haptic.h"
|
45
|
+
#include "SDL_hints.h"
|
46
|
+
#include "SDL_joystick.h"
|
47
|
+
#include "SDL_loadso.h"
|
48
|
+
#include "SDL_log.h"
|
49
|
+
#include "SDL_messagebox.h"
|
50
|
+
#include "SDL_metal.h"
|
51
|
+
#include "SDL_mutex.h"
|
52
|
+
#include "SDL_power.h"
|
53
|
+
#include "SDL_render.h"
|
54
|
+
#include "SDL_rwops.h"
|
55
|
+
#include "SDL_sensor.h"
|
56
|
+
#include "SDL_shape.h"
|
57
|
+
#include "SDL_system.h"
|
58
|
+
#include "SDL_thread.h"
|
59
|
+
#include "SDL_timer.h"
|
60
|
+
#include "SDL_version.h"
|
61
|
+
#include "SDL_video.h"
|
62
|
+
#include "SDL_locale.h"
|
63
|
+
#include "SDL_misc.h"
|
64
|
+
|
65
|
+
#include "begin_code.h"
|
66
|
+
/* Set up for C function definitions, even when using C++ */
|
67
|
+
#ifdef __cplusplus
|
68
|
+
extern "C" {
|
69
|
+
#endif
|
70
|
+
|
71
|
+
/* As of version 0.5, SDL is loaded dynamically into the application */
|
72
|
+
|
73
|
+
/**
|
74
|
+
* \name SDL_INIT_*
|
75
|
+
*
|
76
|
+
* These are the flags which may be passed to SDL_Init(). You should
|
77
|
+
* specify the subsystems which you will be using in your application.
|
78
|
+
*/
|
79
|
+
/* @{ */
|
80
|
+
#define SDL_INIT_TIMER 0x00000001u
|
81
|
+
#define SDL_INIT_AUDIO 0x00000010u
|
82
|
+
#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
|
83
|
+
#define SDL_INIT_JOYSTICK 0x00000200u /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
|
84
|
+
#define SDL_INIT_HAPTIC 0x00001000u
|
85
|
+
#define SDL_INIT_GAMECONTROLLER 0x00002000u /**< SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */
|
86
|
+
#define SDL_INIT_EVENTS 0x00004000u
|
87
|
+
#define SDL_INIT_SENSOR 0x00008000u
|
88
|
+
#define SDL_INIT_NOPARACHUTE 0x00100000u /**< compatibility; this flag is ignored. */
|
89
|
+
#define SDL_INIT_EVERYTHING ( \
|
90
|
+
SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \
|
91
|
+
SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_SENSOR \
|
92
|
+
)
|
93
|
+
/* @} */
|
94
|
+
|
95
|
+
/**
|
96
|
+
* This function initializes the subsystems specified by \c flags
|
97
|
+
*/
|
98
|
+
extern DECLSPEC int SDLCALL SDL_Init(Uint32 flags);
|
99
|
+
|
100
|
+
/**
|
101
|
+
* This function initializes specific SDL subsystems
|
102
|
+
*
|
103
|
+
* Subsystem initialization is ref-counted, you must call
|
104
|
+
* SDL_QuitSubSystem() for each SDL_InitSubSystem() to correctly
|
105
|
+
* shutdown a subsystem manually (or call SDL_Quit() to force shutdown).
|
106
|
+
* If a subsystem is already loaded then this call will
|
107
|
+
* increase the ref-count and return.
|
108
|
+
*/
|
109
|
+
extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags);
|
110
|
+
|
111
|
+
/**
|
112
|
+
* This function cleans up specific SDL subsystems
|
113
|
+
*/
|
114
|
+
extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags);
|
115
|
+
|
116
|
+
/**
|
117
|
+
* This function returns a mask of the specified subsystems which have
|
118
|
+
* previously been initialized.
|
119
|
+
*
|
120
|
+
* If \c flags is 0, it returns a mask of all initialized subsystems.
|
121
|
+
*/
|
122
|
+
extern DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags);
|
123
|
+
|
124
|
+
/**
|
125
|
+
* This function cleans up all initialized subsystems. You should
|
126
|
+
* call it upon all exit conditions.
|
127
|
+
*/
|
128
|
+
extern DECLSPEC void SDLCALL SDL_Quit(void);
|
129
|
+
|
130
|
+
/* Ends C function definitions when using C++ */
|
131
|
+
#ifdef __cplusplus
|
132
|
+
}
|
133
|
+
#endif
|
134
|
+
#include "close_code.h"
|
135
|
+
|
136
|
+
#endif /* SDL_h_ */
|
137
|
+
|
138
|
+
/* vi: set ts=4 sw=4 expandtab: */
|
@@ -0,0 +1,293 @@
|
|
1
|
+
/*
|
2
|
+
Simple DirectMedia Layer
|
3
|
+
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
4
|
+
|
5
|
+
This software is provided 'as-is', without any express or implied
|
6
|
+
warranty. In no event will the authors be held liable for any damages
|
7
|
+
arising from the use of this software.
|
8
|
+
|
9
|
+
Permission is granted to anyone to use this software for any purpose,
|
10
|
+
including commercial applications, and to alter it and redistribute it
|
11
|
+
freely, subject to the following restrictions:
|
12
|
+
|
13
|
+
1. The origin of this software must not be misrepresented; you must not
|
14
|
+
claim that you wrote the original software. If you use this software
|
15
|
+
in a product, an acknowledgment in the product documentation would be
|
16
|
+
appreciated but is not required.
|
17
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
18
|
+
misrepresented as being the original software.
|
19
|
+
3. This notice may not be removed or altered from any source distribution.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#ifndef SDL_assert_h_
|
23
|
+
#define SDL_assert_h_
|
24
|
+
|
25
|
+
#include "SDL_config.h"
|
26
|
+
|
27
|
+
#include "begin_code.h"
|
28
|
+
/* Set up for C function definitions, even when using C++ */
|
29
|
+
#ifdef __cplusplus
|
30
|
+
extern "C" {
|
31
|
+
#endif
|
32
|
+
|
33
|
+
#ifndef SDL_ASSERT_LEVEL
|
34
|
+
#ifdef SDL_DEFAULT_ASSERT_LEVEL
|
35
|
+
#define SDL_ASSERT_LEVEL SDL_DEFAULT_ASSERT_LEVEL
|
36
|
+
#elif defined(_DEBUG) || defined(DEBUG) || \
|
37
|
+
(defined(__GNUC__) && !defined(__OPTIMIZE__))
|
38
|
+
#define SDL_ASSERT_LEVEL 2
|
39
|
+
#else
|
40
|
+
#define SDL_ASSERT_LEVEL 1
|
41
|
+
#endif
|
42
|
+
#endif /* SDL_ASSERT_LEVEL */
|
43
|
+
|
44
|
+
/*
|
45
|
+
These are macros and not first class functions so that the debugger breaks
|
46
|
+
on the assertion line and not in some random guts of SDL, and so each
|
47
|
+
assert can have unique static variables associated with it.
|
48
|
+
*/
|
49
|
+
|
50
|
+
#if defined(_MSC_VER)
|
51
|
+
/* Don't include intrin.h here because it contains C++ code */
|
52
|
+
extern void __cdecl __debugbreak(void);
|
53
|
+
#define SDL_TriggerBreakpoint() __debugbreak()
|
54
|
+
#elif ( (!defined(__NACL__)) && ((defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))) )
|
55
|
+
#define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "int $3\n\t" )
|
56
|
+
#elif ( defined(__APPLE__) && defined(__arm64__) ) /* this might work on other ARM targets, but this is a known quantity... */
|
57
|
+
#define SDL_TriggerBreakpoint() __asm__ __volatile__ ( "brk #22\n\t" )
|
58
|
+
#elif defined(__386__) && defined(__WATCOMC__)
|
59
|
+
#define SDL_TriggerBreakpoint() { _asm { int 0x03 } }
|
60
|
+
#elif defined(HAVE_SIGNAL_H) && !defined(__WATCOMC__)
|
61
|
+
#include <signal.h>
|
62
|
+
#define SDL_TriggerBreakpoint() raise(SIGTRAP)
|
63
|
+
#else
|
64
|
+
/* How do we trigger breakpoints on this platform? */
|
65
|
+
#define SDL_TriggerBreakpoint()
|
66
|
+
#endif
|
67
|
+
|
68
|
+
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 supports __func__ as a standard. */
|
69
|
+
# define SDL_FUNCTION __func__
|
70
|
+
#elif ((__GNUC__ >= 2) || defined(_MSC_VER) || defined (__WATCOMC__))
|
71
|
+
# define SDL_FUNCTION __FUNCTION__
|
72
|
+
#else
|
73
|
+
# define SDL_FUNCTION "???"
|
74
|
+
#endif
|
75
|
+
#define SDL_FILE __FILE__
|
76
|
+
#define SDL_LINE __LINE__
|
77
|
+
|
78
|
+
/*
|
79
|
+
sizeof (x) makes the compiler still parse the expression even without
|
80
|
+
assertions enabled, so the code is always checked at compile time, but
|
81
|
+
doesn't actually generate code for it, so there are no side effects or
|
82
|
+
expensive checks at run time, just the constant size of what x WOULD be,
|
83
|
+
which presumably gets optimized out as unused.
|
84
|
+
This also solves the problem of...
|
85
|
+
|
86
|
+
int somevalue = blah();
|
87
|
+
SDL_assert(somevalue == 1);
|
88
|
+
|
89
|
+
...which would cause compiles to complain that somevalue is unused if we
|
90
|
+
disable assertions.
|
91
|
+
*/
|
92
|
+
|
93
|
+
/* "while (0,0)" fools Microsoft's compiler's /W4 warning level into thinking
|
94
|
+
this condition isn't constant. And looks like an owl's face! */
|
95
|
+
#ifdef _MSC_VER /* stupid /W4 warnings. */
|
96
|
+
#define SDL_NULL_WHILE_LOOP_CONDITION (0,0)
|
97
|
+
#else
|
98
|
+
#define SDL_NULL_WHILE_LOOP_CONDITION (0)
|
99
|
+
#endif
|
100
|
+
|
101
|
+
#define SDL_disabled_assert(condition) \
|
102
|
+
do { (void) sizeof ((condition)); } while (SDL_NULL_WHILE_LOOP_CONDITION)
|
103
|
+
|
104
|
+
typedef enum
|
105
|
+
{
|
106
|
+
SDL_ASSERTION_RETRY, /**< Retry the assert immediately. */
|
107
|
+
SDL_ASSERTION_BREAK, /**< Make the debugger trigger a breakpoint. */
|
108
|
+
SDL_ASSERTION_ABORT, /**< Terminate the program. */
|
109
|
+
SDL_ASSERTION_IGNORE, /**< Ignore the assert. */
|
110
|
+
SDL_ASSERTION_ALWAYS_IGNORE /**< Ignore the assert from now on. */
|
111
|
+
} SDL_AssertState;
|
112
|
+
|
113
|
+
typedef struct SDL_AssertData
|
114
|
+
{
|
115
|
+
int always_ignore;
|
116
|
+
unsigned int trigger_count;
|
117
|
+
const char *condition;
|
118
|
+
const char *filename;
|
119
|
+
int linenum;
|
120
|
+
const char *function;
|
121
|
+
const struct SDL_AssertData *next;
|
122
|
+
} SDL_AssertData;
|
123
|
+
|
124
|
+
#if (SDL_ASSERT_LEVEL > 0)
|
125
|
+
|
126
|
+
/* Never call this directly. Use the SDL_assert* macros. */
|
127
|
+
extern DECLSPEC SDL_AssertState SDLCALL SDL_ReportAssertion(SDL_AssertData *,
|
128
|
+
const char *,
|
129
|
+
const char *, int)
|
130
|
+
#if defined(__clang__)
|
131
|
+
#if __has_feature(attribute_analyzer_noreturn)
|
132
|
+
/* this tells Clang's static analysis that we're a custom assert function,
|
133
|
+
and that the analyzer should assume the condition was always true past this
|
134
|
+
SDL_assert test. */
|
135
|
+
__attribute__((analyzer_noreturn))
|
136
|
+
#endif
|
137
|
+
#endif
|
138
|
+
;
|
139
|
+
|
140
|
+
/* the do {} while(0) avoids dangling else problems:
|
141
|
+
if (x) SDL_assert(y); else blah();
|
142
|
+
... without the do/while, the "else" could attach to this macro's "if".
|
143
|
+
We try to handle just the minimum we need here in a macro...the loop,
|
144
|
+
the static vars, and break points. The heavy lifting is handled in
|
145
|
+
SDL_ReportAssertion(), in SDL_assert.c.
|
146
|
+
*/
|
147
|
+
#define SDL_enabled_assert(condition) \
|
148
|
+
do { \
|
149
|
+
while ( !(condition) ) { \
|
150
|
+
static struct SDL_AssertData sdl_assert_data = { \
|
151
|
+
0, 0, #condition, 0, 0, 0, 0 \
|
152
|
+
}; \
|
153
|
+
const SDL_AssertState sdl_assert_state = SDL_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \
|
154
|
+
if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
|
155
|
+
continue; /* go again. */ \
|
156
|
+
} else if (sdl_assert_state == SDL_ASSERTION_BREAK) { \
|
157
|
+
SDL_TriggerBreakpoint(); \
|
158
|
+
} \
|
159
|
+
break; /* not retrying. */ \
|
160
|
+
} \
|
161
|
+
} while (SDL_NULL_WHILE_LOOP_CONDITION)
|
162
|
+
|
163
|
+
#endif /* enabled assertions support code */
|
164
|
+
|
165
|
+
/* Enable various levels of assertions. */
|
166
|
+
#if SDL_ASSERT_LEVEL == 0 /* assertions disabled */
|
167
|
+
# define SDL_assert(condition) SDL_disabled_assert(condition)
|
168
|
+
# define SDL_assert_release(condition) SDL_disabled_assert(condition)
|
169
|
+
# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
|
170
|
+
#elif SDL_ASSERT_LEVEL == 1 /* release settings. */
|
171
|
+
# define SDL_assert(condition) SDL_disabled_assert(condition)
|
172
|
+
# define SDL_assert_release(condition) SDL_enabled_assert(condition)
|
173
|
+
# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
|
174
|
+
#elif SDL_ASSERT_LEVEL == 2 /* normal settings. */
|
175
|
+
# define SDL_assert(condition) SDL_enabled_assert(condition)
|
176
|
+
# define SDL_assert_release(condition) SDL_enabled_assert(condition)
|
177
|
+
# define SDL_assert_paranoid(condition) SDL_disabled_assert(condition)
|
178
|
+
#elif SDL_ASSERT_LEVEL == 3 /* paranoid settings. */
|
179
|
+
# define SDL_assert(condition) SDL_enabled_assert(condition)
|
180
|
+
# define SDL_assert_release(condition) SDL_enabled_assert(condition)
|
181
|
+
# define SDL_assert_paranoid(condition) SDL_enabled_assert(condition)
|
182
|
+
#else
|
183
|
+
# error Unknown assertion level.
|
184
|
+
#endif
|
185
|
+
|
186
|
+
/* this assertion is never disabled at any level. */
|
187
|
+
#define SDL_assert_always(condition) SDL_enabled_assert(condition)
|
188
|
+
|
189
|
+
|
190
|
+
typedef SDL_AssertState (SDLCALL *SDL_AssertionHandler)(
|
191
|
+
const SDL_AssertData* data, void* userdata);
|
192
|
+
|
193
|
+
/**
|
194
|
+
* \brief Set an application-defined assertion handler.
|
195
|
+
*
|
196
|
+
* This allows an app to show its own assertion UI and/or force the
|
197
|
+
* response to an assertion failure. If the app doesn't provide this, SDL
|
198
|
+
* will try to do the right thing, popping up a system-specific GUI dialog,
|
199
|
+
* and probably minimizing any fullscreen windows.
|
200
|
+
*
|
201
|
+
* This callback may fire from any thread, but it runs wrapped in a mutex, so
|
202
|
+
* it will only fire from one thread at a time.
|
203
|
+
*
|
204
|
+
* Setting the callback to NULL restores SDL's original internal handler.
|
205
|
+
*
|
206
|
+
* This callback is NOT reset to SDL's internal handler upon SDL_Quit()!
|
207
|
+
*
|
208
|
+
* Return SDL_AssertState value of how to handle the assertion failure.
|
209
|
+
*
|
210
|
+
* \param handler Callback function, called when an assertion fails.
|
211
|
+
* \param userdata A pointer passed to the callback as-is.
|
212
|
+
*/
|
213
|
+
extern DECLSPEC void SDLCALL SDL_SetAssertionHandler(
|
214
|
+
SDL_AssertionHandler handler,
|
215
|
+
void *userdata);
|
216
|
+
|
217
|
+
/**
|
218
|
+
* \brief Get the default assertion handler.
|
219
|
+
*
|
220
|
+
* This returns the function pointer that is called by default when an
|
221
|
+
* assertion is triggered. This is an internal function provided by SDL,
|
222
|
+
* that is used for assertions when SDL_SetAssertionHandler() hasn't been
|
223
|
+
* used to provide a different function.
|
224
|
+
*
|
225
|
+
* \return The default SDL_AssertionHandler that is called when an assert triggers.
|
226
|
+
*/
|
227
|
+
extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetDefaultAssertionHandler(void);
|
228
|
+
|
229
|
+
/**
|
230
|
+
* \brief Get the current assertion handler.
|
231
|
+
*
|
232
|
+
* This returns the function pointer that is called when an assertion is
|
233
|
+
* triggered. This is either the value last passed to
|
234
|
+
* SDL_SetAssertionHandler(), or if no application-specified function is
|
235
|
+
* set, is equivalent to calling SDL_GetDefaultAssertionHandler().
|
236
|
+
*
|
237
|
+
* \param puserdata Pointer to a void*, which will store the "userdata"
|
238
|
+
* pointer that was passed to SDL_SetAssertionHandler().
|
239
|
+
* This value will always be NULL for the default handler.
|
240
|
+
* If you don't care about this data, it is safe to pass
|
241
|
+
* a NULL pointer to this function to ignore it.
|
242
|
+
* \return The SDL_AssertionHandler that is called when an assert triggers.
|
243
|
+
*/
|
244
|
+
extern DECLSPEC SDL_AssertionHandler SDLCALL SDL_GetAssertionHandler(void **puserdata);
|
245
|
+
|
246
|
+
/**
|
247
|
+
* \brief Get a list of all assertion failures.
|
248
|
+
*
|
249
|
+
* Get all assertions triggered since last call to SDL_ResetAssertionReport(),
|
250
|
+
* or the start of the program.
|
251
|
+
*
|
252
|
+
* The proper way to examine this data looks something like this:
|
253
|
+
*
|
254
|
+
* <code>
|
255
|
+
* const SDL_AssertData *item = SDL_GetAssertionReport();
|
256
|
+
* while (item) {
|
257
|
+
* printf("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\\n",
|
258
|
+
* item->condition, item->function, item->filename,
|
259
|
+
* item->linenum, item->trigger_count,
|
260
|
+
* item->always_ignore ? "yes" : "no");
|
261
|
+
* item = item->next;
|
262
|
+
* }
|
263
|
+
* </code>
|
264
|
+
*
|
265
|
+
* \return List of all assertions.
|
266
|
+
* \sa SDL_ResetAssertionReport
|
267
|
+
*/
|
268
|
+
extern DECLSPEC const SDL_AssertData * SDLCALL SDL_GetAssertionReport(void);
|
269
|
+
|
270
|
+
/**
|
271
|
+
* \brief Reset the list of all assertion failures.
|
272
|
+
*
|
273
|
+
* Reset list of all assertions triggered.
|
274
|
+
*
|
275
|
+
* \sa SDL_GetAssertionReport
|
276
|
+
*/
|
277
|
+
extern DECLSPEC void SDLCALL SDL_ResetAssertionReport(void);
|
278
|
+
|
279
|
+
|
280
|
+
/* these had wrong naming conventions until 2.0.4. Please update your app! */
|
281
|
+
#define SDL_assert_state SDL_AssertState
|
282
|
+
#define SDL_assert_data SDL_AssertData
|
283
|
+
|
284
|
+
|
285
|
+
/* Ends C function definitions when using C++ */
|
286
|
+
#ifdef __cplusplus
|
287
|
+
}
|
288
|
+
#endif
|
289
|
+
#include "close_code.h"
|
290
|
+
|
291
|
+
#endif /* SDL_assert_h_ */
|
292
|
+
|
293
|
+
/* vi: set ts=4 sw=4 expandtab: */
|
@@ -0,0 +1,295 @@
|
|
1
|
+
/*
|
2
|
+
Simple DirectMedia Layer
|
3
|
+
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
4
|
+
|
5
|
+
This software is provided 'as-is', without any express or implied
|
6
|
+
warranty. In no event will the authors be held liable for any damages
|
7
|
+
arising from the use of this software.
|
8
|
+
|
9
|
+
Permission is granted to anyone to use this software for any purpose,
|
10
|
+
including commercial applications, and to alter it and redistribute it
|
11
|
+
freely, subject to the following restrictions:
|
12
|
+
|
13
|
+
1. The origin of this software must not be misrepresented; you must not
|
14
|
+
claim that you wrote the original software. If you use this software
|
15
|
+
in a product, an acknowledgment in the product documentation would be
|
16
|
+
appreciated but is not required.
|
17
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
18
|
+
misrepresented as being the original software.
|
19
|
+
3. This notice may not be removed or altered from any source distribution.
|
20
|
+
*/
|
21
|
+
|
22
|
+
/**
|
23
|
+
* \file SDL_atomic.h
|
24
|
+
*
|
25
|
+
* Atomic operations.
|
26
|
+
*
|
27
|
+
* IMPORTANT:
|
28
|
+
* If you are not an expert in concurrent lockless programming, you should
|
29
|
+
* only be using the atomic lock and reference counting functions in this
|
30
|
+
* file. In all other cases you should be protecting your data structures
|
31
|
+
* with full mutexes.
|
32
|
+
*
|
33
|
+
* The list of "safe" functions to use are:
|
34
|
+
* SDL_AtomicLock()
|
35
|
+
* SDL_AtomicUnlock()
|
36
|
+
* SDL_AtomicIncRef()
|
37
|
+
* SDL_AtomicDecRef()
|
38
|
+
*
|
39
|
+
* Seriously, here be dragons!
|
40
|
+
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
41
|
+
*
|
42
|
+
* You can find out a little more about lockless programming and the
|
43
|
+
* subtle issues that can arise here:
|
44
|
+
* http://msdn.microsoft.com/en-us/library/ee418650%28v=vs.85%29.aspx
|
45
|
+
*
|
46
|
+
* There's also lots of good information here:
|
47
|
+
* http://www.1024cores.net/home/lock-free-algorithms
|
48
|
+
* http://preshing.com/
|
49
|
+
*
|
50
|
+
* These operations may or may not actually be implemented using
|
51
|
+
* processor specific atomic operations. When possible they are
|
52
|
+
* implemented as true processor specific atomic operations. When that
|
53
|
+
* is not possible the are implemented using locks that *do* use the
|
54
|
+
* available atomic operations.
|
55
|
+
*
|
56
|
+
* All of the atomic operations that modify memory are full memory barriers.
|
57
|
+
*/
|
58
|
+
|
59
|
+
#ifndef SDL_atomic_h_
|
60
|
+
#define SDL_atomic_h_
|
61
|
+
|
62
|
+
#include "SDL_stdinc.h"
|
63
|
+
#include "SDL_platform.h"
|
64
|
+
|
65
|
+
#include "begin_code.h"
|
66
|
+
|
67
|
+
/* Set up for C function definitions, even when using C++ */
|
68
|
+
#ifdef __cplusplus
|
69
|
+
extern "C" {
|
70
|
+
#endif
|
71
|
+
|
72
|
+
/**
|
73
|
+
* \name SDL AtomicLock
|
74
|
+
*
|
75
|
+
* The atomic locks are efficient spinlocks using CPU instructions,
|
76
|
+
* but are vulnerable to starvation and can spin forever if a thread
|
77
|
+
* holding a lock has been terminated. For this reason you should
|
78
|
+
* minimize the code executed inside an atomic lock and never do
|
79
|
+
* expensive things like API or system calls while holding them.
|
80
|
+
*
|
81
|
+
* The atomic locks are not safe to lock recursively.
|
82
|
+
*
|
83
|
+
* Porting Note:
|
84
|
+
* The spin lock functions and type are required and can not be
|
85
|
+
* emulated because they are used in the atomic emulation code.
|
86
|
+
*/
|
87
|
+
/* @{ */
|
88
|
+
|
89
|
+
typedef int SDL_SpinLock;
|
90
|
+
|
91
|
+
/**
|
92
|
+
* \brief Try to lock a spin lock by setting it to a non-zero value.
|
93
|
+
*
|
94
|
+
* \param lock Points to the lock.
|
95
|
+
*
|
96
|
+
* \return SDL_TRUE if the lock succeeded, SDL_FALSE if the lock is already held.
|
97
|
+
*/
|
98
|
+
extern DECLSPEC SDL_bool SDLCALL SDL_AtomicTryLock(SDL_SpinLock *lock);
|
99
|
+
|
100
|
+
/**
|
101
|
+
* \brief Lock a spin lock by setting it to a non-zero value.
|
102
|
+
*
|
103
|
+
* \param lock Points to the lock.
|
104
|
+
*/
|
105
|
+
extern DECLSPEC void SDLCALL SDL_AtomicLock(SDL_SpinLock *lock);
|
106
|
+
|
107
|
+
/**
|
108
|
+
* \brief Unlock a spin lock by setting it to 0. Always returns immediately
|
109
|
+
*
|
110
|
+
* \param lock Points to the lock.
|
111
|
+
*/
|
112
|
+
extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock);
|
113
|
+
|
114
|
+
/* @} *//* SDL AtomicLock */
|
115
|
+
|
116
|
+
|
117
|
+
/**
|
118
|
+
* The compiler barrier prevents the compiler from reordering
|
119
|
+
* reads and writes to globally visible variables across the call.
|
120
|
+
*/
|
121
|
+
#if defined(_MSC_VER) && (_MSC_VER > 1200) && !defined(__clang__)
|
122
|
+
void _ReadWriteBarrier(void);
|
123
|
+
#pragma intrinsic(_ReadWriteBarrier)
|
124
|
+
#define SDL_CompilerBarrier() _ReadWriteBarrier()
|
125
|
+
#elif (defined(__GNUC__) && !defined(__EMSCRIPTEN__)) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5120))
|
126
|
+
/* This is correct for all CPUs when using GCC or Solaris Studio 12.1+. */
|
127
|
+
#define SDL_CompilerBarrier() __asm__ __volatile__ ("" : : : "memory")
|
128
|
+
#elif defined(__WATCOMC__)
|
129
|
+
extern _inline void SDL_CompilerBarrier (void);
|
130
|
+
#pragma aux SDL_CompilerBarrier = "" parm [] modify exact [];
|
131
|
+
#else
|
132
|
+
#define SDL_CompilerBarrier() \
|
133
|
+
{ SDL_SpinLock _tmp = 0; SDL_AtomicLock(&_tmp); SDL_AtomicUnlock(&_tmp); }
|
134
|
+
#endif
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Memory barriers are designed to prevent reads and writes from being
|
138
|
+
* reordered by the compiler and being seen out of order on multi-core CPUs.
|
139
|
+
*
|
140
|
+
* A typical pattern would be for thread A to write some data and a flag,
|
141
|
+
* and for thread B to read the flag and get the data. In this case you
|
142
|
+
* would insert a release barrier between writing the data and the flag,
|
143
|
+
* guaranteeing that the data write completes no later than the flag is
|
144
|
+
* written, and you would insert an acquire barrier between reading the
|
145
|
+
* flag and reading the data, to ensure that all the reads associated
|
146
|
+
* with the flag have completed.
|
147
|
+
*
|
148
|
+
* In this pattern you should always see a release barrier paired with
|
149
|
+
* an acquire barrier and you should gate the data reads/writes with a
|
150
|
+
* single flag variable.
|
151
|
+
*
|
152
|
+
* For more information on these semantics, take a look at the blog post:
|
153
|
+
* http://preshing.com/20120913/acquire-and-release-semantics
|
154
|
+
*/
|
155
|
+
extern DECLSPEC void SDLCALL SDL_MemoryBarrierReleaseFunction(void);
|
156
|
+
extern DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
|
157
|
+
|
158
|
+
#if defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
|
159
|
+
#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("lwsync" : : : "memory")
|
160
|
+
#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("lwsync" : : : "memory")
|
161
|
+
#elif defined(__GNUC__) && defined(__aarch64__)
|
162
|
+
#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory")
|
163
|
+
#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("dmb ish" : : : "memory")
|
164
|
+
#elif defined(__GNUC__) && defined(__arm__)
|
165
|
+
#if 0 /* defined(__LINUX__) || defined(__ANDROID__) */
|
166
|
+
/* Information from:
|
167
|
+
https://chromium.googlesource.com/chromium/chromium/+/trunk/base/atomicops_internals_arm_gcc.h#19
|
168
|
+
|
169
|
+
The Linux kernel provides a helper function which provides the right code for a memory barrier,
|
170
|
+
hard-coded at address 0xffff0fa0
|
171
|
+
*/
|
172
|
+
typedef void (*SDL_KernelMemoryBarrierFunc)();
|
173
|
+
#define SDL_MemoryBarrierRelease() ((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
|
174
|
+
#define SDL_MemoryBarrierAcquire() ((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
|
175
|
+
#elif 0 /* defined(__QNXNTO__) */
|
176
|
+
#include <sys/cpuinline.h>
|
177
|
+
|
178
|
+
#define SDL_MemoryBarrierRelease() __cpu_membarrier()
|
179
|
+
#define SDL_MemoryBarrierAcquire() __cpu_membarrier()
|
180
|
+
#else
|
181
|
+
#if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) || defined(__ARM_ARCH_8A__)
|
182
|
+
#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("dmb ish" : : : "memory")
|
183
|
+
#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("dmb ish" : : : "memory")
|
184
|
+
#elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6T2__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_5TE__)
|
185
|
+
#ifdef __thumb__
|
186
|
+
/* The mcr instruction isn't available in thumb mode, use real functions */
|
187
|
+
#define SDL_MEMORY_BARRIER_USES_FUNCTION
|
188
|
+
#define SDL_MemoryBarrierRelease() SDL_MemoryBarrierReleaseFunction()
|
189
|
+
#define SDL_MemoryBarrierAcquire() SDL_MemoryBarrierAcquireFunction()
|
190
|
+
#else
|
191
|
+
#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r"(0) : "memory")
|
192
|
+
#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r"(0) : "memory")
|
193
|
+
#endif /* __thumb__ */
|
194
|
+
#else
|
195
|
+
#define SDL_MemoryBarrierRelease() __asm__ __volatile__ ("" : : : "memory")
|
196
|
+
#define SDL_MemoryBarrierAcquire() __asm__ __volatile__ ("" : : : "memory")
|
197
|
+
#endif /* __LINUX__ || __ANDROID__ */
|
198
|
+
#endif /* __GNUC__ && __arm__ */
|
199
|
+
#else
|
200
|
+
#if (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5120))
|
201
|
+
/* This is correct for all CPUs on Solaris when using Solaris Studio 12.1+. */
|
202
|
+
#include <mbarrier.h>
|
203
|
+
#define SDL_MemoryBarrierRelease() __machine_rel_barrier()
|
204
|
+
#define SDL_MemoryBarrierAcquire() __machine_acq_barrier()
|
205
|
+
#else
|
206
|
+
/* This is correct for the x86 and x64 CPUs, and we'll expand this over time. */
|
207
|
+
#define SDL_MemoryBarrierRelease() SDL_CompilerBarrier()
|
208
|
+
#define SDL_MemoryBarrierAcquire() SDL_CompilerBarrier()
|
209
|
+
#endif
|
210
|
+
#endif
|
211
|
+
|
212
|
+
/**
|
213
|
+
* \brief A type representing an atomic integer value. It is a struct
|
214
|
+
* so people don't accidentally use numeric operations on it.
|
215
|
+
*/
|
216
|
+
typedef struct { int value; } SDL_atomic_t;
|
217
|
+
|
218
|
+
/**
|
219
|
+
* \brief Set an atomic variable to a new value if it is currently an old value.
|
220
|
+
*
|
221
|
+
* \return SDL_TRUE if the atomic variable was set, SDL_FALSE otherwise.
|
222
|
+
*
|
223
|
+
* \note If you don't know what this function is for, you shouldn't use it!
|
224
|
+
*/
|
225
|
+
extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval);
|
226
|
+
|
227
|
+
/**
|
228
|
+
* \brief Set an atomic variable to a value.
|
229
|
+
*
|
230
|
+
* \return The previous value of the atomic variable.
|
231
|
+
*/
|
232
|
+
extern DECLSPEC int SDLCALL SDL_AtomicSet(SDL_atomic_t *a, int v);
|
233
|
+
|
234
|
+
/**
|
235
|
+
* \brief Get the value of an atomic variable
|
236
|
+
*/
|
237
|
+
extern DECLSPEC int SDLCALL SDL_AtomicGet(SDL_atomic_t *a);
|
238
|
+
|
239
|
+
/**
|
240
|
+
* \brief Add to an atomic variable.
|
241
|
+
*
|
242
|
+
* \return The previous value of the atomic variable.
|
243
|
+
*
|
244
|
+
* \note This same style can be used for any number operation
|
245
|
+
*/
|
246
|
+
extern DECLSPEC int SDLCALL SDL_AtomicAdd(SDL_atomic_t *a, int v);
|
247
|
+
|
248
|
+
/**
|
249
|
+
* \brief Increment an atomic variable used as a reference count.
|
250
|
+
*/
|
251
|
+
#ifndef SDL_AtomicIncRef
|
252
|
+
#define SDL_AtomicIncRef(a) SDL_AtomicAdd(a, 1)
|
253
|
+
#endif
|
254
|
+
|
255
|
+
/**
|
256
|
+
* \brief Decrement an atomic variable used as a reference count.
|
257
|
+
*
|
258
|
+
* \return SDL_TRUE if the variable reached zero after decrementing,
|
259
|
+
* SDL_FALSE otherwise
|
260
|
+
*/
|
261
|
+
#ifndef SDL_AtomicDecRef
|
262
|
+
#define SDL_AtomicDecRef(a) (SDL_AtomicAdd(a, -1) == 1)
|
263
|
+
#endif
|
264
|
+
|
265
|
+
/**
|
266
|
+
* \brief Set a pointer to a new value if it is currently an old value.
|
267
|
+
*
|
268
|
+
* \return SDL_TRUE if the pointer was set, SDL_FALSE otherwise.
|
269
|
+
*
|
270
|
+
* \note If you don't know what this function is for, you shouldn't use it!
|
271
|
+
*/
|
272
|
+
extern DECLSPEC SDL_bool SDLCALL SDL_AtomicCASPtr(void **a, void *oldval, void *newval);
|
273
|
+
|
274
|
+
/**
|
275
|
+
* \brief Set a pointer to a value atomically.
|
276
|
+
*
|
277
|
+
* \return The previous value of the pointer.
|
278
|
+
*/
|
279
|
+
extern DECLSPEC void* SDLCALL SDL_AtomicSetPtr(void **a, void* v);
|
280
|
+
|
281
|
+
/**
|
282
|
+
* \brief Get the value of a pointer atomically.
|
283
|
+
*/
|
284
|
+
extern DECLSPEC void* SDLCALL SDL_AtomicGetPtr(void **a);
|
285
|
+
|
286
|
+
/* Ends C function definitions when using C++ */
|
287
|
+
#ifdef __cplusplus
|
288
|
+
}
|
289
|
+
#endif
|
290
|
+
|
291
|
+
#include "close_code.h"
|
292
|
+
|
293
|
+
#endif /* SDL_atomic_h_ */
|
294
|
+
|
295
|
+
/* vi: set ts=4 sw=4 expandtab: */
|