Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2007-11-26 12:01:09


Author: anthonyw
Date: 2007-11-26 12:01:08 EST (Mon, 26 Nov 2007)
New Revision: 41401
URL: http://svn.boost.org/trac/boost/changeset/41401

Log:
once_flag uses zero-initialization on POSIX as well as windows
Text files modified:
   trunk/boost/thread/pthread/once.hpp | 12 ++++++------
   trunk/libs/thread/src/pthread/once.cpp | 5 +++--
   2 files changed, 9 insertions(+), 8 deletions(-)

Modified: trunk/boost/thread/pthread/once.hpp
==============================================================================
--- trunk/boost/thread/pthread/once.hpp (original)
+++ trunk/boost/thread/pthread/once.hpp 2007-11-26 12:01:08 EST (Mon, 26 Nov 2007)
@@ -14,8 +14,8 @@
 #include <pthread.h>
 #include <boost/assert.hpp>
 #include "pthread_mutex_scoped_lock.hpp"
-#include <boost/cstdint.hpp>
 #include <boost/thread/pthread/pthread_mutex_scoped_lock.hpp>
+#include <boost/cstdint.hpp>
 
 namespace boost {
 
@@ -32,7 +32,7 @@
         BOOST_THREAD_DECL extern pthread_cond_t once_epoch_cv;
     }
     
-#define BOOST_ONCE_INITIAL_FLAG_VALUE -1
+#define BOOST_ONCE_INITIAL_FLAG_VALUE 0
 #define BOOST_ONCE_INIT {BOOST_ONCE_INITIAL_FLAG_VALUE}
 
 
@@ -42,15 +42,15 @@
     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;
+ 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();
         
- if(epoch>this_thread_epoch)
+ if(epoch<this_thread_epoch)
         {
             pthread::pthread_mutex_scoped_lock lk(&detail::once_epoch_mutex);
 
- while(flag.epoch>=being_initialized)
+ while(flag.epoch<=being_initialized)
             {
                 if(flag.epoch==uninitialized_flag)
                 {
@@ -66,7 +66,7 @@
                         BOOST_VERIFY(!pthread_cond_broadcast(&detail::once_epoch_cv));
                         throw;
                     }
- flag.epoch=++detail::once_global_epoch;
+ flag.epoch=--detail::once_global_epoch;
                     BOOST_VERIFY(!pthread_cond_broadcast(&detail::once_epoch_cv));
                 }
                 else

Modified: trunk/libs/thread/src/pthread/once.cpp
==============================================================================
--- trunk/libs/thread/src/pthread/once.cpp (original)
+++ trunk/libs/thread/src/pthread/once.cpp 2007-11-26 12:01:08 EST (Mon, 26 Nov 2007)
@@ -3,6 +3,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
 #include <boost/thread/once.hpp>
 #include <boost/assert.hpp>
 #include <pthread.h>
@@ -12,7 +13,7 @@
 {
     namespace detail
     {
- BOOST_THREAD_DECL boost::uintmax_t once_global_epoch=0;
+ BOOST_THREAD_DECL boost::uintmax_t once_global_epoch=UINTMAX_C(~0);
         BOOST_THREAD_DECL pthread_mutex_t once_epoch_mutex=PTHREAD_MUTEX_INITIALIZER;
         BOOST_THREAD_DECL pthread_cond_t once_epoch_cv = PTHREAD_COND_INITIALIZER;
 
@@ -41,7 +42,7 @@
             {
                 data=malloc(sizeof(boost::uintmax_t));
                 BOOST_VERIFY(!pthread_setspecific(epoch_tss_key,data));
- *static_cast<boost::uintmax_t*>(data)=0;
+ *static_cast<boost::uintmax_t*>(data)=UINTMAX_C(~0);
             }
             return *static_cast<boost::uintmax_t*>(data);
         }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk