Merge pull request #195 from jdgleaver/negcon-right-analog
[pcsx_rearmed.git] / frontend / 3ds / pthread.h
1
2 #ifndef _3DS_PTHREAD_WRAP__
3 #define _3DS_PTHREAD_WRAP__
4
5 #include <stdlib.h>
6 #include <string.h>
7 #include <stdio.h>
8
9 #include "3ds_utils.h"
10
11 #define CTR_PTHREAD_STACK_SIZE 0x10000
12
13 typedef struct
14 {
15    int32_t handle;
16    uint32_t* stack;
17 }pthread_t;
18 typedef int pthread_attr_t;
19
20 static inline int pthread_create(pthread_t *thread,
21       const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg)
22 {
23
24    thread->stack =  linearMemAlign(CTR_PTHREAD_STACK_SIZE, 8);
25
26    svcCreateThread(&thread->handle, start_routine, arg,
27                    (uint32_t*)((uint32_t)thread->stack + CTR_PTHREAD_STACK_SIZE),
28                    0x25, 1);
29
30    return 1;
31 }
32
33
34 static inline int pthread_join(pthread_t thread, void **retval)
35 {
36    (void)retval;
37
38    if(svcWaitSynchronization(thread.handle, INT64_MAX))
39       return -1;
40
41    linearFree(thread.stack);
42
43    return 0;
44 }
45
46
47 static inline void pthread_exit(void *retval)
48 {   
49    (void)retval;
50
51    svcExitThread();
52 }
53
54
55 #endif //_3DS_PTHREAD_WRAP__
56