Boost logo

Boost-Commit :

From: nicola.musatti_at_[hidden]
Date: 2007-10-09 16:52:03


Author: nmusatti
Date: 2007-10-09 16:52:02 EDT (Tue, 09 Oct 2007)
New Revision: 39861
URL: http://svn.boost.org/trac/boost/changeset/39861

Log:
Merge from trunk
Added:
   branches/bcbboost/boost/thread/locks.hpp
      - copied unchanged from r39819, /trunk/boost/thread/locks.hpp
   branches/bcbboost/boost/thread/pthread/mutex.hpp
      - copied unchanged from r39819, /trunk/boost/thread/pthread/mutex.hpp
   branches/bcbboost/boost/thread/pthread/recursive_mutex.hpp
      - copied unchanged from r39819, /trunk/boost/thread/pthread/recursive_mutex.hpp
   branches/bcbboost/boost/thread/pthread/timespec.hpp
      - copied unchanged from r39819, /trunk/boost/thread/pthread/timespec.hpp
   branches/bcbboost/boost/thread/thread_time.hpp
      - copied unchanged from r39819, /trunk/boost/thread/thread_time.hpp
   branches/bcbboost/boost/thread/win32/basic_recursive_mutex.hpp
      - copied unchanged from r39819, /trunk/boost/thread/win32/basic_recursive_mutex.hpp
   branches/bcbboost/boost/thread/win32/basic_timed_mutex.hpp
      - copied unchanged from r39819, /trunk/boost/thread/win32/basic_timed_mutex.hpp
   branches/bcbboost/boost/thread/win32/mutex.hpp
      - copied unchanged from r39819, /trunk/boost/thread/win32/mutex.hpp
   branches/bcbboost/boost/thread/win32/recursive_mutex.hpp
      - copied unchanged from r39819, /trunk/boost/thread/win32/recursive_mutex.hpp
Text files modified:
   branches/bcbboost/boost/thread/condition.hpp | 48 ++++-----
   branches/bcbboost/boost/thread/mutex.hpp | 177 ++----------------------------------
   branches/bcbboost/boost/thread/once.hpp | 19 +--
   branches/bcbboost/boost/thread/recursive_mutex.hpp | 191 ++-------------------------------------
   branches/bcbboost/boost/thread/win32/interlocked_read.hpp | 24 ++++
   branches/bcbboost/boost/thread/win32/thread_primitives.hpp | 18 +++
   6 files changed, 89 insertions(+), 388 deletions(-)

Modified: branches/bcbboost/boost/thread/condition.hpp
==============================================================================
--- branches/bcbboost/boost/thread/condition.hpp (original)
+++ branches/bcbboost/boost/thread/condition.hpp 2007-10-09 16:52:02 EDT (Tue, 09 Oct 2007)
@@ -1,5 +1,6 @@
 // Copyright (C) 2001-2003
 // William E. Kempf
+// Copyright (C) 2007 Anthony Williams
 //
 // 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)
@@ -61,6 +62,7 @@
                         // still waiting to be removed from m_queue
 #elif defined(BOOST_HAS_PTHREADS)
     pthread_cond_t m_condition;
+ pthread_mutex_t m_mutex;
 #elif defined(BOOST_HAS_MPTASKS)
     MPSemaphoreID m_gate;
     MPSemaphoreID m_queue;
@@ -90,7 +92,7 @@
         if (!lock)
             throw lock_error();
 
- do_wait(lock.m_mutex);
+ do_wait(*lock.mutex());
     }
 
     template <typename L, typename Pr>
@@ -100,7 +102,7 @@
             throw lock_error();
 
         while (!pred())
- do_wait(lock.m_mutex);
+ do_wait(*lock.mutex());
     }
 
     template <typename L>
@@ -109,7 +111,7 @@
         if (!lock)
             throw lock_error();
 
- return do_timed_wait(lock.m_mutex, xt);
+ return do_timed_wait(*lock.mutex(), xt);
     }
 
     template <typename L, typename Pr>
@@ -120,7 +122,7 @@
 
         while (!pred())
         {
- if (!do_timed_wait(lock.m_mutex, xt))
+ if (!do_timed_wait(*lock.mutex(), xt))
                 return false;
         }
 
@@ -135,25 +137,22 @@
     {
 #if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
         m_impl.enter_wait();
+#else
+ pthread_mutex_lock(&m_impl.m_mutex);
 #endif
 
- typedef detail::thread::lock_ops<M>
-#if defined(__HP_aCC) && __HP_aCC <= 33900 && !defined(BOOST_STRICT_CONFIG)
-# define lock_ops lock_ops_ // HP confuses lock_ops witht the template
-#endif
- lock_ops;
-
- typename lock_ops::lock_state state;
- lock_ops::unlock(mutex, state);
+ mutex.unlock();
 
 #if defined(BOOST_HAS_PTHREADS)
- m_impl.do_wait(state.pmutex);
+ m_impl.do_wait(&m_impl.m_mutex);
 #elif (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
         m_impl.do_wait();
 #endif
 
- lock_ops::lock(mutex, state);
-#undef lock_ops
+#if defined(BOOST_HAS_PTHREADS)
+ pthread_mutex_unlock(&m_impl.m_mutex);
+#endif
+ mutex.lock();
     }
 
     template <typename M>
@@ -161,27 +160,24 @@
     {
 #if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
         m_impl.enter_wait();
+#else
+ pthread_mutex_lock(&m_impl.m_mutex);
 #endif
 
- typedef detail::thread::lock_ops<M>
-#if defined(__HP_aCC) && __HP_aCC <= 33900 && !defined(BOOST_STRICT_CONFIG)
-# define lock_ops lock_ops_ // HP confuses lock_ops witht the template
-#endif
- lock_ops;
-
- typename lock_ops::lock_state state;
- lock_ops::unlock(mutex, state);
+ mutex.unlock();
 
         bool ret = false;
 
 #if defined(BOOST_HAS_PTHREADS)
- ret = m_impl.do_timed_wait(xt, state.pmutex);
+ ret = m_impl.do_timed_wait(xt, &m_impl.m_mutex);
 #elif (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
         ret = m_impl.do_timed_wait(xt);
 #endif
 
- lock_ops::lock(mutex, state);
-#undef lock_ops
+#if defined(BOOST_HAS_PTHREADS)
+ pthread_mutex_unlock(&m_impl.m_mutex);
+#endif
+ mutex.lock();
 
         return ret;
     }

Modified: branches/bcbboost/boost/thread/mutex.hpp
==============================================================================
--- branches/bcbboost/boost/thread/mutex.hpp (original)
+++ branches/bcbboost/boost/thread/mutex.hpp 2007-10-09 16:52:02 EDT (Tue, 09 Oct 2007)
@@ -1,170 +1,15 @@
-// Copyright (C) 2001-2003
-// William E. Kempf
-//
-// 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)
-
-#ifndef BOOST_MUTEX_WEK070601_HPP
-#define BOOST_MUTEX_WEK070601_HPP
-
-#include <boost/thread/detail/config.hpp>
-
-#include <boost/utility.hpp>
-#include <boost/thread/detail/lock.hpp>
-
-#if defined(BOOST_HAS_PTHREADS)
-# include <pthread.h>
-#endif
-
-#if defined(BOOST_HAS_MPTASKS)
-# include "scoped_critical_region.hpp"
-#endif
-
-namespace boost {
+#ifndef BOOST_THREAD_MUTEX_HPP
+#define BOOST_THREAD_MUTEX_HPP
 
-struct xtime;
-// disable warnings about non dll import
-// see: http://www.boost.org/more/separate_compilation.html#dlls
-#ifdef BOOST_MSVC
-# pragma warning(push)
-# pragma warning(disable: 4251 4231 4660 4275)
-#endif
-
-class BOOST_THREAD_DECL mutex
- : private noncopyable
-{
-public:
- friend class detail::thread::lock_ops<mutex>;
-
- typedef detail::thread::scoped_lock<mutex> scoped_lock;
-
- mutex();
- ~mutex();
-
-private:
-#if defined(BOOST_HAS_WINTHREADS)
- typedef void* cv_state;
-#elif defined(BOOST_HAS_PTHREADS)
- struct cv_state
- {
- pthread_mutex_t* pmutex;
- };
-#elif defined(BOOST_HAS_MPTASKS)
- struct cv_state
- {
- };
-#endif
- void do_lock();
- void do_unlock();
- void do_lock(cv_state& state);
- void do_unlock(cv_state& state);
-
-#if defined(BOOST_HAS_WINTHREADS)
- void* m_mutex;
- bool m_critical_section;
-#elif defined(BOOST_HAS_PTHREADS)
- pthread_mutex_t m_mutex;
-#elif defined(BOOST_HAS_MPTASKS)
- threads::mac::detail::scoped_critical_region m_mutex;
- threads::mac::detail::scoped_critical_region m_mutex_mutex;
-#endif
-};
-
-class BOOST_THREAD_DECL try_mutex
- : private noncopyable
-{
-public:
- friend class detail::thread::lock_ops<try_mutex>;
-
- typedef detail::thread::scoped_lock<try_mutex> scoped_lock;
- typedef detail::thread::scoped_try_lock<try_mutex> scoped_try_lock;
-
- try_mutex();
- ~try_mutex();
-
-private:
-#if defined(BOOST_HAS_WINTHREADS)
- typedef void* cv_state;
-#elif defined(BOOST_HAS_PTHREADS)
- struct cv_state
- {
- pthread_mutex_t* pmutex;
- };
-#elif defined(BOOST_HAS_MPTASKS)
- struct cv_state
- {
- };
-#endif
- void do_lock();
- bool do_trylock();
- void do_unlock();
- void do_lock(cv_state& state);
- void do_unlock(cv_state& state);
-
-#if defined(BOOST_HAS_WINTHREADS)
- void* m_mutex;
- bool m_critical_section;
-#elif defined(BOOST_HAS_PTHREADS)
- pthread_mutex_t m_mutex;
-#elif defined(BOOST_HAS_MPTASKS)
- threads::mac::detail::scoped_critical_region m_mutex;
- threads::mac::detail::scoped_critical_region m_mutex_mutex;
-#endif
-};
-
-class BOOST_THREAD_DECL timed_mutex
- : private noncopyable
-{
-public:
- friend class detail::thread::lock_ops<timed_mutex>;
-
- typedef detail::thread::scoped_lock<timed_mutex> scoped_lock;
- typedef detail::thread::scoped_try_lock<timed_mutex> scoped_try_lock;
- typedef detail::thread::scoped_timed_lock<timed_mutex> scoped_timed_lock;
-
- timed_mutex();
- ~timed_mutex();
+// mutex.hpp
+//
+// (C) Copyright 2007 Anthony Williams
+//
+// 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)
 
-private:
-#if defined(BOOST_HAS_WINTHREADS)
- typedef void* cv_state;
-#elif defined(BOOST_HAS_PTHREADS)
- struct cv_state
- {
- pthread_mutex_t* pmutex;
- };
-#elif defined(BOOST_HAS_MPTASKS)
- struct cv_state
- {
- };
-#endif
- void do_lock();
- bool do_trylock();
- bool do_timedlock(const xtime& xt);
- void do_unlock();
- void do_lock(cv_state& state);
- void do_unlock(cv_state& state);
+#include <boost/thread/detail/platform.hpp>
+#include BOOST_THREAD_PLATFORM(mutex.hpp)
 
-#if defined(BOOST_HAS_WINTHREADS)
- void* m_mutex;
-#elif defined(BOOST_HAS_PTHREADS)
- pthread_mutex_t m_mutex;
- pthread_cond_t m_condition;
- bool m_locked;
-#elif defined(BOOST_HAS_MPTASKS)
- threads::mac::detail::scoped_critical_region m_mutex;
- threads::mac::detail::scoped_critical_region m_mutex_mutex;
-#endif
-};
-#ifdef BOOST_MSVC
-# pragma warning(pop)
 #endif
-} // namespace boost
-
-// Change Log:
-// 8 Feb 01 WEKEMPF Initial version.
-// 22 May 01 WEKEMPF Modified to use xtime for time outs. Factored out
-// to three classes, mutex, try_mutex and timed_mutex.
-// 3 Jan 03 WEKEMPF Modified for DLL implementation.
-
-#endif // BOOST_MUTEX_WEK070601_HPP

Modified: branches/bcbboost/boost/thread/once.hpp
==============================================================================
--- branches/bcbboost/boost/thread/once.hpp (original)
+++ branches/bcbboost/boost/thread/once.hpp 2007-10-09 16:52:02 EDT (Tue, 09 Oct 2007)
@@ -10,19 +10,14 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 
 #include <boost/thread/detail/platform.hpp>
-#ifdef BOOST_HAS_MPTASKS
-namespace boost {
-
-typedef long once_flag;
-#define BOOST_ONCE_INIT 0
-
-void call_once(once_flag& flag, void (*func)());
-
-}
-
-#else
 #include BOOST_THREAD_PLATFORM(once.hpp)
-#endif
 
+namespace boost
+{
+ inline void call_once(void (*func)(),once_flag& flag)
+ {
+ call_once(flag,func);
+ }
+}
 
 #endif

Modified: branches/bcbboost/boost/thread/recursive_mutex.hpp
==============================================================================
--- branches/bcbboost/boost/thread/recursive_mutex.hpp (original)
+++ branches/bcbboost/boost/thread/recursive_mutex.hpp 2007-10-09 16:52:02 EDT (Tue, 09 Oct 2007)
@@ -1,184 +1,15 @@
-// Copyright (C) 2001-2003
-// William E. Kempf
-//
-// 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)
-
-#ifndef BOOST_RECURSIVE_MUTEX_WEK070601_HPP
-#define BOOST_RECURSIVE_MUTEX_WEK070601_HPP
-
-#include <boost/thread/detail/config.hpp>
-
-#include <boost/utility.hpp>
-#include <boost/thread/detail/lock.hpp>
-
-#if defined(BOOST_HAS_PTHREADS)
-# include <pthread.h>
-#endif
-
-#if defined(BOOST_HAS_MPTASKS)
-# include "scoped_critical_region.hpp"
-#endif
-
-namespace boost {
-
-struct xtime;
-// disable warnings about non dll import
-// see: http://www.boost.org/more/separate_compilation.html#dlls
-#ifdef BOOST_MSVC
-# pragma warning(push)
-# pragma warning(disable: 4251 4231 4660 4275)
-#endif
-class BOOST_THREAD_DECL recursive_mutex
- : private noncopyable
-{
-public:
- friend class detail::thread::lock_ops<recursive_mutex>;
-
- typedef detail::thread::scoped_lock<recursive_mutex> scoped_lock;
-
- recursive_mutex();
- ~recursive_mutex();
-
-private:
-#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
- typedef std::size_t cv_state;
-#elif defined(BOOST_HAS_PTHREADS)
- struct cv_state
- {
- long count;
- pthread_mutex_t* pmutex;
- };
-#endif
- void do_lock();
- void do_unlock();
- void do_lock(cv_state& state);
- void do_unlock(cv_state& state);
-
-#if defined(BOOST_HAS_WINTHREADS)
- void* m_mutex;
- bool m_critical_section;
- unsigned long m_count;
-#elif defined(BOOST_HAS_PTHREADS)
- pthread_mutex_t m_mutex;
- unsigned m_count;
-# if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE)
- pthread_cond_t m_unlocked;
- pthread_t m_thread_id;
- bool m_valid_id;
-# endif
-#elif defined(BOOST_HAS_MPTASKS)
- threads::mac::detail::scoped_critical_region m_mutex;
- threads::mac::detail::scoped_critical_region m_mutex_mutex;
- std::size_t m_count;
-#endif
-};
-
-class BOOST_THREAD_DECL recursive_try_mutex
- : private noncopyable
-{
-public:
- friend class detail::thread::lock_ops<recursive_try_mutex>;
-
- typedef detail::thread::scoped_lock<recursive_try_mutex> scoped_lock;
- typedef detail::thread::scoped_try_lock<
- recursive_try_mutex> scoped_try_lock;
-
- recursive_try_mutex();
- ~recursive_try_mutex();
-
-private:
-#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
- typedef std::size_t cv_state;
-#elif defined(BOOST_HAS_PTHREADS)
- struct cv_state
- {
- long count;
- pthread_mutex_t* pmutex;
- };
-#endif
- void do_lock();
- bool do_trylock();
- void do_unlock();
- void do_lock(cv_state& state);
- void do_unlock(cv_state& state);
-
-#if defined(BOOST_HAS_WINTHREADS)
- void* m_mutex;
- bool m_critical_section;
- unsigned long m_count;
-#elif defined(BOOST_HAS_PTHREADS)
- pthread_mutex_t m_mutex;
- unsigned m_count;
-# if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE)
- pthread_cond_t m_unlocked;
- pthread_t m_thread_id;
- bool m_valid_id;
-# endif
-#elif defined(BOOST_HAS_MPTASKS)
- threads::mac::detail::scoped_critical_region m_mutex;
- threads::mac::detail::scoped_critical_region m_mutex_mutex;
- std::size_t m_count;
-#endif
-};
+#ifndef BOOST_THREAD_RECURSIVE_MUTEX_HPP
+#define BOOST_THREAD_RECURSIVE_MUTEX_HPP
 
-class BOOST_THREAD_DECL recursive_timed_mutex
- : private noncopyable
-{
-public:
- friend class detail::thread::lock_ops<recursive_timed_mutex>;
-
- typedef detail::thread::scoped_lock<recursive_timed_mutex> scoped_lock;
- typedef detail::thread::scoped_try_lock<
- recursive_timed_mutex> scoped_try_lock;
- typedef detail::thread::scoped_timed_lock<
- recursive_timed_mutex> scoped_timed_lock;
-
- recursive_timed_mutex();
- ~recursive_timed_mutex();
+// recursive_mutex.hpp
+//
+// (C) Copyright 2007 Anthony Williams
+//
+// 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)
 
-private:
-#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
- typedef std::size_t cv_state;
-#elif defined(BOOST_HAS_PTHREADS)
- struct cv_state
- {
- long count;
- pthread_mutex_t* pmutex;
- };
-#endif
- void do_lock();
- bool do_trylock();
- bool do_timedlock(const xtime& xt);
- void do_unlock();
- void do_lock(cv_state& state);
- void do_unlock(cv_state& state);
+#include <boost/thread/detail/platform.hpp>
+#include BOOST_THREAD_PLATFORM(recursive_mutex.hpp)
 
-#if defined(BOOST_HAS_WINTHREADS)
- void* m_mutex;
- unsigned long m_count;
-#elif defined(BOOST_HAS_PTHREADS)
- pthread_mutex_t m_mutex;
- pthread_cond_t m_unlocked;
- pthread_t m_thread_id;
- bool m_valid_id;
- unsigned m_count;
-#elif defined(BOOST_HAS_MPTASKS)
- threads::mac::detail::scoped_critical_region m_mutex;
- threads::mac::detail::scoped_critical_region m_mutex_mutex;
- std::size_t m_count;
-#endif
-};
-#ifdef BOOST_MSVC
-# pragma warning(pop)
 #endif
-} // namespace boost
-
-#endif // BOOST_RECURSIVE_MUTEX_WEK070601_HPP
-
-// Change Log:
-// 8 Feb 01 WEKEMPF Initial version.
-// 1 Jun 01 WEKEMPF Modified to use xtime for time outs. Factored out
-// to three classes, mutex, try_mutex and timed_mutex.
-// 11 Jun 01 WEKEMPF Modified to use PTHREAD_MUTEX_RECURSIVE if available.
-// 3 Jan 03 WEKEMPF Modified for DLL implementation.

Modified: branches/bcbboost/boost/thread/win32/interlocked_read.hpp
==============================================================================
--- branches/bcbboost/boost/thread/win32/interlocked_read.hpp (original)
+++ branches/bcbboost/boost/thread/win32/interlocked_read.hpp 2007-10-09 16:52:02 EDT (Tue, 09 Oct 2007)
@@ -9,7 +9,7 @@
 // accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
-#include <boost/detail/interlocked.hpp>
+#ifdef BOOST_MSVC
 
 extern "C" void _ReadWriteBarrier(void);
 #pragma intrinsic(_ReadWriteBarrier)
@@ -33,4 +33,26 @@
     }
 }
 
+#else
+
+#include <boost/detail/interlocked.hpp>
+
+namespace boost
+{
+ namespace detail
+ {
+ inline long interlocked_read_acquire(long volatile* x)
+ {
+ return BOOST_INTERLOCKED_COMPARE_EXCHANGE(x,0,0);
+ }
+ inline void* interlocked_read_acquire(void* volatile* x)
+ {
+ return BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(x,0,0);
+ }
+ }
+}
+
+#endif
+
+
 #endif

Modified: branches/bcbboost/boost/thread/win32/thread_primitives.hpp
==============================================================================
--- branches/bcbboost/boost/thread/win32/thread_primitives.hpp (original)
+++ branches/bcbboost/boost/thread/win32/thread_primitives.hpp 2007-10-09 16:52:02 EDT (Tue, 09 Oct 2007)
@@ -113,13 +113,21 @@
             inline handle create_anonymous_event(event_type type,initial_event_state state)
             {
                 handle const res=CreateEventA(0,type,state,0);
- return res?res:throw thread_resource_error();
+ if(!res)
+ {
+ throw thread_resource_error();
+ }
+ return res;
             }
 
             inline handle create_anonymous_semaphore(long initial_count,long max_count)
             {
                 handle const res=CreateSemaphoreA(NULL,initial_count,max_count,NULL);
- return res?res:throw thread_resource_error();
+ if(!res)
+ {
+ throw thread_resource_error();
+ }
+ return res;
             }
 
             inline handle duplicate_handle(handle source)
@@ -128,7 +136,11 @@
                 long const same_access_flag=2;
                 handle new_handle=0;
                 bool const success=DuplicateHandle(current_process,source,current_process,&new_handle,0,false,same_access_flag)!=0;
- return success?new_handle:throw thread_resource_error();
+ if(!success)
+ {
+ throw thread_resource_error();
+ }
+ return new_handle;
             }
 
             inline void release_semaphore(handle semaphore,long count)


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