Skip to content

Commit 0aa7a98

Browse files
authored
threads: enable access to pthread_attr_get functions (#357)
The pthreads API exposes functions for querying the attributes of a thread. This change allows these functions to be compiled in the `THREAD_MODEL=posix` build. Some functions are skipped (and documented); they can be added if/when needed. This change is motivated by a `libc-test` test that uses these functions.
1 parent 7250bd4 commit 0aa7a98

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
200200
thread/__timedwait.c \
201201
thread/default_attr.c \
202202
thread/pthread_attr_destroy.c \
203+
thread/pthread_attr_get.c \
203204
thread/pthread_attr_init.c \
204205
thread/pthread_attr_setstack.c \
205206
thread/pthread_attr_setstacksize.c \

expected/wasm32-wasi/posix/defined-symbols.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,16 +972,24 @@ program_invocation_short_name
972972
pselect
973973
psignal
974974
pthread_attr_destroy
975+
pthread_attr_getdetachstate
976+
pthread_attr_getguardsize
977+
pthread_attr_getinheritsched
978+
pthread_attr_getscope
979+
pthread_attr_getstack
980+
pthread_attr_getstacksize
975981
pthread_attr_init
976982
pthread_attr_setstack
977983
pthread_attr_setstacksize
984+
pthread_barrierattr_getpshared
978985
pthread_cond_broadcast
979986
pthread_cond_destroy
980987
pthread_cond_init
981988
pthread_cond_signal
982989
pthread_cond_timedwait
983990
pthread_cond_wait
984991
pthread_condattr_destroy
992+
pthread_condattr_getpshared
985993
pthread_condattr_init
986994
pthread_condattr_setclock
987995
pthread_condattr_setpshared
@@ -1000,6 +1008,10 @@ pthread_mutex_timedlock
10001008
pthread_mutex_trylock
10011009
pthread_mutex_unlock
10021010
pthread_mutexattr_destroy
1011+
pthread_mutexattr_getprotocol
1012+
pthread_mutexattr_getpshared
1013+
pthread_mutexattr_getrobust
1014+
pthread_mutexattr_gettype
10031015
pthread_mutexattr_init
10041016
pthread_mutexattr_setprotocol
10051017
pthread_mutexattr_setpshared
@@ -1016,6 +1028,7 @@ pthread_rwlock_trywrlock
10161028
pthread_rwlock_unlock
10171029
pthread_rwlock_wrlock
10181030
pthread_rwlockattr_destroy
1031+
pthread_rwlockattr_getpshared
10191032
pthread_rwlockattr_init
10201033
pthread_rwlockattr_setpshared
10211034
pthread_self

libc-top-half/musl/src/thread/pthread_attr_get.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ int pthread_attr_getinheritsched(const pthread_attr_t *restrict a, int *restrict
1717
return 0;
1818
}
1919

20+
#ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */
2021
int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param)
2122
{
2223
param->sched_priority = a->_a_prio;
@@ -28,6 +29,7 @@ int pthread_attr_getschedpolicy(const pthread_attr_t *restrict a, int *restrict
2829
*policy = a->_a_policy;
2930
return 0;
3031
}
32+
#endif
3133

3234
int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope)
3335
{
@@ -56,11 +58,13 @@ int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int
5658
return 0;
5759
}
5860

61+
#ifdef __wasilibc_unmodified_upstream /* Forward declaration of WASI's `__clockid` type. */
5962
int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk)
6063
{
6164
*clk = a->__attr & 0x7fffffff;
6265
return 0;
6366
}
67+
#endif
6468

6569
int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared)
6670
{

0 commit comments

Comments
 (0)