Add pthread_setschedprio.
Bug: http://b/26204555
Test: ran tests
Change-Id: Ic34062b9b6036a1ce2642a069514bab48a893338
diff --git a/docs/status.md b/docs/status.md
index e6fb7a4..c119439 100644
--- a/docs/status.md
+++ b/docs/status.md
@@ -14,6 +14,7 @@
* `glob`/`globfree` (adding <glob.h>)
* `hcreate`/hcreate_r`/`hdestroy`/`hdestroy_r`/`hsearch`/`hsearch_r` (completing <search.h>)
* `iconv`/`iconv_close`/`iconv_open` (adding <iconv.h>)
+ * `pthread_setschedprio`
* <spawn.h>
* `syncfs`
@@ -89,7 +90,6 @@
pthread_mutexattr_setrobust
pthread_setcancelstate
pthread_setcanceltype
-pthread_setschedprio
pthread_testcancel
sockatmark
swab
diff --git a/libc/bionic/pthread_setschedparam.cpp b/libc/bionic/pthread_setschedparam.cpp
index 3e80959..10826d1 100644
--- a/libc/bionic/pthread_setschedparam.cpp
+++ b/libc/bionic/pthread_setschedparam.cpp
@@ -27,9 +27,10 @@
*/
#include <errno.h>
+#include <pthread.h>
+#include <sched.h>
#include "private/ErrnoRestorer.h"
-#include "pthread_internal.h"
int pthread_setschedparam(pthread_t t, int policy, const sched_param* param) {
ErrnoRestorer errno_restorer;
@@ -39,3 +40,13 @@
return (sched_setscheduler(tid, policy, param) == -1) ? errno : 0;
}
+
+int pthread_setschedprio(pthread_t t, int priority) {
+ ErrnoRestorer errno_restorer;
+
+ pid_t tid = pthread_gettid_np(t);
+ if (tid == -1) return ESRCH;
+
+ sched_param param = { .sched_priority = priority };
+ return (sched_setparam(tid, ¶m) == -1) ? errno : 0;
+}
diff --git a/libc/include/pthread.h b/libc/include/pthread.h
index 32315fe..2253e0d 100644
--- a/libc/include/pthread.h
+++ b/libc/include/pthread.h
@@ -220,6 +220,7 @@
int pthread_setname_np(pthread_t __pthread, const char* __name);
int pthread_setschedparam(pthread_t __pthread, int __policy, const struct sched_param* __param);
+int pthread_setschedprio(pthread_t __pthread, int __priority) __INTRODUCED_IN_FUTURE;
int pthread_setspecific(pthread_key_t __key, const void* __value);
diff --git a/libc/libc.arm.map b/libc/libc.arm.map
index 82d6872..981dd59 100644
--- a/libc/libc.arm.map
+++ b/libc/libc.arm.map
@@ -1362,6 +1362,7 @@
posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init;
posix_spawnp;
+ pthread_setschedprio;
sethostent;
setnetent;
setprotoent;
diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map
index 5dfe93b..29c5235 100644
--- a/libc/libc.arm64.map
+++ b/libc/libc.arm64.map
@@ -1282,6 +1282,7 @@
posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init;
posix_spawnp;
+ pthread_setschedprio;
sethostent;
setnetent;
setprotoent;
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index 8f7b599..eafbbd7 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -1387,6 +1387,7 @@
posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init;
posix_spawnp;
+ pthread_setschedprio;
sethostent;
setnetent;
setprotoent;
diff --git a/libc/libc.mips.map b/libc/libc.mips.map
index 3a039c5..a32131f 100644
--- a/libc/libc.mips.map
+++ b/libc/libc.mips.map
@@ -1346,6 +1346,7 @@
posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init;
posix_spawnp;
+ pthread_setschedprio;
sethostent;
setnetent;
setprotoent;
diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map
index 5dfe93b..29c5235 100644
--- a/libc/libc.mips64.map
+++ b/libc/libc.mips64.map
@@ -1282,6 +1282,7 @@
posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init;
posix_spawnp;
+ pthread_setschedprio;
sethostent;
setnetent;
setprotoent;
diff --git a/libc/libc.x86.map b/libc/libc.x86.map
index 2b165cc..f1308ea 100644
--- a/libc/libc.x86.map
+++ b/libc/libc.x86.map
@@ -1344,6 +1344,7 @@
posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init;
posix_spawnp;
+ pthread_setschedprio;
sethostent;
setnetent;
setprotoent;
diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map
index 5dfe93b..29c5235 100644
--- a/libc/libc.x86_64.map
+++ b/libc/libc.x86_64.map
@@ -1282,6 +1282,7 @@
posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init;
posix_spawnp;
+ pthread_setschedprio;
sethostent;
setnetent;
setprotoent;
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index f342577..85978bd 100755
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -566,6 +566,18 @@
EXPECT_EQ(ESRCH, pthread_setschedparam(null_thread, policy, ¶m));
}
+TEST_F(pthread_DeathTest, pthread_setschedprio__no_such_thread) {
+ pthread_t dead_thread;
+ MakeDeadThread(dead_thread);
+
+ EXPECT_DEATH(pthread_setschedprio(dead_thread, 123), "invalid pthread_t");
+}
+
+TEST_F(pthread_DeathTest, pthread_setschedprio__null_thread) {
+ pthread_t null_thread = 0;
+ EXPECT_EQ(ESRCH, pthread_setschedprio(null_thread, 123));
+}
+
TEST_F(pthread_DeathTest, pthread_join__no_such_thread) {
pthread_t dead_thread;
MakeDeadThread(dead_thread);
@@ -2147,3 +2159,12 @@
ASSERT_EQ(0, munmap(pages[i], kPageSize));
}
}
+
+TEST(pthread, pthread_setschedparam) {
+ sched_param p = { .sched_priority = INT_MIN };
+ ASSERT_EQ(EINVAL, pthread_setschedparam(pthread_self(), INT_MIN, &p));
+}
+
+TEST(pthread, pthread_setschedprio) {
+ ASSERT_EQ(EINVAL, pthread_setschedprio(pthread_self(), INT_MIN));
+}