c++ - std::atomic<bool> fetch_and() and fetch_or() realization -
c++11 doc defines std::atomic::fetch_or()
, std::atomic::fetch_and()
integral types. in way, msvc++ 2012 std::atomic<bool>
not implements functions. know why?
i found solution. implement specialization std::atomic_fetch_or<bool>
, std::atomic_fetch_or<and>
.
namespace std { template<> inline bool atomic_fetch_or<bool>(std::atomic<bool>* atom, bool val) { bool bres = !val; atom->compare_exchange_strong(bres, true); return bres; } template<> inline bool atomic_fetch_or_explicit<bool>(std::atomic<bool>* atom, bool val, std::memory_order order) { bool bres = !val; atom->compare_exchange_strong(bres, true, order); return bres; } template<> inline bool atomic_fetch_and<bool>(std::atomic<bool>* atom, bool val) { bool bres = true; atom->compare_exchange_strong(bres, val); return bres; } template<> inline bool atomic_fetch_and_explicit<bool>(std::atomic<bool>* atom, bool val, std::memory_order order) { bool bres = true; atom->compare_exchange_strong(bres, val, order); return bres; } }
unfortunately inconvenient use if built-in operators.
Comments
Post a Comment