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