Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions workspace/all/common/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3858,6 +3858,22 @@ int PAD_tappedSelect(uint32_t now)
return PAD_tappedBtn(BTN_SELECT, now);
}

///////////////////////////////

// the RLIMIT_STACK default (8MB per thread) wastes address space
// workaround for libretro/gpsp#248 and NextUI#814
#define THREAD_STACK_SIZE (1024 * 1024)

static int spawn_thread(pthread_t *pt, void *(*fn)(void *), void *arg)
{
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE);
int rc = pthread_create(pt, &attr, fn, arg);
pthread_attr_destroy(&attr);
return rc;
}

///////////////////////////////
static struct VIB_Context
{
Expand Down Expand Up @@ -3891,7 +3907,7 @@ static void *VIB_thread(void *arg)
void VIB_init(void)
{
vib.queued_strength = vib.strength = 0;
pthread_create(&vib.pt, NULL, &VIB_thread, NULL);
spawn_thread(&vib.pt, &VIB_thread, NULL);
vib.initialized = 1;
}
void VIB_quit(void)
Expand Down Expand Up @@ -4026,7 +4042,7 @@ void PWR_init(void)

PWR_updateBatteryStatus();

pthread_create(&pwr.battery_pt, NULL, &PWR_monitorBattery, &pwr);
spawn_thread(&pwr.battery_pt, &PWR_monitorBattery, &pwr);
LOG_info("PWR_init complete\n");
}
void PWR_quit(void)
Expand Down
11 changes: 11 additions & 0 deletions workspace/all/minarch/minarch.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <stdlib.h>
#include <msettings.h>
#ifdef __GLIBC__
#include <malloc.h>
#endif

#include <SDL2/SDL_image.h>

Expand Down Expand Up @@ -139,6 +142,14 @@ int main(int argc , char* argv[]) {
if(argc < 2)
return EXIT_FAILURE;

// keep malloc arenas and thread stacks out of the address range dynarec cores
// need for their JIT cache (must happen before any thread is created)
// workaround for libretro/gpsp#248 and NextUI#814
#ifdef __GLIBC__
mallopt(M_ARENA_MAX, 2); // glibc extension
#endif
SDL_SetHint(SDL_HINT_THREAD_STACK_SIZE, "1048576");

PWR_setCPUSpeed(CPU_SPEED_PERFORMANCE); // start in performance mode for fast loading
PWR_pinToCores(CPU_CORE_PERFORMANCE); // thread affinity

Expand Down
Loading