]> git.proxmox.com Git - wasi-libc.git/commitdiff
threads: implement support for pthread_condattr (#320)
authorMarcin Kolny <marcin.kolny@gmail.com>
Tue, 6 Sep 2022 17:13:21 +0000 (19:13 +0200)
committerGitHub <noreply@github.com>
Tue, 6 Sep 2022 17:13:21 +0000 (10:13 -0700)
Makefile
expected/wasm32-wasi/posix/defined-symbols.txt
libc-top-half/musl/src/thread/pthread_condattr_setclock.c

index 16da0f88ef455b5df6199ad1d06fc48be11b30f1..542455929fa6935c0ec9531f9f82b982a354bf18 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -192,6 +192,10 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
     $(addprefix $(LIBC_TOP_HALF_MUSL_SRC_DIR)/, \
         thread/__wait.c \
         thread/__timedwait.c \
+        thread/pthread_condattr_destroy.c \
+        thread/pthread_condattr_init.c \
+        thread/pthread_condattr_setclock.c \
+        thread/pthread_condattr_setpshared.c \
         thread/pthread_cleanup_push.c \
         thread/pthread_mutex_consistent.c \
         thread/pthread_mutex_destroy.c \
@@ -264,6 +268,9 @@ ifeq ($(THREAD_MODEL), posix)
 # Specify the tls-model until LLVM 15 is released (which should contain
 # https://reviews.llvm.org/D130053).
 CFLAGS += -mthread-model posix -pthread -ftls-model=local-exec
+
+# Include cloudlib's directory to access the structure definition of clockid_t
+CFLAGS += -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)
 endif
 
 # Expose the public headers to the implementation. We use `-isystem` for
index fe91e4f17d81ae672d06b800d3b53d75588c13fb..6d82e1cf2ef977af43221103b0a585ffa7525a64 100644 (file)
@@ -930,6 +930,10 @@ program_invocation_name
 program_invocation_short_name
 pselect
 psignal
+pthread_condattr_destroy
+pthread_condattr_init
+pthread_condattr_setclock
+pthread_condattr_setpshared
 pthread_mutex_consistent
 pthread_mutex_destroy
 pthread_mutex_getprioceiling
index 71125941341d1392661eccdf6367793d270b0c2a..21ca070c3ecde0e9c3e44cea86fab3096ce6b651 100644 (file)
@@ -1,9 +1,21 @@
 #include "pthread_impl.h"
 
+#ifndef __wasilibc_unmodified_upstream
+#include <common/clock.h>
+#endif
+
 int pthread_condattr_setclock(pthread_condattr_t *a, clockid_t clk)
 {
+#ifdef __wasilibc_unmodified_upstream
        if (clk < 0 || clk-2U < 2) return EINVAL;
+#else
+       if (clk->id < 0 || clk->id-2U < 2) return EINVAL;
+#endif
        a->__attr &= 0x80000000;
+#ifdef __wasilibc_unmodified_upstream
        a->__attr |= clk;
+#else
+       a->__attr |= clk->id;
+#endif
        return 0;
 }