Fix compiling with ndk r11 >
[pcsx_rearmed.git] / frontend / 3ds / pthread.h
CommitLineData
fc99395c 1
2#ifndef _3DS_PTHREAD_WRAP__
3#define _3DS_PTHREAD_WRAP__
4
f72db18e 5#include <stdlib.h>
6#include <string.h>
7#include <stdio.h>
fc99395c 8
f72db18e 9#include "3ds_utils.h"
fc99395c 10
11#define CTR_PTHREAD_STACK_SIZE 0x10000
12
13typedef struct
14{
f72db18e 15 int32_t handle;
16 uint32_t* stack;
fc99395c 17}pthread_t;
18typedef int pthread_attr_t;
19
fc99395c 20static 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
f72db18e 26 svcCreateThread(&thread->handle, start_routine, arg,
27 (uint32_t*)((uint32_t)thread->stack + CTR_PTHREAD_STACK_SIZE),
fc99395c 28 0x25, 1);
29
30 return 1;
31}
32
33
34static 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
47static inline void pthread_exit(void *retval)
48{
49 (void)retval;
50
fc99395c 51 svcExitThread();
52}
53
fc99395c 54
55#endif //_3DS_PTHREAD_WRAP__
56