aboutsummaryrefslogtreecommitdiff
path: root/frontend/3ds/pthread.h
blob: 56d9085212b0a9d4ad32eec0a33cfb9216cc296d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef _3DS_PTHREAD_WRAP__
#define _3DS_PTHREAD_WRAP__

#include "3ds.h"
#include "stdlib.h"
#include "string.h"
#include "stdio.h"


#define CTR_PTHREAD_STACK_SIZE 0x10000

typedef struct
{
   Handle handle;
   u32* stack;
}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);

   return 1;
}


static inline int pthread_join(pthread_t thread, void **retval)
{
   (void)retval;

   if(svcWaitSynchronization(thread.handle, INT64_MAX))
      return -1;

   linearFree(thread.stack);

   return 0;
}


static inline void pthread_exit(void *retval)
{   
   (void)retval;

   svcExitThread();
}


#endif //_3DS_PTHREAD_WRAP__