(3DS) Set pthread stack size to 12MB - possible solution for crashes
[pcsx_rearmed.git] / frontend / 3ds / pthread.h
index 56d9085..286ea7a 100644 (file)
@@ -2,31 +2,21 @@
 #ifndef _3DS_PTHREAD_WRAP__
 #define _3DS_PTHREAD_WRAP__
 
-#include "3ds.h"
-#include "stdlib.h"
-#include "string.h"
-#include "stdio.h"
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
 
+#include "3ds_utils.h"
 
-#define CTR_PTHREAD_STACK_SIZE 0x10000
+#define CTR_PTHREAD_STACK_SIZE (1000000 * 12)
 
-typedef struct
-{
-   Handle handle;
-   u32* stack;
-}pthread_t;
+typedef int32_t pthread_t;
 typedef int pthread_attr_t;
 
 static inline int pthread_create(pthread_t *thread,
       const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg)
 {
-
-   thread->stack =  linearMemAlign(CTR_PTHREAD_STACK_SIZE, 8);
-
-   svcCreateThread(&thread->handle, (ThreadFunc)start_routine,arg,
-                   (u32*)((u32)thread->stack + CTR_PTHREAD_STACK_SIZE),
-                   0x25, 1);
-
+   thread = threadCreate(start_routine, arg, CTR_PTHREAD_STACK_SIZE, 0x25, -2, FALSE);
    return 1;
 }
 
@@ -35,10 +25,10 @@ static inline int pthread_join(pthread_t thread, void **retval)
 {
    (void)retval;
 
-   if(svcWaitSynchronization(thread.handle, INT64_MAX))
+   if(threadJoin(thread, INT64_MAX))
       return -1;
 
-   linearFree(thread.stack);
+   threadFree(thread);
 
    return 0;
 }
@@ -48,7 +38,7 @@ static inline void pthread_exit(void *retval)
 {   
    (void)retval;
 
-   svcExitThread();
+   threadExit(0);
 }