From 8334f4e68a992dce2ea076bb55d3758d02b37bc1 Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Sun, 12 Aug 2012 18:31:09 +0000 Subject: [PATCH] Thread: name type for pthread/once epoch so that we can choose better an /atomic/ type for it [SVN r79984] --- include/boost/thread/pthread/once.hpp | 22 ++++++++++++++-------- src/pthread/once.cpp | 10 +++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/boost/thread/pthread/once.hpp b/include/boost/thread/pthread/once.hpp index 80aa09ee..bc3b5b7c 100644 --- a/include/boost/thread/pthread/once.hpp +++ b/include/boost/thread/pthread/once.hpp @@ -25,6 +25,12 @@ namespace boost #define BOOST_ONCE_INITIAL_FLAG_VALUE 0 + namespace thread_detail + { + typedef unsigned long uintmax_atomic_t; +#define BOOST_THREAD_DETAIL_UINTMAX_ATOMIC_C(value) value##ul + } + #ifdef BOOST_THREAD_PROVIDES_ONCE_CXX11 struct once_flag @@ -34,7 +40,7 @@ namespace boost : epoch(BOOST_ONCE_INITIAL_FLAG_VALUE) {} private: - boost::uintmax_t epoch; + volatile thread_detail::uintmax_atomic_t epoch; template friend void call_once(once_flag& flag,Function f); @@ -44,7 +50,7 @@ namespace boost struct once_flag { - boost::uintmax_t epoch; + volatile thread_detail::uintmax_atomic_t epoch; }; #define BOOST_ONCE_INIT {BOOST_ONCE_INITIAL_FLAG_VALUE} @@ -52,8 +58,8 @@ namespace boost namespace detail { - BOOST_THREAD_DECL boost::uintmax_t& get_once_per_thread_epoch(); - BOOST_THREAD_DECL extern boost::uintmax_t once_global_epoch; + BOOST_THREAD_DECL thread_detail::uintmax_atomic_t& get_once_per_thread_epoch(); + BOOST_THREAD_DECL extern thread_detail::uintmax_atomic_t once_global_epoch; BOOST_THREAD_DECL extern pthread_mutex_t once_epoch_mutex; BOOST_THREAD_DECL extern pthread_cond_t once_epoch_cv; } @@ -63,10 +69,10 @@ namespace boost template void call_once(once_flag& flag,Function f) { - static boost::uintmax_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE; - static boost::uintmax_t const being_initialized=uninitialized_flag+1; - boost::uintmax_t const epoch=flag.epoch; - boost::uintmax_t& this_thread_epoch=detail::get_once_per_thread_epoch(); + static thread_detail::uintmax_atomic_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE; + static thread_detail::uintmax_atomic_t const being_initialized=uninitialized_flag+1; + thread_detail::uintmax_atomic_t const epoch=flag.epoch; + thread_detail::uintmax_atomic_t& this_thread_epoch=detail::get_once_per_thread_epoch(); if(epoch(data)=UINTMAX_C(~0); + *static_cast(data)=BOOST_THREAD_DETAIL_UINTMAX_ATOMIC_C(~0); } - return *static_cast(data); + return *static_cast(data); } }