Android set thread affinity

后端 未结 3 1456
余生分开走
余生分开走 2021-01-05 08:59

Following the answer from this StackOverflow question how do I create the proper integer for mask?

I made some googling and the everything I found uses CPU_SE

3条回答
  •  無奈伤痛
    2021-01-05 09:38

    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))
    

    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.

提交回复
热议问题