Sam Lantinga
4f55271571
Removed temporary memory from the API
...
It was intended to make the API easier to use, but various automatic garbage collection all had flaws, and making the application periodically clean up temporary memory added cognitive load to using the API, and in many cases was it was difficult to restructure threaded code to handle this.
So, we're largely going back to the original system, where the API returns allocated results and you free them.
In addition, to solve the problems we originally wanted temporary memory for:
* Short strings with a finite count, like device names, get stored in a per-thread string pool.
* Events continue to use temporary memory internally, which is cleaned up on the next event processing cycle.
2024-07-26 20:59:14 -07:00
Sam Lantinga
a7c0192017
Renamed SDL_PostSemaphore() to SDL_SignalSemphore()
2024-07-24 13:37:40 -07:00
Sam Lantinga
bb96320cc4
Make sure we always copy the data returned using SDL_GetStringRule
...
This prevents race conditions where calling an API from one thread returns the data and it's freed by updates on another thread
2024-07-19 12:22:03 -07:00
Sam Lantinga
ec3bb4c029
Removed the need for SDL_CreateTLS()
...
This eliminates the tap dancing needed for allocating TLS slots, we'll automatically allocate them as needed, in a thread-safe way.
2024-07-16 12:01:51 -07:00
Sam Lantinga
54366181c3
Rename functions in SDL_system.h to match SDL 3.0 naming convention
...
Fixes https://github.com/libsdl-org/SDL/issues/10277
2024-07-15 16:27:48 -07:00
Anonymous Maarten
933f2fc239
pthread: timespec.tv_nsec must be less then 1000000000 ns
2024-07-14 17:28:54 +02:00
Sam Lantinga
5bf6bc4d7d
Renamed SDL_Get/SetProperty() to SDL_Get/SetPointerProperty()
...
This is consistent with the naming for the functions that affect other data types
Fixes https://github.com/libsdl-org/SDL/issues/10241
2024-07-12 10:41:02 -07:00
Sam Lantinga
bd041b4831
Make sure SDL subsystems are initialized before starting threads
2024-07-12 09:10:05 -07:00
Sam Lantinga
b517043936
Added TLS initialization and shutdown functions
...
Fixes https://github.com/libsdl-org/SDL/issues/8576
2024-07-11 12:11:01 -07:00
Edoardo Lolletti
64acde86de
stdcpp threads, simplify SDL_GetCurrentThreadID implementation
...
Removed the workaround that handrolled a thread id using a thread_local variable alongside static mutexes
2024-06-26 09:06:27 -04:00
Edoardo Lolletti
20dbe90771
Fix std::thread memory leak
...
In the stdcpp thread implementation, the allocated std::thread objects were never deleted after joining/detaching
2024-06-24 14:20:10 -04:00
Ryan C. Gordon
96f2ef77ab
include: Make function pointer params into typedefs.
...
This is easier to read and document in general, but will also make some
new parsing work in wikiheaders much easier.
2024-06-11 12:22:46 -04:00
Ryan C. Gordon
e23257307e
Introduce formal policy for APIs that return strings.
...
This declares that any `const char *` returned from SDL is owned by SDL, and
promises to be valid _at least_ until the next time the event queue runs, or
SDL_Quit() is called, even if the thing that owns the string gets destroyed
or changed before then.
This is noted in the headers as "the SDL_GetStringRule", so this will both be
greppable to find a detailed explaination in docs/README-strings.md and
wikiheaders will automatically turn it into a link we can point at the
appropriate documentation.
Fixes #9902 .
(and several FIXMEs, both known and yet-undocumented.)
2024-06-03 14:20:49 -04:00
Ryan C. Gordon
b83bb035e6
thread: SDL_CreateThreadWithStackSize is now SDL_CreateThreadWithProperties.
2024-05-22 11:39:43 -04:00
Ryan C. Gordon
0ec716819e
thread: Reworked SDL_CreateThread to be consistent across platforms.
...
Also documented missing and weird bits, rename typedefs to fit SDL standards.
2024-05-22 11:39:43 -04:00
Sam Lantinga
6f2621438a
Renamed DECLSPEC to SDL_DECLSPEC
2024-05-17 17:09:09 -07:00
Ozkan Sezer
e909c0360f
remove most of SDL_OutOfMemory() calls where SDL is the allocator.
...
Since commit 447b508a77 , SDL_malloc,
SDL_calloc, and SDL_realloc already calls SDL_OutOfMemory().
2024-05-08 20:00:50 +03:00
Ryan C. Gordon
fdcc3e1151
thread: make generic SDL_Condition a no-op if built with SDL_THREADS_DISABLED.
...
Otherwise, when you call SDL_CreateCondition() in something that can otherwise
survive in a single-threaded build, you'll get an error that seems fatal.
We already do this for mutexes and rwlocks (but not semaphores!)
Fixes #9558 .
2024-04-16 15:07:56 -04:00
Mark Delk
dd4636e3fd
SDL_sysmutex.c: fix void return compile error
2024-03-21 13:25:01 -07:00
Sam Lantinga
9920e062d5
Removed SDL_HINT_THREAD_STACK_SIZE
...
The stack size can be specified using SDL_CreateThreadWithStackSize()
2024-02-12 09:54:33 -08:00
Anonymous Maarten
31d133db40
Define SDL_PLATFORM_* macros instead of underscored ones ( #8875 )
2024-01-24 01:40:51 +00:00
Sam Lantinga
fa5bfe577c
Fixed warnings building for UWP
2024-01-21 06:55:29 -08:00
Sam Lantinga
b566bfce07
Fixed warning C4152: nonstandard extension, function/data pointer conversion in expression
2024-01-19 06:49:53 -08:00
Edoardo Lolletti
42d6cf9ce7
Update thread naming on windows
2024-01-18 10:19:18 -08:00
Sam Lantinga
df4b855af5
Updated SDL_TLSID to use the same type as other IDs in SDL
2024-01-18 08:18:37 -08:00
Sam Lantinga
fc0c774976
Renamed SDL_ThreadID() to SDL_GetCurrentThreadID()
...
Also renamed SDL_threadID to SDL_ThreadID and made it Uint64 for consistency with other ID types
2024-01-18 08:18:37 -08:00
Sam Lantinga
a2665f54c8
Updated the atomic API for SDL 3.0 naming conventions
...
Fixes https://github.com/libsdl-org/SDL/issues/7388
2024-01-18 04:41:34 -08:00
Sam Lantinga
5b3ee51c6c
Updated copyright for 2024
2024-01-01 13:15:26 -08:00
Julian Uy
10a8b750a0
Use common generic syscond for platforms with no cond implementation
2023-12-24 06:52:42 -08:00
Julian Uy
4914e5bb78
PS2 use WaitSemaEx for waiting for semaphore with timeout
2023-12-24 06:52:27 -08:00
Sam Lantinga
72b7acfe8a
Don't create a TLS error buffer if we're just clearing the error
...
Fixes https://github.com/libsdl-org/SDL/issues/7600
2023-12-16 21:28:43 -08:00
Ryan C. Gordon
447b508a77
error: SDL's allocators now call SDL_OutOfMemory on error.
...
This means the allocator's caller doesn't need to use SDL_OutOfMemory directly
if the allocation fails.
This applies to the usual allocators: SDL_malloc, SDL_calloc, SDL_realloc
(all of these regardless of if the app supplied a custom allocator or we're
using system malloc() or an internal copy of dlmalloc under the hood),
SDL_aligned_alloc, SDL_small_alloc, SDL_strdup, SDL_asprintf, SDL_wcsdup...
probably others. If it returns something you can pass to SDL_free, it should
work.
The caller might still need to use SDL_OutOfMemory if something that wasn't
SDL allocated the memory: operator new in C++ code, Objective-C's alloc
message, win32 GlobalAlloc, etc.
Fixes #8642 .
2023-11-30 00:14:27 -05:00
meyraud705
8708ba7393
Don't leak if realloc fails
2023-11-10 06:33:39 -08:00
Sylvain
d8600f717e
Pointer as bool (libsdl-org#7214)
2023-11-09 14:18:36 -08:00
Ryan C. Gordon
e6116d399a
mutex: Removed SDL_MUTEX_MAXWAIT.
...
Fixes #8436 .
2023-10-26 14:21:53 -04:00
Ryan C. Gordon
899eb0d042
thread: Locking mutexes and rwlocks are now void functions.
...
Almost nothing checks these return values, and there's no reason a valid
lock should fail to operate. The cases where a lock isn't valid (it's a
bogus pointer, it was previously destroyed, a thread is unlocking a lock it
doesn't own, etc) are undefined behavior and always were, and should be
treated as an application bug.
Reference Issue #8096 .
2023-10-26 08:57:34 -04:00
Ryan C. Gordon
ace0c2c297
mutex: Fixed bug where generic SDL_TryLockMutex would incorrectly block.
...
Fixes #8433 .
2023-10-25 13:03:46 -04:00
Ryan C. Gordon
b61706373c
n3ds: Check that audio thread name starts with "SDLAudioP"
...
The string has a number after it, so a basic SDL_strcmp() will never match.
Reference PR #8346 .
(cherry picked from commit cba6090398 )
2023-10-24 23:58:30 -04:00
ds-sloth
6827b3331d
n3ds systhread - use 80kb thread stack size as default, remove hard cap
...
(cherry picked from commit 3823ba1ded )
2023-10-24 23:57:12 -04:00
ds-sloth
e4cd1d4059
n3ds systhread - prefer to put audio thread on system core
...
(cherry picked from commit 301ee21f33 )
2023-10-24 23:56:34 -04:00
Sam Lantinga
6c8ad975c7
Like mutexes, operations on NULL rwlocks are no-ops
...
Fixes a crash when performing operations on a NULL rwlock before rwlock implementation is chosen
2023-10-11 09:49:44 -07:00
Ryan C. Gordon
b75c751dfc
rwlock: Make generic implmentations work on single-threaded platforms.
...
Fixes #8101 .
2023-08-11 15:03:32 -04:00
Ozkan Sezer
77446e2029
Unaligned stacks on i686-w64-mingw32 may lead to crashes
...
Port of original SDL2 patch by Christopher Wellons (@skeeto, #7607 )
to SDL3.
2023-08-05 17:39:30 +03:00
luzpaz
37e567994d
Fix remaining typos ( #7921 )
...
* Fix remaining typos
Found via `codespell -q 3 -S *.hex,*.pdf,./src/libm,./src/hidapi,./src/stdlib/SDL_malloc.c,./src/video/x11/edid.h -L caf,currenty,datas,einstance,fo,hda,lod,mata,parm,parms,pevent,pevents,pixelx,requestor,ser,statics,te,texturers,thid,uscaled,windowz`
2023-07-03 12:46:47 -07:00
Sam Lantinga
cb73bed6eb
SDL API renaming: SDL TLS functions
...
Fixes https://github.com/libsdl-org/SDL/issues/7743
2023-05-26 08:33:15 -07:00
Sam Lantinga
ddbdd73258
Updated source to match SDL function prototype style
2023-05-23 11:29:41 -07:00
Sam Lantinga
737aa881fa
Updated source to match SDL function prototype style
2023-05-23 09:37:07 -07:00
Sam Lantinga
87ad71f9b2
Rename SDL mutex, semaphore and condition variable types to match SDL 3.0 naming convention
2023-04-28 12:08:33 -07:00
Sam Lantinga
61c0c009ab
Rename SDL semaphore and condition variable functions to match SDL 3.0 naming convention
...
Fixes https://github.com/libsdl-org/SDL/issues/7642
2023-04-28 12:08:33 -07:00
Ryan C. Gordon
e474047ff8
rwlock: Added SDL_rwlock API for shared locks.
2023-04-27 21:54:02 -04:00