Fixed tbb hang in Android apps
This commit is contained in:
8
3rdparty/tbb/CMakeLists.txt
vendored
8
3rdparty/tbb/CMakeLists.txt
vendored
@@ -92,16 +92,16 @@ list(APPEND lib_srcs "${tbb_src_dir}/src/rml/client/rml_tbb.cpp")
|
|||||||
|
|
||||||
add_definitions(-D__TBB_DYNAMIC_LOAD_ENABLED=0 #required
|
add_definitions(-D__TBB_DYNAMIC_LOAD_ENABLED=0 #required
|
||||||
-D__TBB_BUILD=1 #required
|
-D__TBB_BUILD=1 #required
|
||||||
-D__TBB_USE_GENERIC_DWORD_LOAD_STORE=1 #needed by TBB 4.0 update 1,2
|
-D__TBB_SURVIVE_THREAD_SWITCH=0 #no cilk on Android
|
||||||
-D__TBB_TASK_CPP_DIRECTLY_INCLUDED=1 #needed by TBB 4.0 update 3
|
-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_GCC_BUILTINS=1 #required
|
||||||
-DTBB_USE_DEBUG=0 #just ot be sure
|
-DTBB_USE_DEBUG=0 #just ot be sure
|
||||||
-DTBB_NO_LEGACY=1 #don't need backward compatibility
|
-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
|
-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)
|
target_link_libraries(tbb c m dl)
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -include \"${CMAKE_CURRENT_SOURCE_DIR}/android_additional.h\"")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -include \"${CMAKE_CURRENT_SOURCE_DIR}/android_additional.h\"")
|
||||||
|
|||||||
58
3rdparty/tbb/android_additional.h
vendored
58
3rdparty/tbb/android_additional.h
vendored
@@ -1,27 +1,41 @@
|
|||||||
#include <sys/syscall.h>
|
#include <cstdio>
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
typedef unsigned long cpu_set_t;
|
static inline int getPossibleCPUs()
|
||||||
#define __NCPUBITS (8 * sizeof (unsigned long))
|
|
||||||
|
|
||||||
|
|
||||||
#define CPU_SET(cpu, cpusetp) \
|
|
||||||
((*(cpusetp)) |= (1UL << ((cpu) % __NCPUBITS)))
|
|
||||||
|
|
||||||
#define CPU_ISSET(cpu, cpusetp) \
|
|
||||||
((*(cpusetp)) & (1UL << ((cpu) % __NCPUBITS)))
|
|
||||||
|
|
||||||
#define CPU_ZERO(cpusetp) \
|
|
||||||
memset((cpusetp), 0, sizeof(cpu_set_t))
|
|
||||||
|
|
||||||
inline static int
|
|
||||||
sched_setaffinity(pid_t pid, size_t len, cpu_set_t const * cpusetp)
|
|
||||||
{
|
{
|
||||||
return syscall(__NR_sched_setaffinity, pid, len, cpusetp);
|
FILE* cpuPossible = fopen("/sys/devices/system/cpu/possible", "r");
|
||||||
|
if(!cpuPossible)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
//parse string of form "0-1,3,5-7,10,13-15"
|
||||||
|
int cpusAvailable = 0;
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static int
|
|
||||||
sched_getaffinity(pid_t pid, size_t len, cpu_set_t const * cpusetp)
|
|
||||||
{
|
|
||||||
return syscall(__NR_sched_getaffinity, pid, len, cpusetp);
|
|
||||||
}
|
}
|
||||||
|
return cpusAvailable ? cpusAvailable : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define __TBB_HardwareConcurrency() getPossibleCPUs()
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
|
|||||||
# Profiling?
|
# Profiling?
|
||||||
if(ENABLE_PROFILING)
|
if(ENABLE_PROFILING)
|
||||||
set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -pg -g")
|
set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -pg -g")
|
||||||
elseif(NOT APPLE)
|
elseif(NOT APPLE AND NOT ANDROID)
|
||||||
# Remove unreferenced functions: function level linking
|
# Remove unreferenced functions: function level linking
|
||||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -ffunction-sections")
|
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -ffunction-sections")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user