Revert "pulseaudio: cleanup TLS every time we finish a threaded-mainloop callback."

This reverts commit 3b91017682.

This apparently is cleaning up more threads than expected, so this needs a
rethink.

Fixes #12986.
Fixes https://github.com/libsdl-org/sdl2-compat/issues/486
Fixes https://github.com/libsdl-org/sdl2-compat/issues/482
This commit is contained in:
Ryan C. Gordon 2025-05-11 10:55:42 -04:00
parent 84308e7fba
commit e1066ceea1
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 9 additions and 19 deletions

View File

@ -269,19 +269,9 @@ static const char *getAppName(void)
return SDL_GetAppMetadataProperty(SDL_PROP_APP_METADATA_NAME_STRING); return SDL_GetAppMetadataProperty(SDL_PROP_APP_METADATA_NAME_STRING);
} }
static void ThreadedMainloopSignal(void)
{
PULSEAUDIO_pa_threaded_mainloop_signal(pulseaudio_threaded_mainloop, 0); // alert waiting threads to unblock.
// we need to kill any SDL_SetError state; we didn't create this thread
// so its SDL TLS slot will leak otherwise, so we do this every time
// we're (presumably) losing control of the thread.
SDL_CleanupTLS();
}
static void OperationStateChangeCallback(pa_operation *o, void *userdata) static void OperationStateChangeCallback(pa_operation *o, void *userdata)
{ {
ThreadedMainloopSignal(); // just signal any waiting code, it can look up the details. PULSEAUDIO_pa_threaded_mainloop_signal(pulseaudio_threaded_mainloop, 0); // just signal any waiting code, it can look up the details.
} }
/* This function assume you are holding `mainloop`'s lock. The operation is unref'd in here, assuming /* This function assume you are holding `mainloop`'s lock. The operation is unref'd in here, assuming
@ -323,7 +313,7 @@ static void DisconnectFromPulseServer(void)
static void PulseContextStateChangeCallback(pa_context *context, void *userdata) static void PulseContextStateChangeCallback(pa_context *context, void *userdata)
{ {
ThreadedMainloopSignal(); // just signal any waiting code, it can look up the details. PULSEAUDIO_pa_threaded_mainloop_signal(pulseaudio_threaded_mainloop, 0); // just signal any waiting code, it can look up the details.
} }
static bool ConnectToPulseServer(void) static bool ConnectToPulseServer(void)
@ -410,7 +400,7 @@ static void WriteCallback(pa_stream *p, size_t nbytes, void *userdata)
struct SDL_PrivateAudioData *h = (struct SDL_PrivateAudioData *)userdata; struct SDL_PrivateAudioData *h = (struct SDL_PrivateAudioData *)userdata;
//SDL_Log("PULSEAUDIO WRITE CALLBACK! nbytes=%u", (unsigned int) nbytes); //SDL_Log("PULSEAUDIO WRITE CALLBACK! nbytes=%u", (unsigned int) nbytes);
h->bytes_requested += nbytes; h->bytes_requested += nbytes;
ThreadedMainloopSignal(); PULSEAUDIO_pa_threaded_mainloop_signal(pulseaudio_threaded_mainloop, 0);
} }
// This function waits until it is possible to write a full sound buffer // This function waits until it is possible to write a full sound buffer
@ -481,7 +471,7 @@ static Uint8 *PULSEAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
static void ReadCallback(pa_stream *p, size_t nbytes, void *userdata) static void ReadCallback(pa_stream *p, size_t nbytes, void *userdata)
{ {
//SDL_Log("PULSEAUDIO READ CALLBACK! nbytes=%u", (unsigned int) nbytes); //SDL_Log("PULSEAUDIO READ CALLBACK! nbytes=%u", (unsigned int) nbytes);
ThreadedMainloopSignal(); // the recording code queries what it needs, we just need to signal to end any wait PULSEAUDIO_pa_threaded_mainloop_signal(pulseaudio_threaded_mainloop, 0); // the recording code queries what it needs, we just need to signal to end any wait
} }
static bool PULSEAUDIO_WaitRecordingDevice(SDL_AudioDevice *device) static bool PULSEAUDIO_WaitRecordingDevice(SDL_AudioDevice *device)
@ -602,7 +592,7 @@ static void PULSEAUDIO_CloseDevice(SDL_AudioDevice *device)
static void PulseStreamStateChangeCallback(pa_stream *stream, void *userdata) static void PulseStreamStateChangeCallback(pa_stream *stream, void *userdata)
{ {
ThreadedMainloopSignal(); // just signal any waiting code, it can look up the details. PULSEAUDIO_pa_threaded_mainloop_signal(pulseaudio_threaded_mainloop, 0); // just signal any waiting code, it can look up the details.
} }
static bool PULSEAUDIO_OpenDevice(SDL_AudioDevice *device) static bool PULSEAUDIO_OpenDevice(SDL_AudioDevice *device)
@ -803,7 +793,7 @@ static void SinkInfoCallback(pa_context *c, const pa_sink_info *i, int is_last,
if (i) { if (i) {
AddPulseAudioDevice(false, i->description, i->name, i->index, &i->sample_spec); AddPulseAudioDevice(false, i->description, i->name, i->index, &i->sample_spec);
} }
ThreadedMainloopSignal(); PULSEAUDIO_pa_threaded_mainloop_signal(pulseaudio_threaded_mainloop, 0);
} }
// This is called when PulseAudio adds a recording ("source") device. // This is called when PulseAudio adds a recording ("source") device.
@ -813,7 +803,7 @@ static void SourceInfoCallback(pa_context *c, const pa_source_info *i, int is_la
if (i && (include_monitors || (i->monitor_of_sink == PA_INVALID_INDEX))) { if (i && (include_monitors || (i->monitor_of_sink == PA_INVALID_INDEX))) {
AddPulseAudioDevice(true, i->description, i->name, i->index, &i->sample_spec); AddPulseAudioDevice(true, i->description, i->name, i->index, &i->sample_spec);
} }
ThreadedMainloopSignal(); PULSEAUDIO_pa_threaded_mainloop_signal(pulseaudio_threaded_mainloop, 0);
} }
static void ServerInfoCallback(pa_context *c, const pa_server_info *i, void *data) static void ServerInfoCallback(pa_context *c, const pa_server_info *i, void *data)
@ -838,7 +828,7 @@ static void ServerInfoCallback(pa_context *c, const pa_server_info *i, void *dat
} }
} }
ThreadedMainloopSignal(); PULSEAUDIO_pa_threaded_mainloop_signal(pulseaudio_threaded_mainloop, 0);
} }
static bool FindAudioDeviceByIndex(SDL_AudioDevice *device, void *userdata) static bool FindAudioDeviceByIndex(SDL_AudioDevice *device, void *userdata)
@ -882,7 +872,7 @@ static void HotplugCallback(pa_context *c, pa_subscription_event_type_t t, uint3
SDL_AudioDeviceDisconnected(SDL_FindPhysicalAudioDeviceByCallback(FindAudioDeviceByIndex, (void *)(uintptr_t)idx)); SDL_AudioDeviceDisconnected(SDL_FindPhysicalAudioDeviceByCallback(FindAudioDeviceByIndex, (void *)(uintptr_t)idx));
} }
} }
ThreadedMainloopSignal(); PULSEAUDIO_pa_threaded_mainloop_signal(pulseaudio_threaded_mainloop, 0);
} }
static bool CheckDefaultDevice(const bool changed, char *device_path) static bool CheckDefaultDevice(const bool changed, char *device_path)