2
0
mirror of https://github.com/boostorg/thread.git synced 2026-01-29 08:02:12 +00:00

Thread: name type for pthread/once epoch so that we can choose better an /atomic/ type for it

[SVN r79984]
This commit is contained in:
Vicente J. Botet Escriba
2012-08-12 18:31:09 +00:00
parent 1ac7e7129d
commit 8334f4e68a
2 changed files with 19 additions and 13 deletions

View File

@@ -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<typename Function>
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<typename Function>
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<this_thread_epoch)
{