Skip to content

Commit 3d00b96

Browse files
authored
threads: implement support for pthread_condattr (#320)
1 parent 2057ce9 commit 3d00b96

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
192192
$(addprefix $(LIBC_TOP_HALF_MUSL_SRC_DIR)/, \
193193
thread/__wait.c \
194194
thread/__timedwait.c \
195+
thread/pthread_condattr_destroy.c \
196+
thread/pthread_condattr_init.c \
197+
thread/pthread_condattr_setclock.c \
198+
thread/pthread_condattr_setpshared.c \
195199
thread/pthread_cleanup_push.c \
196200
thread/pthread_mutex_consistent.c \
197201
thread/pthread_mutex_destroy.c \
@@ -264,6 +268,9 @@ ifeq ($(THREAD_MODEL), posix)
264268
# Specify the tls-model until LLVM 15 is released (which should contain
265269
# https://reviews.llvm.org/D130053).
266270
CFLAGS += -mthread-model posix -pthread -ftls-model=local-exec
271+
272+
# Include cloudlib's directory to access the structure definition of clockid_t
273+
CFLAGS += -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)
267274
endif
268275

269276
# Expose the public headers to the implementation. We use `-isystem` for

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,10 @@ program_invocation_name
930930
program_invocation_short_name
931931
pselect
932932
psignal
933+
pthread_condattr_destroy
934+
pthread_condattr_init
935+
pthread_condattr_setclock
936+
pthread_condattr_setpshared
933937
pthread_mutex_consistent
934938
pthread_mutex_destroy
935939
pthread_mutex_getprioceiling
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
#include "pthread_impl.h"
22

3+
#ifndef __wasilibc_unmodified_upstream
4+
#include <common/clock.h>
5+
#endif
6+
37
int pthread_condattr_setclock(pthread_condattr_t *a, clockid_t clk)
48
{
9+
#ifdef __wasilibc_unmodified_upstream
510
if (clk < 0 || clk-2U < 2) return EINVAL;
11+
#else
12+
if (clk->id < 0 || clk->id-2U < 2) return EINVAL;
13+
#endif
614
a->__attr &= 0x80000000;
15+
#ifdef __wasilibc_unmodified_upstream
716
a->__attr |= clk;
17+
#else
18+
a->__attr |= clk->id;
19+
#endif
820
return 0;
921
}

0 commit comments

Comments
 (0)