Debian Codegraph @

thread/gx_pthread.h

raw symbols SCIP
1 /* RetroArch - A frontend for libretro.
2 * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
3 * Copyright (C) 2011-2014 - Daniel De Matteis
4 *
5 * RetroArch is free software: you can redistribute it and/or modify it under the terms
6 * of the GNU General Public License as published by the Free Software Found-
7 * ation, either version 3 of the License, or (at your option) any later version.
8 *
9 * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with RetroArch.
14 * If not, see <http://www.gnu.org/licenses/>.
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 /* unused */, arg, 0, STACKSIZE, 64, 0 /* unused */);
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 /* FIXME: No LWP equivalent for this? */
118 (void)retval;
119 }
120
121 static inline int pthread_detach(pthread_t thread)
122 {
123 /* FIXME: pthread_detach equivalent missing? */
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