|
Boost-Commit : |
From: anthony_at_[hidden]
Date: 2008-07-23 05:35:41
Author: anthonyw
Date: 2008-07-23 05:35:40 EDT (Wed, 23 Jul 2008)
New Revision: 47700
URL: http://svn.boost.org/trac/boost/changeset/47700
Log:
Merged changes over from trunk
Text files modified:
branches/release/boost/thread/detail/move.hpp | 4
branches/release/boost/thread/detail/thread.hpp | 11 +
branches/release/boost/thread/locks.hpp | 322 +++++++++++++++++++++++++++++----------
branches/release/libs/thread/src/pthread/thread.cpp | 4
branches/release/libs/thread/test/test_generic_locks.cpp | 10 +
5 files changed, 267 insertions(+), 84 deletions(-)
Modified: branches/release/boost/thread/detail/move.hpp
==============================================================================
--- branches/release/boost/thread/detail/move.hpp (original)
+++ branches/release/boost/thread/detail/move.hpp 2008-07-23 05:35:40 EDT (Wed, 23 Jul 2008)
@@ -6,8 +6,10 @@
#ifndef BOOST_THREAD_MOVE_HPP
#define BOOST_THREAD_MOVE_HPP
+#ifndef BOOST_NO_SFINAE
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_convertible.hpp>
+#endif
#include <boost/config/abi_prefix.hpp>
@@ -37,11 +39,13 @@
};
}
+#ifndef BOOST_NO_SFINAE
template<typename T>
typename enable_if<boost::is_convertible<T&,detail::thread_move_t<T> >, detail::thread_move_t<T> >::type move(T& t)
{
return t;
}
+#endif
template<typename T>
detail::thread_move_t<T> move(detail::thread_move_t<T> t)
Modified: branches/release/boost/thread/detail/thread.hpp
==============================================================================
--- branches/release/boost/thread/detail/thread.hpp (original)
+++ branches/release/boost/thread/detail/thread.hpp 2008-07-23 05:35:40 EDT (Wed, 23 Jul 2008)
@@ -173,15 +173,24 @@
}
#else
+#ifdef BOOST_NO_SFINAE
+ template <class F>
+ explicit thread(F f):
+ thread_info(make_thread_info(f))
+ {
+ start_thread();
+ }
+#else
template <class F>
explicit thread(F f,typename disable_if<boost::is_convertible<F&,detail::thread_move_t<F> >, dummy* >::type=0):
thread_info(make_thread_info(f))
{
start_thread();
}
+#endif
template <class F>
- thread(detail::thread_move_t<F> f):
+ explicit thread(detail::thread_move_t<F> f):
thread_info(make_thread_info(f))
{
start_thread();
Modified: branches/release/boost/thread/locks.hpp
==============================================================================
--- branches/release/boost/thread/locks.hpp (original)
+++ branches/release/boost/thread/locks.hpp 2008-07-23 05:35:40 EDT (Wed, 23 Jul 2008)
@@ -10,14 +10,21 @@
#include <algorithm>
#include <iterator>
#include <boost/thread/thread_time.hpp>
-#include <boost/utility/enable_if.hpp>
+#include <boost/detail/workaround.hpp>
#include <boost/config/abi_prefix.hpp>
namespace boost
{
struct xtime;
-
+
+#if defined(BOOST_NO_SFINAE) || \
+ BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600)) || \
+ BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
+#define BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES
+#endif
+
+#ifndef BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES
namespace detail
{
template<typename T>
@@ -79,7 +86,13 @@
detail::has_member_try_lock<T>::value);
};
-
+#else
+ template<typename T>
+ struct is_mutex_type
+ {
+ BOOST_STATIC_CONSTANT(bool, value = false);
+ };
+#endif
struct defer_lock_t
{};
@@ -99,6 +112,74 @@
class upgrade_lock;
template<typename Mutex>
+ class unique_lock;
+
+ namespace detail
+ {
+ template<typename Mutex>
+ class try_lock_wrapper;
+ }
+
+#ifdef BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES
+ template<typename T>
+ struct is_mutex_type<unique_lock<T> >
+ {
+ BOOST_STATIC_CONSTANT(bool, value = true);
+ };
+
+ template<typename T>
+ struct is_mutex_type<shared_lock<T> >
+ {
+ BOOST_STATIC_CONSTANT(bool, value = true);
+ };
+
+ template<typename T>
+ struct is_mutex_type<upgrade_lock<T> >
+ {
+ BOOST_STATIC_CONSTANT(bool, value = true);
+ };
+
+ template<typename T>
+ struct is_mutex_type<detail::try_lock_wrapper<T> >
+ {
+ BOOST_STATIC_CONSTANT(bool, value = true);
+ };
+
+ class mutex;
+ class timed_mutex;
+ class recursive_mutex;
+ class recursive_timed_mutex;
+ class shared_mutex;
+
+ template<>
+ struct is_mutex_type<mutex>
+ {
+ BOOST_STATIC_CONSTANT(bool, value = true);
+ };
+ template<>
+ struct is_mutex_type<timed_mutex>
+ {
+ BOOST_STATIC_CONSTANT(bool, value = true);
+ };
+ template<>
+ struct is_mutex_type<recursive_mutex>
+ {
+ BOOST_STATIC_CONSTANT(bool, value = true);
+ };
+ template<>
+ struct is_mutex_type<recursive_timed_mutex>
+ {
+ BOOST_STATIC_CONSTANT(bool, value = true);
+ };
+ template<>
+ struct is_mutex_type<shared_mutex>
+ {
+ BOOST_STATIC_CONSTANT(bool, value = true);
+ };
+
+#endif
+
+ template<typename Mutex>
class lock_guard
{
private:
@@ -449,7 +530,7 @@
std::swap(m,other.m);
std::swap(is_locked,other.is_locked);
}
- void swap(boost::detail::thread_move_t<shared_lock> other)
+ void swap(boost::detail::thread_move_t<shared_lock<Mutex> > other)
{
std::swap(m,other->m);
std::swap(is_locked,other->is_locked);
@@ -515,7 +596,7 @@
is_locked=false;
}
- typedef void (shared_lock::*bool_type)();
+ typedef void (shared_lock<Mutex>::*bool_type)();
operator bool_type() const
{
return is_locked?&shared_lock::lock:0;
@@ -846,7 +927,7 @@
typedef typename base::bool_type bool_type;
operator bool_type() const
{
- return static_cast<base const&>(*this);
+ return base::operator bool_type();
}
};
@@ -987,28 +1068,63 @@
}
}
- template<typename MutexType1,typename MutexType2>
- typename enable_if<is_mutex_type<MutexType1>, void>::type lock(MutexType1& m1,MutexType2& m2)
+ namespace detail
{
- unsigned const lock_count=2;
- unsigned lock_first=0;
- while(true)
+ template<bool x>
+ struct is_mutex_type_wrapper
+ {};
+
+ template<typename MutexType1,typename MutexType2>
+ void lock_impl(MutexType1& m1,MutexType2& m2,is_mutex_type_wrapper<true>)
{
- switch(lock_first)
+ unsigned const lock_count=2;
+ unsigned lock_first=0;
+ while(true)
{
- case 0:
- lock_first=detail::lock_helper(m1,m2);
- if(!lock_first)
- return;
- break;
- case 1:
- lock_first=detail::lock_helper(m2,m1);
- if(!lock_first)
- return;
- lock_first=(lock_first+1)%lock_count;
- break;
+ switch(lock_first)
+ {
+ case 0:
+ lock_first=detail::lock_helper(m1,m2);
+ if(!lock_first)
+ return;
+ break;
+ case 1:
+ lock_first=detail::lock_helper(m2,m1);
+ if(!lock_first)
+ return;
+ lock_first=(lock_first+1)%lock_count;
+ break;
+ }
}
}
+
+ template<typename Iterator>
+ void lock_impl(Iterator begin,Iterator end,is_mutex_type_wrapper<false>);
+ }
+
+
+ template<typename MutexType1,typename MutexType2>
+ void lock(MutexType1& m1,MutexType2& m2)
+ {
+ detail::lock_impl(m1,m2,detail::is_mutex_type_wrapper<is_mutex_type<MutexType1>::value>());
+ }
+
+ template<typename MutexType1,typename MutexType2>
+ void lock(const MutexType1& m1,MutexType2& m2)
+ {
+ detail::lock_impl(m1,m2,detail::is_mutex_type_wrapper<is_mutex_type<MutexType1>::value>());
+ }
+
+ template<typename MutexType1,typename MutexType2>
+ void lock(MutexType1& m1,const MutexType2& m2)
+ {
+ detail::lock_impl(m1,m2,detail::is_mutex_type_wrapper<is_mutex_type<MutexType1>::value>());
+ }
+
+ template<typename MutexType1,typename MutexType2>
+ void lock(const MutexType1& m1,const MutexType2& m2)
+ {
+ detail::lock_impl(m1,m2,detail::is_mutex_type_wrapper<is_mutex_type<MutexType1>::value>());
}
template<typename MutexType1,typename MutexType2,typename MutexType3>
@@ -1123,10 +1239,52 @@
}
}
+ namespace detail
+ {
+ template<typename Mutex,bool x=is_mutex_type<Mutex>::value>
+ struct try_lock_impl_return
+ {
+ typedef int type;
+ };
+
+ template<typename Iterator>
+ struct try_lock_impl_return<Iterator,false>
+ {
+ typedef Iterator type;
+ };
+
+ template<typename MutexType1,typename MutexType2>
+ int try_lock_impl(MutexType1& m1,MutexType2& m2,is_mutex_type_wrapper<true>)
+ {
+ return ((int)detail::try_lock_internal(m1,m2))-1;
+ }
+
+ template<typename Iterator>
+ Iterator try_lock_impl(Iterator begin,Iterator end,is_mutex_type_wrapper<false>);
+ }
+
+ template<typename MutexType1,typename MutexType2>
+ typename detail::try_lock_impl_return<MutexType1>::type try_lock(MutexType1& m1,MutexType2& m2)
+ {
+ return detail::try_lock_impl(m1,m2,detail::is_mutex_type_wrapper<is_mutex_type<MutexType1>::value>());
+ }
+
+ template<typename MutexType1,typename MutexType2>
+ typename detail::try_lock_impl_return<MutexType1>::type try_lock(const MutexType1& m1,MutexType2& m2)
+ {
+ return detail::try_lock_impl(m1,m2,detail::is_mutex_type_wrapper<is_mutex_type<MutexType1>::value>());
+ }
+
+ template<typename MutexType1,typename MutexType2>
+ typename detail::try_lock_impl_return<MutexType1>::type try_lock(MutexType1& m1,const MutexType2& m2)
+ {
+ return detail::try_lock_impl(m1,m2,detail::is_mutex_type_wrapper<is_mutex_type<MutexType1>::value>());
+ }
+
template<typename MutexType1,typename MutexType2>
- typename enable_if<is_mutex_type<MutexType1>, int>::type try_lock(MutexType1& m1,MutexType2& m2)
+ typename detail::try_lock_impl_return<MutexType1>::type try_lock(const MutexType1& m1,const MutexType2& m2)
{
- return ((int)detail::try_lock_internal(m1,m2))-1;
+ return detail::try_lock_impl(m1,m2,detail::is_mutex_type_wrapper<is_mutex_type<MutexType1>::value>());
}
template<typename MutexType1,typename MutexType2,typename MutexType3>
@@ -1148,9 +1306,6 @@
}
- template<typename Iterator>
- typename disable_if<is_mutex_type<Iterator>, void>::type lock(Iterator begin,Iterator end);
-
namespace detail
{
template<typename Iterator>
@@ -1178,70 +1333,59 @@
}
}
};
- }
- template<typename Iterator>
- typename disable_if<is_mutex_type<Iterator>, Iterator>::type try_lock(Iterator begin,Iterator end)
- {
- if(begin==end)
- {
- return end;
- }
- typedef typename std::iterator_traits<Iterator>::value_type lock_type;
- unique_lock<lock_type> guard(*begin,try_to_lock);
-
- if(!guard.owns_lock())
- {
- return begin;
- }
- Iterator const failed=try_lock(++begin,end);
- if(failed==end)
+ template<typename Iterator>
+ Iterator try_lock_impl(Iterator begin,Iterator end,is_mutex_type_wrapper<false>)
+
{
- guard.release();
+ if(begin==end)
+ {
+ return end;
+ }
+ typedef typename std::iterator_traits<Iterator>::value_type lock_type;
+ unique_lock<lock_type> guard(*begin,try_to_lock);
+
+ if(!guard.owns_lock())
+ {
+ return begin;
+ }
+ Iterator const failed=try_lock(++begin,end);
+ if(failed==end)
+ {
+ guard.release();
+ }
+
+ return failed;
}
-
- return failed;
}
+
- template<typename Iterator>
- typename disable_if<is_mutex_type<Iterator>, void>::type lock(Iterator begin,Iterator end)
+ namespace detail
{
- typedef typename std::iterator_traits<Iterator>::value_type lock_type;
-
- if(begin==end)
+ template<typename Iterator>
+ void lock_impl(Iterator begin,Iterator end,is_mutex_type_wrapper<false>)
{
- return;
- }
- bool start_with_begin=true;
- Iterator second=begin;
- ++second;
- Iterator next=second;
+ typedef typename std::iterator_traits<Iterator>::value_type lock_type;
- for(;;)
- {
- unique_lock<lock_type> begin_lock(*begin,defer_lock);
- if(start_with_begin)
+ if(begin==end)
{
- begin_lock.lock();
- Iterator const failed_lock=try_lock(next,end);
- if(failed_lock==end)
- {
- begin_lock.release();
- return;
- }
- start_with_begin=false;
- next=failed_lock;
+ return;
}
- else
+ bool start_with_begin=true;
+ Iterator second=begin;
+ ++second;
+ Iterator next=second;
+
+ for(;;)
{
- detail::range_lock_guard<Iterator> guard(next,end);
- if(begin_lock.try_lock())
+ unique_lock<lock_type> begin_lock(*begin,defer_lock);
+ if(start_with_begin)
{
- Iterator const failed_lock=try_lock(second,next);
- if(failed_lock==next)
+ begin_lock.lock();
+ Iterator const failed_lock=try_lock(next,end);
+ if(failed_lock==end)
{
begin_lock.release();
- guard.release();
return;
}
start_with_begin=false;
@@ -1249,16 +1393,32 @@
}
else
{
- start_with_begin=true;
- next=second;
+ detail::range_lock_guard<Iterator> guard(next,end);
+ if(begin_lock.try_lock())
+ {
+ Iterator const failed_lock=try_lock(second,next);
+ if(failed_lock==next)
+ {
+ begin_lock.release();
+ guard.release();
+ return;
+ }
+ start_with_begin=false;
+ next=failed_lock;
+ }
+ else
+ {
+ start_with_begin=true;
+ next=second;
+ }
}
}
}
+
}
}
#include <boost/config/abi_suffix.hpp>
-#include <boost/mpl/identity.hpp>
#endif
Modified: branches/release/libs/thread/src/pthread/thread.cpp
==============================================================================
--- branches/release/libs/thread/src/pthread/thread.cpp (original)
+++ branches/release/libs/thread/src/pthread/thread.cpp 2008-07-23 05:35:40 EDT (Wed, 23 Jul 2008)
@@ -18,7 +18,7 @@
#elif defined(__APPLE__) || defined(__FreeBSD__)
#include <sys/types.h>
#include <sys/sysctl.h>
-#elif defined(__sun) || defined(__CYGWIN__)
+#elif defined BOOST_HAS_UNISTD_H
#include <unistd.h>
#endif
@@ -394,7 +394,7 @@
int count;
size_t size=sizeof(count);
return sysctlbyname("hw.ncpu",&count,&size,NULL,0)?0:count;
-#elif defined(__sun) || defined(__CYGWIN__)
+#elif defined(BOOST_HAS_UNISTD_H) && defined(_SC_NPROCESSORS_ONLN)
int const count=sysconf(_SC_NPROCESSORS_ONLN);
return (count>0)?count:0;
#else
Modified: branches/release/libs/thread/test/test_generic_locks.cpp
==============================================================================
--- branches/release/libs/thread/test/test_generic_locks.cpp (original)
+++ branches/release/libs/thread/test/test_generic_locks.cpp 2008-07-23 05:35:40 EDT (Wed, 23 Jul 2008)
@@ -272,6 +272,16 @@
}
};
+namespace boost
+{
+ template<>
+ struct is_mutex_type<dummy_mutex>
+ {
+ BOOST_STATIC_CONSTANT(bool, value = true);
+ };
+}
+
+
void test_lock_five_in_range()
{
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