mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-05 11:40:40 +08:00
Fix bug #466: race condition destected by helgrind in manage_caching_sizes.
After all, the solution based on threadprivate is not that costly. (transplanted from f2849fac20fd4ef756d5c86b3f1264491645d217 )
This commit is contained in:
parent
bfe9b35152
commit
15b1558483
@ -30,7 +30,8 @@ namespace internal {
|
|||||||
template<typename _LhsScalar, typename _RhsScalar, bool _ConjLhs=false, bool _ConjRhs=false>
|
template<typename _LhsScalar, typename _RhsScalar, bool _ConjLhs=false, bool _ConjRhs=false>
|
||||||
class gebp_traits;
|
class gebp_traits;
|
||||||
|
|
||||||
inline std::ptrdiff_t manage_caching_sizes_second_if_negative(std::ptrdiff_t a, std::ptrdiff_t b)
|
/** \internal \returns b if a<=0, and returns a otherwise. */
|
||||||
|
inline std::ptrdiff_t manage_caching_sizes_helper(std::ptrdiff_t a, std::ptrdiff_t b)
|
||||||
{
|
{
|
||||||
return a<=0 ? b : a;
|
return a<=0 ? b : a;
|
||||||
}
|
}
|
||||||
@ -38,8 +39,14 @@ inline std::ptrdiff_t manage_caching_sizes_second_if_negative(std::ptrdiff_t a,
|
|||||||
/** \internal */
|
/** \internal */
|
||||||
inline void manage_caching_sizes(Action action, std::ptrdiff_t* l1=0, std::ptrdiff_t* l2=0)
|
inline void manage_caching_sizes(Action action, std::ptrdiff_t* l1=0, std::ptrdiff_t* l2=0)
|
||||||
{
|
{
|
||||||
static std::ptrdiff_t m_l1CacheSize = manage_caching_sizes_second_if_negative(queryL1CacheSize(),8 * 1024);
|
static std::ptrdiff_t m_l1CacheSize = 0;
|
||||||
static std::ptrdiff_t m_l2CacheSize = manage_caching_sizes_second_if_negative(queryTopLevelCacheSize(),1*1024*1024);
|
static std::ptrdiff_t m_l2CacheSize = 0;
|
||||||
|
#pragma omp threadprivate(m_l1CacheSize,m_l2CacheSize)
|
||||||
|
if(m_l1CacheSize==0)
|
||||||
|
{
|
||||||
|
m_l1CacheSize = manage_caching_sizes_helper(queryL1CacheSize(),8 * 1024);
|
||||||
|
m_l2CacheSize = manage_caching_sizes_helper(queryTopLevelCacheSize(),1*1024*1024);
|
||||||
|
}
|
||||||
|
|
||||||
if(action==SetAction)
|
if(action==SetAction)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user