Skip to content

Commit d320b6e

Browse files
committed
SDL3 mutex support
1 parent 3017133 commit d320b6e

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

src_c/_pygame.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@
7777
#define PG_SoftStretchNearest(src, srcrect, dst, dstrect) \
7878
SDL_SoftStretch(src, srcrect, dst, dstrect, SDL_SCALEMODE_NEAREST)
7979

80+
/* Emulating SDL2 SDL_LockMutex API. In SDL3, it returns void. */
81+
static inline int
82+
PG_LockMutex(SDL_mutex *mutex)
83+
{
84+
SDL_LockMutex(mutex);
85+
return 0;
86+
}
87+
88+
/* Emulating SDL2 SDL_UnlockMutex API. In SDL3, it returns void. */
89+
static inline int
90+
PG_UnlockMutex(SDL_mutex *mutex)
91+
{
92+
SDL_UnlockMutex(mutex);
93+
return 0;
94+
}
95+
8096
#else /* ~SDL_VERSION_ATLEAST(3, 0, 0)*/
8197
#define PG_ShowCursor() SDL_ShowCursor(SDL_ENABLE)
8298
#define PG_HideCursor() SDL_ShowCursor(SDL_DISABLE)
@@ -109,6 +125,18 @@
109125
#define PG_SoftStretchNearest(src, srcrect, dst, dstrect) \
110126
SDL_SoftStretch(src, srcrect, dst, dstrect)
111127

128+
static inline int
129+
PG_LockMutex(SDL_mutex *mutex)
130+
{
131+
return SDL_LockMutex(mutex);
132+
}
133+
134+
static inline int
135+
PG_UnlockMutex(SDL_mutex *mutex)
136+
{
137+
return SDL_UnlockMutex(mutex);
138+
}
139+
112140
#if SDL_VERSION_ATLEAST(2, 0, 14)
113141
#define PG_SurfaceHasRLE SDL_HasSurfaceRLE
114142
#else

src_c/event.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static char released_keys[SDL_NUM_SCANCODES] = {0};
104104

105105
#define PG_LOCK_EVFILTER_MUTEX \
106106
if (pg_evfilter_mutex) { \
107-
if (SDL_LockMutex(pg_evfilter_mutex) < 0) { \
107+
if (PG_LockMutex(pg_evfilter_mutex) < 0) { \
108108
/* TODO: better error handling with future error-event API */ \
109109
/* since this error is very rare, we can completely give up if \
110110
* this happens for now */ \
@@ -116,7 +116,7 @@ static char released_keys[SDL_NUM_SCANCODES] = {0};
116116

117117
#define PG_UNLOCK_EVFILTER_MUTEX \
118118
if (pg_evfilter_mutex) { \
119-
if (SDL_UnlockMutex(pg_evfilter_mutex) < 0) { \
119+
if (PG_UnlockMutex(pg_evfilter_mutex) < 0) { \
120120
/* TODO: handle errors with future error-event API */ \
121121
/* since this error is very rare, we can completely give up if \
122122
* this happens for now */ \

src_c/time.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static SDL_mutex *pg_timer_mutex = NULL;
8888
* easily */
8989
#define PG_LOCK_TIMER_MUTEX \
9090
if (pg_timer_mutex) { \
91-
if (SDL_LockMutex(pg_timer_mutex) < 0) { \
91+
if (PG_LockMutex(pg_timer_mutex) < 0) { \
9292
/* TODO: better error handling with future error-event API */ \
9393
/* since this error is very rare, we can completely give up if \
9494
* this happens for now */ \
@@ -100,7 +100,7 @@ static SDL_mutex *pg_timer_mutex = NULL;
100100

101101
#define PG_UNLOCK_TIMER_MUTEX \
102102
if (pg_timer_mutex) { \
103-
if (SDL_UnlockMutex(pg_timer_mutex) < 0) { \
103+
if (PG_UnlockMutex(pg_timer_mutex) < 0) { \
104104
/* TODO: handle errors with future error-event API */ \
105105
/* since this error is very rare, we can completely give up if \
106106
* this happens for now */ \
@@ -441,7 +441,7 @@ time_set_timer(PyObject *self, PyObject *args, PyObject *kwargs)
441441
Py_BEGIN_ALLOW_THREADS;
442442

443443
#ifndef __EMSCRIPTEN__
444-
if (SDL_LockMutex(pg_timer_mutex) < 0) {
444+
if (PG_LockMutex(pg_timer_mutex) < 0) {
445445
ecode = PG_TIMER_SDL_ERROR;
446446
goto end_no_mutex;
447447
}
@@ -475,7 +475,7 @@ time_set_timer(PyObject *self, PyObject *args, PyObject *kwargs)
475475

476476
end:
477477
#ifndef __EMSCRIPTEN__
478-
if (SDL_UnlockMutex(pg_timer_mutex)) {
478+
if (PG_UnlockMutex(pg_timer_mutex)) {
479479
ecode = PG_TIMER_SDL_ERROR;
480480
}
481481

0 commit comments

Comments
 (0)