Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2008-05-22 07:49:49


Author: anthonyw
Date: 2008-05-22 07:49:48 EDT (Thu, 22 May 2008)
New Revision: 45647
URL: http://svn.boost.org/trac/boost/changeset/45647

Log:
Refactored boost::thread code to try and remove duplication
Added:
   trunk/boost/thread/detail/thread.hpp (contents, props changed)
   trunk/boost/thread/detail/thread_heap_alloc.hpp (contents, props changed)
   trunk/boost/thread/pthread/thread_heap_alloc.hpp (contents, props changed)
   trunk/boost/thread/win32/thread_data.hpp (contents, props changed)
Removed:
   trunk/boost/thread/pthread/thread.hpp
   trunk/boost/thread/win32/thread.hpp
Text files modified:
   trunk/boost/thread/exceptions.hpp | 6
   trunk/boost/thread/pthread/thread_data.hpp | 26 +++
   trunk/boost/thread/thread.hpp | 9
   trunk/boost/thread/win32/thread_heap_alloc.hpp | 224 ++++++++++++++++++++++++++++++++++-
   trunk/libs/thread/src/pthread/thread.cpp | 248 ++++++++++++++++++++--------------------
   trunk/libs/thread/src/win32/thread.cpp | 53 ++-----
   6 files changed, 386 insertions(+), 180 deletions(-)

Added: trunk/boost/thread/detail/thread.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/thread/detail/thread.hpp 2008-05-22 07:49:48 EDT (Thu, 22 May 2008)
@@ -0,0 +1,517 @@
+#ifndef BOOST_THREAD_THREAD_COMMON_HPP
+#define BOOST_THREAD_THREAD_COMMON_HPP
+// 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)
+// (C) Copyright 2007-8 Anthony Williams
+
+#include <boost/thread/exceptions.hpp>
+#include <ostream>
+#include <boost/thread/detail/move.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/xtime.hpp>
+#include <boost/thread/detail/thread_heap_alloc.hpp>
+#include <boost/utility.hpp>
+#include <boost/assert.hpp>
+#include <list>
+#include <algorithm>
+#include <boost/ref.hpp>
+#include <boost/cstdint.hpp>
+#include <boost/bind.hpp>
+#include <stdlib.h>
+#include <memory>
+
+#ifdef BOOST_MSVC
+#pragma warning(push)
+#pragma warning(disable:4251)
+#endif
+
+namespace boost
+{
+ class BOOST_THREAD_DECL thread
+ {
+ private:
+ thread(thread&);
+ thread& operator=(thread&);
+
+ void release_handle();
+
+ template<typename F>
+ struct thread_data:
+ detail::thread_data_base
+ {
+ F f;
+
+#ifdef BOOST_HAS_RVALUE_REFS
+ thread_data(F&& f_):
+ f(static_cast<F&&>(f_))
+ {}
+#else
+ thread_data(F f_):
+ f(f_)
+ {}
+ thread_data(detail::thread_move_t<F> f_):
+ f(f_)
+ {}
+#endif
+ void run()
+ {
+ f();
+ }
+ private:
+ void operator=(thread_data&);
+ thread_data(thread_data&);
+ };
+
+ mutable boost::mutex thread_info_mutex;
+ detail::thread_data_ptr thread_info;
+
+ void start_thread();
+
+ explicit thread(detail::thread_data_ptr data);
+
+ detail::thread_data_ptr get_thread_info() const;
+
+#ifdef BOOST_HAS_RVALUE_REFS
+ template<typename F>
+ static inline detail::thread_data_ptr make_thread_info(F&& f)
+ {
+ return detail::thread_data_ptr(detail::heap_new<thread_data<F> >(static_cast<F&&>(f)));
+ }
+#else
+ template<typename F>
+ static inline detail::thread_data_ptr make_thread_info(F f)
+ {
+ return detail::thread_data_ptr(detail::heap_new<thread_data<F> >(f));
+ }
+ template<typename F>
+ static inline detail::thread_data_ptr make_thread_info(boost::detail::thread_move_t<F> f)
+ {
+ return detail::thread_data_ptr(detail::heap_new<thread_data<F> >(f));
+ }
+#endif
+ public:
+ thread();
+ ~thread();
+
+#ifdef BOOST_HAS_RVALUE_REFS
+ template <class F>
+ thread(F&& f):
+ thread_info(make_thread_info(static_cast<F&&>(f)))
+ {
+ start_thread();
+ }
+
+ thread(thread&& other)
+ {
+ thread_info.swap(other.thread_info);
+ }
+
+ thread& operator=(thread&& other)
+ {
+ thread_info=other.thread_info;
+ other.thread_info.reset();
+ return *this;
+ }
+
+ thread&& move()
+ {
+ return static_cast<thread&&>(*this);
+ }
+
+#else
+ template <class F>
+ explicit thread(F f):
+ thread_info(make_thread_info(f))
+ {
+ start_thread();
+ }
+
+ template <class F>
+ thread(detail::thread_move_t<F> f):
+ thread_info(make_thread_info(f))
+ {
+ start_thread();
+ }
+
+ thread(detail::thread_move_t<thread> x);
+ thread& operator=(detail::thread_move_t<thread> x);
+ operator detail::thread_move_t<thread>();
+ detail::thread_move_t<thread> move();
+
+#endif
+
+ template <class F,class A1>
+ thread(F f,A1 a1):
+ thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1)))
+ {
+ start_thread();
+ }
+ template <class F,class A1,class A2>
+ thread(F f,A1 a1,A2 a2):
+ thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2)))
+ {
+ start_thread();
+ }
+
+ template <class F,class A1,class A2,class A3>
+ thread(F f,A1 a1,A2 a2,A3 a3):
+ thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3)))
+ {
+ start_thread();
+ }
+
+ template <class F,class A1,class A2,class A3,class A4>
+ thread(F f,A1 a1,A2 a2,A3 a3,A4 a4):
+ thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4)))
+ {
+ start_thread();
+ }
+
+ template <class F,class A1,class A2,class A3,class A4,class A5>
+ thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5):
+ thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5)))
+ {
+ start_thread();
+ }
+
+ template <class F,class A1,class A2,class A3,class A4,class A5,class A6>
+ thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6):
+ thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5,a6)))
+ {
+ start_thread();
+ }
+
+ template <class F,class A1,class A2,class A3,class A4,class A5,class A6,class A7>
+ thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7):
+ thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5,a6,a7)))
+ {
+ start_thread();
+ }
+
+ template <class F,class A1,class A2,class A3,class A4,class A5,class A6,class A7,class A8>
+ thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7,A8 a8):
+ thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5,a6,a7,a8)))
+ {
+ start_thread();
+ }
+
+ template <class F,class A1,class A2,class A3,class A4,class A5,class A6,class A7,class A8,class A9>
+ thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7,A8 a8,A9 a9):
+ thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5,a6,a7,a8,a9)))
+ {
+ start_thread();
+ }
+
+ void swap(thread& x);
+
+ class id;
+ id get_id() const;
+
+
+ bool joinable() const;
+ void join();
+ bool timed_join(const system_time& wait_until);
+
+ template<typename TimeDuration>
+ inline bool timed_join(TimeDuration const& rel_time)
+ {
+ return timed_join(get_system_time()+rel_time);
+ }
+ void detach();
+
+ static unsigned hardware_concurrency();
+
+ typedef detail::thread_data_base::native_handle_type native_handle_type;
+ native_handle_type native_handle();
+
+ // backwards compatibility
+ bool operator==(const thread& other) const;
+ bool operator!=(const thread& other) const;
+
+ static inline void yield()
+ {
+ this_thread::yield();
+ }
+
+ static inline void sleep(const system_time& xt)
+ {
+ this_thread::sleep(xt);
+ }
+
+ // extensions
+ void interrupt();
+ bool interruption_requested() const;
+ };
+
+#ifdef BOOST_HAS_RVALUE_REFS
+ inline thread&& move(thread&& t)
+ {
+ return t;
+ }
+#else
+ inline detail::thread_move_t<thread> move(detail::thread_move_t<thread> t)
+ {
+ return t;
+ }
+#endif
+
+ template<typename F>
+ struct thread::thread_data<boost::reference_wrapper<F> >:
+ detail::thread_data_base
+ {
+ F& f;
+
+ thread_data(boost::reference_wrapper<F> f_):
+ f(f_)
+ {}
+
+ void run()
+ {
+ f();
+ }
+ };
+
+ template<typename F>
+ struct thread::thread_data<const boost::reference_wrapper<F> >:
+ detail::thread_data_base
+ {
+ F& f;
+
+ thread_data(const boost::reference_wrapper<F> f_):
+ f(f_)
+ {}
+
+ void run()
+ {
+ f();
+ }
+ };
+
+
+ namespace this_thread
+ {
+ class BOOST_THREAD_DECL disable_interruption
+ {
+ disable_interruption(const disable_interruption&);
+ disable_interruption& operator=(const disable_interruption&);
+
+ bool interruption_was_enabled;
+ friend class restore_interruption;
+ public:
+ disable_interruption();
+ ~disable_interruption();
+ };
+
+ class BOOST_THREAD_DECL restore_interruption
+ {
+ restore_interruption(const restore_interruption&);
+ restore_interruption& operator=(const restore_interruption&);
+ public:
+ explicit restore_interruption(disable_interruption& d);
+ ~restore_interruption();
+ };
+
+ thread::id BOOST_THREAD_DECL get_id();
+
+ void BOOST_THREAD_DECL interruption_point();
+ bool BOOST_THREAD_DECL interruption_enabled();
+ bool BOOST_THREAD_DECL interruption_requested();
+
+ inline void sleep(xtime const& abs_time)
+ {
+ sleep(system_time(abs_time));
+ }
+ }
+
+ class thread::id
+ {
+ private:
+ detail::thread_data_ptr thread_data;
+
+ id(detail::thread_data_ptr thread_data_):
+ thread_data(thread_data_)
+ {}
+ friend class thread;
+ friend id this_thread::get_id();
+ public:
+ id():
+ thread_data()
+ {}
+
+ bool operator==(const id& y) const
+ {
+ return thread_data==y.thread_data;
+ }
+
+ bool operator!=(const id& y) const
+ {
+ return thread_data!=y.thread_data;
+ }
+
+ bool operator<(const id& y) const
+ {
+ return thread_data<y.thread_data;
+ }
+
+ bool operator>(const id& y) const
+ {
+ return y.thread_data<thread_data;
+ }
+
+ bool operator<=(const id& y) const
+ {
+ return !(y.thread_data<thread_data);
+ }
+
+ bool operator>=(const id& y) const
+ {
+ return !(thread_data<y.thread_data);
+ }
+
+ template<class charT, class traits>
+ friend std::basic_ostream<charT, traits>&
+ operator<<(std::basic_ostream<charT, traits>& os, const id& x)
+ {
+ if(x.thread_data)
+ {
+ return os<<x.thread_data;
+ }
+ else
+ {
+ return os<<"{Not-any-thread}";
+ }
+ }
+ };
+
+ inline bool thread::operator==(const thread& other) const
+ {
+ return get_id()==other.get_id();
+ }
+
+ inline bool thread::operator!=(const thread& other) const
+ {
+ return get_id()!=other.get_id();
+ }
+
+ namespace detail
+ {
+ struct thread_exit_function_base
+ {
+ virtual ~thread_exit_function_base()
+ {}
+ virtual void operator()() const=0;
+ };
+
+ template<typename F>
+ struct thread_exit_function:
+ thread_exit_function_base
+ {
+ F f;
+
+ thread_exit_function(F f_):
+ f(f_)
+ {}
+
+ void operator()() const
+ {
+ f();
+ }
+ };
+
+ void add_thread_exit_function(thread_exit_function_base*);
+ }
+
+ namespace this_thread
+ {
+ template<typename F>
+ void at_thread_exit(F f)
+ {
+ detail::thread_exit_function_base* const thread_exit_func=detail::heap_new<detail::thread_exit_function<F> >(f);
+ detail::add_thread_exit_function(thread_exit_func);
+ }
+ }
+
+ class thread_group:
+ private noncopyable
+ {
+ public:
+ ~thread_group()
+ {
+ for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
+ it!=end;
+ ++it)
+ {
+ delete *it;
+ }
+ }
+
+ template<typename F>
+ thread* create_thread(F threadfunc)
+ {
+ boost::lock_guard<mutex> guard(m);
+ std::auto_ptr<thread> new_thread(new thread(threadfunc));
+ threads.push_back(new_thread.get());
+ return new_thread.release();
+ }
+
+ void add_thread(thread* thrd)
+ {
+ if(thrd)
+ {
+ boost::lock_guard<mutex> guard(m);
+ threads.push_back(thrd);
+ }
+ }
+
+ void remove_thread(thread* thrd)
+ {
+ boost::lock_guard<mutex> guard(m);
+ std::list<thread*>::iterator const it=std::find(threads.begin(),threads.end(),thrd);
+ if(it!=threads.end())
+ {
+ threads.erase(it);
+ }
+ }
+
+ void join_all()
+ {
+ boost::lock_guard<mutex> guard(m);
+
+ for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
+ it!=end;
+ ++it)
+ {
+ (*it)->join();
+ }
+ }
+
+ void interrupt_all()
+ {
+ boost::lock_guard<mutex> guard(m);
+
+ for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
+ it!=end;
+ ++it)
+ {
+ (*it)->interrupt();
+ }
+ }
+
+ size_t size() const
+ {
+ boost::lock_guard<mutex> guard(m);
+ return threads.size();
+ }
+
+ private:
+ std::list<thread*> threads;
+ mutable mutex m;
+ };
+}
+
+#ifdef BOOST_MSVC
+#pragma warning(pop)
+#endif
+
+#endif

Added: trunk/boost/thread/detail/thread_heap_alloc.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/thread/detail/thread_heap_alloc.hpp 2008-05-22 07:49:48 EDT (Thu, 22 May 2008)
@@ -0,0 +1,23 @@
+#ifndef BOOST_THREAD_THREAD_HEAP_ALLOC_HPP
+#define BOOST_THREAD_THREAD_HEAP_ALLOC_HPP
+
+// thread_heap_alloc.hpp
+//
+// (C) Copyright 2008 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)
+
+#include <boost/thread/detail/platform.hpp>
+
+#if defined(BOOST_THREAD_PLATFORM_WIN32)
+#include <boost/thread/win32/thread_heap_alloc.hpp>
+#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
+#include <boost/thread/pthread/thread_heap_alloc.hpp>
+#else
+#error "Boost threads unavailable on this platform"
+#endif
+
+
+#endif

Modified: trunk/boost/thread/exceptions.hpp
==============================================================================
--- trunk/boost/thread/exceptions.hpp (original)
+++ trunk/boost/thread/exceptions.hpp 2008-05-22 07:49:48 EDT (Thu, 22 May 2008)
@@ -19,7 +19,11 @@
 #include <string>
 #include <stdexcept>
 
-namespace boost {
+namespace boost
+{
+
+ class BOOST_THREAD_DECL thread_interrupted
+ {};
 
 class BOOST_THREAD_DECL thread_exception : public std::exception
 {

Deleted: trunk/boost/thread/pthread/thread.hpp
==============================================================================
--- trunk/boost/thread/pthread/thread.hpp 2008-05-22 07:49:48 EDT (Thu, 22 May 2008)
+++ (empty file)
@@ -1,396 +0,0 @@
-#ifndef BOOST_THREAD_THREAD_PTHREAD_HPP
-#define BOOST_THREAD_THREAD_PTHREAD_HPP
-// 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)
-
-#include <boost/thread/detail/config.hpp>
-
-#include <boost/utility.hpp>
-#include <boost/function.hpp>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/condition_variable.hpp>
-#include <list>
-#include <memory>
-
-#include <pthread.h>
-#include <boost/optional.hpp>
-#include <boost/thread/detail/move.hpp>
-#include <boost/shared_ptr.hpp>
-#include "thread_data.hpp"
-#include <boost/bind.hpp>
-#include <stdlib.h>
-
-#ifdef BOOST_MSVC
-#pragma warning(push)
-#pragma warning(disable:4251)
-#endif
-
-namespace boost
-{
- class thread;
-
- namespace detail
- {
- class thread_id;
- }
-
- namespace this_thread
- {
- BOOST_THREAD_DECL detail::thread_id get_id();
- }
-
- namespace detail
- {
- class thread_id
- {
- private:
- detail::thread_data_ptr thread_data;
-
- thread_id(detail::thread_data_ptr thread_data_):
- thread_data(thread_data_)
- {}
- friend class boost::thread;
- friend thread_id this_thread::get_id();
- public:
- thread_id():
- thread_data()
- {}
-
- bool operator==(const thread_id& y) const
- {
- return thread_data==y.thread_data;
- }
-
- bool operator!=(const thread_id& y) const
- {
- return thread_data!=y.thread_data;
- }
-
- bool operator<(const thread_id& y) const
- {
- return thread_data<y.thread_data;
- }
-
- bool operator>(const thread_id& y) const
- {
- return y.thread_data<thread_data;
- }
-
- bool operator<=(const thread_id& y) const
- {
- return !(y.thread_data<thread_data);
- }
-
- bool operator>=(const thread_id& y) const
- {
- return !(thread_data<y.thread_data);
- }
-
- template<class charT, class traits>
- friend std::basic_ostream<charT, traits>&
- operator<<(std::basic_ostream<charT, traits>& os, const thread_id& x)
- {
- if(x.thread_data)
- {
- return os<<x.thread_data;
- }
- else
- {
- return os<<"{Not-any-thread}";
- }
- }
- };
- }
-
- struct xtime;
- class BOOST_THREAD_DECL thread
- {
- private:
- thread(thread&);
- thread& operator=(thread&);
-
- template<typename F>
- struct thread_data:
- detail::thread_data_base
- {
- F f;
-
- thread_data(F f_):
- f(f_)
- {}
- thread_data(detail::thread_move_t<F> f_):
- f(f_)
- {}
-
- void run()
- {
- f();
- }
- };
-
- mutable boost::mutex thread_info_mutex;
- detail::thread_data_ptr thread_info;
-
- void start_thread();
-
- explicit thread(detail::thread_data_ptr data);
-
- detail::thread_data_ptr get_thread_info() const;
-
- template<typename F>
- static inline detail::thread_data_ptr make_thread_info(F f)
- {
- return detail::thread_data_ptr(new thread_data<F>(f));
- }
-
- public:
- thread();
- ~thread();
-
- template <class F>
- explicit thread(F f):
- thread_info(make_thread_info(f))
- {
- start_thread();
- }
- template <class F>
- thread(detail::thread_move_t<F> f):
- thread_info(make_thread_info(f))
- {
- start_thread();
- }
-
- template <class F,class A1>
- thread(F f,A1 a1):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2>
- thread(F f,A1 a1,A2 a2):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3>
- thread(F f,A1 a1,A2 a2,A3 a3):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3,class A4>
- thread(F f,A1 a1,A2 a2,A3 a3,A4 a4):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3,class A4,class A5>
- thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3,class A4,class A5,class A6>
- thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5,a6)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3,class A4,class A5,class A6,class A7>
- thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5,a6,a7)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3,class A4,class A5,class A6,class A7,class A8>
- thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7,A8 a8):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5,a6,a7,a8)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3,class A4,class A5,class A6,class A7,class A8,class A9>
- thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7,A8 a8,A9 a9):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5,a6,a7,a8,a9)))
- {
- start_thread();
- }
-
- thread(detail::thread_move_t<thread> x);
- thread& operator=(detail::thread_move_t<thread> x);
- operator detail::thread_move_t<thread>();
- detail::thread_move_t<thread> move();
-
- void swap(thread& x);
-
- typedef detail::thread_id id;
-
- id get_id() const;
-
- bool joinable() const;
- void join();
- bool timed_join(const system_time& wait_until);
-
- template<typename TimeDuration>
- inline bool timed_join(TimeDuration const& rel_time)
- {
- return timed_join(get_system_time()+rel_time);
- }
- void detach();
-
- static unsigned hardware_concurrency();
-
- // backwards compatibility
- bool operator==(const thread& other) const;
- bool operator!=(const thread& other) const;
-
- static void sleep(const system_time& xt);
- static void yield();
-
- typedef pthread_t native_handle_type;
- native_handle_type native_handle();
-
- // extensions
- void interrupt();
- bool interruption_requested() const;
- };
-
- inline detail::thread_move_t<thread> move(detail::thread_move_t<thread> t)
- {
- return t;
- }
-
- template<typename F>
- struct thread::thread_data<boost::reference_wrapper<F> >:
- detail::thread_data_base
- {
- F& f;
-
- thread_data(boost::reference_wrapper<F> f_):
- f(f_)
- {}
-
- void run()
- {
- f();
- }
- };
-
- namespace this_thread
- {
- class BOOST_THREAD_DECL disable_interruption
- {
- disable_interruption(const disable_interruption&);
- disable_interruption& operator=(const disable_interruption&);
-
- bool interruption_was_enabled;
- friend class restore_interruption;
- public:
- disable_interruption();
- ~disable_interruption();
- };
-
- class BOOST_THREAD_DECL restore_interruption
- {
- restore_interruption(const restore_interruption&);
- restore_interruption& operator=(const restore_interruption&);
- public:
- explicit restore_interruption(disable_interruption& d);
- ~restore_interruption();
- };
-
- BOOST_THREAD_DECL thread::id get_id();
-
- BOOST_THREAD_DECL void interruption_point();
- BOOST_THREAD_DECL bool interruption_enabled();
- BOOST_THREAD_DECL bool interruption_requested();
-
- inline void yield()
- {
- thread::yield();
- }
-
- template<typename TimeDuration>
- inline void sleep(TimeDuration const& rel_time)
- {
- thread::sleep(get_system_time()+rel_time);
- }
- }
-
- namespace detail
- {
- struct thread_exit_function_base
- {
- virtual ~thread_exit_function_base()
- {}
- virtual void operator()() const=0;
- };
-
- template<typename F>
- struct thread_exit_function:
- thread_exit_function_base
- {
- F f;
-
- thread_exit_function(F f_):
- f(f_)
- {}
-
- void operator()() const
- {
- f();
- }
- };
-
- BOOST_THREAD_DECL void add_thread_exit_function(thread_exit_function_base*);
- }
-
- namespace this_thread
- {
- template<typename F>
- inline void at_thread_exit(F f)
- {
- detail::thread_exit_function_base* const thread_exit_func=new detail::thread_exit_function<F>(f);
- detail::add_thread_exit_function(thread_exit_func);
- }
- }
-
- class BOOST_THREAD_DECL thread_group
- {
- public:
- thread_group();
- ~thread_group();
-
- thread* create_thread(const function0<void>& threadfunc);
- void add_thread(thread* thrd);
- void remove_thread(thread* thrd);
- void join_all();
- void interrupt_all();
- size_t size() const;
-
- private:
- thread_group(thread_group&);
- void operator=(thread_group&);
-
- std::list<thread*> m_threads;
- mutex m_mutex;
- };
-} // namespace boost
-
-#ifdef BOOST_MSVC
-#pragma warning(pop)
-#endif
-
-
-#endif

Modified: trunk/boost/thread/pthread/thread_data.hpp
==============================================================================
--- trunk/boost/thread/pthread/thread_data.hpp (original)
+++ trunk/boost/thread/pthread/thread_data.hpp 2008-05-22 07:49:48 EDT (Thu, 22 May 2008)
@@ -6,6 +6,7 @@
 // (C) Copyright 2007 Anthony Williams
 
 #include <boost/thread/detail/config.hpp>
+#include <boost/thread/exceptions.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/enable_shared_from_this.hpp>
 #include <boost/thread/mutex.hpp>
@@ -15,9 +16,8 @@
 
 namespace boost
 {
- class thread_interrupted
- {};
-
+ class thread;
+
     namespace detail
     {
         struct thread_exit_callback_node;
@@ -26,7 +26,7 @@
         struct thread_data_base;
         typedef boost::shared_ptr<thread_data_base> thread_data_ptr;
         
- struct thread_data_base:
+ struct BOOST_THREAD_DECL thread_data_base:
             enable_shared_from_this<thread_data_base>
         {
             thread_data_ptr self;
@@ -51,8 +51,9 @@
                 interrupt_requested(false),
                 current_cond(0)
             {}
- virtual ~thread_data_base()
- {}
+ virtual ~thread_data_base();
+
+ typedef pthread_t native_handle_type;
 
             virtual void run()=0;
         };
@@ -95,6 +96,19 @@
             }
         };
     }
+
+ namespace this_thread
+ {
+ void BOOST_THREAD_DECL yield();
+
+ void BOOST_THREAD_DECL sleep(system_time const& abs_time);
+
+ template<typename TimeDuration>
+ inline void sleep(TimeDuration const& rel_time)
+ {
+ this_thread::sleep(get_system_time()+rel_time);
+ }
+ }
 }
 
 

Added: trunk/boost/thread/pthread/thread_heap_alloc.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/thread/pthread/thread_heap_alloc.hpp 2008-05-22 07:49:48 EDT (Thu, 22 May 2008)
@@ -0,0 +1,239 @@
+// 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)
+// (C) Copyright 2008 Anthony Williams
+#ifndef THREAD_HEAP_ALLOC_PTHREAD_HPP
+#define THREAD_HEAP_ALLOC_PTHREAD_HPP
+
+namespace boost
+{
+ namespace detail
+ {
+ template<typename T>
+ inline T* heap_new()
+ {
+ return new T();
+ }
+
+#ifdef BOOST_HAS_RVALUE_REFS
+ template<typename T,typename A1>
+ inline T* heap_new(A1&& a1)
+ {
+ return new T(static_cast<A1&&>(a1));
+ }
+ template<typename T,typename A1,typename A2>
+ inline T* heap_new(A1&& a1,A2&& a2)
+ {
+ return new T(static_cast<A1&&>(a1),static_cast<A2&&>(a2));
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1&& a1,A2&& a2,A3&& a3)
+ {
+ return new T(static_cast<A1&&>(a1),static_cast<A2&&>(a2),
+ static_cast<A3&&>(a3));
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1&& a1,A2&& a2,A3&& a3,A4&& a4)
+ {
+ return new T(static_cast<A1&&>(a1),static_cast<A2&&>(a2),
+ static_cast<A3&&>(a3),static_cast<A4&&>(a4));
+ }
+#else
+ template<typename T,typename A1>
+ inline T* heap_new_impl(A1 a1)
+ {
+ return new T(a1);
+ }
+ template<typename T,typename A1,typename A2>
+ inline T* heap_new_impl(A1 a1,A2 a2)
+ {
+ return new T(a1,a2);
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new_impl(A1 a1,A2 a2,A3 a3)
+ {
+ return new T(a1,a2,a3);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new_impl(A1 a1,A2 a2,A3 a3,A4 a4)
+ {
+ return new T(a1,a2,a3,a4);
+ }
+
+ template<typename T,typename A1>
+ inline T* heap_new(A1 const& a1)
+ {
+ return heap_new_impl<T,A1 const&>(a1);
+ }
+ template<typename T,typename A1>
+ inline T* heap_new(A1& a1)
+ {
+ return heap_new_impl<T,A1&>(a1);
+ }
+
+ template<typename T,typename A1,typename A2>
+ inline T* heap_new(A1 const& a1,A2 const& a2)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&>(a1,a2);
+ }
+ template<typename T,typename A1,typename A2>
+ inline T* heap_new(A1& a1,A2 const& a2)
+ {
+ return heap_new_impl<T,A1&,A2 const&>(a1,a2);
+ }
+ template<typename T,typename A1,typename A2>
+ inline T* heap_new(A1 const& a1,A2& a2)
+ {
+ return heap_new_impl<T,A1 const&,A2&>(a1,a2);
+ }
+ template<typename T,typename A1,typename A2>
+ inline T* heap_new(A1& a1,A2& a2)
+ {
+ return heap_new_impl<T,A1&,A2&>(a1,a2);
+ }
+
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1 const& a1,A2 const& a2,A3 const& a3)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&,A3 const&>(a1,a2,a3);
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1& a1,A2 const& a2,A3 const& a3)
+ {
+ return heap_new_impl<T,A1&,A2 const&,A3 const&>(a1,a2,a3);
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1 const& a1,A2& a2,A3 const& a3)
+ {
+ return heap_new_impl<T,A1 const&,A2&,A3 const&>(a1,a2,a3);
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1& a1,A2& a2,A3 const& a3)
+ {
+ return heap_new_impl<T,A1&,A2&,A3 const&>(a1,a2,a3);
+ }
+
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1 const& a1,A2 const& a2,A3& a3)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&,A3&>(a1,a2,a3);
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1& a1,A2 const& a2,A3& a3)
+ {
+ return heap_new_impl<T,A1&,A2 const&,A3&>(a1,a2,a3);
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1 const& a1,A2& a2,A3& a3)
+ {
+ return heap_new_impl<T,A1 const&,A2&,A3&>(a1,a2,a3);
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1& a1,A2& a2,A3& a3)
+ {
+ return heap_new_impl<T,A1&,A2&,A3&>(a1,a2,a3);
+ }
+
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2 const& a2,A3 const& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&,A3 const&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2 const& a2,A3 const& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1&,A2 const&,A3 const&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2& a2,A3 const& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2&,A3 const&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2& a2,A3 const& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1&,A2&,A3 const&,A4 const&>(a1,a2,a3,a4);
+ }
+
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2 const& a2,A3& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&,A3&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2 const& a2,A3& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1&,A2 const&,A3&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2& a2,A3& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2&,A3&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2& a2,A3& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1&,A2&,A3&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2 const& a2,A3 const& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&,A3 const&,A4&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2 const& a2,A3 const& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1&,A2 const&,A3 const&,A4&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2& a2,A3 const& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2&,A3 const&,A4&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2& a2,A3 const& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1&,A2&,A3 const&,A4&>(a1,a2,a3,a4);
+ }
+
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2 const& a2,A3& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&,A3&,A4&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2 const& a2,A3& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1&,A2 const&,A3&,A4&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2& a2,A3& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2&,A3&,A4&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2& a2,A3& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1&,A2&,A3&,A4&>(a1,a2,a3,a4);
+ }
+
+#endif
+ template<typename T>
+ inline void heap_delete(T* data)
+ {
+ delete data;
+ }
+
+ template<typename T>
+ struct do_heap_delete
+ {
+ void operator()(T* data) const
+ {
+ detail::heap_delete(data);
+ }
+ };
+ }
+}
+
+
+#endif

Modified: trunk/boost/thread/thread.hpp
==============================================================================
--- trunk/boost/thread/thread.hpp (original)
+++ trunk/boost/thread/thread.hpp 2008-05-22 07:49:48 EDT (Thu, 22 May 2008)
@@ -3,7 +3,7 @@
 
 // thread.hpp
 //
-// (C) Copyright 2007 Anthony Williams
+// (C) Copyright 2007-8 Anthony Williams
 //
 // Distributed under the Boost Software License, Version 1.0. (See
 // accompanying file LICENSE_1_0.txt or copy at
@@ -12,11 +12,14 @@
 #include <boost/thread/detail/platform.hpp>
 
 #if defined(BOOST_THREAD_PLATFORM_WIN32)
-#include <boost/thread/win32/thread.hpp>
+#include <boost/thread/win32/thread_data.hpp>
 #elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
-#include <boost/thread/pthread/thread.hpp>
+#include <boost/thread/pthread/thread_data.hpp>
 #else
 #error "Boost threads unavailable on this platform"
 #endif
 
+#include <boost/thread/detail/thread.hpp>
+
+
 #endif

Deleted: trunk/boost/thread/win32/thread.hpp
==============================================================================
--- trunk/boost/thread/win32/thread.hpp 2008-05-22 07:49:48 EDT (Thu, 22 May 2008)
+++ (empty file)
@@ -1,665 +0,0 @@
-#ifndef BOOST_THREAD_THREAD_WIN32_HPP
-#define BOOST_THREAD_THREAD_WIN32_HPP
-// 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)
-// (C) Copyright 2007-8 Anthony Williams
-
-#include <exception>
-#include <boost/thread/exceptions.hpp>
-#include <ostream>
-#include <boost/thread/detail/move.hpp>
-#include <boost/intrusive_ptr.hpp>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/thread_time.hpp>
-#include "thread_primitives.hpp"
-#include "thread_heap_alloc.hpp"
-#include <boost/utility.hpp>
-#include <boost/assert.hpp>
-#include <list>
-#include <algorithm>
-#include <boost/ref.hpp>
-#include <boost/cstdint.hpp>
-#include <boost/bind.hpp>
-#include <stdlib.h>
-#include <memory>
-
-#ifdef BOOST_MSVC
-#pragma warning(push)
-#pragma warning(disable:4251)
-#endif
-
-namespace boost
-{
- class thread_interrupted
- {};
-
- namespace detail
- {
- struct thread_exit_callback_node;
- struct tss_data_node;
-
- struct thread_data_base;
- void intrusive_ptr_add_ref(thread_data_base * p);
- void intrusive_ptr_release(thread_data_base * p);
-
- struct thread_data_base
- {
- long count;
- detail::win32::handle_manager thread_handle;
- detail::win32::handle_manager interruption_handle;
- boost::detail::thread_exit_callback_node* thread_exit_callbacks;
- boost::detail::tss_data_node* tss_data;
- bool interruption_enabled;
- unsigned id;
-
- thread_data_base():
- count(0),thread_handle(detail::win32::invalid_handle_value),
- interruption_handle(create_anonymous_event(detail::win32::manual_reset_event,detail::win32::event_initially_reset)),
- thread_exit_callbacks(0),tss_data(0),
- interruption_enabled(true),
- id(0)
- {}
- virtual ~thread_data_base()
- {}
-
- friend void intrusive_ptr_add_ref(thread_data_base * p)
- {
- BOOST_INTERLOCKED_INCREMENT(&p->count);
- }
-
- friend void intrusive_ptr_release(thread_data_base * p)
- {
- if(!BOOST_INTERLOCKED_DECREMENT(&p->count))
- {
- detail::heap_delete(p);
- }
- }
-
- void interrupt()
- {
- BOOST_VERIFY(detail::win32::SetEvent(interruption_handle)!=0);
- }
-
-
- virtual void run()=0;
- };
-
- typedef boost::intrusive_ptr<detail::thread_data_base> thread_data_ptr;
-
- struct timeout
- {
- unsigned long start;
- uintmax_t milliseconds;
- bool relative;
- boost::system_time abs_time;
-
- static unsigned long const max_non_infinite_wait=0xfffffffe;
-
- timeout(uintmax_t milliseconds_):
- start(win32::GetTickCount()),
- milliseconds(milliseconds_),
- relative(true),
- abs_time(boost::get_system_time())
- {}
-
- timeout(boost::system_time const& abs_time_):
- start(win32::GetTickCount()),
- milliseconds(0),
- relative(false),
- abs_time(abs_time_)
- {}
-
- struct remaining_time
- {
- bool more;
- unsigned long milliseconds;
-
- remaining_time(uintmax_t remaining):
- more(remaining>max_non_infinite_wait),
- milliseconds(more?max_non_infinite_wait:(unsigned long)remaining)
- {}
- };
-
- remaining_time remaining_milliseconds() const
- {
- if(is_sentinel())
- {
- return remaining_time(win32::infinite);
- }
- else if(relative)
- {
- unsigned long const now=win32::GetTickCount();
- unsigned long const elapsed=now-start;
- return remaining_time((elapsed<milliseconds)?(milliseconds-elapsed):0);
- }
- else
- {
- system_time const now=get_system_time();
- if(abs_time<=now)
- {
- return remaining_time(0);
- }
- return remaining_time((abs_time-now).total_milliseconds()+1);
- }
- }
-
- bool is_sentinel() const
- {
- return milliseconds==~uintmax_t(0);
- }
-
-
- static timeout sentinel()
- {
- return timeout(sentinel_type());
- }
- private:
- struct sentinel_type
- {};
-
- explicit timeout(sentinel_type):
- start(0),milliseconds(~uintmax_t(0)),relative(true)
- {}
- };
- }
-
- class BOOST_THREAD_DECL thread
- {
- private:
- thread(thread&);
- thread& operator=(thread&);
-
- void release_handle();
-
- template<typename F>
- struct thread_data:
- detail::thread_data_base
- {
- F f;
-
-#ifdef BOOST_HAS_RVALUE_REFS
- thread_data(F&& f_):
- f(static_cast<F&&>(f_))
- {}
-#else
- thread_data(F f_):
- f(f_)
- {}
- thread_data(detail::thread_move_t<F> f_):
- f(f_)
- {}
-#endif
- void run()
- {
- f();
- }
- private:
- void operator=(thread_data&);
- thread_data(thread_data&);
- };
-
- mutable boost::mutex thread_info_mutex;
- detail::thread_data_ptr thread_info;
-
- static unsigned __stdcall thread_start_function(void* param);
-
- void start_thread();
-
- explicit thread(detail::thread_data_ptr data);
-
- detail::thread_data_ptr get_thread_info() const;
-
-#ifdef BOOST_HAS_RVALUE_REFS
- template<typename F>
- static inline detail::thread_data_ptr make_thread_info(F&& f)
- {
- return detail::heap_new<thread_data<F> >(static_cast<F&&>(f));
- }
-#else
- template<typename F>
- static inline detail::thread_data_ptr make_thread_info(F f)
- {
- return detail::heap_new<thread_data<F> >(f);
- }
- template<typename F>
- static inline detail::thread_data_ptr make_thread_info(boost::detail::thread_move_t<F> f)
- {
- return detail::heap_new<thread_data<F> >(f);
- }
-#endif
- public:
- thread();
- ~thread();
-
-#ifdef BOOST_HAS_RVALUE_REFS
- template <class F>
- thread(F&& f):
- thread_info(make_thread_info(static_cast<F&&>(f)))
- {
- start_thread();
- }
-
- thread(thread&& other)
- {
- thread_info.swap(other.thread_info);
- }
-
- thread& operator=(thread&& other)
- {
- thread_info=other.thread_info;
- other.thread_info.reset();
- return *this;
- }
-
- thread&& move()
- {
- return static_cast<thread&&>(*this);
- }
-
-#else
- template <class F>
- explicit thread(F f):
- thread_info(make_thread_info(f))
- {
- start_thread();
- }
-
- template <class F>
- thread(detail::thread_move_t<F> f):
- thread_info(make_thread_info(f))
- {
- start_thread();
- }
-
- thread(detail::thread_move_t<thread> x);
- thread& operator=(detail::thread_move_t<thread> x);
- operator detail::thread_move_t<thread>();
- detail::thread_move_t<thread> move();
-
-#endif
-
- template <class F,class A1>
- thread(F f,A1 a1):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1)))
- {
- start_thread();
- }
- template <class F,class A1,class A2>
- thread(F f,A1 a1,A2 a2):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3>
- thread(F f,A1 a1,A2 a2,A3 a3):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3,class A4>
- thread(F f,A1 a1,A2 a2,A3 a3,A4 a4):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3,class A4,class A5>
- thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3,class A4,class A5,class A6>
- thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5,a6)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3,class A4,class A5,class A6,class A7>
- thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5,a6,a7)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3,class A4,class A5,class A6,class A7,class A8>
- thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7,A8 a8):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5,a6,a7,a8)))
- {
- start_thread();
- }
-
- template <class F,class A1,class A2,class A3,class A4,class A5,class A6,class A7,class A8,class A9>
- thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7,A8 a8,A9 a9):
- thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1,a2,a3,a4,a5,a6,a7,a8,a9)))
- {
- start_thread();
- }
-
- void swap(thread& x);
-
- class id;
- id get_id() const;
-
-
- bool joinable() const;
- void join();
- bool timed_join(const system_time& wait_until);
-
- template<typename TimeDuration>
- inline bool timed_join(TimeDuration const& rel_time)
- {
- return timed_join(get_system_time()+rel_time);
- }
- void detach();
-
- static unsigned hardware_concurrency();
-
- typedef detail::win32::handle native_handle_type;
- native_handle_type native_handle();
-
- // backwards compatibility
- bool operator==(const thread& other) const;
- bool operator!=(const thread& other) const;
-
- static void yield();
- static void sleep(const system_time& xt);
-
- // extensions
- void interrupt();
- bool interruption_requested() const;
- };
-
-#ifdef BOOST_HAS_RVALUE_REFS
- inline thread&& move(thread&& t)
- {
- return t;
- }
-#else
- inline detail::thread_move_t<thread> move(detail::thread_move_t<thread> t)
- {
- return t;
- }
-#endif
-
- template<typename F>
- struct thread::thread_data<boost::reference_wrapper<F> >:
- detail::thread_data_base
- {
- F& f;
-
- thread_data(boost::reference_wrapper<F> f_):
- f(f_)
- {}
-
- void run()
- {
- f();
- }
- };
-
- template<typename F>
- struct thread::thread_data<const boost::reference_wrapper<F> >:
- detail::thread_data_base
- {
- F& f;
-
- thread_data(const boost::reference_wrapper<F> f_):
- f(f_)
- {}
-
- void run()
- {
- f();
- }
- };
-
-
- namespace this_thread
- {
- class BOOST_THREAD_DECL disable_interruption
- {
- disable_interruption(const disable_interruption&);
- disable_interruption& operator=(const disable_interruption&);
-
- bool interruption_was_enabled;
- friend class restore_interruption;
- public:
- disable_interruption();
- ~disable_interruption();
- };
-
- class BOOST_THREAD_DECL restore_interruption
- {
- restore_interruption(const restore_interruption&);
- restore_interruption& operator=(const restore_interruption&);
- public:
- explicit restore_interruption(disable_interruption& d);
- ~restore_interruption();
- };
-
- thread::id BOOST_THREAD_DECL get_id();
-
- bool BOOST_THREAD_DECL interruptible_wait(detail::win32::handle handle_to_wait_for,detail::timeout target_time);
- inline bool interruptible_wait(unsigned long milliseconds)
- {
- return interruptible_wait(detail::win32::invalid_handle_value,milliseconds);
- }
-
- void BOOST_THREAD_DECL interruption_point();
- bool BOOST_THREAD_DECL interruption_enabled();
- bool BOOST_THREAD_DECL interruption_requested();
-
- void BOOST_THREAD_DECL yield();
- template<typename TimeDuration>
- void sleep(TimeDuration const& rel_time)
- {
- interruptible_wait(static_cast<unsigned long>(rel_time.total_milliseconds()));
- }
- }
-
- class thread::id
- {
- private:
- detail::thread_data_ptr thread_data;
-
- id(detail::thread_data_ptr thread_data_):
- thread_data(thread_data_)
- {}
- friend class thread;
- friend id this_thread::get_id();
- public:
- id():
- thread_data(0)
- {}
-
- bool operator==(const id& y) const
- {
- return thread_data==y.thread_data;
- }
-
- bool operator!=(const id& y) const
- {
- return thread_data!=y.thread_data;
- }
-
- bool operator<(const id& y) const
- {
- return thread_data<y.thread_data;
- }
-
- bool operator>(const id& y) const
- {
- return y.thread_data<thread_data;
- }
-
- bool operator<=(const id& y) const
- {
- return !(y.thread_data<thread_data);
- }
-
- bool operator>=(const id& y) const
- {
- return !(thread_data<y.thread_data);
- }
-
- template<class charT, class traits>
- friend std::basic_ostream<charT, traits>&
- operator<<(std::basic_ostream<charT, traits>& os, const id& x)
- {
- if(x.thread_data)
- {
- return os<<x.thread_data;
- }
- else
- {
- return os<<"{Not-any-thread}";
- }
- }
-
- void interrupt()
- {
- if(thread_data)
- {
- thread_data->interrupt();
- }
- }
-
- };
-
- inline bool thread::operator==(const thread& other) const
- {
- return get_id()==other.get_id();
- }
-
- inline bool thread::operator!=(const thread& other) const
- {
- return get_id()!=other.get_id();
- }
-
- namespace detail
- {
- struct thread_exit_function_base
- {
- virtual ~thread_exit_function_base()
- {}
- virtual void operator()() const=0;
- };
-
- template<typename F>
- struct thread_exit_function:
- thread_exit_function_base
- {
- F f;
-
- thread_exit_function(F f_):
- f(f_)
- {}
-
- void operator()() const
- {
- f();
- }
- };
-
- void add_thread_exit_function(thread_exit_function_base*);
- }
-
- namespace this_thread
- {
- template<typename F>
- void at_thread_exit(F f)
- {
- detail::thread_exit_function_base* const thread_exit_func=detail::heap_new<detail::thread_exit_function<F> >(f);
- detail::add_thread_exit_function(thread_exit_func);
- }
- }
-
- class thread_group:
- private noncopyable
- {
- public:
- ~thread_group()
- {
- for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
- it!=end;
- ++it)
- {
- delete *it;
- }
- }
-
- template<typename F>
- thread* create_thread(F threadfunc)
- {
- boost::lock_guard<mutex> guard(m);
- std::auto_ptr<thread> new_thread(new thread(threadfunc));
- threads.push_back(new_thread.get());
- return new_thread.release();
- }
-
- void add_thread(thread* thrd)
- {
- if(thrd)
- {
- boost::lock_guard<mutex> guard(m);
- threads.push_back(thrd);
- }
- }
-
- void remove_thread(thread* thrd)
- {
- boost::lock_guard<mutex> guard(m);
- std::list<thread*>::iterator const it=std::find(threads.begin(),threads.end(),thrd);
- if(it!=threads.end())
- {
- threads.erase(it);
- }
- }
-
- void join_all()
- {
- boost::lock_guard<mutex> guard(m);
-
- for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
- it!=end;
- ++it)
- {
- (*it)->join();
- }
- }
-
- void interrupt_all()
- {
- boost::lock_guard<mutex> guard(m);
-
- for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
- it!=end;
- ++it)
- {
- (*it)->interrupt();
- }
- }
-
- size_t size() const
- {
- boost::lock_guard<mutex> guard(m);
- return threads.size();
- }
-
- private:
- std::list<thread*> threads;
- mutable mutex m;
- };
-}
-
-#ifdef BOOST_MSVC
-#pragma warning(pop)
-#endif
-
-#endif

Added: trunk/boost/thread/win32/thread_data.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/thread/win32/thread_data.hpp 2008-05-22 07:49:48 EDT (Thu, 22 May 2008)
@@ -0,0 +1,175 @@
+#ifndef BOOST_THREAD_PTHREAD_THREAD_DATA_HPP
+#define BOOST_THREAD_PTHREAD_THREAD_DATA_HPP
+// 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)
+// (C) Copyright 2008 Anthony Williams
+
+#include <boost/thread/detail/config.hpp>
+#include <boost/intrusive_ptr.hpp>
+#include <boost/thread/thread_time.hpp>
+#include "thread_primitives.hpp"
+#include "thread_heap_alloc.hpp"
+
+namespace boost
+{
+ namespace detail
+ {
+ struct thread_exit_callback_node;
+ struct tss_data_node;
+
+ struct thread_data_base;
+ void intrusive_ptr_add_ref(thread_data_base * p);
+ void intrusive_ptr_release(thread_data_base * p);
+
+ struct thread_data_base
+ {
+ long count;
+ detail::win32::handle_manager thread_handle;
+ detail::win32::handle_manager interruption_handle;
+ boost::detail::thread_exit_callback_node* thread_exit_callbacks;
+ boost::detail::tss_data_node* tss_data;
+ bool interruption_enabled;
+ unsigned id;
+
+ thread_data_base():
+ count(0),thread_handle(detail::win32::invalid_handle_value),
+ interruption_handle(create_anonymous_event(detail::win32::manual_reset_event,detail::win32::event_initially_reset)),
+ thread_exit_callbacks(0),tss_data(0),
+ interruption_enabled(true),
+ id(0)
+ {}
+ virtual ~thread_data_base()
+ {}
+
+ friend void intrusive_ptr_add_ref(thread_data_base * p)
+ {
+ BOOST_INTERLOCKED_INCREMENT(&p->count);
+ }
+
+ friend void intrusive_ptr_release(thread_data_base * p)
+ {
+ if(!BOOST_INTERLOCKED_DECREMENT(&p->count))
+ {
+ detail::heap_delete(p);
+ }
+ }
+
+ void interrupt()
+ {
+ BOOST_VERIFY(detail::win32::SetEvent(interruption_handle)!=0);
+ }
+
+ typedef detail::win32::handle native_handle_type;
+
+ virtual void run()=0;
+ };
+
+ typedef boost::intrusive_ptr<detail::thread_data_base> thread_data_ptr;
+
+ struct timeout
+ {
+ unsigned long start;
+ uintmax_t milliseconds;
+ bool relative;
+ boost::system_time abs_time;
+
+ static unsigned long const max_non_infinite_wait=0xfffffffe;
+
+ timeout(uintmax_t milliseconds_):
+ start(win32::GetTickCount()),
+ milliseconds(milliseconds_),
+ relative(true),
+ abs_time(boost::get_system_time())
+ {}
+
+ timeout(boost::system_time const& abs_time_):
+ start(win32::GetTickCount()),
+ milliseconds(0),
+ relative(false),
+ abs_time(abs_time_)
+ {}
+
+ struct remaining_time
+ {
+ bool more;
+ unsigned long milliseconds;
+
+ remaining_time(uintmax_t remaining):
+ more(remaining>max_non_infinite_wait),
+ milliseconds(more?max_non_infinite_wait:(unsigned long)remaining)
+ {}
+ };
+
+ remaining_time remaining_milliseconds() const
+ {
+ if(is_sentinel())
+ {
+ return remaining_time(win32::infinite);
+ }
+ else if(relative)
+ {
+ unsigned long const now=win32::GetTickCount();
+ unsigned long const elapsed=now-start;
+ return remaining_time((elapsed<milliseconds)?(milliseconds-elapsed):0);
+ }
+ else
+ {
+ system_time const now=get_system_time();
+ if(abs_time<=now)
+ {
+ return remaining_time(0);
+ }
+ return remaining_time((abs_time-now).total_milliseconds()+1);
+ }
+ }
+
+ bool is_sentinel() const
+ {
+ return milliseconds==~uintmax_t(0);
+ }
+
+
+ static timeout sentinel()
+ {
+ return timeout(sentinel_type());
+ }
+ private:
+ struct sentinel_type
+ {};
+
+ explicit timeout(sentinel_type):
+ start(0),milliseconds(~uintmax_t(0)),relative(true)
+ {}
+ };
+ }
+
+ namespace this_thread
+ {
+ void BOOST_THREAD_DECL yield();
+
+ bool BOOST_THREAD_DECL interruptible_wait(detail::win32::handle handle_to_wait_for,detail::timeout target_time);
+ inline void interruptible_wait(unsigned long milliseconds)
+ {
+ interruptible_wait(detail::win32::invalid_handle_value,milliseconds);
+ }
+ inline void interruptible_wait(system_time const& abs_time)
+ {
+ interruptible_wait(detail::win32::invalid_handle_value,abs_time);
+ }
+
+ template<typename TimeDuration>
+ inline void sleep(TimeDuration const& rel_time)
+ {
+ interruptible_wait(static_cast<unsigned long>(rel_time.total_milliseconds()));
+ }
+ inline void sleep(system_time const& abs_time)
+ {
+ interruptible_wait(abs_time);
+ }
+ }
+
+}
+
+
+#endif

Modified: trunk/boost/thread/win32/thread_heap_alloc.hpp
==============================================================================
--- trunk/boost/thread/win32/thread_heap_alloc.hpp (original)
+++ trunk/boost/thread/win32/thread_heap_alloc.hpp 2008-05-22 07:49:48 EDT (Thu, 22 May 2008)
@@ -69,7 +69,7 @@
         }
             
         template<typename T>
- T* heap_new()
+ inline T* heap_new()
         {
             void* const heap_memory=allocate_raw_heap_memory(sizeof(T));
             try
@@ -86,7 +86,7 @@
 
 #ifdef BOOST_HAS_RVALUE_REFS
         template<typename T,typename A1>
- T* heap_new(A1&& a1)
+ inline T* heap_new(A1&& a1)
         {
             void* const heap_memory=allocate_raw_heap_memory(sizeof(T));
             try
@@ -100,9 +100,56 @@
                 throw;
             }
         }
+ template<typename T,typename A1,typename A2>
+ inline T* heap_new(A1&& a1,A2&& a2)
+ {
+ void* const heap_memory=allocate_raw_heap_memory(sizeof(T));
+ try
+ {
+ T* const data=new (heap_memory) T(static_cast<A1&&>(a1),static_cast<A2&&>(a2));
+ return data;
+ }
+ catch(...)
+ {
+ free_raw_heap_memory(heap_memory);
+ throw;
+ }
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1&& a1,A2&& a2,A3&& a3)
+ {
+ void* const heap_memory=allocate_raw_heap_memory(sizeof(T));
+ try
+ {
+ T* const data=new (heap_memory) T(static_cast<A1&&>(a1),static_cast<A2&&>(a2),
+ static_cast<A3&&>(a3));
+ return data;
+ }
+ catch(...)
+ {
+ free_raw_heap_memory(heap_memory);
+ throw;
+ }
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1&& a1,A2&& a2,A3&& a3,A4&& a4)
+ {
+ void* const heap_memory=allocate_raw_heap_memory(sizeof(T));
+ try
+ {
+ T* const data=new (heap_memory) T(static_cast<A1&&>(a1),static_cast<A2&&>(a2),
+ static_cast<A3&&>(a3),static_cast<A4&&>(a4));
+ return data;
+ }
+ catch(...)
+ {
+ free_raw_heap_memory(heap_memory);
+ throw;
+ }
+ }
 #else
         template<typename T,typename A1>
- T* heap_new(A1 a1)
+ inline T* heap_new_impl(A1 a1)
         {
             void* const heap_memory=allocate_raw_heap_memory(sizeof(T));
             try
@@ -116,9 +163,9 @@
                 throw;
             }
         }
-#endif
+
         template<typename T,typename A1,typename A2>
- T* heap_new(A1 a1,A2 a2)
+ inline T* heap_new_impl(A1 a1,A2 a2)
         {
             void* const heap_memory=allocate_raw_heap_memory(sizeof(T));
             try
@@ -134,7 +181,7 @@
         }
 
         template<typename T,typename A1,typename A2,typename A3>
- T* heap_new(A1 a1,A2 a2,A3 a3)
+ inline T* heap_new_impl(A1 a1,A2 a2,A3 a3)
         {
             void* const heap_memory=allocate_raw_heap_memory(sizeof(T));
             try
@@ -148,9 +195,9 @@
                 throw;
             }
         }
-
+
         template<typename T,typename A1,typename A2,typename A3,typename A4>
- T* heap_new(A1 a1,A2 a2,A3 a3,A4 a4)
+ inline T* heap_new_impl(A1 a1,A2 a2,A3 a3,A4 a4)
         {
             void* const heap_memory=allocate_raw_heap_memory(sizeof(T));
             try
@@ -164,9 +211,168 @@
                 throw;
             }
         }
+
+
+ template<typename T,typename A1>
+ inline T* heap_new(A1 const& a1)
+ {
+ return heap_new_impl<T,A1 const&>(a1);
+ }
+ template<typename T,typename A1>
+ inline T* heap_new(A1& a1)
+ {
+ return heap_new_impl<T,A1&>(a1);
+ }
+
+ template<typename T,typename A1,typename A2>
+ inline T* heap_new(A1 const& a1,A2 const& a2)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&>(a1,a2);
+ }
+ template<typename T,typename A1,typename A2>
+ inline T* heap_new(A1& a1,A2 const& a2)
+ {
+ return heap_new_impl<T,A1&,A2 const&>(a1,a2);
+ }
+ template<typename T,typename A1,typename A2>
+ inline T* heap_new(A1 const& a1,A2& a2)
+ {
+ return heap_new_impl<T,A1 const&,A2&>(a1,a2);
+ }
+ template<typename T,typename A1,typename A2>
+ inline T* heap_new(A1& a1,A2& a2)
+ {
+ return heap_new_impl<T,A1&,A2&>(a1,a2);
+ }
+
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1 const& a1,A2 const& a2,A3 const& a3)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&,A3 const&>(a1,a2,a3);
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1& a1,A2 const& a2,A3 const& a3)
+ {
+ return heap_new_impl<T,A1&,A2 const&,A3 const&>(a1,a2,a3);
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1 const& a1,A2& a2,A3 const& a3)
+ {
+ return heap_new_impl<T,A1 const&,A2&,A3 const&>(a1,a2,a3);
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1& a1,A2& a2,A3 const& a3)
+ {
+ return heap_new_impl<T,A1&,A2&,A3 const&>(a1,a2,a3);
+ }
+
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1 const& a1,A2 const& a2,A3& a3)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&,A3&>(a1,a2,a3);
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1& a1,A2 const& a2,A3& a3)
+ {
+ return heap_new_impl<T,A1&,A2 const&,A3&>(a1,a2,a3);
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1 const& a1,A2& a2,A3& a3)
+ {
+ return heap_new_impl<T,A1 const&,A2&,A3&>(a1,a2,a3);
+ }
+ template<typename T,typename A1,typename A2,typename A3>
+ inline T* heap_new(A1& a1,A2& a2,A3& a3)
+ {
+ return heap_new_impl<T,A1&,A2&,A3&>(a1,a2,a3);
+ }
+
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2 const& a2,A3 const& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&,A3 const&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2 const& a2,A3 const& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1&,A2 const&,A3 const&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2& a2,A3 const& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2&,A3 const&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2& a2,A3 const& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1&,A2&,A3 const&,A4 const&>(a1,a2,a3,a4);
+ }
+
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2 const& a2,A3& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&,A3&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2 const& a2,A3& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1&,A2 const&,A3&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2& a2,A3& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2&,A3&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2& a2,A3& a3,A4 const& a4)
+ {
+ return heap_new_impl<T,A1&,A2&,A3&,A4 const&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2 const& a2,A3 const& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&,A3 const&,A4&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2 const& a2,A3 const& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1&,A2 const&,A3 const&,A4&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2& a2,A3 const& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2&,A3 const&,A4&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2& a2,A3 const& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1&,A2&,A3 const&,A4&>(a1,a2,a3,a4);
+ }
+
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2 const& a2,A3& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2 const&,A3&,A4&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2 const& a2,A3& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1&,A2 const&,A3&,A4&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1 const& a1,A2& a2,A3& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1 const&,A2&,A3&,A4&>(a1,a2,a3,a4);
+ }
+ template<typename T,typename A1,typename A2,typename A3,typename A4>
+ inline T* heap_new(A1& a1,A2& a2,A3& a3,A4& a4)
+ {
+ return heap_new_impl<T,A1&,A2&,A3&,A4&>(a1,a2,a3,a4);
+ }
         
+#endif
         template<typename T>
- void heap_delete(T* data)
+ inline void heap_delete(T* data)
         {
             data->~T();
             free_raw_heap_memory(data);

Modified: trunk/libs/thread/src/pthread/thread.cpp
==============================================================================
--- trunk/libs/thread/src/pthread/thread.cpp (original)
+++ trunk/libs/thread/src/pthread/thread.cpp 2008-05-22 07:49:48 EDT (Thu, 22 May 2008)
@@ -28,6 +28,9 @@
 {
     namespace detail
     {
+ thread_data_base::~thread_data_base()
+ {}
+
         struct thread_exit_callback_node
         {
             boost::detail::thread_exit_function_base* func;
@@ -119,7 +122,7 @@
         {
             void* thread_proxy(void* param)
             {
- boost::shared_ptr<boost::detail::thread_data_base> thread_info = static_cast<boost::detail::thread_data_base*>(param)->self;
+ boost::detail::thread_data_ptr thread_info = static_cast<boost::detail::thread_data_base*>(param)->self;
                 thread_info->self.reset();
                 detail::set_current_thread_data(thread_info.get());
                 try
@@ -153,6 +156,10 @@
             
             void run()
             {}
+
+ private:
+ externally_launched_thread(externally_launched_thread&);
+ void operator=(externally_launched_thread&);
         };
 
         detail::thread_data_base* make_external_thread_data()
@@ -226,17 +233,6 @@
         thread_info.swap(x.thread_info);
     }
 
-
- bool thread::operator==(const thread& other) const
- {
- return get_id()==other.get_id();
- }
-
- bool thread::operator!=(const thread& other) const
- {
- return !operator==(other);
- }
-
     detail::thread_data_ptr thread::get_thread_info() const
     {
         lock_guard<mutex> l(thread_info_mutex);
@@ -361,57 +357,61 @@
         }
     }
 
- void thread::sleep(const system_time& st)
+ namespace this_thread
     {
- detail::thread_data_base* const thread_info=detail::get_current_thread_data();
         
- if(thread_info)
+ void sleep(const system_time& st)
         {
- unique_lock<mutex> lk(thread_info->sleep_mutex);
- while(thread_info->sleep_condition.timed_wait(lk,st));
- }
- else
- {
- xtime const xt=get_xtime(st);
-
- for (int foo=0; foo < 5; ++foo)
+ detail::thread_data_base* const thread_info=detail::get_current_thread_data();
+
+ if(thread_info)
+ {
+ unique_lock<mutex> lk(thread_info->sleep_mutex);
+ while(thread_info->sleep_condition.timed_wait(lk,st));
+ }
+ else
             {
+ xtime const xt=get_xtime(st);
+
+ for (int foo=0; foo < 5; ++foo)
+ {
 # if defined(BOOST_HAS_PTHREAD_DELAY_NP)
- timespec ts;
- to_timespec_duration(xt, ts);
- BOOST_VERIFY(!pthread_delay_np(&ts));
+ timespec ts;
+ to_timespec_duration(xt, ts);
+ BOOST_VERIFY(!pthread_delay_np(&ts));
 # elif defined(BOOST_HAS_NANOSLEEP)
- timespec ts;
- to_timespec_duration(xt, ts);
+ timespec ts;
+ to_timespec_duration(xt, ts);
                 
- // nanosleep takes a timespec that is an offset, not
- // an absolute time.
- nanosleep(&ts, 0);
+ // nanosleep takes a timespec that is an offset, not
+ // an absolute time.
+ nanosleep(&ts, 0);
 # else
- mutex mx;
- mutex::scoped_lock lock(mx);
- condition cond;
- cond.timed_wait(lock, xt);
+ mutex mx;
+ mutex::scoped_lock lock(mx);
+ condition cond;
+ cond.timed_wait(lock, xt);
 # endif
- xtime cur;
- xtime_get(&cur, TIME_UTC);
- if (xtime_cmp(xt, cur) <= 0)
- return;
+ xtime cur;
+ xtime_get(&cur, TIME_UTC);
+ if (xtime_cmp(xt, cur) <= 0)
+ return;
+ }
             }
         }
- }
 
- void thread::yield()
- {
+ void yield()
+ {
 # if defined(BOOST_HAS_SCHED_YIELD)
- BOOST_VERIFY(!sched_yield());
+ BOOST_VERIFY(!sched_yield());
 # elif defined(BOOST_HAS_PTHREAD_YIELD)
- BOOST_VERIFY(!pthread_yield());
+ BOOST_VERIFY(!pthread_yield());
 # else
- xtime xt;
- xtime_get(&xt, TIME_UTC);
- sleep(xt);
+ xtime xt;
+ xtime_get(&xt, TIME_UTC);
+ sleep(xt);
 # endif
+ }
     }
 
     unsigned thread::hardware_concurrency()
@@ -622,85 +622,85 @@
         }
     }
 
- thread_group::thread_group()
- {
- }
-
- thread_group::~thread_group()
- {
- // We shouldn't have to scoped_lock here, since referencing this object
- // from another thread while we're deleting it in the current thread is
- // going to lead to undefined behavior any way.
- for (std::list<thread*>::iterator it = m_threads.begin();
- it != m_threads.end(); ++it)
- {
- delete (*it);
- }
- }
-
- thread* thread_group::create_thread(const function0<void>& threadfunc)
- {
- // No scoped_lock required here since the only "shared data" that's
- // modified here occurs inside add_thread which does scoped_lock.
- std::auto_ptr<thread> thrd(new thread(threadfunc));
- add_thread(thrd.get());
- return thrd.release();
- }
-
- void thread_group::add_thread(thread* thrd)
- {
- mutex::scoped_lock scoped_lock(m_mutex);
-
- // For now we'll simply ignore requests to add a thread object multiple
- // times. Should we consider this an error and either throw or return an
- // error value?
- std::list<thread*>::iterator it = std::find(m_threads.begin(),
- m_threads.end(), thrd);
- BOOST_ASSERT(it == m_threads.end());
- if (it == m_threads.end())
- m_threads.push_back(thrd);
- }
-
- void thread_group::remove_thread(thread* thrd)
- {
- mutex::scoped_lock scoped_lock(m_mutex);
-
- // For now we'll simply ignore requests to remove a thread object that's
- // not in the group. Should we consider this an error and either throw or
- // return an error value?
- std::list<thread*>::iterator it = std::find(m_threads.begin(),
- m_threads.end(), thrd);
- BOOST_ASSERT(it != m_threads.end());
- if (it != m_threads.end())
- m_threads.erase(it);
- }
-
- void thread_group::join_all()
- {
- mutex::scoped_lock scoped_lock(m_mutex);
- for (std::list<thread*>::iterator it = m_threads.begin();
- it != m_threads.end(); ++it)
- {
- (*it)->join();
- }
- }
-
- void thread_group::interrupt_all()
- {
- boost::lock_guard<mutex> guard(m_mutex);
+// thread_group::thread_group()
+// {
+// }
+
+// thread_group::~thread_group()
+// {
+// // We shouldn't have to scoped_lock here, since referencing this object
+// // from another thread while we're deleting it in the current thread is
+// // going to lead to undefined behavior any way.
+// for (std::list<thread*>::iterator it = m_threads.begin();
+// it != m_threads.end(); ++it)
+// {
+// delete (*it);
+// }
+// }
+
+// thread* thread_group::create_thread(const function0<void>& threadfunc)
+// {
+// // No scoped_lock required here since the only "shared data" that's
+// // modified here occurs inside add_thread which does scoped_lock.
+// std::auto_ptr<thread> thrd(new thread(threadfunc));
+// add_thread(thrd.get());
+// return thrd.release();
+// }
+
+// void thread_group::add_thread(thread* thrd)
+// {
+// mutex::scoped_lock scoped_lock(m_mutex);
+
+// // For now we'll simply ignore requests to add a thread object multiple
+// // times. Should we consider this an error and either throw or return an
+// // error value?
+// std::list<thread*>::iterator it = std::find(m_threads.begin(),
+// m_threads.end(), thrd);
+// BOOST_ASSERT(it == m_threads.end());
+// if (it == m_threads.end())
+// m_threads.push_back(thrd);
+// }
+
+// void thread_group::remove_thread(thread* thrd)
+// {
+// mutex::scoped_lock scoped_lock(m_mutex);
+
+// // For now we'll simply ignore requests to remove a thread object that's
+// // not in the group. Should we consider this an error and either throw or
+// // return an error value?
+// std::list<thread*>::iterator it = std::find(m_threads.begin(),
+// m_threads.end(), thrd);
+// BOOST_ASSERT(it != m_threads.end());
+// if (it != m_threads.end())
+// m_threads.erase(it);
+// }
+
+// void thread_group::join_all()
+// {
+// mutex::scoped_lock scoped_lock(m_mutex);
+// for (std::list<thread*>::iterator it = m_threads.begin();
+// it != m_threads.end(); ++it)
+// {
+// (*it)->join();
+// }
+// }
+
+// void thread_group::interrupt_all()
+// {
+// boost::lock_guard<mutex> guard(m_mutex);
             
- for(std::list<thread*>::iterator it=m_threads.begin(),end=m_threads.end();
- it!=end;
- ++it)
- {
- (*it)->interrupt();
- }
- }
+// for(std::list<thread*>::iterator it=m_threads.begin(),end=m_threads.end();
+// it!=end;
+// ++it)
+// {
+// (*it)->interrupt();
+// }
+// }
         
 
- size_t thread_group::size() const
- {
- return m_threads.size();
- }
+// size_t thread_group::size() const
+// {
+// return m_threads.size();
+// }
 
 }

Modified: trunk/libs/thread/src/win32/thread.cpp
==============================================================================
--- trunk/libs/thread/src/win32/thread.cpp (original)
+++ trunk/libs/thread/src/win32/thread.cpp 2008-05-22 07:49:48 EDT (Thu, 22 May 2008)
@@ -81,25 +81,6 @@
 
     }
 
- void thread::yield()
- {
- this_thread::yield();
- }
-
- void thread::sleep(const system_time& target)
- {
- system_time const now(get_system_time());
-
- if(target<=now)
- {
- this_thread::yield();
- }
- else
- {
- this_thread::sleep(target-now);
- }
- }
-
     namespace detail
     {
         struct thread_exit_callback_node
@@ -164,26 +145,24 @@
             set_current_thread_data(0);
         }
         
- }
-
-
- unsigned __stdcall thread::thread_start_function(void* param)
- {
- detail::thread_data_base* const thread_info(reinterpret_cast<detail::thread_data_base*>(param));
- set_current_thread_data(thread_info);
- try
- {
- thread_info->run();
- }
- catch(thread_interrupted const&)
- {
- }
- catch(...)
+ unsigned __stdcall thread_start_function(void* param)
         {
- std::terminate();
+ detail::thread_data_base* const thread_info(reinterpret_cast<detail::thread_data_base*>(param));
+ set_current_thread_data(thread_info);
+ try
+ {
+ thread_info->run();
+ }
+ catch(thread_interrupted const&)
+ {
+ }
+ catch(...)
+ {
+ std::terminate();
+ }
+ run_thread_exit_callbacks();
+ return 0;
         }
- run_thread_exit_callbacks();
- return 0;
     }
 
     thread::thread()


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