@@ -156,6 +156,84 @@ void __SYSCALL(exit)(int rc) {
156156 __ctru_exit (rc );
157157}
158158
159+ int __SYSCALL (cond_signal )(_COND_T * cond )
160+ {
161+ CondVar_Signal ((CondVar * )cond );
162+ return 0 ;
163+ }
164+
165+ int __SYSCALL (cond_broadcast )(_COND_T * cond )
166+ {
167+ CondVar_Broadcast ((CondVar * )cond );
168+ return 0 ;
169+ }
170+
171+ int __SYSCALL (cond_wait )(_COND_T * cond , _LOCK_T * lock , uint64_t timeout_ns )
172+ {
173+ return CondVar_WaitTimeout ((CondVar * )cond , lock , timeout_ns ) ? ETIMEDOUT : 0 ;
174+ }
175+
176+ int __SYSCALL (cond_wait_recursive )(_COND_T * cond , _LOCK_RECURSIVE_T * lock , uint64_t timeout_ns )
177+ {
178+ uint32_t thread_tag_backup = 0 ;
179+ if (lock -> counter != 1 )
180+ return EBADF ;
181+
182+ thread_tag_backup = lock -> thread_tag ;
183+ lock -> thread_tag = 0 ;
184+ lock -> counter = 0 ;
185+
186+ int err = CondVar_WaitTimeout ((CondVar * )cond , & lock -> lock , timeout_ns );
187+
188+ lock -> thread_tag = thread_tag_backup ;
189+ lock -> counter = 1 ;
190+
191+ return err ? ETIMEDOUT : 0 ;
192+ }
193+
194+ int __SYSCALL (thread_create )(struct __pthread_t * * thread , void * (* func )(void * ), void * arg , void * stack_addr , size_t stack_size )
195+ {
196+ if (stack_addr ) {
197+ return EINVAL ;
198+ }
199+
200+ if (!stack_size ) {
201+ stack_size = 32 * 1024 ;
202+ }
203+
204+ Thread t = threadCreate ((ThreadFunc )func , arg , stack_size , 0x3F , 0 , false);
205+ if (t ) {
206+ * thread = (struct __pthread_t * )t ;
207+ return 0 ;
208+ }
209+
210+ return ENOMEM ;
211+ }
212+
213+ void * __SYSCALL (thread_join )(struct __pthread_t * thread )
214+ {
215+ threadJoin ((Thread )thread , U64_MAX );
216+ void * rc = (void * )threadGetExitCode ((Thread )thread );
217+ threadFree ((Thread )thread );
218+ return rc ;
219+ }
220+
221+ int __SYSCALL (thread_detach )(struct __pthread_t * thread )
222+ {
223+ threadDetach ((Thread )thread );
224+ return 0 ;
225+ }
226+
227+ void __SYSCALL (thread_exit )(void * value )
228+ {
229+ threadExit ((int )value );
230+ }
231+
232+ struct __pthread_t * __SYSCALL (thread_self )(void )
233+ {
234+ return (struct __pthread_t * )threadGetCurrent ();
235+ }
236+
159237void initThreadVars (struct Thread_tag * thread )
160238{
161239 ThreadVars * tv = getThreadVars ();
0 commit comments