mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge pull request #19029 from diablodale:fix19004-memthreadstart
add thread-safe startup of fastMalloc and fastFree * add perf test core memory allocation * fix threading in isAlignedAllocationEnabled() * tweaks requested by maintainer
This commit is contained in:
@@ -100,25 +100,27 @@ static bool readMemoryAlignmentParameter()
|
||||
// TODO add checks for valgrind, ASAN if value == false
|
||||
return value;
|
||||
}
|
||||
|
||||
#if defined _MSC_VER
|
||||
#pragma warning(suppress:4714) // preventive: const marked as __forceinline not inlined
|
||||
static __forceinline
|
||||
#else
|
||||
static inline
|
||||
#endif
|
||||
bool isAlignedAllocationEnabled()
|
||||
{
|
||||
static bool initialized = false;
|
||||
static bool useMemalign = true;
|
||||
if (!initialized)
|
||||
{
|
||||
initialized = true; // trick to avoid stuck in acquire (works only if allocations are scope based)
|
||||
useMemalign = readMemoryAlignmentParameter();
|
||||
}
|
||||
// use construct on first use idiom https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use
|
||||
// details: https://github.com/opencv/opencv/issues/15691
|
||||
static bool useMemalign = readMemoryAlignmentParameter();
|
||||
return useMemalign;
|
||||
}
|
||||
// do not use variable directly, details: https://github.com/opencv/opencv/issues/15691
|
||||
|
||||
// need for this static const is disputed; retaining as it doesn't cause harm
|
||||
static const bool g_force_initialization_memalign_flag
|
||||
#if defined __GNUC__
|
||||
__attribute__((unused))
|
||||
#endif
|
||||
= isAlignedAllocationEnabled();
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef OPENCV_ALLOC_ENABLE_STATISTICS
|
||||
|
||||
Reference in New Issue
Block a user