[libc-commits] [libc] [libc] Implement pthread_attr_[gs]etinheritsched (PR #223322)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Mon Sep 14 01:03:19 PDT 2026


https://github.com/labath created https://github.com/llvm/llvm-project/pull/223322

This patch implements pthread_attr_setinheritsched and pthread_attr_getinheritsched.

Like the previous scheduler attribute patches, this commit only operates on the pthread_attr_t object and does not attempt to install scheduling parameters when creating a new thread.

Unlike schedpolicy and schedparam, where the validity of arguments is checked by the kernel, inheritsched is purely a userspace pthread concept. Therefore, we validate the inheritsched argument and reject unsupported values with EINVAL.

While in there:
- update the file headers in pthread_attr_init to the modern llvm format
- use proxy headers instead of direct pthread.h inclusion

Assisted-by: Gemini

>From f978eee7e7f9053ac518c13f65047de70776dff7 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Mon, 14 Sep 2026 07:20:20 +0000
Subject: [PATCH] [libc] Implement pthread_attr_[gs]etinheritsched

This patch implements pthread_attr_setinheritsched and
pthread_attr_getinheritsched.

Like the previous scheduler attribute patches, this commit only
operates on the pthread_attr_t object and does not attempt to
install scheduling parameters when creating a new thread.

Unlike schedpolicy and schedparam, where the validity of arguments
is checked by the kernel, inheritsched is purely a userspace pthread
concept. Therefore, we validate the inheritsched argument and reject
unsupported values with EINVAL.

While in there:
- update the file headers in pthread_attr_init to the modern llvm format
- use proxy headers instead of direct pthread.h inclusion

Assisted-by: Gemini
---
 libc/config/linux/aarch64/entrypoints.txt     |  2 +
 libc/config/linux/riscv/entrypoints.txt       |  2 +
 libc/config/linux/x86_64/entrypoints.txt      |  2 +
 .../include/llvm-libc-macros/pthread-macros.h |  3 ++
 libc/include/llvm-libc-types/pthread_attr_t.h |  1 +
 libc/include/pthread.yaml                     | 18 +++++++++
 libc/src/pthread/CMakeLists.txt               | 35 +++++++++++++++-
 .../pthread/pthread_attr_getinheritsched.cpp  | 31 ++++++++++++++
 .../pthread/pthread_attr_getinheritsched.h    | 28 +++++++++++++
 libc/src/pthread/pthread_attr_init.cpp        | 17 +++++---
 libc/src/pthread/pthread_attr_init.h          |  9 ++++-
 .../pthread/pthread_attr_setinheritsched.cpp  | 37 +++++++++++++++++
 .../pthread/pthread_attr_setinheritsched.h    | 27 +++++++++++++
 libc/test/src/pthread/CMakeLists.txt          |  4 +-
 libc/test/src/pthread/pthread_attr_test.cpp   | 40 ++++++++++++++++++-
 15 files changed, 246 insertions(+), 10 deletions(-)
 create mode 100644 libc/src/pthread/pthread_attr_getinheritsched.cpp
 create mode 100644 libc/src/pthread/pthread_attr_getinheritsched.h
 create mode 100644 libc/src/pthread/pthread_attr_setinheritsched.cpp
 create mode 100644 libc/src/pthread/pthread_attr_setinheritsched.h

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index a96057944af75..7f67d3822f424 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1119,6 +1119,7 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.pthread.pthread_attr_destroy
     libc.src.pthread.pthread_attr_getdetachstate
     libc.src.pthread.pthread_attr_getguardsize
+    libc.src.pthread.pthread_attr_getinheritsched
     libc.src.pthread.pthread_attr_getschedparam
     libc.src.pthread.pthread_attr_getschedpolicy
     libc.src.pthread.pthread_attr_getscope
@@ -1127,6 +1128,7 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.pthread.pthread_attr_init
     libc.src.pthread.pthread_attr_setdetachstate
     libc.src.pthread.pthread_attr_setguardsize
+    libc.src.pthread.pthread_attr_setinheritsched
     libc.src.pthread.pthread_attr_setschedparam
     libc.src.pthread.pthread_attr_setschedpolicy
     libc.src.pthread.pthread_attr_setscope
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 4b2f6e2e72120..93e73b0b63cf2 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1312,6 +1312,7 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.pthread.pthread_attr_destroy
     libc.src.pthread.pthread_attr_getdetachstate
     libc.src.pthread.pthread_attr_getguardsize
+    libc.src.pthread.pthread_attr_getinheritsched
     libc.src.pthread.pthread_attr_getschedparam
     libc.src.pthread.pthread_attr_getschedpolicy
     libc.src.pthread.pthread_attr_getscope
@@ -1320,6 +1321,7 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.pthread.pthread_attr_init
     libc.src.pthread.pthread_attr_setdetachstate
     libc.src.pthread.pthread_attr_setguardsize
+    libc.src.pthread.pthread_attr_setinheritsched
     libc.src.pthread.pthread_attr_setschedparam
     libc.src.pthread.pthread_attr_setschedpolicy
     libc.src.pthread.pthread_attr_setscope
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index c4856700e9ea8..ebbb46dbeb3d3 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1323,6 +1323,7 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.pthread.pthread_attr_destroy
     libc.src.pthread.pthread_attr_getdetachstate
     libc.src.pthread.pthread_attr_getguardsize
+    libc.src.pthread.pthread_attr_getinheritsched
     libc.src.pthread.pthread_attr_getschedparam
     libc.src.pthread.pthread_attr_getschedpolicy
     libc.src.pthread.pthread_attr_getscope
@@ -1331,6 +1332,7 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.pthread.pthread_attr_init
     libc.src.pthread.pthread_attr_setdetachstate
     libc.src.pthread.pthread_attr_setguardsize
+    libc.src.pthread.pthread_attr_setinheritsched
     libc.src.pthread.pthread_attr_setschedparam
     libc.src.pthread.pthread_attr_setschedpolicy
     libc.src.pthread.pthread_attr_setscope
diff --git a/libc/include/llvm-libc-macros/pthread-macros.h b/libc/include/llvm-libc-macros/pthread-macros.h
index 1d79383c8cbf9..5f96305468297 100644
--- a/libc/include/llvm-libc-macros/pthread-macros.h
+++ b/libc/include/llvm-libc-macros/pthread-macros.h
@@ -32,6 +32,9 @@
 #define PTHREAD_SCOPE_SYSTEM 0
 #define PTHREAD_SCOPE_PROCESS 1
 
+#define PTHREAD_INHERIT_SCHED 0
+#define PTHREAD_EXPLICIT_SCHED 1
+
 #ifdef __linux__
 #define PTHREAD_MUTEX_INITIALIZER                                              \
   {                                                                            \
diff --git a/libc/include/llvm-libc-types/pthread_attr_t.h b/libc/include/llvm-libc-types/pthread_attr_t.h
index 0e42c0d04fdf7..0e5fa228e6a32 100644
--- a/libc/include/llvm-libc-types/pthread_attr_t.h
+++ b/libc/include/llvm-libc-types/pthread_attr_t.h
@@ -14,6 +14,7 @@
 
 typedef struct {
   int __detachstate;
+  int __inheritsched;
   int __schedpolicy;
   struct sched_param __schedparam;
   void *__stack;
diff --git a/libc/include/pthread.yaml b/libc/include/pthread.yaml
index a13a7b400ca1a..875dec99f7fdf 100644
--- a/libc/include/pthread.yaml
+++ b/libc/include/pthread.yaml
@@ -32,6 +32,10 @@ macros:
     macro_header: pthread-macros.h
   - macro_name: "PTHREAD_SCOPE_PROCESS"
     macro_header: pthread-macros.h
+  - macro_name: "PTHREAD_INHERIT_SCHED"
+    macro_header: pthread-macros.h
+  - macro_name: "PTHREAD_EXPLICIT_SCHED"
+    macro_header: pthread-macros.h
   - macro_name: "PTHREAD_MUTEX_INITIALIZER"
     macro_header: pthread-macros.h
   - macro_name: "PTHREAD_COND_INITIALIZER"
@@ -96,6 +100,13 @@ functions:
     arguments:
       - type: const pthread_attr_t *__restrict
       - type: size_t *__restrict
+  - name: pthread_attr_getinheritsched
+    standards:
+      - posix
+    return_type: int
+    arguments:
+      - type: const pthread_attr_t *__restrict
+      - type: int *__restrict
   - name: pthread_attr_getschedparam
     return_type: int
     arguments:
@@ -138,6 +149,13 @@ functions:
     arguments:
       - type: pthread_attr_t *
       - type: size_t
+  - name: pthread_attr_setinheritsched
+    standards:
+      - posix
+    return_type: int
+    arguments:
+      - type: pthread_attr_t *
+      - type: int
   - name: pthread_attr_setschedparam
     return_type: int
     arguments:
diff --git a/libc/src/pthread/CMakeLists.txt b/libc/src/pthread/CMakeLists.txt
index 7eb081a64f78a..cfbcb152ecc48 100644
--- a/libc/src/pthread/CMakeLists.txt
+++ b/libc/src/pthread/CMakeLists.txt
@@ -5,8 +5,13 @@ add_entrypoint_object(
   HDRS
     pthread_attr_init.h
   DEPENDS
-    libc.include.pthread
+    libc.hdr.pthread_macros
     libc.hdr.sched_macros
+    libc.hdr.types.pthread_attr_t
+    libc.src.__support.common
+    libc.src.__support.macros.config
+    libc.src.__support.macros.null_check
+    libc.src.__support.threads.thread
 )
 
 add_entrypoint_object(
@@ -61,6 +66,19 @@ add_entrypoint_object(
     libc.src.errno.errno
 )
 
+add_entrypoint_object(
+  pthread_attr_getinheritsched
+  SRCS
+    pthread_attr_getinheritsched.cpp
+  HDRS
+    pthread_attr_getinheritsched.h
+  DEPENDS
+    libc.hdr.types.pthread_attr_t
+    libc.src.__support.common
+    libc.src.__support.macros.config
+    libc.src.__support.macros.null_check
+)
+
 add_entrypoint_object(
   pthread_attr_getschedparam
   SRCS
@@ -102,6 +120,21 @@ add_entrypoint_object(
     libc.src.__support.macros.null_check
 )
 
+add_entrypoint_object(
+  pthread_attr_setinheritsched
+  SRCS
+    pthread_attr_setinheritsched.cpp
+  HDRS
+    pthread_attr_setinheritsched.h
+  DEPENDS
+    libc.hdr.errno_macros
+    libc.hdr.pthread_macros
+    libc.hdr.types.pthread_attr_t
+    libc.src.__support.common
+    libc.src.__support.macros.config
+    libc.src.__support.macros.null_check
+)
+
 add_entrypoint_object(
   pthread_attr_setschedparam
   SRCS
diff --git a/libc/src/pthread/pthread_attr_getinheritsched.cpp b/libc/src/pthread/pthread_attr_getinheritsched.cpp
new file mode 100644
index 0000000000000..0f2e5bdcf7e0e
--- /dev/null
+++ b/libc/src/pthread/pthread_attr_getinheritsched.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of pthread_attr_getinheritsched.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/pthread/pthread_attr_getinheritsched.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, pthread_attr_getinheritsched,
+                   (const pthread_attr_t *__restrict attr,
+                    int *__restrict inheritsched)) {
+  LIBC_CRASH_ON_NULLPTR(attr);
+  LIBC_CRASH_ON_NULLPTR(inheritsched);
+
+  *inheritsched = attr->__inheritsched;
+  return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/pthread/pthread_attr_getinheritsched.h b/libc/src/pthread/pthread_attr_getinheritsched.h
new file mode 100644
index 0000000000000..b6a03789cb673
--- /dev/null
+++ b/libc/src/pthread/pthread_attr_getinheritsched.h
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for pthread_attr_getinheritsched.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_ATTR_GETINHERITSCHED_H
+#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_ATTR_GETINHERITSCHED_H
+
+#include "hdr/types/pthread_attr_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+/// Get the inherit scheduler attribute from \p attr.
+int pthread_attr_getinheritsched(const pthread_attr_t *__restrict attr,
+                                 int *__restrict inheritsched);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_ATTR_GETINHERITSCHED_H
diff --git a/libc/src/pthread/pthread_attr_init.cpp b/libc/src/pthread/pthread_attr_init.cpp
index 9ae7acebec391..f2e22e10d60e4 100644
--- a/libc/src/pthread/pthread_attr_init.cpp
+++ b/libc/src/pthread/pthread_attr_init.cpp
@@ -1,25 +1,32 @@
-//===-- Implementation of the pthread_attr_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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of pthread_attr_init.
+///
+//===----------------------------------------------------------------------===//
 
-#include "pthread_attr_init.h"
-
+#include "src/pthread/pthread_attr_init.h"
+#include "hdr/pthread_macros.h"
 #include "hdr/sched_macros.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
 #include "src/__support/threads/thread.h" // For thread::DEFAULT_*
 
-#include <pthread.h>
-
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, pthread_attr_init, (pthread_attr_t * attr)) {
+  LIBC_CRASH_ON_NULLPTR(attr);
+
   *attr = pthread_attr_t{
       PTHREAD_CREATE_JOINABLE,   // Not detached
+      PTHREAD_INHERIT_SCHED,     // Default inherit scheduler
       SCHED_OTHER,               // Default scheduling policy
       {},                        // Default scheduling parameters
       nullptr,                   // Let the thread manage its stack
diff --git a/libc/src/pthread/pthread_attr_init.h b/libc/src/pthread/pthread_attr_init.h
index 69969980725b8..7dbab3b58fa82 100644
--- a/libc/src/pthread/pthread_attr_init.h
+++ b/libc/src/pthread/pthread_attr_init.h
@@ -1,16 +1,21 @@
-//===-- Implementation header for pthread_attr_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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for pthread_attr_init.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_ATTR_INIT_H
 #define LLVM_LIBC_SRC_PTHREAD_PTHREAD_ATTR_INIT_H
 
+#include "hdr/types/pthread_attr_t.h"
 #include "src/__support/macros/config.h"
-#include <pthread.h>
 
 namespace LIBC_NAMESPACE_DECL {
 
diff --git a/libc/src/pthread/pthread_attr_setinheritsched.cpp b/libc/src/pthread/pthread_attr_setinheritsched.cpp
new file mode 100644
index 0000000000000..87503b47cd6bb
--- /dev/null
+++ b/libc/src/pthread/pthread_attr_setinheritsched.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of pthread_attr_setinheritsched.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/pthread/pthread_attr_setinheritsched.h"
+#include "hdr/errno_macros.h"
+#include "hdr/pthread_macros.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, pthread_attr_setinheritsched,
+                   (pthread_attr_t * attr, int inheritsched)) {
+  LIBC_CRASH_ON_NULLPTR(attr);
+
+  switch (inheritsched) {
+  case PTHREAD_INHERIT_SCHED:
+  case PTHREAD_EXPLICIT_SCHED:
+    attr->__inheritsched = inheritsched;
+    return 0;
+  default:
+    return EINVAL;
+  }
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/pthread/pthread_attr_setinheritsched.h b/libc/src/pthread/pthread_attr_setinheritsched.h
new file mode 100644
index 0000000000000..ceb3013c7fc56
--- /dev/null
+++ b/libc/src/pthread/pthread_attr_setinheritsched.h
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for pthread_attr_setinheritsched.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_ATTR_SETINHERITSCHED_H
+#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_ATTR_SETINHERITSCHED_H
+
+#include "hdr/types/pthread_attr_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+/// Set the inherit scheduler attribute in \p attr.
+int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_ATTR_SETINHERITSCHED_H
diff --git a/libc/test/src/pthread/CMakeLists.txt b/libc/test/src/pthread/CMakeLists.txt
index d6dd107b74ef6..c59d30373fabb 100644
--- a/libc/test/src/pthread/CMakeLists.txt
+++ b/libc/test/src/pthread/CMakeLists.txt
@@ -7,7 +7,6 @@ add_libc_test(
   SRCS
     pthread_attr_test.cpp
   DEPENDS
-    libc.include.pthread
     libc.src.pthread.pthread_attr_destroy
     libc.src.pthread.pthread_attr_init
     libc.src.pthread.pthread_attr_getdetachstate
@@ -18,6 +17,8 @@ add_libc_test(
     libc.src.pthread.pthread_attr_setguardsize
     libc.src.pthread.pthread_attr_setstacksize
     libc.src.pthread.pthread_attr_setstack
+    libc.src.pthread.pthread_attr_getinheritsched
+    libc.src.pthread.pthread_attr_setinheritsched
     libc.src.pthread.pthread_attr_getschedparam
     libc.src.pthread.pthread_attr_setschedparam
     libc.src.pthread.pthread_attr_getschedpolicy
@@ -27,6 +28,7 @@ add_libc_test(
     libc.hdr.errno_macros
     libc.hdr.pthread_macros
     libc.hdr.sched_macros
+    libc.hdr.types.pthread_attr_t
     libc.hdr.types.struct_sched_param
 )
 
diff --git a/libc/test/src/pthread/pthread_attr_test.cpp b/libc/test/src/pthread/pthread_attr_test.cpp
index d371705948dfd..8bd18e421351e 100644
--- a/libc/test/src/pthread/pthread_attr_test.cpp
+++ b/libc/test/src/pthread/pthread_attr_test.cpp
@@ -14,10 +14,12 @@
 #include "hdr/errno_macros.h"
 #include "hdr/pthread_macros.h"
 #include "hdr/sched_macros.h"
+#include "hdr/types/pthread_attr_t.h"
 #include "hdr/types/struct_sched_param.h"
 #include "src/pthread/pthread_attr_destroy.h"
 #include "src/pthread/pthread_attr_getdetachstate.h"
 #include "src/pthread/pthread_attr_getguardsize.h"
+#include "src/pthread/pthread_attr_getinheritsched.h"
 #include "src/pthread/pthread_attr_getschedparam.h"
 #include "src/pthread/pthread_attr_getschedpolicy.h"
 #include "src/pthread/pthread_attr_getscope.h"
@@ -26,6 +28,7 @@
 #include "src/pthread/pthread_attr_init.h"
 #include "src/pthread/pthread_attr_setdetachstate.h"
 #include "src/pthread/pthread_attr_setguardsize.h"
+#include "src/pthread/pthread_attr_setinheritsched.h"
 #include "src/pthread/pthread_attr_setschedparam.h"
 #include "src/pthread/pthread_attr_setschedpolicy.h"
 #include "src/pthread/pthread_attr_setscope.h"
@@ -35,7 +38,6 @@
 #include "test/UnitTest/Test.h"
 
 #include <linux/param.h> // For EXEC_PAGESIZE.
-#include <pthread.h>
 
 TEST(LlvmLibcPThreadAttrTest, InitAndDestroy) {
   pthread_attr_t attr;
@@ -132,6 +134,42 @@ TEST(LlvmLibcPThreadattrTest, SetAndGetStack) {
   ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_destroy(&attr), 0);
 }
 
+TEST(LlvmLibcPThreadattrTest, SetAndGetInheritSched) {
+  pthread_attr_t attr;
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_init(&attr), 0);
+
+  int inheritsched;
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_getinheritsched(&attr, &inheritsched),
+            0);
+  ASSERT_EQ(inheritsched, PTHREAD_INHERIT_SCHED);
+
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_setinheritsched(
+                &attr, PTHREAD_EXPLICIT_SCHED),
+            0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_getinheritsched(&attr, &inheritsched),
+            0);
+  ASSERT_EQ(inheritsched, PTHREAD_EXPLICIT_SCHED);
+
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_setinheritsched(&attr,
+                                                         PTHREAD_INHERIT_SCHED),
+            0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_getinheritsched(&attr, &inheritsched),
+            0);
+  ASSERT_EQ(inheritsched, PTHREAD_INHERIT_SCHED);
+
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_setinheritsched(&attr, 0xBAD), EINVAL);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_getinheritsched(&attr, &inheritsched),
+            0);
+  ASSERT_EQ(inheritsched, PTHREAD_INHERIT_SCHED);
+
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_setinheritsched(&attr, -1), EINVAL);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_getinheritsched(&attr, &inheritsched),
+            0);
+  ASSERT_EQ(inheritsched, PTHREAD_INHERIT_SCHED);
+
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_destroy(&attr), 0);
+}
+
 TEST(LlvmLibcPThreadattrTest, SetAndGetSchedParam) {
   pthread_attr_t attr;
   ASSERT_EQ(LIBC_NAMESPACE::pthread_attr_init(&attr), 0);



More information about the libc-commits mailing list