2
0
mirror of https://github.com/boostorg/thread.git synced 2026-02-03 09:42:16 +00:00

Compare commits

...

8 Commits

Author SHA1 Message Date
Daniel James
5664452c47 Create a branch for inspect fixes.
[SVN r61439]
2010-04-20 21:11:27 +00:00
Anthony Williams
58fd27399e Added patch to fix issue #2501
[SVN r61429]
2010-04-20 15:02:47 +00:00
Anthony Williams
5f88ba1e47 Fix use of rvalue ref in futures
[SVN r60990]
2010-04-01 12:56:44 +00:00
Anthony Williams
ab569461d8 Modified boost::thread to work with MSVC10 RC
[SVN r59856]
2010-02-23 13:46:13 +00:00
Anthony Williams
7093fc670b Disable templated rvalue ref constructor for MSVC10
[SVN r59758]
2010-02-19 09:54:00 +00:00
Anthony Williams
6f2b030253 Fixes to some uses of rvalue references; patch to avoid var size warnings on 64-bit platforms in future.hpp
[SVN r59752]
2010-02-18 21:54:46 +00:00
Anthony Williams
0e61e679af Overload boost::move for thread& and thread&&
[SVN r59727]
2010-02-17 08:34:09 +00:00
Anthony Williams
b40998e1b5 Changed boost.thread to use BOOST_NO_RVALUE_REFERENCES rather than BOOST_HAS_RVALUE_REFS
[SVN r59699]
2010-02-16 14:57:30 +00:00
7 changed files with 121 additions and 44 deletions

View File

@@ -39,10 +39,13 @@ namespace boost
public detail::thread_data_base
{
public:
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
thread_data(F&& f_):
f(static_cast<F&&>(f_))
{}
thread_data(F& f_):
f(f_)
{}
#else
thread_data(F f_):
f(f_)
@@ -119,7 +122,7 @@ namespace boost
detail::thread_data_ptr get_thread_info() const;
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
template<typename F>
static inline detail::thread_data_ptr make_thread_info(F&& f)
{
@@ -127,7 +130,7 @@ namespace boost
}
static inline detail::thread_data_ptr make_thread_info(void (*f)())
{
return detail::thread_data_ptr(detail::heap_new<detail::thread_data<void(*)()> >(f));
return detail::thread_data_ptr(detail::heap_new<detail::thread_data<void(*)()> >(static_cast<void(*&&)()>(f)));
}
#else
template<typename F>
@@ -141,8 +144,8 @@ namespace boost
return detail::thread_data_ptr(detail::heap_new<detail::thread_data<F> >(f));
}
struct dummy;
#endif
struct dummy;
public:
#ifdef __SUNPRO_CC
thread(const volatile thread&);
@@ -150,13 +153,22 @@ namespace boost
thread();
~thread();
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
#ifdef BOOST_MSVC
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();
}
#else
template <class F>
thread(F&& f):
thread_info(make_thread_info(static_cast<F&&>(f)))
{
start_thread();
}
#endif
thread(thread&& other)
{
@@ -343,10 +355,14 @@ namespace boost
return lhs.swap(rhs);
}
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
inline thread&& move(thread& t)
{
return static_cast<thread&&>(t);
}
inline thread&& move(thread&& t)
{
return t;
return static_cast<thread&&>(t);
}
#else
inline detail::thread_move_t<thread> move(detail::thread_move_t<thread> t)

View File

@@ -1,4 +1,4 @@
// (C) Copyright 2008-9 Anthony Williams
// (C) Copyright 2008-10 Anthony Williams
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -219,7 +219,7 @@ namespace boost
struct future_traits
{
typedef boost::scoped_ptr<T> storage_type;
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
typedef T const& source_reference_type;
struct dummy;
typedef typename boost::mpl::if_<boost::is_fundamental<T>,dummy&,T&&>::type rvalue_source_type;
@@ -324,7 +324,7 @@ namespace boost
move_dest_type get()
{
wait();
return *result;
return static_cast<move_dest_type>(*result);
}
future_state::state get_state()
@@ -404,13 +404,14 @@ namespace boost
struct all_futures_lock
{
unsigned count;
typedef std::vector<registered_waiter>::size_type count_type;
count_type count;
boost::scoped_array<boost::unique_lock<boost::mutex> > locks;
all_futures_lock(std::vector<registered_waiter>& futures):
count(futures.size()),locks(new boost::unique_lock<boost::mutex>[count])
{
for(unsigned i=0;i<count;++i)
for(count_type i=0;i<count;++i)
{
locks[i]=boost::unique_lock<boost::mutex>(futures[i].future->mutex);
}
@@ -633,7 +634,7 @@ namespace boost
~unique_future()
{}
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
unique_future(unique_future && other)
{
future.swap(other.future);
@@ -768,7 +769,7 @@ namespace boost
future=other.future;
return *this;
}
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
shared_future(shared_future && other)
{
future.swap(other.future);
@@ -930,7 +931,7 @@ namespace boost
}
// Assignment
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
promise(promise && rhs):
future_obtained(rhs.future_obtained)
{
@@ -1064,7 +1065,7 @@ namespace boost
}
// Assignment
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
promise(promise && rhs):
future_obtained(rhs.future_obtained)
{
@@ -1284,7 +1285,7 @@ namespace boost
}
// assignment
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
packaged_task(packaged_task&& other):
future_obtained(other.future_obtained)
{

View File

@@ -248,7 +248,7 @@ namespace boost
{
timed_lock(target_time);
}
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
unique_lock(unique_lock&& other):
m(other.m),is_locked(other.is_locked)
{
@@ -321,17 +321,17 @@ namespace boost
swap(temp);
return *this;
}
void swap(unique_lock& other)
{
std::swap(m,other.m);
std::swap(is_locked,other.is_locked);
}
void swap(detail::thread_move_t<unique_lock<Mutex> > other)
{
std::swap(m,other->m);
std::swap(is_locked,other->is_locked);
}
#endif
void swap(unique_lock& other)
{
std::swap(m,other.m);
std::swap(is_locked,other.is_locked);
}
~unique_lock()
{
@@ -416,25 +416,36 @@ namespace boost
friend class upgrade_lock<Mutex>;
};
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
template<typename Mutex>
void swap(unique_lock<Mutex>&& lhs,unique_lock<Mutex>&& rhs)
{
lhs.swap(rhs);
}
#else
template<typename Mutex>
inline upgrade_lock<Mutex>&& move(upgrade_lock<Mutex>&& ul)
{
return ul;
}
#endif
template<typename Mutex>
void swap(unique_lock<Mutex>& lhs,unique_lock<Mutex>& rhs)
{
lhs.swap(rhs);
}
#endif
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
template<typename Mutex>
inline unique_lock<Mutex>&& move(unique_lock<Mutex>&& ul)
{
return ul;
return static_cast<unique_lock<Mutex>&&>(ul);
}
template<typename Mutex>
inline unique_lock<Mutex>&& move(unique_lock<Mutex>& ul)
{
return static_cast<unique_lock<Mutex>&&>(ul);
}
#endif
@@ -535,24 +546,24 @@ namespace boost
return *this;
}
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
void swap(shared_lock&& other)
{
std::swap(m,other.m);
std::swap(is_locked,other.is_locked);
}
#else
void swap(shared_lock& other)
{
std::swap(m,other.m);
std::swap(is_locked,other.is_locked);
}
void swap(boost::detail::thread_move_t<shared_lock<Mutex> > other)
{
std::swap(m,other->m);
std::swap(is_locked,other->is_locked);
}
#endif
void swap(shared_lock& other)
{
std::swap(m,other.m);
std::swap(is_locked,other.is_locked);
}
Mutex* mutex() const
{
@@ -629,7 +640,7 @@ namespace boost
};
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
template<typename Mutex>
void swap(shared_lock<Mutex>&& lhs,shared_lock<Mutex>&& rhs)
{
@@ -673,6 +684,39 @@ namespace boost
{
try_lock();
}
#ifdef BOOST_HAS_RVALUE_REFS
upgrade_lock(upgrade_lock<Mutex>&& other):
m(other.m),is_locked(other.is_locked)
{
other.is_locked=false;
other.m=0;
}
upgrade_lock(unique_lock<Mutex>&& other):
m(other.m),is_locked(other.is_locked)
{
if(is_locked)
{
m->unlock_and_lock_upgrade();
}
other.is_locked=false;
other.m=0;
}
upgrade_lock& operator=(upgrade_lock<Mutex>&& other)
{
upgrade_lock temp(other);
swap(temp);
return *this;
}
upgrade_lock& operator=(unique_lock<Mutex>&& other)
{
upgrade_lock temp(other);
swap(temp);
return *this;
}
#else
upgrade_lock(detail::thread_move_t<upgrade_lock<Mutex> > other):
m(other->m),is_locked(other->is_locked)
{
@@ -715,6 +759,7 @@ namespace boost
swap(temp);
return *this;
}
#endif
void swap(upgrade_lock& other)
{
@@ -775,7 +820,7 @@ namespace boost
};
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
template<typename Mutex>
unique_lock<Mutex>::unique_lock(upgrade_lock<Mutex>&& other):
m(other.m),is_locked(other.is_locked)
@@ -819,6 +864,20 @@ namespace boost
}
}
#ifdef BOOST_HAS_RVALUE_REFS
upgrade_to_unique_lock(upgrade_to_unique_lock<Mutex>&& other):
source(other.source),exclusive(move(other.exclusive))
{
other.source=0;
}
upgrade_to_unique_lock& operator=(upgrade_to_unique_lock<Mutex>&& other)
{
upgrade_to_unique_lock temp(other);
swap(temp);
return *this;
}
#else
upgrade_to_unique_lock(detail::thread_move_t<upgrade_to_unique_lock<Mutex> > other):
source(other->source),exclusive(move(other->exclusive))
{
@@ -831,6 +890,7 @@ namespace boost
swap(temp);
return *this;
}
#endif
void swap(upgrade_to_unique_lock& other)
{
std::swap(source,other.source);
@@ -875,7 +935,7 @@ namespace boost
try_lock_wrapper(Mutex& m_,try_to_lock_t):
base(m_,try_to_lock)
{}
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
try_lock_wrapper(try_lock_wrapper&& other):
base(other.move())
{}
@@ -963,7 +1023,7 @@ namespace boost
}
};
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
template<typename Mutex>
void swap(try_lock_wrapper<Mutex>&& lhs,try_lock_wrapper<Mutex>&& rhs)
{

View File

@@ -17,7 +17,7 @@ namespace boost
return new T();
}
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
template<typename T,typename A1>
inline T* heap_new(A1&& a1)
{

View File

@@ -87,7 +87,7 @@ namespace boost
}
}
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
template<typename T,typename A1>
inline T* heap_new(A1&& a1)
{

0
src/pthread/once.cpp Executable file → Normal file
View File

View File

@@ -1,4 +1,4 @@
// (C) Copyright 2008-9 Anthony Williams
// (C) Copyright 2008-10 Anthony Williams
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -14,7 +14,7 @@
#include <boost/test/unit_test.hpp>
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
template<typename T>
typename boost::remove_reference<T>::type&& cast_to_rval(T&& t)
{
@@ -41,7 +41,7 @@ public:
X():
i(42)
{}
#ifdef BOOST_HAS_RVALUE_REFS
#ifndef BOOST_NO_RVALUE_REFERENCES
X(X&& other):
i(other.i)
{
@@ -89,7 +89,7 @@ void set_promise_exception_thread(boost::promise<int>* p)
void test_store_value_from_thread()
{
boost::promise<int> pi2;
boost::unique_future<int> fi2=pi2.get_future();
boost::unique_future<int> fi2(pi2.get_future());
boost::thread(set_promise_thread,&pi2);
int j=fi2.get();
BOOST_CHECK(j==42);