Added a hint to specify new thread stack size (thanks, Gabriel!).
Fixes Bugzilla #2019. (we'll do a better fix when we break the API in SDL 2.1.)
parent
bcdc63a38b
commit
a8fa7bd1f7
|
@ -348,6 +348,18 @@ extern "C" {
|
||||||
#define SDL_HINT_TIMER_RESOLUTION "SDL_TIMER_RESOLUTION"
|
#define SDL_HINT_TIMER_RESOLUTION "SDL_TIMER_RESOLUTION"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief A string specifying SDL's threads stack size in bytes or "-1" for the backend's default size
|
||||||
|
*
|
||||||
|
* Use this hint in case you need to set SDL's threads stack size to other than the default.
|
||||||
|
* This is specially useful if you build SDL against a non glibc libc library (such as musl) which
|
||||||
|
* provides a relatively small default thread stack size (a few kilobytes versus the default 8MB glibc uses).
|
||||||
|
* Support for this hint is currenly available only in the pthread backend.
|
||||||
|
* As a precaution, this hint can not be set via an environment variable.
|
||||||
|
*/
|
||||||
|
#define SDL_HINT_THREAD_STACK_SIZE "SDL_THREAD_STACK_SIZE"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief If set to 1, then do not allow high-DPI windows. ("Retina" on Mac and iOS)
|
* \brief If set to 1, then do not allow high-DPI windows. ("Retina" on Mac and iOS)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -107,6 +107,7 @@ SDL_SetMainReady(void)
|
||||||
int
|
int
|
||||||
SDL_InitSubSystem(Uint32 flags)
|
SDL_InitSubSystem(Uint32 flags)
|
||||||
{
|
{
|
||||||
|
static Uint32 hints_initialized = SDL_FALSE;
|
||||||
if (!SDL_MainIsReady) {
|
if (!SDL_MainIsReady) {
|
||||||
SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
|
SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -115,6 +116,13 @@ SDL_InitSubSystem(Uint32 flags)
|
||||||
/* Clear the error message */
|
/* Clear the error message */
|
||||||
SDL_ClearError();
|
SDL_ClearError();
|
||||||
|
|
||||||
|
if (hints_initialized == SDL_FALSE) {
|
||||||
|
/* Set a default of -1 for SDL_HINT_THREAD_STACK_SIZE to prevent the
|
||||||
|
end user from interfering it's value with environment variables */
|
||||||
|
SDL_SetHintWithPriority(SDL_HINT_THREAD_STACK_SIZE, "-1", SDL_HINT_OVERRIDE);
|
||||||
|
hints_initialized = SDL_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||||
if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) {
|
if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) {
|
||||||
if (SDL_HelperWindowCreate() < 0) {
|
if (SDL_HelperWindowCreate() < 0) {
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
|
|
||||||
#include "SDL_platform.h"
|
#include "SDL_platform.h"
|
||||||
#include "SDL_thread.h"
|
#include "SDL_thread.h"
|
||||||
|
#include "SDL_hints.h"
|
||||||
#include "../SDL_thread_c.h"
|
#include "../SDL_thread_c.h"
|
||||||
#include "../SDL_systhread.h"
|
#include "../SDL_systhread.h"
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
|
@ -86,6 +87,8 @@ int
|
||||||
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
||||||
{
|
{
|
||||||
pthread_attr_t type;
|
pthread_attr_t type;
|
||||||
|
size_t ss;
|
||||||
|
const char *hint = SDL_GetHint(SDL_HINT_THREAD_STACK_SIZE);
|
||||||
|
|
||||||
/* do this here before any threads exist, so there's no race condition. */
|
/* do this here before any threads exist, so there's no race condition. */
|
||||||
#if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
|
#if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
|
||||||
|
@ -106,6 +109,13 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
||||||
}
|
}
|
||||||
pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
|
pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
|
||||||
|
|
||||||
|
/* If the SDL_HINT_THREAD_STACK_SIZE exists and it seems to be a positive number, use it */
|
||||||
|
if (hint && hint[0] >= '0' && hint[0] <= '9') {
|
||||||
|
pthread_attr_setstacksize(&type, (size_t)SDL_atoi(hint));
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_attr_getstacksize(&type, &ss);
|
||||||
|
|
||||||
/* Create the thread and go! */
|
/* Create the thread and go! */
|
||||||
if (pthread_create(&thread->handle, &type, RunThread, args) != 0) {
|
if (pthread_create(&thread->handle, &type, RunThread, args) != 0) {
|
||||||
return SDL_SetError("Not enough resources to create thread");
|
return SDL_SetError("Not enough resources to create thread");
|
||||||
|
|
|
@ -88,6 +88,8 @@ main(int argc, char *argv[])
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_SetHintWithPriority(SDL_HINT_THREAD_STACK_SIZE, SDL_getenv(SDL_HINT_THREAD_STACK_SIZE), SDL_HINT_OVERRIDE);
|
||||||
|
|
||||||
signal(SIGSEGV, SIG_DFL);
|
signal(SIGSEGV, SIG_DFL);
|
||||||
for (i = 0; i < NUMTHREADS; i++) {
|
for (i = 0; i < NUMTHREADS; i++) {
|
||||||
char name[64];
|
char name[64];
|
||||||
|
|
Loading…
Reference in New Issue