| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef _GX_PTHREAD_WRAP_GX_ |
| 18 |
#define _GX_PTHREAD_WRAP_GX_ |
| 19 |
|
| 20 |
#include <ogcsys.h> |
| 21 |
#include <gccore.h> |
| 22 |
#include <ogc/cond.h> |
| 23 |
|
| 24 |
#ifndef OSThread |
| 25 |
#define OSThread lwp_t |
| 26 |
#endif |
| 27 |
|
| 28 |
#ifndef OSCond |
| 29 |
#define OSCond lwpq_t |
| 30 |
#endif |
| 31 |
|
| 32 |
#ifndef OSThreadQueue |
| 33 |
#define OSThreadQueue lwpq_t |
| 34 |
#endif |
| 35 |
|
| 36 |
#ifndef OSInitMutex |
| 37 |
#define OSInitMutex(mutex) LWP_MutexInit(mutex, 0) |
| 38 |
#endif |
| 39 |
|
| 40 |
#ifndef OSLockMutex |
| 41 |
#define OSLockMutex(mutex) LWP_MutexLock(mutex) |
| 42 |
#endif |
| 43 |
|
| 44 |
#ifndef OSUnlockMutex |
| 45 |
#define OSUnlockMutex(mutex) LWP_MutexUnlock(mutex) |
| 46 |
#endif |
| 47 |
|
| 48 |
#ifndef OSTryLockMutex |
| 49 |
#define OSTryLockMutex(mutex) LWP_MutexTryLock(mutex) |
| 50 |
#endif |
| 51 |
|
| 52 |
#ifndef OSInitCond |
| 53 |
#define OSInitCond(cond) LWP_CondInit(cond) |
| 54 |
#endif |
| 55 |
|
| 56 |
#ifndef OSSignalCond |
| 57 |
#define OSSignalCond(cond) LWP_ThreadSignal(cond) |
| 58 |
#endif |
| 59 |
|
| 60 |
#ifndef OSWaitCond |
| 61 |
#define OSWaitCond(cond, mutex) LWP_CondWait(cond, mutex) |
| 62 |
#endif |
| 63 |
|
| 64 |
#ifndef OSInitThreadQueue |
| 65 |
#define OSInitThreadQueue(queue) LWP_InitQueue(queue) |
| 66 |
#endif |
| 67 |
|
| 68 |
#ifndef OSSleepThread |
| 69 |
#define OSSleepThread(queue) LWP_ThreadSleep(queue) |
| 70 |
#endif |
| 71 |
|
| 72 |
#ifndef OSJoinThread |
| 73 |
#define OSJoinThread(thread, val) LWP_JoinThread(thread, val) |
| 74 |
#endif |
| 75 |
|
| 76 |
#ifndef OSCreateThread |
| 77 |
#define OSCreateThread(thread, func, intarg, ptrarg, stackbase, stacksize, priority, attrs) LWP_CreateThread(thread, func, ptrarg, stackbase, stacksize, priority) |
| 78 |
#endif |
| 79 |
|
| 80 |
#define STACKSIZE (8 * 1024) |
| 81 |
|
| 82 |
typedef OSThread pthread_t; |
| 83 |
typedef mutex_t pthread_mutex_t; |
| 84 |
typedef void* pthread_mutexattr_t; |
| 85 |
typedef int pthread_attr_t; |
| 86 |
typedef cond_t pthread_cond_t; |
| 87 |
typedef cond_t pthread_condattr_t; |
| 88 |
|
| 89 |
static inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg) |
| 90 |
{ |
| 91 |
*thread = 0; |
| 92 |
return OSCreateThread(thread, start_routine, 0 , arg, 0, STACKSIZE, 64, 0 ); |
| 93 |
} |
| 94 |
|
| 95 |
static inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) |
| 96 |
{ |
| 97 |
return OSInitMutex(mutex); |
| 98 |
} |
| 99 |
|
| 100 |
static inline int pthread_mutex_destroy(pthread_mutex_t *mutex) |
| 101 |
{ |
| 102 |
return LWP_MutexDestroy(*mutex); |
| 103 |
} |
| 104 |
|
| 105 |
static inline int pthread_mutex_lock(pthread_mutex_t *mutex) |
| 106 |
{ |
| 107 |
return OSLockMutex(*mutex); |
| 108 |
} |
| 109 |
|
| 110 |
static inline int pthread_mutex_unlock(pthread_mutex_t *mutex) |
| 111 |
{ |
| 112 |
return OSUnlockMutex(*mutex); |
| 113 |
} |
| 114 |
|
| 115 |
static inline void pthread_exit(void *retval) |
| 116 |
{ |
| 117 |
|
| 118 |
(void)retval; |
| 119 |
} |
| 120 |
|
| 121 |
static inline int pthread_detach(pthread_t thread) |
| 122 |
{ |
| 123 |
|
| 124 |
(void)thread; |
| 125 |
return 0; |
| 126 |
} |
| 127 |
|
| 128 |
static inline int pthread_join(pthread_t thread, void **retval) |
| 129 |
{ |
| 130 |
return OSJoinThread(thread, retval); |
| 131 |
} |
| 132 |
|
| 133 |
static inline int pthread_mutex_trylock(pthread_mutex_t *mutex) |
| 134 |
{ |
| 135 |
return OSTryLockMutex(*mutex); |
| 136 |
} |
| 137 |
|
| 138 |
static inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) |
| 139 |
{ |
| 140 |
return OSWaitCond(*cond, *mutex); |
| 141 |
} |
| 142 |
|
| 143 |
static inline int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) |
| 144 |
{ |
| 145 |
return LWP_CondTimedWait(*cond, *mutex, abstime); |
| 146 |
} |
| 147 |
|
| 148 |
static inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) |
| 149 |
{ |
| 150 |
return OSInitCond(cond); |
| 151 |
} |
| 152 |
|
| 153 |
static inline int pthread_cond_signal(pthread_cond_t *cond) |
| 154 |
{ |
| 155 |
return LWP_CondSignal(*cond); |
| 156 |
} |
| 157 |
|
| 158 |
static inline int pthread_cond_broadcast(pthread_cond_t *cond) |
| 159 |
{ |
| 160 |
return LWP_CondBroadcast(*cond); |
| 161 |
} |
| 162 |
|
| 163 |
static inline int pthread_cond_destroy(pthread_cond_t *cond) |
| 164 |
{ |
| 165 |
return LWP_CondDestroy(*cond); |
| 166 |
} |
| 167 |
|
| 168 |
#endif |