Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thread: Locking mutexes and rwlocks are now void functions. #8435

Merged
merged 1 commit into from
Oct 26, 2023

Conversation

icculus
Copy link
Collaborator

@icculus icculus commented Oct 25, 2023

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.

(This is a draft PR until the builders all pass, but it's otherwise ready to merge, if we want to do this.)

@icculus icculus force-pushed the sdl3-void-lock-functions branch 2 times, most recently from ec2eb2c to 7c71acf Compare October 25, 2023 17:31
@icculus icculus added this to the 3.2.0 milestone Oct 25, 2023
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 libsdl-org#8096.
@icculus icculus marked this pull request as ready for review October 25, 2023 18:54
@icculus
Copy link
Collaborator Author

icculus commented Oct 25, 2023

Okay, this can merge now.

If we're putting this one in, we should probably do the same work to semaphores and condition variables.

@icculus icculus merged commit 899eb0d into libsdl-org:main Oct 26, 2023
33 checks passed
@icculus icculus deleted the sdl3-void-lock-functions branch October 26, 2023 12:57
@sezero
Copy link
Contributor

sezero commented Oct 26, 2023

sdl2-compat should always return success (0) ?

@sezero
Copy link
Contributor

sezero commented Oct 26, 2023

sdl2-compat should always return success (0) ?

I mean, do we want the following?

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 4e555f9..5bbe221 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -3439,6 +3439,21 @@ SDL_RenderGetIntegerScale(SDL_Renderer *renderer)
     return SDL_FALSE;
 }
 
+
+DECLSPEC int SDLCALL
+SDL_LockMutex(SDL_Mutex *a)
+{
+    SDL3_LockMutex(a);
+    return 0;
+}
+
+DECLSPEC int SDLCALL
+SDL_UnlockMutex(SDL_Mutex *a)
+{
+    SDL3_UnlockMutex(a);
+    return 0;
+}
+
 DECLSPEC int SDLCALL
 SDL_AudioInit(const char *driver_name)
 {
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 473f448..36215ed 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -238,9 +238,9 @@ SDL3_SYM_PASSTHROUGH(SDL_Cursor*,GetCursor,(void),(),return)
 SDL3_SYM_PASSTHROUGH(SDL_Cursor*,GetDefaultCursor,(void),(),return)
 SDL3_SYM_RENAMED(void,FreeCursor,DestroyCursor,(SDL_Cursor *a),(a),)
 SDL3_SYM_PASSTHROUGH(SDL_Mutex*,CreateMutex,(void),(),return)
-SDL3_SYM_PASSTHROUGH(int,LockMutex,(SDL_Mutex *a),(a),return)
+SDL3_SYM(void,LockMutex,(SDL_Mutex *a),(a),)
 SDL3_SYM_PASSTHROUGH(int,TryLockMutex,(SDL_Mutex *a),(a),return)
-SDL3_SYM_PASSTHROUGH(int,UnlockMutex,(SDL_Mutex *a),(a),return)
+SDL3_SYM(void,UnlockMutex,(SDL_Mutex *a),(a),)
 SDL3_SYM_PASSTHROUGH(void,DestroyMutex,(SDL_Mutex *a),(a),)
 SDL3_SYM_PASSTHROUGH(SDL_Semaphore*,CreateSemaphore,(Uint32 a),(a),return)
 SDL3_SYM_PASSTHROUGH(void,DestroySemaphore,(SDL_Semaphore *a),(a),)

@icculus
Copy link
Collaborator Author

icculus commented Oct 26, 2023

Yes, go ahead and commit that, please!

@sezero
Copy link
Contributor

sezero commented Oct 26, 2023

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants