Skip to content

Commit d3ca061

Browse files
authored
Restructure thread implementations (#731)
This PR restructures the current two `pthreads` implementations into parallel directories to prepare for a third implementation for `wasip3`. - Move the single-threaded stubbed implementation from `wasi-libc/thread-stub` to `wasi-libc/libc-top-half/musl/src/thread/single-threaded` - Move the `wasi-threads` implementation from `wasi-libc/libc-top-half/musl/src/thread` to `wasi-libc/libc-top-half/musl/src/thread/wasi-threads` - Move common files into `wasi-libc/libc-top-half/musl/src/thread/common` - Delete the unused architecture subfolders from `wasi-libc/libc-top-half/musl/src/thread` The implementation for wasip3 will live in `wasi-libc/libc-top-half/musl/src/thread/coop-threads`, which will be created and populated in future PRs.
1 parent 5692cf1 commit d3ca061

238 files changed

Lines changed: 119 additions & 2095 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

libc-top-half/CMakeLists.txt

Lines changed: 113 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -224,49 +224,49 @@ set(top_half_sources
224224
musl/src/network/ntohl.c
225225
musl/src/network/ntohs.c
226226
musl/src/stat/futimesat.c
227-
musl/src/thread/default_attr.c
228-
musl/src/thread/pthread_attr_destroy.c
229-
musl/src/thread/pthread_attr_get.c
230-
musl/src/thread/pthread_attr_init.c
231-
musl/src/thread/pthread_attr_setdetachstate.c
232-
musl/src/thread/pthread_attr_setguardsize.c
233-
musl/src/thread/pthread_attr_setschedparam.c
234-
musl/src/thread/pthread_attr_setstack.c
235-
musl/src/thread/pthread_attr_setstacksize.c
236-
musl/src/thread/pthread_barrierattr_destroy.c
237-
musl/src/thread/pthread_barrierattr_init.c
238-
musl/src/thread/pthread_barrierattr_setpshared.c
239-
musl/src/thread/pthread_cancel.c
240-
musl/src/thread/pthread_cleanup_push.c
241-
musl/src/thread/pthread_condattr_destroy.c
242-
musl/src/thread/pthread_condattr_init.c
243-
musl/src/thread/pthread_condattr_setclock.c
244-
musl/src/thread/pthread_condattr_setpshared.c
245-
musl/src/thread/pthread_equal.c
246-
musl/src/thread/pthread_getattr_np.c
247-
musl/src/thread/pthread_getspecific.c
248-
musl/src/thread/pthread_key_create.c
249-
musl/src/thread/pthread_mutex_destroy.c
250-
musl/src/thread/pthread_mutex_init.c
251-
musl/src/thread/pthread_mutexattr_destroy.c
252-
musl/src/thread/pthread_mutexattr_init.c
253-
musl/src/thread/pthread_mutexattr_setprotocol.c
254-
musl/src/thread/pthread_mutexattr_setpshared.c
255-
musl/src/thread/pthread_mutexattr_setrobust.c
256-
musl/src/thread/pthread_mutexattr_settype.c
257-
musl/src/thread/pthread_rwlock_destroy.c
258-
musl/src/thread/pthread_rwlock_init.c
259-
musl/src/thread/pthread_rwlockattr_destroy.c
260-
musl/src/thread/pthread_rwlockattr_init.c
261-
musl/src/thread/pthread_rwlockattr_setpshared.c
262-
musl/src/thread/pthread_self.c
263-
musl/src/thread/pthread_setcancelstate.c
264-
musl/src/thread/pthread_setcanceltype.c
265-
musl/src/thread/pthread_setspecific.c
266-
musl/src/thread/pthread_spin_destroy.c
267-
musl/src/thread/pthread_spin_init.c
268-
musl/src/thread/pthread_testcancel.c
269-
musl/src/thread/thrd_sleep.c
227+
musl/src/thread/common/default_attr.c
228+
musl/src/thread/common/pthread_attr_destroy.c
229+
musl/src/thread/common/pthread_attr_get.c
230+
musl/src/thread/common/pthread_attr_init.c
231+
musl/src/thread/common/pthread_attr_setdetachstate.c
232+
musl/src/thread/common/pthread_attr_setguardsize.c
233+
musl/src/thread/common/pthread_attr_setschedparam.c
234+
musl/src/thread/common/pthread_attr_setstack.c
235+
musl/src/thread/common/pthread_attr_setstacksize.c
236+
musl/src/thread/common/pthread_barrierattr_destroy.c
237+
musl/src/thread/common/pthread_barrierattr_init.c
238+
musl/src/thread/common/pthread_barrierattr_setpshared.c
239+
musl/src/thread/common/pthread_cancel.c
240+
musl/src/thread/common/pthread_cleanup_push.c
241+
musl/src/thread/common/pthread_condattr_destroy.c
242+
musl/src/thread/common/pthread_condattr_init.c
243+
musl/src/thread/common/pthread_condattr_setclock.c
244+
musl/src/thread/common/pthread_condattr_setpshared.c
245+
musl/src/thread/common/pthread_equal.c
246+
musl/src/thread/common/pthread_getattr_np.c
247+
musl/src/thread/common/pthread_getspecific.c
248+
musl/src/thread/common/pthread_key_create.c
249+
musl/src/thread/common/pthread_mutex_destroy.c
250+
musl/src/thread/common/pthread_mutex_init.c
251+
musl/src/thread/common/pthread_mutexattr_destroy.c
252+
musl/src/thread/common/pthread_mutexattr_init.c
253+
musl/src/thread/common/pthread_mutexattr_setprotocol.c
254+
musl/src/thread/common/pthread_mutexattr_setpshared.c
255+
musl/src/thread/common/pthread_mutexattr_setrobust.c
256+
musl/src/thread/common/pthread_mutexattr_settype.c
257+
musl/src/thread/common/pthread_rwlock_destroy.c
258+
musl/src/thread/common/pthread_rwlock_init.c
259+
musl/src/thread/common/pthread_rwlockattr_destroy.c
260+
musl/src/thread/common/pthread_rwlockattr_init.c
261+
musl/src/thread/common/pthread_rwlockattr_setpshared.c
262+
musl/src/thread/common/pthread_self.c
263+
musl/src/thread/common/pthread_setcancelstate.c
264+
musl/src/thread/common/pthread_setcanceltype.c
265+
musl/src/thread/common/pthread_setspecific.c
266+
musl/src/thread/common/pthread_spin_destroy.c
267+
musl/src/thread/common/pthread_spin_init.c
268+
musl/src/thread/common/pthread_testcancel.c
269+
musl/src/thread/common/thrd_sleep.c
270270
musl/src/time/__month_to_secs.c
271271
musl/src/time/__secs_to_tm.c
272272
musl/src/time/__tm_to_secs.c
@@ -396,80 +396,80 @@ if (THREADS)
396396
musl/src/stdio/flockfile.c
397397
musl/src/stdio/ftrylockfile.c
398398
musl/src/stdio/funlockfile.c
399-
musl/src/thread/__lock.c
400-
musl/src/thread/__wait.c
401-
musl/src/thread/__timedwait.c
402-
musl/src/thread/pthread_barrier_destroy.c
403-
musl/src/thread/pthread_barrier_init.c
404-
musl/src/thread/pthread_barrier_wait.c
405-
musl/src/thread/pthread_cond_broadcast.c
406-
musl/src/thread/pthread_cond_destroy.c
407-
musl/src/thread/pthread_cond_init.c
408-
musl/src/thread/pthread_cond_signal.c
409-
musl/src/thread/pthread_cond_timedwait.c
410-
musl/src/thread/pthread_cond_wait.c
411-
musl/src/thread/pthread_create.c
412-
musl/src/thread/pthread_detach.c
413-
musl/src/thread/pthread_join.c
414-
musl/src/thread/pthread_mutex_consistent.c
415-
musl/src/thread/pthread_mutex_getprioceiling.c
416-
musl/src/thread/pthread_mutex_lock.c
417-
musl/src/thread/pthread_mutex_timedlock.c
418-
musl/src/thread/pthread_mutex_trylock.c
419-
musl/src/thread/pthread_mutex_unlock.c
420-
musl/src/thread/pthread_once.c
421-
musl/src/thread/pthread_rwlock_rdlock.c
422-
musl/src/thread/pthread_rwlock_timedrdlock.c
423-
musl/src/thread/pthread_rwlock_timedwrlock.c
424-
musl/src/thread/pthread_rwlock_tryrdlock.c
425-
musl/src/thread/pthread_rwlock_trywrlock.c
426-
musl/src/thread/pthread_rwlock_unlock.c
427-
musl/src/thread/pthread_rwlock_wrlock.c
428-
musl/src/thread/pthread_spin_lock.c
429-
musl/src/thread/pthread_spin_trylock.c
430-
musl/src/thread/pthread_spin_unlock.c
431-
musl/src/thread/sem_destroy.c
432-
musl/src/thread/sem_getvalue.c
433-
musl/src/thread/sem_init.c
434-
musl/src/thread/sem_post.c
435-
musl/src/thread/sem_timedwait.c
436-
musl/src/thread/sem_trywait.c
437-
musl/src/thread/sem_wait.c
438-
musl/src/thread/wasm32/wasi_thread_start.s
439-
musl/src/thread/wasm32/__wasilibc_busywait.c
399+
musl/src/thread/wasi-threads/__lock.c
400+
musl/src/thread/wasi-threads/__wait.c
401+
musl/src/thread/wasi-threads/__timedwait.c
402+
musl/src/thread/wasi-threads/pthread_barrier_destroy.c
403+
musl/src/thread/wasi-threads/pthread_barrier_init.c
404+
musl/src/thread/wasi-threads/pthread_barrier_wait.c
405+
musl/src/thread/wasi-threads/pthread_cond_broadcast.c
406+
musl/src/thread/wasi-threads/pthread_cond_destroy.c
407+
musl/src/thread/wasi-threads/pthread_cond_init.c
408+
musl/src/thread/wasi-threads/pthread_cond_signal.c
409+
musl/src/thread/wasi-threads/pthread_cond_timedwait.c
410+
musl/src/thread/wasi-threads/pthread_cond_wait.c
411+
musl/src/thread/wasi-threads/pthread_create.c
412+
musl/src/thread/wasi-threads/pthread_detach.c
413+
musl/src/thread/wasi-threads/pthread_join.c
414+
musl/src/thread/wasi-threads/pthread_mutex_consistent.c
415+
musl/src/thread/wasi-threads/pthread_mutex_getprioceiling.c
416+
musl/src/thread/wasi-threads/pthread_mutex_lock.c
417+
musl/src/thread/wasi-threads/pthread_mutex_timedlock.c
418+
musl/src/thread/wasi-threads/pthread_mutex_trylock.c
419+
musl/src/thread/wasi-threads/pthread_mutex_unlock.c
420+
musl/src/thread/wasi-threads/pthread_once.c
421+
musl/src/thread/wasi-threads/pthread_rwlock_rdlock.c
422+
musl/src/thread/wasi-threads/pthread_rwlock_timedrdlock.c
423+
musl/src/thread/wasi-threads/pthread_rwlock_timedwrlock.c
424+
musl/src/thread/wasi-threads/pthread_rwlock_tryrdlock.c
425+
musl/src/thread/wasi-threads/pthread_rwlock_trywrlock.c
426+
musl/src/thread/wasi-threads/pthread_rwlock_unlock.c
427+
musl/src/thread/wasi-threads/pthread_rwlock_wrlock.c
428+
musl/src/thread/wasi-threads/pthread_spin_lock.c
429+
musl/src/thread/wasi-threads/pthread_spin_trylock.c
430+
musl/src/thread/wasi-threads/pthread_spin_unlock.c
431+
musl/src/thread/wasi-threads/sem_destroy.c
432+
musl/src/thread/wasi-threads/sem_getvalue.c
433+
musl/src/thread/wasi-threads/sem_init.c
434+
musl/src/thread/wasi-threads/sem_post.c
435+
musl/src/thread/wasi-threads/sem_timedwait.c
436+
musl/src/thread/wasi-threads/sem_trywait.c
437+
musl/src/thread/wasi-threads/sem_wait.c
438+
musl/src/thread/wasi-threads/wasi_thread_start.s
439+
musl/src/thread/wasi-threads/__wasilibc_busywait.c
440440
)
441441
else()
442442
# pthreads stubs for single-threaded environment
443443
list(APPEND top_half_sources
444-
../thread-stub/pthread_barrier_destroy.c
445-
../thread-stub/pthread_barrier_init.c
446-
../thread-stub/pthread_barrier_wait.c
447-
../thread-stub/pthread_cond_broadcast.c
448-
../thread-stub/pthread_cond_destroy.c
449-
../thread-stub/pthread_cond_init.c
450-
../thread-stub/pthread_cond_signal.c
451-
../thread-stub/pthread_cond_timedwait.c
452-
../thread-stub/pthread_cond_wait.c
453-
../thread-stub/pthread_create.c
454-
../thread-stub/pthread_detach.c
455-
../thread-stub/pthread_join.c
456-
../thread-stub/pthread_mutex_consistent.c
457-
../thread-stub/pthread_mutex_getprioceiling.c
458-
../thread-stub/pthread_mutex_lock.c
459-
../thread-stub/pthread_mutex_timedlock.c
460-
../thread-stub/pthread_mutex_trylock.c
461-
../thread-stub/pthread_mutex_unlock.c
462-
../thread-stub/pthread_once.c
463-
../thread-stub/pthread_rwlock_rdlock.c
464-
../thread-stub/pthread_rwlock_timedrdlock.c
465-
../thread-stub/pthread_rwlock_timedwrlock.c
466-
../thread-stub/pthread_rwlock_tryrdlock.c
467-
../thread-stub/pthread_rwlock_trywrlock.c
468-
../thread-stub/pthread_rwlock_unlock.c
469-
../thread-stub/pthread_rwlock_wrlock.c
470-
../thread-stub/pthread_spin_lock.c
471-
../thread-stub/pthread_spin_trylock.c
472-
../thread-stub/pthread_spin_unlock.c
444+
musl/src/thread/single-threaded/pthread_barrier_destroy.c
445+
musl/src/thread/single-threaded/pthread_barrier_init.c
446+
musl/src/thread/single-threaded/pthread_barrier_wait.c
447+
musl/src/thread/single-threaded/pthread_cond_broadcast.c
448+
musl/src/thread/single-threaded/pthread_cond_destroy.c
449+
musl/src/thread/single-threaded/pthread_cond_init.c
450+
musl/src/thread/single-threaded/pthread_cond_signal.c
451+
musl/src/thread/single-threaded/pthread_cond_timedwait.c
452+
musl/src/thread/single-threaded/pthread_cond_wait.c
453+
musl/src/thread/single-threaded/pthread_create.c
454+
musl/src/thread/single-threaded/pthread_detach.c
455+
musl/src/thread/single-threaded/pthread_join.c
456+
musl/src/thread/single-threaded/pthread_mutex_consistent.c
457+
musl/src/thread/single-threaded/pthread_mutex_getprioceiling.c
458+
musl/src/thread/single-threaded/pthread_mutex_lock.c
459+
musl/src/thread/single-threaded/pthread_mutex_timedlock.c
460+
musl/src/thread/single-threaded/pthread_mutex_trylock.c
461+
musl/src/thread/single-threaded/pthread_mutex_unlock.c
462+
musl/src/thread/single-threaded/pthread_once.c
463+
musl/src/thread/single-threaded/pthread_rwlock_rdlock.c
464+
musl/src/thread/single-threaded/pthread_rwlock_timedrdlock.c
465+
musl/src/thread/single-threaded/pthread_rwlock_timedwrlock.c
466+
musl/src/thread/single-threaded/pthread_rwlock_tryrdlock.c
467+
musl/src/thread/single-threaded/pthread_rwlock_trywrlock.c
468+
musl/src/thread/single-threaded/pthread_rwlock_unlock.c
469+
musl/src/thread/single-threaded/pthread_rwlock_wrlock.c
470+
musl/src/thread/single-threaded/pthread_spin_lock.c
471+
musl/src/thread/single-threaded/pthread_spin_trylock.c
472+
musl/src/thread/single-threaded/pthread_spin_unlock.c
473473
)
474474
endif()
475475

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# pthreads
2+
3+
This directory contains two implementations of the `pthreads` library:
4+
5+
- `wasi-threads` - based on the original musl implementation, used for the `wasm32-wasip1-threads` target; see [`wasi-threads`](https://github.com/WebAssembly/wasi-threads) for details
6+
- `single-threaded` - used for single-threaded WASIP1 and WASIP2 targets; is never able to spawn new threads, but otherwise follows the letter of the specification

libc-top-half/musl/src/thread/aarch64/__set_thread_area.s

Lines changed: 0 additions & 7 deletions
This file was deleted.

libc-top-half/musl/src/thread/aarch64/__unmapself.s

Lines changed: 0 additions & 7 deletions
This file was deleted.

libc-top-half/musl/src/thread/aarch64/clone.s

Lines changed: 0 additions & 30 deletions
This file was deleted.

libc-top-half/musl/src/thread/aarch64/syscall_cp.s

Lines changed: 0 additions & 32 deletions
This file was deleted.

libc-top-half/musl/src/thread/arm/__aeabi_read_tp.s

Lines changed: 0 additions & 10 deletions
This file was deleted.

libc-top-half/musl/src/thread/arm/__set_thread_area.c

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)