[LIBNX] Improve Threading, Fix Video Threaded. Scan content no longer crashes.

This commit is contained in:
M4xw 2018-09-28 03:24:12 +02:00
parent 26eca6bbd6
commit ef736d02c2

View File

@ -57,36 +57,24 @@ static INLINE ThreadVars *getThreadVars(void)
return (ThreadVars *)((u8 *)armGetTls() + 0x1E0); return (ThreadVars *)((u8 *)armGetTls() + 0x1E0);
} }
#define STACKSIZE (8 * 1024) #define STACKSIZE (128 * 1024)
/* libnx threads return void but pthreads return void pointer */
static uint32_t threadCounter = 1; static uint32_t threadCounter = 1;
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
{ {
u32 prio = 0; u32 prio = 0;
u64 core_mask = 0;
Thread new_switch_thread; Thread new_switch_thread;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE); svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
svcGetInfo(&core_mask, 0, CUR_PROCESS_HANDLE, 0);
// Launch threads on Core 1 // Launch threads on Core 1
int rc = threadCreate(&new_switch_thread, (void (*)(void *))start_routine, arg, STACKSIZE, prio - 1, -2); int rc = threadCreate(&new_switch_thread, (void (*)(void *))start_routine, arg, STACKSIZE, prio - 1, 1);
if (R_FAILED(rc)) if (R_FAILED(rc))
{ {
return EAGAIN; return EAGAIN;
} }
rc = svcSetThreadCoreMask(new_switch_thread.handle, -1, core_mask);
if (R_FAILED(rc))
{
return -1;
}
printf("[Threading]: Starting Thread(#%i)\n", threadCounter); printf("[Threading]: Starting Thread(#%i)\n", threadCounter);
if (R_FAILED(threadStart(&new_switch_thread))) if (R_FAILED(threadStart(&new_switch_thread)))
{ {