
I'm interested in getting something like "needs_lock" below into the normal traits, perhaps as part of boost thread. It informs you whether of not an operation on such a contiguous block needs a lock to be atomic. For example, on ia32 32 bit aligned ops are atomic, on ia64 it is 64 bit. doubles on ia32 need locking to be atomic, on ia64 they don't. sizeof(void*) works generically for these two platforms as is included in the code below. A default, safety first implementation might return true always for needs lock, or perhaps, true for all sizeof's greater than a byte. "Ifdef" hell for platforms can read to readability problems and big config.hpp equivalents. An alternative is to redirect headers to generic, where possible, or platform specific headers, where necessary, but this may lead to a bit of a maintenance nightmare due to supporting similar code for different platforms even though the code is typically much more readable. Another often intertwined approach is to include a platform independent api/function layer that is then used by the library, e.g. ACE's os.h. Any suggestions on best practice for this? Regards, Matt Hurd matthurd@acm.org www.hurd.com.au /*_____________________________________________________________________ created: 2004-6-7 16:20 filename: needs_lock.hpp author: Matt Hurd _______________________________________________________________________*/ #ifndef NEEDS_LOCK_HPP_200467 #define NEEDS_LOCK_HPP_200467 #include <boost/type_traits.hpp> #include "boost/type_traits/is_integral.hpp" #include "boost/type_traits/is_float.hpp" #include "boost/type_traits/detail/ice_or.hpp" #include "boost/config.hpp" // should be the last #include #include "boost/type_traits/detail/bool_trait_def.hpp" namespace boost { namespace detail { template< typename T > struct needs_lock_impl { BOOST_STATIC_CONSTANT(bool, value = (sizeof(T) > sizeof( void *)) ); }; } // namespace detail BOOST_TT_AUX_BOOL_TRAIT_DEF1(needs_lock,T,::boost::detail::needs_lock_impl<T>::value) } // namespace boost #include "boost/type_traits/detail/bool_trait_undef.hpp" #endif