继this StackOverflow的问题的如何创建正确的 整数面具?
Following the answer from this StackOverflow question how do I create the proper integer for mask?
我做了一些google搜索的一切,我发现使用 CPU_SET
宏从 sched.h中
,但它运行在 cpu_set_t
结构使用NDK时,这是不确定的。当尝试使用 CPU_SET
链接给我未定义的引用错误(尽管我反对的pthread链接)。
I made some googling and the everything I found uses CPU_SET
macro from sched.h
but it operates on cpu_set_t
structures which are undefined when using NDK. When try using CPU_SET
linker gives me undefined reference error (even though I link against pthread).
那么,在最后,我发现这是直接从 sched.h中
采取了一些版本。林张贴此位置如果任何人有同样的问题,不希望花时间寻找它。这是非常有用的。
Well, in the end I found some version which was taken directly from sched.h
. Im posting this here if anyone has the same problem and doesn't want to spend the time searching for it. This is quite useful.
#define CPU_SETSIZE 1024
#define __NCPUBITS (8 * sizeof (unsigned long))
typedef struct
{
unsigned long __bits[CPU_SETSIZE / __NCPUBITS];
} cpu_set_t;
#define CPU_SET(cpu, cpusetp) \
((cpusetp)->__bits[(cpu)/__NCPUBITS] |= (1UL << ((cpu) % __NCPUBITS)))
#define CPU_ZERO(cpusetp) \
memset((cpusetp), 0, sizeof(cpu_set_t))
这工作得很好,当在参数类型原 setCurrentThreadAffinityMask
(从问题中提到的职位)仅被替换 cpu_set_t
。
This works well when the parameter type in the original setCurrentThreadAffinityMask
(from the post mentioned in the question) is simply replaced with cpu_set_t
.