Merge "Add pthread_setschedprio." am: 435e6384de am: 0cf1a3699b

am: 463ab4b0f5

Change-Id: If6f7adf5f9c824e24309682309762e9ed40ab83b
This commit is contained in:
Elliott Hughes 2017-10-17 18:08:58 +00:00 committed by android-build-merger
commit 9793ea25c4
11 changed files with 42 additions and 2 deletions

View file

@ -14,6 +14,7 @@ New libc functions in P:
* `glob`/`globfree` (adding <glob.h>) * `glob`/`globfree` (adding <glob.h>)
* `hcreate`/hcreate_r`/`hdestroy`/`hdestroy_r`/`hsearch`/`hsearch_r` (completing <search.h>) * `hcreate`/hcreate_r`/`hdestroy`/`hdestroy_r`/`hsearch`/`hsearch_r` (completing <search.h>)
* `iconv`/`iconv_close`/`iconv_open` (adding <iconv.h>) * `iconv`/`iconv_close`/`iconv_open` (adding <iconv.h>)
* `pthread_setschedprio`
* <spawn.h> * <spawn.h>
* `syncfs` * `syncfs`
@ -89,7 +90,6 @@ pthread_mutexattr_setprotocol
pthread_mutexattr_setrobust pthread_mutexattr_setrobust
pthread_setcancelstate pthread_setcancelstate
pthread_setcanceltype pthread_setcanceltype
pthread_setschedprio
pthread_testcancel pthread_testcancel
sockatmark sockatmark
swab swab

View file

@ -27,9 +27,10 @@
*/ */
#include <errno.h> #include <errno.h>
#include <pthread.h>
#include <sched.h>
#include "private/ErrnoRestorer.h" #include "private/ErrnoRestorer.h"
#include "pthread_internal.h"
int pthread_setschedparam(pthread_t t, int policy, const sched_param* param) { int pthread_setschedparam(pthread_t t, int policy, const sched_param* param) {
ErrnoRestorer errno_restorer; ErrnoRestorer errno_restorer;
@ -39,3 +40,13 @@ int pthread_setschedparam(pthread_t t, int policy, const sched_param* param) {
return (sched_setscheduler(tid, policy, param) == -1) ? errno : 0; 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, &param) == -1) ? errno : 0;
}

View file

@ -220,6 +220,7 @@ int pthread_getname_np(pthread_t __pthread, char* __buf, size_t __n) __INTRODUCE
int pthread_setname_np(pthread_t __pthread, const char* __name); 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_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); int pthread_setspecific(pthread_key_t __key, const void* __value);

View file

@ -1362,6 +1362,7 @@ LIBC_P { # introduced=P
posix_spawn_file_actions_destroy; posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init; posix_spawn_file_actions_init;
posix_spawnp; posix_spawnp;
pthread_setschedprio;
sethostent; sethostent;
setnetent; setnetent;
setprotoent; setprotoent;

View file

@ -1282,6 +1282,7 @@ LIBC_P { # introduced=P
posix_spawn_file_actions_destroy; posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init; posix_spawn_file_actions_init;
posix_spawnp; posix_spawnp;
pthread_setschedprio;
sethostent; sethostent;
setnetent; setnetent;
setprotoent; setprotoent;

View file

@ -1387,6 +1387,7 @@ LIBC_P { # introduced=P
posix_spawn_file_actions_destroy; posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init; posix_spawn_file_actions_init;
posix_spawnp; posix_spawnp;
pthread_setschedprio;
sethostent; sethostent;
setnetent; setnetent;
setprotoent; setprotoent;

View file

@ -1346,6 +1346,7 @@ LIBC_P { # introduced=P
posix_spawn_file_actions_destroy; posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init; posix_spawn_file_actions_init;
posix_spawnp; posix_spawnp;
pthread_setschedprio;
sethostent; sethostent;
setnetent; setnetent;
setprotoent; setprotoent;

View file

@ -1282,6 +1282,7 @@ LIBC_P { # introduced=P
posix_spawn_file_actions_destroy; posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init; posix_spawn_file_actions_init;
posix_spawnp; posix_spawnp;
pthread_setschedprio;
sethostent; sethostent;
setnetent; setnetent;
setprotoent; setprotoent;

View file

@ -1344,6 +1344,7 @@ LIBC_P { # introduced=P
posix_spawn_file_actions_destroy; posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init; posix_spawn_file_actions_init;
posix_spawnp; posix_spawnp;
pthread_setschedprio;
sethostent; sethostent;
setnetent; setnetent;
setprotoent; setprotoent;

View file

@ -1282,6 +1282,7 @@ LIBC_P { # introduced=P
posix_spawn_file_actions_destroy; posix_spawn_file_actions_destroy;
posix_spawn_file_actions_init; posix_spawn_file_actions_init;
posix_spawnp; posix_spawnp;
pthread_setschedprio;
sethostent; sethostent;
setnetent; setnetent;
setprotoent; setprotoent;

View file

@ -566,6 +566,18 @@ TEST_F(pthread_DeathTest, pthread_setschedparam__null_thread) {
EXPECT_EQ(ESRCH, pthread_setschedparam(null_thread, policy, &param)); EXPECT_EQ(ESRCH, pthread_setschedparam(null_thread, policy, &param));
} }
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) { TEST_F(pthread_DeathTest, pthread_join__no_such_thread) {
pthread_t dead_thread; pthread_t dead_thread;
MakeDeadThread(dead_thread); MakeDeadThread(dead_thread);
@ -2147,3 +2159,12 @@ TEST(pthread, pthread_create__mmap_failures) {
ASSERT_EQ(0, munmap(pages[i], kPageSize)); 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));
}