threads,android: use syscall directly for affinity
The posix symbol may not be always available, but the linux one seems to be consistently available. Refs: https://github.com/libuv/libuv/issues/2655 (fixes one issue) PR-URL: https://github.com/libuv/libuv/pull/3247 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
parent
4fe755bc5b
commit
853f66f0b1
@ -232,7 +232,6 @@ static void uv__process_child_init(const uv_process_options_t* options,
|
||||
int fd;
|
||||
int n;
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
int r;
|
||||
int i;
|
||||
int cpumask_size;
|
||||
uv__cpu_set_t cpuset;
|
||||
@ -327,9 +326,15 @@ static void uv__process_child_init(const uv_process_options_t* options,
|
||||
}
|
||||
}
|
||||
|
||||
r = -pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
|
||||
if (r != 0) {
|
||||
uv__write_int(error_fd, r);
|
||||
#if defined(__linux__)
|
||||
err = sched_setaffinity(0, sizeof(cpuset), &cpuset);
|
||||
#else
|
||||
err = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
|
||||
if (err)
|
||||
err = errno;
|
||||
#endif
|
||||
if (err) {
|
||||
uv__write_int(error_fd, UV__ERR(err));
|
||||
_exit(127);
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,7 +284,13 @@ int uv_thread_setaffinity(uv_thread_t* tid,
|
||||
if (cpumask[i])
|
||||
CPU_SET(i, &cpuset);
|
||||
|
||||
return UV__ERR(pthread_setaffinity_np(*tid, sizeof(cpuset), &cpuset));
|
||||
#if defined(__ANDROID__)
|
||||
r = sched_setaffinity(pthread_gettid_np(*tid), sizeof(cpuset), &cpuset);
|
||||
#else
|
||||
r = pthread_setaffinity_np(*tid, sizeof(cpuset), &cpuset);
|
||||
#endif
|
||||
|
||||
return UV__ERR(r);
|
||||
}
|
||||
|
||||
|
||||
@ -303,7 +309,11 @@ int uv_thread_getaffinity(uv_thread_t* tid,
|
||||
return UV_EINVAL;
|
||||
|
||||
CPU_ZERO(&cpuset);
|
||||
#if defined(__ANDROID__)
|
||||
r = sched_getaffinity(pthread_gettid_np(*tid), sizeof(cpuset), &cpuset);
|
||||
#else
|
||||
r = pthread_getaffinity_np(*tid, sizeof(cpuset), &cpuset);
|
||||
#endif
|
||||
if (r)
|
||||
return UV__ERR(r);
|
||||
for (i = 0; i < cpumasksize; i++)
|
||||
|
||||
@ -304,7 +304,11 @@ static int maybe_run_test(int argc, char **argv) {
|
||||
}
|
||||
#else
|
||||
CPU_ZERO(&cpuset);
|
||||
#ifdef __linux__
|
||||
r = sched_getaffinity(0, sizeof(cpuset), &cpuset);
|
||||
#else
|
||||
r = pthread_getaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
|
||||
#endif
|
||||
ASSERT(r == 0);
|
||||
for (i = 0; i < cpumask_size; ++i) {
|
||||
ASSERT(CPU_ISSET(i, &cpuset) == (i == cpu));
|
||||
|
||||
@ -1539,7 +1539,11 @@ TEST_IMPL(spawn_affinity) {
|
||||
}
|
||||
#else
|
||||
CPU_ZERO(&cpuset);
|
||||
#ifdef __linux__
|
||||
r = sched_getaffinity(0, sizeof(cpuset), &cpuset);
|
||||
#else
|
||||
r = pthread_getaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
|
||||
#endif
|
||||
ASSERT(r == 0);
|
||||
for (i = 0; i < cpumask_size; ++i) {
|
||||
if (CPU_ISSET(i, &cpuset)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user