gosu 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +108 -14
  3. data/dependencies/SDL/include/SDL_assert.h +81 -50
  4. data/dependencies/SDL/include/SDL_atomic.h +135 -35
  5. data/dependencies/SDL/include/SDL_audio.h +960 -355
  6. data/dependencies/SDL/include/SDL_bits.h +11 -6
  7. data/dependencies/SDL/include/SDL_blendmode.h +91 -14
  8. data/dependencies/SDL/include/SDL_clipboard.h +30 -7
  9. data/dependencies/SDL/include/SDL_config.h +277 -27
  10. data/dependencies/SDL/include/SDL_config_android.h +13 -38
  11. data/dependencies/SDL/include/SDL_config_iphoneos.h +21 -62
  12. data/dependencies/SDL/include/SDL_config_macosx.h +23 -92
  13. data/dependencies/SDL/include/SDL_config_minimal.h +1 -4
  14. data/dependencies/SDL/include/SDL_config_pandora.h +15 -22
  15. data/dependencies/SDL/include/SDL_config_psp.h +16 -37
  16. data/dependencies/SDL/include/SDL_config_windows.h +28 -91
  17. data/dependencies/SDL/include/SDL_config_winrt.h +33 -61
  18. data/dependencies/SDL/include/SDL_config_wiz.h +28 -56
  19. data/dependencies/SDL/include/SDL_copying.h +1 -1
  20. data/dependencies/SDL/include/SDL_cpuinfo.h +331 -71
  21. data/dependencies/SDL/include/SDL_egl.h +906 -280
  22. data/dependencies/SDL/include/SDL_endian.h +101 -47
  23. data/dependencies/SDL/include/SDL_error.h +70 -19
  24. data/dependencies/SDL/include/SDL_events.h +387 -79
  25. data/dependencies/SDL/include/SDL_filesystem.h +73 -64
  26. data/dependencies/SDL/include/SDL_gamecontroller.h +585 -125
  27. data/dependencies/SDL/include/SDL_gesture.h +36 -6
  28. data/dependencies/SDL/include/SDL_haptic.h +304 -210
  29. data/dependencies/SDL/include/SDL_hidapi.h +451 -0
  30. data/dependencies/SDL/include/SDL_hints.h +1286 -897
  31. data/dependencies/SDL/include/SDL_joystick.h +577 -130
  32. data/dependencies/SDL/include/SDL_keyboard.h +162 -63
  33. data/dependencies/SDL/include/SDL_keycode.h +7 -5
  34. data/dependencies/SDL/include/SDL_loadso.h +42 -8
  35. data/dependencies/SDL/include/SDL_locale.h +34 -32
  36. data/dependencies/SDL/include/SDL_log.h +212 -19
  37. data/dependencies/SDL/include/SDL_main.h +72 -17
  38. data/dependencies/SDL/include/SDL_messagebox.h +70 -23
  39. data/dependencies/SDL/include/SDL_metal.h +27 -32
  40. data/dependencies/SDL/include/SDL_misc.h +19 -15
  41. data/dependencies/SDL/include/SDL_mouse.h +262 -110
  42. data/dependencies/SDL/include/SDL_mutex.h +286 -66
  43. data/dependencies/SDL/include/SDL_name.h +1 -1
  44. data/dependencies/SDL/include/SDL_opengl.h +1 -1
  45. data/dependencies/SDL/include/SDL_opengles.h +1 -1
  46. data/dependencies/SDL/include/SDL_opengles2.h +2 -2
  47. data/dependencies/SDL/include/SDL_pixels.h +199 -34
  48. data/dependencies/SDL/include/SDL_platform.h +39 -2
  49. data/dependencies/SDL/include/SDL_power.h +23 -10
  50. data/dependencies/SDL/include/SDL_quit.h +1 -1
  51. data/dependencies/SDL/include/SDL_rect.h +78 -28
  52. data/dependencies/SDL/include/SDL_render.h +1204 -472
  53. data/dependencies/SDL/include/SDL_revision.h +2 -2
  54. data/dependencies/SDL/include/SDL_rwops.h +605 -33
  55. data/dependencies/SDL/include/SDL_scancode.h +1 -1
  56. data/dependencies/SDL/include/SDL_sensor.h +76 -42
  57. data/dependencies/SDL/include/SDL_shape.h +38 -27
  58. data/dependencies/SDL/include/SDL_stdinc.h +96 -24
  59. data/dependencies/SDL/include/SDL_surface.h +571 -139
  60. data/dependencies/SDL/include/SDL_system.h +339 -101
  61. data/dependencies/SDL/include/SDL_syswm.h +50 -20
  62. data/dependencies/SDL/include/SDL_test.h +1 -1
  63. data/dependencies/SDL/include/SDL_test_assert.h +2 -2
  64. data/dependencies/SDL/include/SDL_test_common.h +23 -6
  65. data/dependencies/SDL/include/SDL_test_compare.h +1 -1
  66. data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
  67. data/dependencies/SDL/include/SDL_test_font.h +3 -3
  68. data/dependencies/SDL/include/SDL_test_fuzzer.h +28 -26
  69. data/dependencies/SDL/include/SDL_test_harness.h +6 -6
  70. data/dependencies/SDL/include/SDL_test_images.h +1 -1
  71. data/dependencies/SDL/include/SDL_test_log.h +1 -1
  72. data/dependencies/SDL/include/SDL_test_md5.h +1 -1
  73. data/dependencies/SDL/include/SDL_test_memory.h +1 -1
  74. data/dependencies/SDL/include/SDL_test_random.h +2 -2
  75. data/dependencies/SDL/include/SDL_thread.h +226 -128
  76. data/dependencies/SDL/include/SDL_timer.h +129 -22
  77. data/dependencies/SDL/include/SDL_touch.h +48 -8
  78. data/dependencies/SDL/include/SDL_types.h +1 -1
  79. data/dependencies/SDL/include/SDL_version.h +72 -46
  80. data/dependencies/SDL/include/SDL_video.h +1266 -460
  81. data/dependencies/SDL/include/SDL_vulkan.h +100 -161
  82. data/dependencies/SDL/include/begin_code.h +22 -1
  83. data/dependencies/SDL/include/close_code.h +1 -1
  84. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  85. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  86. data/dependencies/SDL_sound/SDL_sound.c +83 -7
  87. data/dependencies/SDL_sound/SDL_sound.h +4 -4
  88. data/dependencies/SDL_sound/SDL_sound_aiff.c +9 -12
  89. data/dependencies/SDL_sound/SDL_sound_au.c +7 -7
  90. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +3 -3
  91. data/dependencies/SDL_sound/SDL_sound_flac.c +1 -1
  92. data/dependencies/SDL_sound/SDL_sound_internal.h +17 -10
  93. data/dependencies/SDL_sound/SDL_sound_modplug.c +25 -27
  94. data/dependencies/SDL_sound/SDL_sound_mp3.c +5 -17
  95. data/dependencies/SDL_sound/SDL_sound_raw.c +11 -11
  96. data/dependencies/SDL_sound/SDL_sound_shn.c +8 -7
  97. data/dependencies/SDL_sound/SDL_sound_voc.c +6 -4
  98. data/dependencies/SDL_sound/SDL_sound_vorbis.c +6 -11
  99. data/dependencies/SDL_sound/SDL_sound_wav.c +35 -29
  100. data/dependencies/SDL_sound/dr_flac.h +618 -220
  101. data/dependencies/SDL_sound/dr_mp3.h +263 -94
  102. data/dependencies/SDL_sound/libmodplug/fastmix.c +58 -64
  103. data/dependencies/SDL_sound/libmodplug/libmodplug.h +25 -103
  104. data/dependencies/SDL_sound/libmodplug/load_669.c +14 -17
  105. data/dependencies/SDL_sound/libmodplug/load_amf.c +11 -7
  106. data/dependencies/SDL_sound/libmodplug/load_ams.c +65 -22
  107. data/dependencies/SDL_sound/libmodplug/load_dbm.c +8 -4
  108. data/dependencies/SDL_sound/libmodplug/load_dmf.c +55 -25
  109. data/dependencies/SDL_sound/libmodplug/load_far.c +9 -13
  110. data/dependencies/SDL_sound/libmodplug/load_gdm.c +448 -0
  111. data/dependencies/SDL_sound/libmodplug/load_it.c +45 -49
  112. data/dependencies/SDL_sound/libmodplug/load_mdl.c +80 -53
  113. data/dependencies/SDL_sound/libmodplug/load_med.c +20 -12
  114. data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
  115. data/dependencies/SDL_sound/libmodplug/load_mt2.c +29 -17
  116. data/dependencies/SDL_sound/libmodplug/load_okt.c +12 -8
  117. data/dependencies/SDL_sound/libmodplug/load_psm.c +101 -78
  118. data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -17
  119. data/dependencies/SDL_sound/libmodplug/load_s3m.c +9 -7
  120. data/dependencies/SDL_sound/libmodplug/load_stm.c +3 -2
  121. data/dependencies/SDL_sound/libmodplug/load_ult.c +2 -2
  122. data/dependencies/SDL_sound/libmodplug/load_umx.c +315 -35
  123. data/dependencies/SDL_sound/libmodplug/load_xm.c +25 -21
  124. data/dependencies/SDL_sound/libmodplug/mmcmp.c +295 -149
  125. data/dependencies/SDL_sound/libmodplug/modplug.c +7 -123
  126. data/dependencies/SDL_sound/libmodplug/modplug.h +32 -29
  127. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +0 -1
  128. data/dependencies/SDL_sound/libmodplug/snd_flt.c +2 -2
  129. data/dependencies/SDL_sound/libmodplug/snd_fx.c +24 -18
  130. data/dependencies/SDL_sound/libmodplug/sndfile.c +55 -156
  131. data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -12
  132. data/dependencies/SDL_sound/libmodplug/tables.h +10 -15
  133. data/dependencies/SDL_sound/stb_vorbis.h +508 -325
  134. data/dependencies/{al_soft → mojoAL}/AL/al.h +38 -30
  135. data/dependencies/{al_soft → mojoAL}/AL/alc.h +27 -56
  136. data/dependencies/mojoAL/mojoal.c +4594 -0
  137. data/ext/gosu/extconf.rb +29 -30
  138. data/include/Gosu/Audio.hpp +70 -85
  139. data/include/Gosu/Color.hpp +19 -11
  140. data/include/Gosu/Font.hpp +40 -44
  141. data/include/Gosu/Graphics.hpp +58 -71
  142. data/include/Gosu/GraphicsBase.hpp +26 -33
  143. data/include/Gosu/Image.hpp +56 -62
  144. data/include/Gosu/ImageData.hpp +23 -27
  145. data/include/Gosu/Inspection.hpp +1 -4
  146. data/include/Gosu/TextInput.hpp +34 -40
  147. data/include/Gosu/Version.hpp +1 -1
  148. data/include/Gosu/Window.hpp +71 -70
  149. data/lib/SDL2.dll +0 -0
  150. data/lib/gosu/compat.rb +24 -37
  151. data/lib/gosu.rb +2 -2
  152. data/lib64/SDL2.dll +0 -0
  153. data/src/Audio.cpp +86 -86
  154. data/src/AudioFile.hpp +6 -6
  155. data/src/AudioFileAudioToolbox.cpp +1 -1
  156. data/src/AudioFileSDLSound.cpp +1 -1
  157. data/src/AudioImpl.hpp +5 -5
  158. data/src/BitmapIO.cpp +0 -20
  159. data/src/BlockAllocator.cpp +2 -1
  160. data/src/Channel.cpp +22 -20
  161. data/src/Color.cpp +12 -9
  162. data/src/EmptyImageData.hpp +15 -17
  163. data/src/FileUnix.cpp +1 -1
  164. data/src/FileWin.cpp +1 -1
  165. data/src/Font.cpp +48 -53
  166. data/src/Graphics.cpp +135 -143
  167. data/src/Image.cpp +41 -42
  168. data/src/Input.cpp +1 -1
  169. data/src/InputUIKit.cpp +1 -1
  170. data/src/LargeImageData.cpp +108 -101
  171. data/src/LargeImageData.hpp +17 -15
  172. data/src/Log.hpp +6 -6
  173. data/src/Macro.cpp +35 -37
  174. data/src/Macro.hpp +11 -11
  175. data/src/Math.cpp +8 -1
  176. data/src/Resolution.cpp +12 -7
  177. data/src/RubyGosu.cxx +5 -5
  178. data/src/TexChunk.cpp +50 -41
  179. data/src/TexChunk.hpp +22 -22
  180. data/src/Text.cpp +37 -37
  181. data/src/TextBuilder.cpp +60 -57
  182. data/src/TextBuilder.hpp +20 -20
  183. data/src/TextInput.cpp +127 -135
  184. data/src/TrueTypeFont.cpp +107 -107
  185. data/src/TrueTypeFont.hpp +39 -38
  186. data/src/TrueTypeFontApple.cpp +19 -22
  187. data/src/TrueTypeFontUnix.cpp +21 -26
  188. data/src/TrueTypeFontWin.cpp +30 -30
  189. data/src/Window.cpp +95 -86
  190. data/src/WindowUIKit.cpp +46 -49
  191. metadata +7 -17
  192. data/dependencies/SDL/include/SDL_config_os2.h +0 -188
  193. data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
  194. data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
  195. data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
  196. data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
  197. data/dependencies/al_soft/AL/alext.h +0 -585
  198. data/dependencies/al_soft/AL/efx-creative.h +0 -3
  199. data/dependencies/al_soft/AL/efx-presets.h +0 -402
  200. data/dependencies/al_soft/AL/efx.h +0 -762
  201. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  202. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  203. data/lib/OpenAL32.dll +0 -0
  204. data/lib64/OpenAL32.dll +0 -0
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  Simple DirectMedia Layer
3
- Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
3
+ Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
4
4
 
5
5
  This software is provided 'as-is', without any express or implied
6
6
  warranty. In no event will the authors be held liable for any damages
@@ -35,6 +35,17 @@
35
35
  #include "SDL_atomic.h"
36
36
  #include "SDL_mutex.h"
37
37
 
38
+ #if defined(__WIN32__)
39
+ #include <process.h> /* _beginthreadex() and _endthreadex() */
40
+ #endif
41
+ #if defined(__OS2__) /* for _beginthread() and _endthread() */
42
+ #ifndef __EMX__
43
+ #include <process.h>
44
+ #else
45
+ #include <stdlib.h>
46
+ #endif
47
+ #endif
48
+
38
49
  #include "begin_code.h"
39
50
  /* Set up for C function definitions, even when using C++ */
40
51
  #ifdef __cplusplus
@@ -69,11 +80,14 @@ typedef enum {
69
80
  } SDL_ThreadPriority;
70
81
 
71
82
  /**
72
- * The function passed to SDL_CreateThread().
73
- * It is passed a void* user context parameter and returns an int.
83
+ * The function passed to SDL_CreateThread().
84
+ *
85
+ * \param data what was passed as `data` to SDL_CreateThread()
86
+ * \returns a value that can be reported through SDL_WaitThread().
74
87
  */
75
88
  typedef int (SDLCALL * SDL_ThreadFunction) (void *data);
76
89
 
90
+
77
91
  #if defined(__WIN32__)
78
92
  /**
79
93
  * \file SDL_thread.h
@@ -96,7 +110,6 @@ typedef int (SDLCALL * SDL_ThreadFunction) (void *data);
96
110
  * library!
97
111
  */
98
112
  #define SDL_PASSED_BEGINTHREAD_ENDTHREAD
99
- #include <process.h> /* _beginthreadex() and _endthreadex() */
100
113
 
101
114
  typedef uintptr_t (__cdecl * pfnSDL_CurrentBeginThread)
102
115
  (void *, unsigned, unsigned (__stdcall *func)(void *),
@@ -110,9 +123,6 @@ typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
110
123
  #define SDL_endthread _endthreadex
111
124
  #endif
112
125
 
113
- /**
114
- * Create a thread.
115
- */
116
126
  extern DECLSPEC SDL_Thread *SDLCALL
117
127
  SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data,
118
128
  pfnSDL_CurrentBeginThread pfnBeginThread,
@@ -125,9 +135,6 @@ SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
125
135
  pfnSDL_CurrentEndThread pfnEndThread);
126
136
 
127
137
 
128
- /**
129
- * Create a thread.
130
- */
131
138
  #if defined(SDL_CreateThread) && SDL_DYNAMIC_API
132
139
  #undef SDL_CreateThread
133
140
  #define SDL_CreateThread(fn, name, data) SDL_CreateThread_REAL(fn, name, data, (pfnSDL_CurrentBeginThread)SDL_beginthread, (pfnSDL_CurrentEndThread)SDL_endthread)
@@ -145,12 +152,6 @@ SDL_CreateThreadWithStackSize(int (SDLCALL * fn) (void *),
145
152
  */
146
153
  #define SDL_PASSED_BEGINTHREAD_ENDTHREAD
147
154
 
148
- #ifndef __EMX__
149
- #include <process.h>
150
- #else
151
- #include <stdlib.h>
152
- #endif
153
-
154
155
  typedef int (*pfnSDL_CurrentBeginThread)(void (*func)(void *), void *, unsigned, void * /*arg*/);
155
156
  typedef void (*pfnSDL_CurrentEndThread)(void);
156
157
 
@@ -183,39 +184,71 @@ SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const siz
183
184
  #else
184
185
 
185
186
  /**
186
- * Create a thread with a default stack size.
187
+ * Create a new thread with a default stack size.
188
+ *
189
+ * This is equivalent to calling:
190
+ *
191
+ * ```c
192
+ * SDL_CreateThreadWithStackSize(fn, name, 0, data);
193
+ * ```
187
194
  *
188
- * This is equivalent to calling:
189
- * SDL_CreateThreadWithStackSize(fn, name, 0, data);
195
+ * \param fn the SDL_ThreadFunction function to call in the new thread
196
+ * \param name the name of the thread
197
+ * \param data a pointer that is passed to `fn`
198
+ * \returns an opaque pointer to the new thread object on success, NULL if the
199
+ * new thread could not be created; call SDL_GetError() for more
200
+ * information.
201
+ *
202
+ * \since This function is available since SDL 2.0.0.
203
+ *
204
+ * \sa SDL_CreateThreadWithStackSize
205
+ * \sa SDL_WaitThread
190
206
  */
191
207
  extern DECLSPEC SDL_Thread *SDLCALL
192
208
  SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data);
193
209
 
194
210
  /**
195
- * Create a thread.
196
- *
197
- * Thread naming is a little complicated: Most systems have very small
198
- * limits for the string length (Haiku has 32 bytes, Linux currently has 16,
199
- * Visual C++ 6.0 has nine!), and possibly other arbitrary rules. You'll
200
- * have to see what happens with your system's debugger. The name should be
201
- * UTF-8 (but using the naming limits of C identifiers is a better bet).
202
- * There are no requirements for thread naming conventions, so long as the
203
- * string is null-terminated UTF-8, but these guidelines are helpful in
204
- * choosing a name:
205
- *
206
- * http://stackoverflow.com/questions/149932/naming-conventions-for-threads
207
- *
208
- * If a system imposes requirements, SDL will try to munge the string for
209
- * it (truncate, etc), but the original string contents will be available
210
- * from SDL_GetThreadName().
211
- *
212
- * The size (in bytes) of the new stack can be specified. Zero means "use
213
- * the system default" which might be wildly different between platforms
214
- * (x86 Linux generally defaults to eight megabytes, an embedded device
215
- * might be a few kilobytes instead).
216
- *
217
- * In SDL 2.1, stacksize will be folded into the original SDL_CreateThread
218
- * function.
211
+ * Create a new thread with a specific stack size.
212
+ *
213
+ * SDL makes an attempt to report `name` to the system, so that debuggers can
214
+ * display it. Not all platforms support this.
215
+ *
216
+ * Thread naming is a little complicated: Most systems have very small limits
217
+ * for the string length (Haiku has 32 bytes, Linux currently has 16, Visual
218
+ * C++ 6.0 has _nine_!), and possibly other arbitrary rules. You'll have to
219
+ * see what happens with your system's debugger. The name should be UTF-8 (but
220
+ * using the naming limits of C identifiers is a better bet). There are no
221
+ * requirements for thread naming conventions, so long as the string is
222
+ * null-terminated UTF-8, but these guidelines are helpful in choosing a name:
223
+ *
224
+ * https://stackoverflow.com/questions/149932/naming-conventions-for-threads
225
+ *
226
+ * If a system imposes requirements, SDL will try to munge the string for it
227
+ * (truncate, etc), but the original string contents will be available from
228
+ * SDL_GetThreadName().
229
+ *
230
+ * The size (in bytes) of the new stack can be specified. Zero means "use the
231
+ * system default" which might be wildly different between platforms. x86
232
+ * Linux generally defaults to eight megabytes, an embedded device might be a
233
+ * few kilobytes instead. You generally need to specify a stack that is a
234
+ * multiple of the system's page size (in many cases, this is 4 kilobytes, but
235
+ * check your system documentation).
236
+ *
237
+ * In SDL 2.1, stack size will be folded into the original SDL_CreateThread
238
+ * function, but for backwards compatibility, this is currently a separate
239
+ * function.
240
+ *
241
+ * \param fn the SDL_ThreadFunction function to call in the new thread
242
+ * \param name the name of the thread
243
+ * \param stacksize the size, in bytes, to allocate for the new thread stack.
244
+ * \param data a pointer that is passed to `fn`
245
+ * \returns an opaque pointer to the new thread object on success, NULL if the
246
+ * new thread could not be created; call SDL_GetError() for more
247
+ * information.
248
+ *
249
+ * \since This function is available since SDL 2.0.9.
250
+ *
251
+ * \sa SDL_WaitThread
219
252
  */
220
253
  extern DECLSPEC SDL_Thread *SDLCALL
221
254
  SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const size_t stacksize, void *data);
@@ -223,137 +256,202 @@ SDL_CreateThreadWithStackSize(SDL_ThreadFunction fn, const char *name, const siz
223
256
  #endif
224
257
 
225
258
  /**
226
- * Get the thread name, as it was specified in SDL_CreateThread().
227
- * This function returns a pointer to a UTF-8 string that names the
228
- * specified thread, or NULL if it doesn't have a name. This is internal
229
- * memory, not to be free()'d by the caller, and remains valid until the
230
- * specified thread is cleaned up by SDL_WaitThread().
259
+ * Get the thread name as it was specified in SDL_CreateThread().
260
+ *
261
+ * This is internal memory, not to be freed by the caller, and remains valid
262
+ * until the specified thread is cleaned up by SDL_WaitThread().
263
+ *
264
+ * \param thread the thread to query
265
+ * \returns a pointer to a UTF-8 string that names the specified thread, or
266
+ * NULL if it doesn't have a name.
267
+ *
268
+ * \since This function is available since SDL 2.0.0.
269
+ *
270
+ * \sa SDL_CreateThread
231
271
  */
232
272
  extern DECLSPEC const char *SDLCALL SDL_GetThreadName(SDL_Thread *thread);
233
273
 
234
274
  /**
235
- * Get the thread identifier for the current thread.
275
+ * Get the thread identifier for the current thread.
276
+ *
277
+ * This thread identifier is as reported by the underlying operating system.
278
+ * If SDL is running on a platform that does not support threads the return
279
+ * value will always be zero.
280
+ *
281
+ * This function also returns a valid thread ID when called from the main
282
+ * thread.
283
+ *
284
+ * \returns the ID of the current thread.
285
+ *
286
+ * \since This function is available since SDL 2.0.0.
287
+ *
288
+ * \sa SDL_GetThreadID
236
289
  */
237
290
  extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
238
291
 
239
292
  /**
240
- * Get the thread identifier for the specified thread.
293
+ * Get the thread identifier for the specified thread.
294
+ *
295
+ * This thread identifier is as reported by the underlying operating system.
296
+ * If SDL is running on a platform that does not support threads the return
297
+ * value will always be zero.
298
+ *
299
+ * \param thread the thread to query
300
+ * \returns the ID of the specified thread, or the ID of the current thread if
301
+ * `thread` is NULL.
241
302
  *
242
- * Equivalent to SDL_ThreadID() if the specified thread is NULL.
303
+ * \since This function is available since SDL 2.0.0.
304
+ *
305
+ * \sa SDL_ThreadID
243
306
  */
244
307
  extern DECLSPEC SDL_threadID SDLCALL SDL_GetThreadID(SDL_Thread * thread);
245
308
 
246
309
  /**
247
- * Set the priority for the current thread
310
+ * Set the priority for the current thread.
311
+ *
312
+ * Note that some platforms will not let you alter the priority (or at least,
313
+ * promote the thread to a higher priority) at all, and some require you to be
314
+ * an administrator account. Be prepared for this to fail.
315
+ *
316
+ * \param priority the SDL_ThreadPriority to set
317
+ * \returns 0 on success or a negative error code on failure; call
318
+ * SDL_GetError() for more information.
319
+ *
320
+ * \since This function is available since SDL 2.0.0.
248
321
  */
249
322
  extern DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority);
250
323
 
251
324
  /**
252
- * Wait for a thread to finish. Threads that haven't been detached will
253
- * remain (as a "zombie") until this function cleans them up. Not doing so
254
- * is a resource leak.
325
+ * Wait for a thread to finish.
255
326
  *
256
- * Once a thread has been cleaned up through this function, the SDL_Thread
257
- * that references it becomes invalid and should not be referenced again.
258
- * As such, only one thread may call SDL_WaitThread() on another.
327
+ * Threads that haven't been detached will remain (as a "zombie") until this
328
+ * function cleans them up. Not doing so is a resource leak.
259
329
  *
260
- * The return code for the thread function is placed in the area
261
- * pointed to by \c status, if \c status is not NULL.
330
+ * Once a thread has been cleaned up through this function, the SDL_Thread
331
+ * that references it becomes invalid and should not be referenced again. As
332
+ * such, only one thread may call SDL_WaitThread() on another.
262
333
  *
263
- * You may not wait on a thread that has been used in a call to
264
- * SDL_DetachThread(). Use either that function or this one, but not
265
- * both, or behavior is undefined.
334
+ * The return code for the thread function is placed in the area pointed to by
335
+ * `status`, if `status` is not NULL.
266
336
  *
267
- * It is safe to pass NULL to this function; it is a no-op.
337
+ * You may not wait on a thread that has been used in a call to
338
+ * SDL_DetachThread(). Use either that function or this one, but not both, or
339
+ * behavior is undefined.
340
+ *
341
+ * It is safe to pass a NULL thread to this function; it is a no-op.
342
+ *
343
+ * Note that the thread pointer is freed by this function and is not valid
344
+ * afterward.
345
+ *
346
+ * \param thread the SDL_Thread pointer that was returned from the
347
+ * SDL_CreateThread() call that started this thread
348
+ * \param status pointer to an integer that will receive the value returned
349
+ * from the thread function by its 'return', or NULL to not
350
+ * receive such value back.
351
+ *
352
+ * \since This function is available since SDL 2.0.0.
353
+ *
354
+ * \sa SDL_CreateThread
355
+ * \sa SDL_DetachThread
268
356
  */
269
357
  extern DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread * thread, int *status);
270
358
 
271
359
  /**
272
- * A thread may be "detached" to signify that it should not remain until
273
- * another thread has called SDL_WaitThread() on it. Detaching a thread
274
- * is useful for long-running threads that nothing needs to synchronize
275
- * with or further manage. When a detached thread is done, it simply
276
- * goes away.
277
- *
278
- * There is no way to recover the return code of a detached thread. If you
279
- * need this, don't detach the thread and instead use SDL_WaitThread().
280
- *
281
- * Once a thread is detached, you should usually assume the SDL_Thread isn't
282
- * safe to reference again, as it will become invalid immediately upon
283
- * the detached thread's exit, instead of remaining until someone has called
284
- * SDL_WaitThread() to finally clean it up. As such, don't detach the same
285
- * thread more than once.
286
- *
287
- * If a thread has already exited when passed to SDL_DetachThread(), it will
288
- * stop waiting for a call to SDL_WaitThread() and clean up immediately.
289
- * It is not safe to detach a thread that might be used with SDL_WaitThread().
290
- *
291
- * You may not call SDL_WaitThread() on a thread that has been detached.
292
- * Use either that function or this one, but not both, or behavior is
293
- * undefined.
294
- *
295
- * It is safe to pass NULL to this function; it is a no-op.
360
+ * Let a thread clean up on exit without intervention.
361
+ *
362
+ * A thread may be "detached" to signify that it should not remain until
363
+ * another thread has called SDL_WaitThread() on it. Detaching a thread is
364
+ * useful for long-running threads that nothing needs to synchronize with or
365
+ * further manage. When a detached thread is done, it simply goes away.
366
+ *
367
+ * There is no way to recover the return code of a detached thread. If you
368
+ * need this, don't detach the thread and instead use SDL_WaitThread().
369
+ *
370
+ * Once a thread is detached, you should usually assume the SDL_Thread isn't
371
+ * safe to reference again, as it will become invalid immediately upon the
372
+ * detached thread's exit, instead of remaining until someone has called
373
+ * SDL_WaitThread() to finally clean it up. As such, don't detach the same
374
+ * thread more than once.
375
+ *
376
+ * If a thread has already exited when passed to SDL_DetachThread(), it will
377
+ * stop waiting for a call to SDL_WaitThread() and clean up immediately. It is
378
+ * not safe to detach a thread that might be used with SDL_WaitThread().
379
+ *
380
+ * You may not call SDL_WaitThread() on a thread that has been detached. Use
381
+ * either that function or this one, but not both, or behavior is undefined.
382
+ *
383
+ * It is safe to pass NULL to this function; it is a no-op.
384
+ *
385
+ * \param thread the SDL_Thread pointer that was returned from the
386
+ * SDL_CreateThread() call that started this thread
387
+ *
388
+ * \since This function is available since SDL 2.0.2.
389
+ *
390
+ * \sa SDL_CreateThread
391
+ * \sa SDL_WaitThread
296
392
  */
297
393
  extern DECLSPEC void SDLCALL SDL_DetachThread(SDL_Thread * thread);
298
394
 
299
395
  /**
300
- * \brief Create an identifier that is globally visible to all threads but refers to data that is thread-specific.
301
- *
302
- * \return The newly created thread local storage identifier, or 0 on error
303
- *
304
- * \code
305
- * static SDL_SpinLock tls_lock;
306
- * static SDL_TLSID thread_local_storage;
307
- *
308
- * void SetMyThreadData(void *value)
309
- * {
310
- * if (!thread_local_storage) {
311
- * SDL_AtomicLock(&tls_lock);
312
- * if (!thread_local_storage) {
313
- * thread_local_storage = SDL_TLSCreate();
314
- * }
315
- * SDL_AtomicUnlock(&tls_lock);
316
- * }
317
- * SDL_TLSSet(thread_local_storage, value, 0);
318
- * }
319
- *
320
- * void *GetMyThreadData(void)
321
- * {
322
- * return SDL_TLSGet(thread_local_storage);
323
- * }
324
- * \endcode
325
- *
326
- * \sa SDL_TLSGet()
327
- * \sa SDL_TLSSet()
396
+ * Create a piece of thread-local storage.
397
+ *
398
+ * This creates an identifier that is globally visible to all threads but
399
+ * refers to data that is thread-specific.
400
+ *
401
+ * \returns the newly created thread local storage identifier or 0 on error.
402
+ *
403
+ * \since This function is available since SDL 2.0.0.
404
+ *
405
+ * \sa SDL_TLSGet
406
+ * \sa SDL_TLSSet
328
407
  */
329
408
  extern DECLSPEC SDL_TLSID SDLCALL SDL_TLSCreate(void);
330
409
 
331
410
  /**
332
- * \brief Get the value associated with a thread local storage ID for the current thread.
411
+ * Get the current thread's value associated with a thread local storage ID.
333
412
  *
334
- * \param id The thread local storage ID
413
+ * \param id the thread local storage ID
414
+ * \returns the value associated with the ID for the current thread or NULL if
415
+ * no value has been set; call SDL_GetError() for more information.
335
416
  *
336
- * \return The value associated with the ID for the current thread, or NULL if no value has been set.
417
+ * \since This function is available since SDL 2.0.0.
337
418
  *
338
- * \sa SDL_TLSCreate()
339
- * \sa SDL_TLSSet()
419
+ * \sa SDL_TLSCreate
420
+ * \sa SDL_TLSSet
340
421
  */
341
422
  extern DECLSPEC void * SDLCALL SDL_TLSGet(SDL_TLSID id);
342
423
 
343
424
  /**
344
- * \brief Set the value associated with a thread local storage ID for the current thread.
425
+ * Set the current thread's value associated with a thread local storage ID.
426
+ *
427
+ * The function prototype for `destructor` is:
428
+ *
429
+ * ```c
430
+ * void destructor(void *value)
431
+ * ```
345
432
  *
346
- * \param id The thread local storage ID
347
- * \param value The value to associate with the ID for the current thread
348
- * \param destructor A function called when the thread exits, to free the value.
433
+ * where its parameter `value` is what was passed as `value` to SDL_TLSSet().
349
434
  *
350
- * \return 0 on success, -1 on error
435
+ * \param id the thread local storage ID
436
+ * \param value the value to associate with the ID for the current thread
437
+ * \param destructor a function called when the thread exits, to free the
438
+ * value
439
+ * \returns 0 on success or a negative error code on failure; call
440
+ * SDL_GetError() for more information.
351
441
  *
352
- * \sa SDL_TLSCreate()
353
- * \sa SDL_TLSGet()
442
+ * \since This function is available since SDL 2.0.0.
443
+ *
444
+ * \sa SDL_TLSCreate
445
+ * \sa SDL_TLSGet
354
446
  */
355
447
  extern DECLSPEC int SDLCALL SDL_TLSSet(SDL_TLSID id, const void *value, void (SDLCALL *destructor)(void*));
356
448
 
449
+ /**
450
+ * Cleanup all TLS data for this thread.
451
+ *
452
+ * \since This function is available since SDL 2.0.16.
453
+ */
454
+ extern DECLSPEC void SDLCALL SDL_TLSCleanup(void);
357
455
 
358
456
  /* Ends C function definitions when using C++ */
359
457
  #ifdef __cplusplus