add_definitions(-D__TBB_DYNAMIC_LOAD_ENABLED=0 #required
-D__TBB_BUILD=1 #required
- -D__TBB_USE_GENERIC_DWORD_LOAD_STORE=1 #needed by TBB 4.0 update 1,2
- -D__TBB_TASK_CPP_DIRECTLY_INCLUDED=1 #needed by TBB 4.0 update 3
+ -D__TBB_SURVIVE_THREAD_SWITCH=0 #no cilk on Android
+ -D__TBB_USE_GENERIC_DWORD_LOAD_STORE=1 #needed by TBB 4.0 update 1,2; fixed in TBB 4.0 update 3 but it has 2 new problems
+ -DUSE_PTHREAD #required
-DTBB_USE_GCC_BUILTINS=1 #required
-DTBB_USE_DEBUG=0 #just ot be sure
-DTBB_NO_LEGACY=1 #don't need backward compatibility
- -DUSE_PTHREAD #required
-DDO_ITT_NOTIFY=0 #it seems that we don't need these notifications
)
-add_library(tbb STATIC ${lib_srcs} ${lib_hdrs})
+add_library(tbb STATIC ${lib_srcs} ${lib_hdrs} "${CMAKE_CURRENT_SOURCE_DIR}/android_additional.h" "${CMAKE_CURRENT_SOURCE_DIR}/version_string.tmp")
target_link_libraries(tbb c m dl)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -include \"${CMAKE_CURRENT_SOURCE_DIR}/android_additional.h\"")
-#include <sys/syscall.h>
-#include <pthread.h>
+#include <cstdio>
-typedef unsigned long cpu_set_t;
-#define __NCPUBITS (8 * sizeof (unsigned long))
-
-
-#define CPU_SET(cpu, cpusetp) \
- ((*(cpusetp)) |= (1UL << ((cpu) % __NCPUBITS)))
+static inline int getPossibleCPUs()
+{
+ FILE* cpuPossible = fopen("/sys/devices/system/cpu/possible", "r");
+ if(!cpuPossible)
+ return 1;
-#define CPU_ISSET(cpu, cpusetp) \
- ((*(cpusetp)) & (1UL << ((cpu) % __NCPUBITS)))
+ 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;
-#define CPU_ZERO(cpusetp) \
- memset((cpusetp), 0, sizeof(cpu_set_t))
+ //parse string of form "0-1,3,5-7,10,13-15"
+ int cpusAvailable = 0;
-inline static int
-sched_setaffinity(pid_t pid, size_t len, cpu_set_t const * cpusetp)
-{
- return syscall(__NR_sched_setaffinity, pid, len, cpusetp);
+ 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;
+ }
+
+ }
+ return cpusAvailable ? cpusAvailable : 1;
}
-inline static int
-sched_getaffinity(pid_t pid, size_t len, cpu_set_t const * cpusetp)
-{
- return syscall(__NR_sched_getaffinity, pid, len, cpusetp);
-}
+#define __TBB_HardwareConcurrency() getPossibleCPUs()