opencv/3rdparty/tbb/android_additional.h

42 lines
949 B
C
Raw Normal View History

2012-02-29 09:11:01 +01:00
#include <cstdio>
2012-02-24 19:16:05 +01:00
2012-02-29 09:11:01 +01:00
static inline int getPossibleCPUs()
{
FILE* cpuPossible = fopen("/sys/devices/system/cpu/possible", "r");
if(!cpuPossible)
return 1;
2012-02-24 19:16:05 +01:00
2012-02-29 09:11:01 +01:00
char buf[2000]; //big enough for 1000 CPUs in worst possible configuration
char* pbuf = fgets(buf, sizeof(buf), cpuPossible);
fclose(cpuPossible);
if(!pbuf)
return 1;
2012-02-24 19:16:05 +01:00
2012-02-29 09:11:01 +01:00
//parse string of form "0-1,3,5-7,10,13-15"
int cpusAvailable = 0;
2012-02-24 19:16:05 +01:00
2012-02-29 09:11:01 +01:00
while(*pbuf)
{
const char* pos = pbuf;
bool range = false;
while(*pbuf && *pbuf != ',')
{
if(*pbuf == '-') range = true;
++pbuf;
}
if(*pbuf) *pbuf++ = 0;
if(!range)
++cpusAvailable;
else
{
int rstart = 0, rend = 0;
sscanf(pos, "%d-%d", &rstart, &rend);
cpusAvailable += rend - rstart + 1;
}
2012-10-17 09:12:04 +02:00
2012-02-29 09:11:01 +01:00
}
return cpusAvailable ? cpusAvailable : 1;
2012-02-24 19:16:05 +01:00
}
2012-02-29 09:11:01 +01:00
#define __TBB_HardwareConcurrency() getPossibleCPUs()