1
0
Fork 0
forked from len0rd/rockbox

sdl: increase default worker thread size.

This fixes a mysterious, long-standing crash that's been bothering me on
ipod6g for ages: a silent stack overflow in the sound mixing thread (which
is triggered upon loading a new sound, apparently) will thrash the memory
which is located directly before it in the address space.

In this case, it was the SDL_ButtonState variable which stores the mouse
button state that was being trashed. This was manifesting itself by making
the player always run forward, since MOUSE2 is mapped to +forward by
default.

Fix this by quadrupling the stack size of SDL-spawned threads (not the main
thread) from 1 KB to 4 KB.

Change-Id: I2d7901b7cee1e3ceb1ccdebb38d4ac5b7ea730e1
This commit is contained in:
Franklin Wei 2021-06-27 22:49:33 -04:00
parent 9f950d8bbf
commit d1a92aafff

View file

@ -42,20 +42,25 @@ static void rbsdl_runthread(void)
SDL_RunThread(args);
}
#define RBSDL_THREAD_STACK_SIZE (DEFAULT_STACK_SIZE * 4)
#define MAX_THREAD 4
static char names[MAX_THREAD][16];
static long stacks[MAX_THREAD][DEFAULT_STACK_SIZE / sizeof(long)];
static long stacks[MAX_THREAD][RBSDL_THREAD_STACK_SIZE / sizeof(long)];
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
{
static int threadnum = 0;
if(threadnum >= MAX_THREAD)
return -1;
snprintf(names[threadnum], 16, "sdl_%d", threadnum);
while(global_args) rb->yield(); /* busy wait, pray that this works */
global_args = args;
thread->handle = rb->create_thread(rbsdl_runthread, stacks[threadnum], DEFAULT_STACK_SIZE,
thread->handle = rb->create_thread(rbsdl_runthread, stacks[threadnum], RBSDL_THREAD_STACK_SIZE,
0, names[threadnum] /* collisions allowed? */
IF_PRIO(, PRIORITY_BUFFERING) // this is used for sound mixing
IF_COP(, CPU));