threads: Move SDL's own thread creation to a new internal API.

This allows us to set an explicit stack size (overriding the system default
and the global hint an app might have set), and remove all the macro salsa
for dealing with _beginthreadex and such, as internal threads always set those
to NULL anyhow.

I've taken some guesses on reasonable (and tiny!) stack sizes for our
internal threads, but some of these might turn out to be too small in
practice and need an increase. Most of them are simple functions, though.
This commit is contained in:
Ryan C. Gordon
2016-04-12 16:45:10 -04:00
parent 7ae2951fca
commit c61675dc5d
13 changed files with 44 additions and 68 deletions

View File

@@ -27,6 +27,7 @@
#include "SDL_audio_c.h"
#include "SDL_audiomem.h"
#include "SDL_sysaudio.h"
#include "../thread/SDL_systhread.h"
#define _THIS SDL_AudioDevice *_this
@@ -1191,19 +1192,15 @@ open_audio_device(const char *devname, int iscapture,
/* Start the audio thread if necessary */
if (!current_audio.impl.ProvidesOwnCallbackThread) {
/* Start the audio thread */
/* !!! FIXME: we don't force the audio thread stack size here because it calls into user code, but maybe we should? */
/* buffer queueing callback only needs a few bytes, so make the stack tiny. */
char name[64];
const size_t stacksize = (device->spec.callback == SDL_BufferQueueDrainCallback) ? 64 * 1024 : 0;
SDL_snprintf(name, sizeof (name), "SDLAudioDev%d", (int) device->id);
/* !!! FIXME: this is nasty. */
#if defined(__WIN32__) && !defined(HAVE_LIBC)
#undef SDL_CreateThread
#if SDL_DYNAMIC_API
device->thread = SDL_CreateThread_REAL(SDL_RunAudio, name, device, NULL, NULL);
#else
device->thread = SDL_CreateThread(SDL_RunAudio, name, device, NULL, NULL);
#endif
#else
device->thread = SDL_CreateThread(SDL_RunAudio, name, device);
#endif
device->thread = SDL_CreateThreadInternal(SDL_RunAudio, name, stacksize, device);
if (device->thread == NULL) {
SDL_CloseAudioDevice(device->id);
SDL_SetError("Couldn't create audio thread");