2 #ifndef _3DS_PTHREAD_WRAP__
3 #define _3DS_PTHREAD_WRAP__
11 #define CTR_PTHREAD_STACK_SIZE 0x10000
14 typedef int32_t pthread_t;
15 typedef int pthread_attr_t;
17 typedef LightLock pthread_mutex_t;
18 typedef int pthread_mutexattr_t;
26 typedef int pthread_condattr_t;
28 static inline int pthread_create(pthread_t *thread,
29 const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg)
31 int procnum = -2; // use default cpu
33 APT_CheckNew3DS(&isNew3DS);
38 *thread = threadCreate(start_routine, arg, CTR_PTHREAD_STACK_SIZE, 0x25, procnum, FALSE);
43 static inline int pthread_join(pthread_t thread, void **retval)
47 if(threadJoin(thread, INT64_MAX))
56 static inline void pthread_exit(void *retval)
63 static inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) {
64 LightLock_Init(mutex);
68 static inline int pthread_mutex_lock(pthread_mutex_t *mutex) {
69 LightLock_Lock(mutex);
73 static inline int pthread_mutex_unlock(pthread_mutex_t *mutex) {
74 LightLock_Unlock(mutex);
78 static inline int pthread_mutex_destroy(pthread_mutex_t *mutex) {
82 static inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) {
83 if (svcCreateSemaphore(&cond->semaphore, 0, 1))
86 LightLock_Init(&cond->lock);
91 svcCloseHandle(cond->semaphore);
95 static inline int pthread_cond_signal(pthread_cond_t *cond) {
97 LightLock_Lock(&cond->lock);
100 svcReleaseSemaphore(&count, cond->semaphore, 1);
102 LightLock_Unlock(&cond->lock);
106 static inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *lock) {
107 LightLock_Lock(&cond->lock);
109 LightLock_Unlock(lock);
110 LightLock_Unlock(&cond->lock);
111 svcWaitSynchronization(cond->semaphore, INT64_MAX);
112 LightLock_Lock(lock);
116 static inline int pthread_cond_destroy(pthread_cond_t *cond) {
117 svcCloseHandle(cond->semaphore);
122 #endif //_3DS_PTHREAD_WRAP__