fc99395c |
1 | |
2 | #ifndef _3DS_PTHREAD_WRAP__ |
3 | #define _3DS_PTHREAD_WRAP__ |
4 | |
5 | #include "3ds.h" |
6 | #include "stdlib.h" |
7 | #include "string.h" |
8 | #include "stdio.h" |
9 | |
10 | |
11 | #define CTR_PTHREAD_STACK_SIZE 0x10000 |
12 | |
13 | typedef struct |
14 | { |
15 | Handle handle; |
16 | u32* stack; |
17 | }pthread_t; |
18 | typedef int pthread_attr_t; |
19 | |
fc99395c |
20 | static inline int pthread_create(pthread_t *thread, |
21 | const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg) |
22 | { |
23 | |
fc99395c |
24 | thread->stack = linearMemAlign(CTR_PTHREAD_STACK_SIZE, 8); |
25 | |
26 | svcCreateThread(&thread->handle, (ThreadFunc)start_routine,arg, |
27 | (u32*)((u32)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 | |
fc99395c |
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 | |
fc99395c |
51 | svcExitThread(); |
52 | } |
53 | |
fc99395c |
54 | |
55 | #endif //_3DS_PTHREAD_WRAP__ |
56 | |