[libc-commits] [libc] [libc][POSIX][pthreads] implement pthread_condattr_t functions (PR #88987)

via libc-commits libc-commits at lists.llvm.org
Tue Apr 16 14:11:02 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

<details>
<summary>Changes</summary>

Implement:
- pthread_condattr_destroy
- pthread_condattr_getclock
- pthread_condattr_getpshared
- pthread_condattr_init
- pthread_condattr_setclock
- pthread_condattr_setpshared

Fixes: #<!-- -->88581


---

Patch is 25.44 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/88987.diff


22 Files Affected:

- (modified) libc/config/linux/api.td (+25-4) 
- (modified) libc/config/linux/x86_64/entrypoints.txt (+6) 
- (modified) libc/include/CMakeLists.txt (+1) 
- (modified) libc/include/llvm-libc-types/CMakeLists.txt (+2-1) 
- (added) libc/include/llvm-libc-types/pthread_condattr_t.h (+18) 
- (modified) libc/include/pthread.h.def (+3) 
- (modified) libc/spec/posix.td (+61-3) 
- (modified) libc/src/pthread/CMakeLists.txt (+65) 
- (added) libc/src/pthread/pthread_condattr_destroy.cpp (+21) 
- (added) libc/src/pthread/pthread_condattr_destroy.h (+20) 
- (added) libc/src/pthread/pthread_condattr_getclock.cpp (+25) 
- (added) libc/src/pthread/pthread_condattr_getclock.h (+22) 
- (added) libc/src/pthread/pthread_condattr_getpshared.cpp (+24) 
- (added) libc/src/pthread/pthread_condattr_getpshared.h (+21) 
- (added) libc/src/pthread/pthread_condattr_init.cpp (+24) 
- (added) libc/src/pthread/pthread_condattr_init.h (+20) 
- (added) libc/src/pthread/pthread_condattr_setclock.cpp (+30) 
- (added) libc/src/pthread/pthread_condattr_setclock.h (+21) 
- (added) libc/src/pthread/pthread_condattr_setpshared.cpp (+28) 
- (added) libc/src/pthread/pthread_condattr_setpshared.h (+20) 
- (modified) libc/test/src/pthread/CMakeLists.txt (+10) 
- (added) libc/test/src/pthread/pthread_condattr_test.cpp (+80) 


``````````diff
diff --git a/libc/config/linux/api.td b/libc/config/linux/api.td
index 9964971f191b75..5fb92a9c299cc3 100644
--- a/libc/config/linux/api.td
+++ b/libc/config/linux/api.td
@@ -175,6 +175,7 @@ def PThreadAPI : PublicAPI<"pthread.h"> {
       "__pthread_start_t",
       "__pthread_tss_dtor_t",
       "pthread_attr_t",
+      "pthread_condattr_t",
       "pthread_mutex_t",
       "pthread_mutexattr_t",
       "pthread_t",
@@ -241,10 +242,30 @@ def SysSendfileAPI : PublicAPI<"sys/sendfile.h"> {
 }
 
 def SysTypesAPI : PublicAPI<"sys/types.h"> {
-  let Types = ["blkcnt_t", "blksize_t", "clockid_t", "dev_t", "gid_t", "ino_t",
-               "mode_t", "nlink_t", "off_t", "pid_t", "pthread_attr_t", "pthread_key_t",
-               "pthread_mutex_t", "pthread_mutexattr_t", "pthread_once_t", "pthread_t",
-               "size_t", "ssize_t", "suseconds_t", "time_t", "uid_t"];
+  let Types = [
+    "blkcnt_t",
+    "blksize_t",
+    "clockid_t",
+    "dev_t",
+    "gid_t",
+    "ino_t",
+    "mode_t",
+    "nlink_t",
+    "off_t",
+    "pid_t",
+    "pthread_attr_t",
+    "pthread_condattr_t",
+    "pthread_key_t",
+    "pthread_mutex_t",
+    "pthread_mutexattr_t",
+    "pthread_once_t",
+    "pthread_t",
+    "size_t",
+    "ssize_t",
+    "suseconds_t",
+    "time_t",
+    "uid_t"
+  ];
 }
 
 def SysUtsNameAPI : PublicAPI<"sys/utsname.h"> {
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 8fdd4575e27e28..8d1dbe794de098 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -638,6 +638,12 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.pthread.pthread_attr_setguardsize
     libc.src.pthread.pthread_attr_setstack
     libc.src.pthread.pthread_attr_setstacksize
+    libc.src.pthread.pthread_condattr_destroy
+    libc.src.pthread.pthread_condattr_getclock
+    libc.src.pthread.pthread_condattr_getpshared
+    libc.src.pthread.pthread_condattr_init
+    libc.src.pthread.pthread_condattr_setclock
+    libc.src.pthread.pthread_condattr_setpshared
     libc.src.pthread.pthread_create
     libc.src.pthread.pthread_detach
     libc.src.pthread.pthread_equal
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index b85366c8deafe0..f5ba2791af3fb8 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -321,6 +321,7 @@ add_gen_header(
     .llvm-libc-types.__pthread_start_t
     .llvm-libc-types.__pthread_tss_dtor_t
     .llvm-libc-types.pthread_attr_t
+    .llvm-libc-types.pthread_condattr_t
     .llvm-libc-types.pthread_mutex_t
     .llvm-libc-types.pthread_mutexattr_t
     .llvm-libc-types.pthread_t
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 93a79e1477b337..f26fc0729dc94c 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -49,11 +49,12 @@ add_header(pid_t HDR pid_t.h)
 add_header(posix_spawn_file_actions_t HDR posix_spawn_file_actions_t.h)
 add_header(posix_spawnattr_t HDR posix_spawnattr_t.h)
 add_header(pthread_attr_t HDR pthread_attr_t.h DEPENDS .size_t)
+add_header(pthread_condattr_t HDR pthread_condattr_t.h DEPENDS .clockid_t)
 add_header(pthread_key_t HDR pthread_key_t.h)
 add_header(pthread_mutex_t HDR pthread_mutex_t.h DEPENDS .__futex_word .__mutex_type)
-add_header(pthread_t HDR pthread_t.h DEPENDS .__thread_type)
 add_header(pthread_mutexattr_t HDR pthread_mutexattr_t.h)
 add_header(pthread_once_t HDR pthread_once_t.h DEPENDS .__futex_word)
+add_header(pthread_t HDR pthread_t.h DEPENDS .__thread_type)
 add_header(rlim_t HDR rlim_t.h)
 add_header(time_t HDR time_t.h)
 add_header(stack_t HDR stack_t.h)
diff --git a/libc/include/llvm-libc-types/pthread_condattr_t.h b/libc/include/llvm-libc-types/pthread_condattr_t.h
new file mode 100644
index 00000000000000..b91fc2950aa3f2
--- /dev/null
+++ b/libc/include/llvm-libc-types/pthread_condattr_t.h
@@ -0,0 +1,18 @@
+//===-- Definition of pthread_condattr_t type -----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_TYPES_PTHREAD_CONDATTR_T_H
+#define LLVM_LIBC_TYPES_PTHREAD_CONDATTR_T_H
+
+#include "clockid_t.h"
+
+typedef struct {
+  clockid_t clock;
+  int pshared;
+} pthread_condattr_t;
+
+#endif // LLVM_LIBC_TYPES_PTHREAD_CONDATTR_T_H
diff --git a/libc/include/pthread.h.def b/libc/include/pthread.h.def
index abeb839ee83d16..0b61a29d55248b 100644
--- a/libc/include/pthread.h.def
+++ b/libc/include/pthread.h.def
@@ -32,6 +32,9 @@ enum {
   PTHREAD_MUTEX_ROBUST = 0x1,
 };
 
+#define PTHREAD_PROCESS_PRIVATE 0
+#define PTHREAD_PROCESS_SHARED 1
+
 %%public_api()
 
 #endif // LLVM_LIBC_PTHREAD_H
diff --git a/libc/spec/posix.td b/libc/spec/posix.td
index 7095a3964ee3fb..0c88dbd848a3fb 100644
--- a/libc/spec/posix.td
+++ b/libc/spec/posix.td
@@ -26,6 +26,7 @@ def UidT : NamedType<"uid_t">;
 def GidT : NamedType<"gid_t">;
 def DevT : NamedType<"dev_t">;
 def ClockIdT : NamedType<"clockid_t">;
+def RestrictedClockIdTPtr : RestrictedPtrType<ClockIdT>;
 def BlkSizeT : NamedType<"blksize_t">;
 def BlkCntT : NamedType<"blkcnt_t">;
 def NLinkT : NamedType<"nlink_t">;
@@ -105,6 +106,10 @@ def POSIX : StandardSpec<"POSIX"> {
   ConstType ConstPThreadAttrTPtr = ConstType<PThreadAttrTPtr>;
   ConstType ConstRestrictedPThreadAttrTPtr = ConstType<RestrictedPThreadAttrTPtr>;
 
+  NamedType PThreadCondAttrTType = NamedType<"pthread_condattr_t">;
+  PtrType PThreadCondAttrTPtr = PtrType<PThreadCondAttrTType>;
+  ConstType ConstRestrictedPThreadCondAttrTPtr = ConstType<RestrictedPtrType<PThreadCondAttrTType>>;
+
   NamedType PThreadMutexAttrTType = NamedType<"pthread_mutexattr_t">;
   PtrType PThreadMutexAttrTPtr = PtrType<PThreadMutexAttrTType>;
   RestrictedPtrType RestrictedPThreadMutexAttrTPtr = RestrictedPtrType<PThreadMutexAttrTType>;
@@ -980,7 +985,9 @@ def POSIX : StandardSpec<"POSIX"> {
     [], // Macros
     [
         AtForkCallbackT,
+        ClockIdT,
         PThreadAttrTType,
+        PThreadCondAttrTType,
         PThreadKeyT,
         PThreadMutexAttrTType,
         PThreadMutexTType,
@@ -1047,6 +1054,36 @@ def POSIX : StandardSpec<"POSIX"> {
           RetValSpec<IntType>,
           [ArgSpec<PThreadAttrTPtr>, ArgSpec<VoidPtr>, ArgSpec<SizeTType>]
       >,
+      FunctionSpec<
+          "pthread_condattr_destroy",
+          RetValSpec<IntType>,
+          [ArgSpec<PThreadCondAttrTPtr>]
+      >,
+      FunctionSpec<
+          "pthread_condattr_getclock",
+          RetValSpec<IntType>,
+          [ArgSpec<ConstRestrictedPThreadCondAttrTPtr>, ArgSpec<RestrictedClockIdTPtr>]
+      >,
+      FunctionSpec<
+          "pthread_condattr_getpshared",
+          RetValSpec<IntType>,
+          [ArgSpec<ConstRestrictedPThreadCondAttrTPtr>, ArgSpec<RestrictedIntPtr>]
+      >,
+      FunctionSpec<
+          "pthread_condattr_init",
+          RetValSpec<IntType>,
+          [ArgSpec<PThreadCondAttrTPtr>]
+      >,
+      FunctionSpec<
+          "pthread_condattr_setclock",
+          RetValSpec<IntType>,
+          [ArgSpec<PThreadCondAttrTPtr>, ArgSpec<ClockIdT>]
+      >,
+      FunctionSpec<
+          "pthread_condattr_setpshared",
+          RetValSpec<IntType>,
+          [ArgSpec<PThreadCondAttrTPtr>, ArgSpec<IntType>]
+      >,
       FunctionSpec<
           "pthread_create",
           RetValSpec<IntType>,
@@ -1522,9 +1559,30 @@ def POSIX : StandardSpec<"POSIX"> {
   HeaderSpec SysTypes = HeaderSpec<
     "sys/types.h",
     [], // Macros
-    [BlkCntT, BlkSizeT, ClockIdT, DevT, GidT, InoT, ModeTType, NLinkT, OffTType, PidT,
-     PThreadAttrTType, PThreadKeyT, PThreadMutexTType, PThreadMutexAttrTType, PThreadOnceT, PThreadTType,
-     SizeTType, SSizeTType, SuSecondsT, TimeTType, UidT],
+    [
+      BlkCntT,
+      BlkSizeT,
+      ClockIdT,
+      DevT,
+      GidT,
+      InoT,
+      ModeTType,
+      NLinkT,
+      OffTType,
+      PThreadAttrTType,
+      PThreadCondAttrTType,
+      PThreadKeyT,
+      PThreadMutexAttrTType,
+      PThreadMutexTType,
+      PThreadOnceT,
+      PThreadTType,
+      PidT,
+      SSizeTType,
+      SizeTType,
+      SuSecondsT,
+      TimeTType,
+      UidT
+    ], // Types
     [], // Enumerations
     []  // Functions
   >;
diff --git a/libc/src/pthread/CMakeLists.txt b/libc/src/pthread/CMakeLists.txt
index d5e6c802a84523..3d6cf6dde010b1 100644
--- a/libc/src/pthread/CMakeLists.txt
+++ b/libc/src/pthread/CMakeLists.txt
@@ -100,6 +100,71 @@ add_entrypoint_object(
     libc.src.pthread.pthread_attr_setstacksize
 )
 
+add_entrypoint_object(
+  pthread_condattr_destroy
+  SRCS
+    pthread_condattr_destroy.cpp
+  HDRS
+    pthread_condattr_destroy.h
+  DEPENDS
+    libc.include.pthread
+)
+
+add_entrypoint_object(
+  pthread_condattr_getclock
+  SRCS
+    pthread_condattr_getclock.cpp
+  HDRS
+    pthread_condattr_getclock.h
+  DEPENDS
+    libc.include.pthread
+    libc.include.sys_types
+)
+
+add_entrypoint_object(
+  pthread_condattr_getpshared
+  SRCS
+    pthread_condattr_getpshared.cpp
+  HDRS
+    pthread_condattr_getpshared.h
+  DEPENDS
+    libc.include.pthread
+)
+
+add_entrypoint_object(
+  pthread_condattr_init
+  SRCS
+    pthread_condattr_init.cpp
+  HDRS
+    pthread_condattr_init.h
+  DEPENDS
+    libc.include.pthread
+    libc.include.time
+)
+
+add_entrypoint_object(
+  pthread_condattr_setclock
+  SRCS
+    pthread_condattr_setclock.cpp
+  HDRS
+    pthread_condattr_setclock.h
+  DEPENDS
+    libc.include.errno
+    libc.include.pthread
+    libc.include.sys_types
+    libc.include.time
+)
+
+add_entrypoint_object(
+  pthread_condattr_setpshared
+  SRCS
+    pthread_condattr_setpshared.cpp
+  HDRS
+    pthread_condattr_setpshared.h
+  DEPENDS
+    libc.include.pthread
+)
+
 add_header_library(
   pthread_mutexattr
   HDRS
diff --git a/libc/src/pthread/pthread_condattr_destroy.cpp b/libc/src/pthread/pthread_condattr_destroy.cpp
new file mode 100644
index 00000000000000..bcd58f79c97589
--- /dev/null
+++ b/libc/src/pthread/pthread_condattr_destroy.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of the pthread_condattr_destroy --------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "pthread_condattr_destroy.h"
+
+#include "src/__support/common.h"
+
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(int, pthread_condattr_destroy, (pthread_condattr_t * attr)) {
+  return 0;
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/pthread/pthread_condattr_destroy.h b/libc/src/pthread/pthread_condattr_destroy.h
new file mode 100644
index 00000000000000..2910fa9f96168a
--- /dev/null
+++ b/libc/src/pthread/pthread_condattr_destroy.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for pthread_condattr_destroy ------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_DESTROY_H
+#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_DESTROY_H
+
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE {
+
+int pthread_condattr_destroy(pthread_condattr_t *attr);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_DESTROY_H
diff --git a/libc/src/pthread/pthread_condattr_getclock.cpp b/libc/src/pthread/pthread_condattr_getclock.cpp
new file mode 100644
index 00000000000000..a3a3963f4f429e
--- /dev/null
+++ b/libc/src/pthread/pthread_condattr_getclock.cpp
@@ -0,0 +1,25 @@
+//===-- Implementation of the pthread_condattr_getclock -------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "pthread_condattr_getclock.h"
+
+#include "src/__support/common.h"
+
+#include <pthread.h>   // pthread_condattr_t
+#include <sys/types.h> // clockid_t
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(int, pthread_condattr_getclock,
+                   (const pthread_condattr_t *__restrict attr,
+                    clockid_t *__restrict clock_id)) {
+  *clock_id = attr->clock;
+  return 0;
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/pthread/pthread_condattr_getclock.h b/libc/src/pthread/pthread_condattr_getclock.h
new file mode 100644
index 00000000000000..d5878c4f45b537
--- /dev/null
+++ b/libc/src/pthread/pthread_condattr_getclock.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for pthread_condattr_getclock -----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_GETCLOCK_H
+#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_GETCLOCK_H
+
+#include <pthread.h>   // pthread_condattr_t
+#include <sys/types.h> // clockid_t
+
+namespace LIBC_NAMESPACE {
+
+int pthread_condattr_getclock(const pthread_condattr_t *__restrict attr,
+                              clockid_t *__restrict clock_id);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_GETCLOCK_H
diff --git a/libc/src/pthread/pthread_condattr_getpshared.cpp b/libc/src/pthread/pthread_condattr_getpshared.cpp
new file mode 100644
index 00000000000000..0c5fdc115c25d7
--- /dev/null
+++ b/libc/src/pthread/pthread_condattr_getpshared.cpp
@@ -0,0 +1,24 @@
+//===-- Implementation of the pthread_condattr_getpshared -----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "pthread_condattr_getpshared.h"
+
+#include "src/__support/common.h"
+
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(int, pthread_condattr_getpshared,
+                   (const pthread_condattr_t *__restrict attr,
+                    int *__restrict pshared)) {
+  *pshared = attr->pshared;
+  return 0;
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/pthread/pthread_condattr_getpshared.h b/libc/src/pthread/pthread_condattr_getpshared.h
new file mode 100644
index 00000000000000..3d7a0c1d357c60
--- /dev/null
+++ b/libc/src/pthread/pthread_condattr_getpshared.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for pthread_condattr_getpshared ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_PSHARED_H
+#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_PSHARED_H
+
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE {
+
+int pthread_condattr_getpshared(const pthread_condattr_t *__restrict attr,
+                                int *__restrict pshared);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_PSHARED_H
diff --git a/libc/src/pthread/pthread_condattr_init.cpp b/libc/src/pthread/pthread_condattr_init.cpp
new file mode 100644
index 00000000000000..54633b2e3a5eaf
--- /dev/null
+++ b/libc/src/pthread/pthread_condattr_init.cpp
@@ -0,0 +1,24 @@
+//===-- Implementation of the pthread_condattr_init -----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "pthread_condattr_init.h"
+
+#include "src/__support/common.h"
+
+#include <pthread.h> // pthread_condattr_t, PTHREAD_PROCESS_PRIVATE
+#include <time.h>    // CLOCK_REALTIME
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(int, pthread_condattr_init, (pthread_condattr_t * attr)) {
+  attr->clock = CLOCK_REALTIME;
+  attr->pshared = PTHREAD_PROCESS_PRIVATE;
+  return 0;
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/pthread/pthread_condattr_init.h b/libc/src/pthread/pthread_condattr_init.h
new file mode 100644
index 00000000000000..9f3c06bb6f4aef
--- /dev/null
+++ b/libc/src/pthread/pthread_condattr_init.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for pthread_condattr_init ---------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_INIT_H
+#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_INIT_H
+
+#include <pthread.h>
+
+namespace LIBC_NAMESPACE {
+
+int pthread_condattr_init(pthread_condattr_t *attr);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_INIT_H
diff --git a/libc/src/pthread/pthread_condattr_setclock.cpp b/libc/src/pthread/pthread_condattr_setclock.cpp
new file mode 100644
index 00000000000000..6eca8b30ef7f8e
--- /dev/null
+++ b/libc/src/pthread/pthread_condattr_setclock.cpp
@@ -0,0 +1,30 @@
+//===-- Implementation of the pthread_condattr_setclock -------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "pthread_condattr_setclock.h"
+
+#include "src/__support/common.h"
+
+#include <errno.h>     // EINVAL
+#include <pthread.h>   // pthread_condattr_t
+#include <sys/types.h> // clockid_t
+#include <time.h>      // CLOCK_MONOTONIC, CLOCK_REALTIME
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(int, pthread_condattr_setclock,
+                   (pthread_condattr_t * attr, clockid_t clock)) {
+
+  if (clock != CLOCK_MONOTONIC && clock != CLOCK_REALTIME)
+    return EINVAL;
+
+  attr->clock = clock;
+  return 0;
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/pthread/pthread_condattr_setclock.h b/libc/src/pthread/pthread_condattr_setclock.h
new file mode 100644
index 00000000000000..328766fe788336
--- /dev/null
+++ b/libc/src/pthread/pthread_condattr_setclock.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for pthread_condattr_setclock -----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_SETCLOCK_H
+#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_SETCLOCK_H
+
+#include <pthread.h>
+#include <sys/types.h> // clockid_t
+
+namespace LIBC_NAMESPACE {
+
+int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_SETCLOCK_H
diff --git a/libc/src/pthread/pthread_condattr_setpshared.cpp b/libc/src/pthread/pthread_condattr_setpshared.cpp
new file mode 100644
index 00000000000000..7f1560acad843e
--- /dev/null
+++ b/libc/src/pthread/pthread_condattr_s...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/88987


More information about the libc-commits mailing list