$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r82905 - in trunk: boost/thread/pthread libs/thread/src/pthread
From: vicente.botet_at_[hidden]
Date: 2013-02-15 12:05:51
Author: viboes
Date: 2013-02-15 12:05:49 EST (Fri, 15 Feb 2013)
New Revision: 82905
URL: http://svn.boost.org/trac/boost/changeset/82905
Log:
Thread: make use of atomic on the header of once_atomic to avoid not needed cast that report some warnings.
Text files modified: 
   trunk/boost/thread/pthread/once_atomic.hpp    |    50 ++++++++++++++++++++++++++++++++++++----
   trunk/libs/thread/src/pthread/once_atomic.cpp |    31 +++++-------------------                
   2 files changed, 52 insertions(+), 29 deletions(-)
Modified: trunk/boost/thread/pthread/once_atomic.hpp
==============================================================================
--- trunk/boost/thread/pthread/once_atomic.hpp	(original)
+++ trunk/boost/thread/pthread/once_atomic.hpp	2013-02-15 12:05:49 EST (Fri, 15 Feb 2013)
@@ -17,6 +17,7 @@
 #include <boost/thread/detail/invoke.hpp>
 #include <boost/detail/no_exceptions_support.hpp>
 #include <boost/bind.hpp>
+#include <boost/atomic.hpp>
 
 #include <boost/config/abi_prefix.hpp>
 
@@ -27,9 +28,28 @@
 
   namespace thread_detail
   {
+
+#if BOOST_ATOMIC_INT_LOCK_FREE == 2
+    typedef unsigned int atomic_int_type;
+#elif BOOST_ATOMIC_SHORT_LOCK_FREE == 2
+    typedef unsigned short atomic_int_type;
+#elif BOOST_ATOMIC_CHAR_LOCK_FREE == 2
+    typedef unsigned char atomic_int_type;
+#elif BOOST_ATOMIC_LONG_LOCK_FREE == 2
+    typedef unsigned long atomic_int_type;
+#elif defined(BOOST_HAS_LONG_LONG) && BOOST_ATOMIC_LLONG_LOCK_FREE == 2
+    typedef ulong_long_type atomic_int_type;
+#else
+    // All tested integer types are not atomic, the spinlock pool will be used
+    typedef unsigned int atomic_int_type;
+#endif
+
+    typedef boost::atomic<atomic_int_type> atomic_type;
+
     BOOST_THREAD_DECL bool enter_once_region(once_flag& flag) BOOST_NOEXCEPT;
     BOOST_THREAD_DECL void commit_once_region(once_flag& flag) BOOST_NOEXCEPT;
     BOOST_THREAD_DECL void rollback_once_region(once_flag& flag) BOOST_NOEXCEPT;
+    inline atomic_type& get_atomic_storage(once_flag& flag)  BOOST_NOEXCEPT;
   }
 
 #ifdef BOOST_THREAD_PROVIDES_ONCE_CXX11
@@ -42,29 +62,49 @@
     }
 
   private:
-  #if defined(__GNUC__)
-    __attribute__((may_alias))
-  #endif
-    uintmax_t storage;
+//  #if defined(__GNUC__)
+//    __attribute__((may_alias))
+//  #endif
+//    thread_detail::atomic_int_type storage;
+    thread_detail::atomic_type storage;
 
     friend BOOST_THREAD_DECL bool thread_detail::enter_once_region(once_flag& flag) BOOST_NOEXCEPT;
     friend BOOST_THREAD_DECL void thread_detail::commit_once_region(once_flag& flag) BOOST_NOEXCEPT;
     friend BOOST_THREAD_DECL void thread_detail::rollback_once_region(once_flag& flag) BOOST_NOEXCEPT;
+    friend thread_detail::atomic_type& thread_detail::get_atomic_storage(once_flag& flag) BOOST_NOEXCEPT;
   };
 
 #define BOOST_ONCE_INIT boost::once_flag()
 
+  namespace thread_detail
+  {
+    inline atomic_type& get_atomic_storage(once_flag& flag) BOOST_NOEXCEPT
+    {
+      //return reinterpret_cast< atomic_type& >(flag.storage);
+      return flag.storage;
+    }
+  }
+
 #else // BOOST_THREAD_PROVIDES_ONCE_CXX11
   struct once_flag
   {
   #if defined(__GNUC__)
     __attribute__((may_alias))
   #endif
-    uintmax_t storage;
+    thread_detail::atomic_int_type storage;
   };
 
   #define BOOST_ONCE_INIT {0}
 
+  namespace thread_detail
+  {
+    inline atomic_type& get_atomic_storage(once_flag& flag) BOOST_NOEXCEPT
+    {
+      return reinterpret_cast< atomic_type& >(flag.storage);
+    }
+
+  }
+
 #endif // BOOST_THREAD_PROVIDES_ONCE_CXX11
 
 #ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
Modified: trunk/libs/thread/src/pthread/once_atomic.cpp
==============================================================================
--- trunk/libs/thread/src/pthread/once_atomic.cpp	(original)
+++ trunk/libs/thread/src/pthread/once_atomic.cpp	2013-02-15 12:05:49 EST (Fri, 15 Feb 2013)
@@ -4,7 +4,7 @@
 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
-#define __STDC_CONSTANT_MACROS
+//#define __STDC_CONSTANT_MACROS
 #include <boost/thread/detail/config.hpp>
 #include <boost/thread/once.hpp>
 #include <boost/thread/pthread/pthread_mutex_scoped_lock.hpp>
@@ -24,34 +24,17 @@
       uninitialized, in_progress, initialized
     };
 
-#if BOOST_ATOMIC_INT_LOCK_FREE == 2
-    typedef unsigned int atomic_int_type;
-#elif BOOST_ATOMIC_SHORT_LOCK_FREE == 2
-    typedef unsigned short atomic_int_type;
-#elif BOOST_ATOMIC_CHAR_LOCK_FREE == 2
-    typedef unsigned char atomic_int_type;
-#elif BOOST_ATOMIC_LONG_LOCK_FREE == 2
-    typedef unsigned long atomic_int_type;
-#elif defined(BOOST_HAS_LONG_LONG) && BOOST_ATOMIC_LLONG_LOCK_FREE == 2
-    typedef ulong_long_type atomic_int_type;
-#else
-    // All tested integer types are not atomic, the spinlock pool will be used
-    typedef unsigned int atomic_int_type;
-#endif
 
-    typedef boost::atomic<atomic_int_type> atomic_type
-    //#if defined(__GNUC__)
-    //    __attribute__((may_alias))
-    //#endif
-    ;
-    BOOST_STATIC_ASSERT_MSG(sizeof(once_flag) >= sizeof(atomic_type), "Boost.Thread: unsupported platform");
+#ifndef BOOST_THREAD_PROVIDES_ONCE_CXX11
+    BOOST_STATIC_ASSERT_MSG(sizeof(atomic_int_type) == sizeof(atomic_type), "Boost.Thread: unsupported platform");
+#endif
 
     static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
     static pthread_cond_t once_cv = PTHREAD_COND_INITIALIZER;
 
     BOOST_THREAD_DECL bool enter_once_region(once_flag& flag) BOOST_NOEXCEPT
     {
-      atomic_type& f = reinterpret_cast< atomic_type& >(flag.storage);
+      atomic_type& f = get_atomic_storage(flag);
       if (f.load(memory_order_acquire) != initialized)
       {
         pthread::pthread_mutex_scoped_lock lk(&once_mutex);
@@ -84,7 +67,7 @@
 
     BOOST_THREAD_DECL void commit_once_region(once_flag& flag) BOOST_NOEXCEPT
     {
-      atomic_type& f = reinterpret_cast< atomic_type& >(flag.storage);
+      atomic_type& f = get_atomic_storage(flag);
       {
         pthread::pthread_mutex_scoped_lock lk(&once_mutex);
         f.store(initialized, memory_order_release);
@@ -94,7 +77,7 @@
 
     BOOST_THREAD_DECL void rollback_once_region(once_flag& flag) BOOST_NOEXCEPT
     {
-      atomic_type& f = reinterpret_cast< atomic_type& >(flag.storage);
+      atomic_type& f = get_atomic_storage(flag);
       {
         pthread::pthread_mutex_scoped_lock lk(&once_mutex);
         f.store(uninitialized, memory_order_release);