Fix #17299, fix setAffinity for android (#17574)

* Fix #17299

* Comment

* Fix typo
This commit is contained in:
Clyybber
2021-03-30 08:05:37 +02:00
committed by GitHub
parent 8db93fd0a2
commit a672ec3c9e

View File

@@ -194,8 +194,23 @@ else:
proc cpusetIncl(cpu: cint; s: var CpuSet) {.
importc: "CPU_SET", header: schedh.}
proc setAffinity(thread: SysThread; setsize: csize_t; s: var CpuSet) {.
importc: "pthread_setaffinity_np", header: pthreadh.}
when defined(android):
# libc of android doesn't implement pthread_setaffinity_np,
# it exposes pthread_gettid_np though, so we can use that in combination
# with sched_setaffinity to set the thread affinity.
type Pid {.importc: "pid_t", header: "<sys/types.h>".} = int32 # From posix_other.nim
proc setAffinityTID(tid: Pid; setsize: csize_t; s: var CpuSet) {.
importc: "sched_setaffinity", header: schedh.}
proc pthread_gettid_np(thread: SysThread): Pid {.
importc: "pthread_gettid_np", header: pthreadh.}
proc setAffinity(thread: SysThread; setsize: csize_t; s: var CpuSet) =
setAffinityTID(pthread_gettid_np(thread), setsize, s)
else:
proc setAffinity(thread: SysThread; setsize: csize_t; s: var CpuSet) {.
importc: "pthread_setaffinity_np", header: pthreadh.}
const