mirror of
https://github.com/boostorg/thread.git
synced 2026-02-08 11:12:23 +00:00
Compare commits
23 Commits
boost-1.35
...
svn-branch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
870d154ca1 | ||
|
|
25ad6e3f8f | ||
|
|
df0197b617 | ||
|
|
a89c4f01ad | ||
|
|
ae67099633 | ||
|
|
57542d3a5c | ||
|
|
9a1da14116 | ||
|
|
ed050d753d | ||
|
|
8bec363710 | ||
|
|
7c68e190a9 | ||
|
|
7ebf5ea3d1 | ||
|
|
11e0435a4b | ||
|
|
d15ee57cd1 | ||
|
|
56d660b7fd | ||
|
|
792958e693 | ||
|
|
914e67dc04 | ||
|
|
b50a7ccb61 | ||
|
|
f827709d42 | ||
|
|
36abb42175 | ||
|
|
40f3b1b4c8 | ||
|
|
4f35e25688 | ||
|
|
270e88edd7 | ||
|
|
5ded171247 |
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.acknowledgements"
|
||||
last-revision="$Date$">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/barrier.hpp"
|
||||
last-revision="$Date$">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<bibliography id="thread.bibliography"
|
||||
last-revision="$Date$">
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Copyright (c) 2007 Roland Schwarz
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.build" last-revision="$Date$">
|
||||
<title>Build</title>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.concepts" last-revision="$Date$">
|
||||
<title>Concepts</title>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/condition.hpp"
|
||||
last-revision="$Date$">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.configuration" last-revision="$Date$">
|
||||
<title>Configuration</title>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.design" last-revision="$Date$">
|
||||
<title>Design</title>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<!ENTITY Boost "<emphasis role='bold'>Boost</emphasis>">
|
||||
<!ENTITY Boost.Thread "<emphasis role='bold'>Boost.Thread</emphasis>">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/exceptions.hpp"
|
||||
last-revision="$Date$">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.faq" last-revision="$Date$">
|
||||
<title>Frequently Asked Questions</title>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<glossary id="thread.glossary" last-revision="$Date$">
|
||||
<title>Glossary</title>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.implementation_notes" last-revision="$Date$">
|
||||
<title>Implementation Notes</title>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<!-- Copyright (c) 2002-2003 Beman Dawes, William E. Kempf.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/mutex.hpp"
|
||||
last-revision="$Date$">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/once.hpp"
|
||||
last-revision="$Date$">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.overview" last-revision="$Date$">
|
||||
<title>Overview</title>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.rationale" last-revision="$Date$">
|
||||
<title>Rationale</title>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/read_write_mutex.hpp"
|
||||
last-revision="$Date$">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/recursive_mutex.hpp"
|
||||
last-revision="$Date$">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<library-reference id="thread.reference"
|
||||
last-revision="$Date$"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<section id="thread.release_notes" last-revision="$Date$">
|
||||
<title>Release Notes</title>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/thread.hpp"
|
||||
last-revision="$Date$">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<library name="Thread" dirname="thread" id="thread"
|
||||
last-revision="$Date$"
|
||||
@@ -25,7 +25,7 @@ xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
</copyright>
|
||||
<legalnotice>
|
||||
<para>Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)</para>
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)</para>
|
||||
</legalnotice>
|
||||
<librarypurpose>Portable C++ multi-threading</librarypurpose>
|
||||
<librarycategory name="category:concurrent" />
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/tss.hpp"
|
||||
last-revision="$Date$">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
]>
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
<header name="boost/thread/xtime.hpp"
|
||||
last-revision="$Date$">
|
||||
|
||||
@@ -40,62 +40,44 @@ namespace boost
|
||||
{
|
||||
class thread_id
|
||||
{
|
||||
private:
|
||||
detail::thread_data_ptr thread_data;
|
||||
|
||||
thread_id(detail::thread_data_ptr thread_data_):
|
||||
thread_data(thread_data_)
|
||||
{}
|
||||
boost::optional<pthread_t> id;
|
||||
|
||||
friend class boost::thread;
|
||||
|
||||
friend thread_id this_thread::get_id();
|
||||
public:
|
||||
thread_id():
|
||||
thread_data()
|
||||
|
||||
thread_id(pthread_t id_):
|
||||
id(id_)
|
||||
{}
|
||||
|
||||
|
||||
public:
|
||||
thread_id()
|
||||
{}
|
||||
|
||||
bool operator==(const thread_id& y) const
|
||||
{
|
||||
return thread_data==y.thread_data;
|
||||
return (id && y.id) && (pthread_equal(*id,*y.id)!=0);
|
||||
}
|
||||
|
||||
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);
|
||||
return !(*this==y);
|
||||
}
|
||||
|
||||
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)
|
||||
if(x.id)
|
||||
{
|
||||
return os<<x.thread_data;
|
||||
return os<<*x.id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return os<<"{Not-any-thread}";
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -126,13 +108,13 @@ namespace boost
|
||||
};
|
||||
|
||||
mutable boost::mutex thread_info_mutex;
|
||||
detail::thread_data_ptr thread_info;
|
||||
boost::shared_ptr<detail::thread_data_base> thread_info;
|
||||
|
||||
void start_thread();
|
||||
|
||||
explicit thread(detail::thread_data_ptr data);
|
||||
explicit thread(boost::shared_ptr<detail::thread_data_base> data);
|
||||
|
||||
detail::thread_data_ptr get_thread_info() const;
|
||||
boost::shared_ptr<detail::thread_data_base> get_thread_info() const;
|
||||
|
||||
public:
|
||||
thread();
|
||||
@@ -237,7 +219,10 @@ namespace boost
|
||||
~restore_interruption();
|
||||
};
|
||||
|
||||
BOOST_THREAD_DECL thread::id get_id();
|
||||
inline thread::id get_id()
|
||||
{
|
||||
return thread::id(pthread_self());
|
||||
}
|
||||
|
||||
BOOST_THREAD_DECL void interruption_point();
|
||||
BOOST_THREAD_DECL bool interruption_enabled();
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <pthread.h>
|
||||
@@ -22,14 +21,10 @@ namespace boost
|
||||
{
|
||||
struct thread_exit_callback_node;
|
||||
struct tss_data_node;
|
||||
|
||||
struct thread_data_base;
|
||||
typedef boost::shared_ptr<thread_data_base> thread_data_ptr;
|
||||
|
||||
struct thread_data_base:
|
||||
enable_shared_from_this<thread_data_base>
|
||||
struct thread_data_base
|
||||
{
|
||||
thread_data_ptr self;
|
||||
boost::shared_ptr<thread_data_base> self;
|
||||
pthread_t thread_handle;
|
||||
boost::mutex data_mutex;
|
||||
boost::condition_variable done_condition;
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace boost
|
||||
|
||||
void operator()(void* data)
|
||||
{
|
||||
cleanup_function(static_cast<T*>(data));
|
||||
cleanup_function(data);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -56,12 +56,6 @@ namespace boost
|
||||
long const current_thread_id=win32::GetCurrentThreadId();
|
||||
return try_recursive_lock(current_thread_id) || try_timed_lock(current_thread_id,target);
|
||||
}
|
||||
template<typename Duration>
|
||||
bool timed_lock(Duration const& timeout)
|
||||
{
|
||||
return timed_lock(get_system_time()+timeout);
|
||||
}
|
||||
|
||||
long get_active_count()
|
||||
{
|
||||
return mutex.get_active_count();
|
||||
|
||||
@@ -104,12 +104,6 @@ namespace boost
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename Duration>
|
||||
bool timed_lock(Duration const& timeout)
|
||||
{
|
||||
return timed_lock(get_system_time()+timeout);
|
||||
}
|
||||
|
||||
long get_active_count()
|
||||
{
|
||||
return ::boost::detail::interlocked_read_acquire(&active_count);
|
||||
|
||||
@@ -94,9 +94,9 @@ namespace boost
|
||||
detail::int_to_string(win32::GetCurrentProcessId(), mutex_name + once_mutex_name_fixed_length + sizeof(void*)*2);
|
||||
|
||||
#ifdef BOOST_NO_ANSI_APIS
|
||||
return win32::CreateMutexW(0, 0, mutex_name);
|
||||
return win32::CreateMutexW(NULL, 0, mutex_name);
|
||||
#else
|
||||
return win32::CreateMutexA(0, 0, mutex_name);
|
||||
return win32::CreateMutexA(NULL, 0, mutex_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -57,12 +57,12 @@ namespace boost
|
||||
{
|
||||
if(old_state.exclusive_waiting)
|
||||
{
|
||||
BOOST_VERIFY(detail::win32::ReleaseSemaphore(exclusive_sem,1,0)!=0);
|
||||
BOOST_VERIFY(detail::win32::ReleaseSemaphore(exclusive_sem,1,NULL)!=0);
|
||||
}
|
||||
|
||||
if(old_state.shared_waiting || old_state.exclusive_waiting)
|
||||
{
|
||||
BOOST_VERIFY(detail::win32::ReleaseSemaphore(unlock_sem,old_state.shared_waiting + (old_state.exclusive_waiting?1:0),0)!=0);
|
||||
BOOST_VERIFY(detail::win32::ReleaseSemaphore(unlock_sem,old_state.shared_waiting + (old_state.exclusive_waiting?1:0),NULL)!=0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace boost
|
||||
{
|
||||
if(old_state.upgrade)
|
||||
{
|
||||
BOOST_VERIFY(detail::win32::ReleaseSemaphore(upgrade_sem,1,0)!=0);
|
||||
BOOST_VERIFY(detail::win32::ReleaseSemaphore(upgrade_sem,1,NULL)!=0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -364,14 +364,7 @@ namespace boost
|
||||
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}";
|
||||
}
|
||||
return os<<x.thread_data;
|
||||
}
|
||||
|
||||
void interrupt()
|
||||
|
||||
@@ -181,9 +181,9 @@ namespace boost
|
||||
inline handle create_anonymous_semaphore(long initial_count,long max_count)
|
||||
{
|
||||
#if !defined(BOOST_NO_ANSI_APIS)
|
||||
handle const res=CreateSemaphoreA(0,initial_count,max_count,0);
|
||||
handle const res=CreateSemaphoreA(NULL,initial_count,max_count,NULL);
|
||||
#else
|
||||
handle const res=CreateSemaphoreW(0,initial_count,max_count,0);
|
||||
handle const res=CreateSemaphoreW(NULL,initial_count,max_count,NULL);
|
||||
#endif
|
||||
if(!res)
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace boost
|
||||
|
||||
void operator()(void* data)
|
||||
{
|
||||
cleanup_function(static_cast<T*>(data));
|
||||
cleanup_function(data);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<!-- Copyright (c) 2002-2003 William E. Kempf.
|
||||
Subject to the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
||||
(See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
|
||||
-->
|
||||
|
||||
<html>
|
||||
|
||||
@@ -13,14 +13,6 @@
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/once.hpp>
|
||||
#include <boost/thread/tss.hpp>
|
||||
#ifdef __linux__
|
||||
#include <sys/sysinfo.h>
|
||||
#elif defined(__APPLE__) || defined(__FreeBSD__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#elif defined(__sun)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "timeconv.inl"
|
||||
|
||||
@@ -237,7 +229,7 @@ namespace boost
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
detail::thread_data_ptr thread::get_thread_info() const
|
||||
boost::shared_ptr<detail::thread_data_base> thread::get_thread_info() const
|
||||
{
|
||||
lock_guard<mutex> l(thread_info_mutex);
|
||||
return thread_info;
|
||||
@@ -245,7 +237,7 @@ namespace boost
|
||||
|
||||
void thread::join()
|
||||
{
|
||||
detail::thread_data_ptr const local_thread_info=get_thread_info();
|
||||
boost::shared_ptr<detail::thread_data_base> const local_thread_info=get_thread_info();
|
||||
if(local_thread_info)
|
||||
{
|
||||
bool do_join=false;
|
||||
@@ -289,7 +281,7 @@ namespace boost
|
||||
|
||||
bool thread::timed_join(system_time const& wait_until)
|
||||
{
|
||||
detail::thread_data_ptr const local_thread_info=get_thread_info();
|
||||
boost::shared_ptr<detail::thread_data_base> const local_thread_info=get_thread_info();
|
||||
if(local_thread_info)
|
||||
{
|
||||
bool do_join=false;
|
||||
@@ -343,7 +335,7 @@ namespace boost
|
||||
|
||||
void thread::detach()
|
||||
{
|
||||
detail::thread_data_ptr local_thread_info;
|
||||
boost::shared_ptr<detail::thread_data_base> local_thread_info;
|
||||
{
|
||||
lock_guard<mutex> l1(thread_info_mutex);
|
||||
thread_info.swap(local_thread_info);
|
||||
@@ -416,28 +408,15 @@ namespace boost
|
||||
|
||||
unsigned thread::hardware_concurrency()
|
||||
{
|
||||
#if defined(PTW32_VERSION) || defined(__hpux)
|
||||
return pthread_num_processors_np();
|
||||
#elif defined(__linux__)
|
||||
return get_nprocs();
|
||||
#elif defined(__APPLE__) || defined(__FreeBSD__)
|
||||
int count;
|
||||
size_t size=sizeof(count);
|
||||
return sysctlbyname("hw.ncpu",&count,&size,NULL,0)?0:count;
|
||||
#elif defined(__sun)
|
||||
int const count=sysconf(_SC_NPROCESSORS_ONLN);
|
||||
return (count>0)?count:0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
thread::id thread::get_id() const
|
||||
{
|
||||
detail::thread_data_ptr const local_thread_info=get_thread_info();
|
||||
boost::shared_ptr<detail::thread_data_base> local_thread_info=get_thread_info();
|
||||
if(local_thread_info)
|
||||
{
|
||||
return id(local_thread_info);
|
||||
return id(local_thread_info->thread_handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -447,7 +426,7 @@ namespace boost
|
||||
|
||||
void thread::interrupt()
|
||||
{
|
||||
detail::thread_data_ptr const local_thread_info=get_thread_info();
|
||||
boost::shared_ptr<detail::thread_data_base> local_thread_info=get_thread_info();
|
||||
if(local_thread_info)
|
||||
{
|
||||
lock_guard<mutex> lk(local_thread_info->data_mutex);
|
||||
@@ -461,7 +440,7 @@ namespace boost
|
||||
|
||||
bool thread::interruption_requested() const
|
||||
{
|
||||
detail::thread_data_ptr const local_thread_info=get_thread_info();
|
||||
boost::shared_ptr<detail::thread_data_base> local_thread_info=get_thread_info();
|
||||
if(local_thread_info)
|
||||
{
|
||||
lock_guard<mutex> lk(local_thread_info->data_mutex);
|
||||
@@ -476,12 +455,6 @@ namespace boost
|
||||
|
||||
namespace this_thread
|
||||
{
|
||||
thread::id get_id()
|
||||
{
|
||||
boost::detail::thread_data_base* const thread_info=get_or_make_current_thread_data();
|
||||
return thread::id(thread_info?thread_info->shared_from_this():detail::thread_data_ptr());
|
||||
}
|
||||
|
||||
void interruption_point()
|
||||
{
|
||||
boost::detail::thread_data_base* const thread_info=detail::get_current_thread_data();
|
||||
|
||||
@@ -35,8 +35,6 @@ rule thread-run ( sources )
|
||||
{
|
||||
test-suite "threads"
|
||||
: [ thread-run test_thread.cpp ]
|
||||
[ thread-run test_thread_id.cpp ]
|
||||
[ thread-run test_hardware_concurrency.cpp ]
|
||||
[ thread-run test_thread_move.cpp ]
|
||||
[ thread-run test_move_function.cpp ]
|
||||
[ thread-run test_mutex.cpp ]
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
// 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/thread.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
void test_hardware_concurrency_is_non_zero()
|
||||
{
|
||||
BOOST_CHECK(boost::thread::hardware_concurrency()!=0);
|
||||
}
|
||||
|
||||
boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
|
||||
{
|
||||
boost::unit_test_framework::test_suite* test =
|
||||
BOOST_TEST_SUITE("Boost.Threads: hardware concurrency test suite");
|
||||
|
||||
test->add(BOOST_TEST_CASE(test_hardware_concurrency_is_non_zero));
|
||||
return test;
|
||||
}
|
||||
@@ -150,17 +150,6 @@ struct test_timedlock
|
||||
boost::system_time target = boost::get_system_time()+boost::posix_time::milliseconds(100);
|
||||
BOOST_CHECK(lock.timed_lock(target));
|
||||
BOOST_CHECK(lock ? true : false);
|
||||
lock.unlock();
|
||||
BOOST_CHECK(!lock);
|
||||
|
||||
BOOST_CHECK(mutex.timed_lock(boost::posix_time::milliseconds(100)));
|
||||
mutex.unlock();
|
||||
|
||||
BOOST_CHECK(lock.timed_lock(boost::posix_time::milliseconds(100)));
|
||||
BOOST_CHECK(lock ? true : false);
|
||||
lock.unlock();
|
||||
BOOST_CHECK(!lock);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
// 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/thread.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
void do_nothing()
|
||||
{}
|
||||
|
||||
void test_thread_id_for_default_constructed_thread_is_default_constructed_id()
|
||||
{
|
||||
boost::thread t;
|
||||
BOOST_CHECK(t.get_id()==boost::thread::id());
|
||||
}
|
||||
|
||||
void test_thread_id_for_running_thread_is_not_default_constructed_id()
|
||||
{
|
||||
boost::thread t(do_nothing);
|
||||
BOOST_CHECK(t.get_id()!=boost::thread::id());
|
||||
t.join();
|
||||
}
|
||||
|
||||
void test_different_threads_have_different_ids()
|
||||
{
|
||||
boost::thread t(do_nothing);
|
||||
boost::thread t2(do_nothing);
|
||||
BOOST_CHECK(t.get_id()!=t2.get_id());
|
||||
t.join();
|
||||
t2.join();
|
||||
}
|
||||
|
||||
void test_thread_ids_have_a_total_order()
|
||||
{
|
||||
boost::thread t(do_nothing);
|
||||
boost::thread t2(do_nothing);
|
||||
boost::thread t3(do_nothing);
|
||||
BOOST_CHECK(t.get_id()!=t2.get_id());
|
||||
BOOST_CHECK(t.get_id()!=t3.get_id());
|
||||
BOOST_CHECK(t2.get_id()!=t3.get_id());
|
||||
|
||||
BOOST_CHECK((t.get_id()<t2.get_id()) != (t2.get_id()<t.get_id()));
|
||||
BOOST_CHECK((t.get_id()<t3.get_id()) != (t3.get_id()<t.get_id()));
|
||||
BOOST_CHECK((t2.get_id()<t3.get_id()) != (t3.get_id()<t2.get_id()));
|
||||
|
||||
BOOST_CHECK((t.get_id()>t2.get_id()) != (t2.get_id()>t.get_id()));
|
||||
BOOST_CHECK((t.get_id()>t3.get_id()) != (t3.get_id()>t.get_id()));
|
||||
BOOST_CHECK((t2.get_id()>t3.get_id()) != (t3.get_id()>t2.get_id()));
|
||||
|
||||
BOOST_CHECK((t.get_id()<t2.get_id()) == (t2.get_id()>t.get_id()));
|
||||
BOOST_CHECK((t2.get_id()<t.get_id()) == (t.get_id()>t2.get_id()));
|
||||
BOOST_CHECK((t.get_id()<t3.get_id()) == (t3.get_id()>t.get_id()));
|
||||
BOOST_CHECK((t3.get_id()<t.get_id()) == (t.get_id()>t3.get_id()));
|
||||
BOOST_CHECK((t2.get_id()<t3.get_id()) == (t3.get_id()>t2.get_id()));
|
||||
BOOST_CHECK((t3.get_id()<t2.get_id()) == (t2.get_id()>t3.get_id()));
|
||||
|
||||
BOOST_CHECK((t.get_id()<t2.get_id()) == (t2.get_id()>=t.get_id()));
|
||||
BOOST_CHECK((t2.get_id()<t.get_id()) == (t.get_id()>=t2.get_id()));
|
||||
BOOST_CHECK((t.get_id()<t3.get_id()) == (t3.get_id()>=t.get_id()));
|
||||
BOOST_CHECK((t3.get_id()<t.get_id()) == (t.get_id()>=t3.get_id()));
|
||||
BOOST_CHECK((t2.get_id()<t3.get_id()) == (t3.get_id()>=t2.get_id()));
|
||||
BOOST_CHECK((t3.get_id()<t2.get_id()) == (t2.get_id()>=t3.get_id()));
|
||||
|
||||
BOOST_CHECK((t.get_id()<=t2.get_id()) == (t2.get_id()>t.get_id()));
|
||||
BOOST_CHECK((t2.get_id()<=t.get_id()) == (t.get_id()>t2.get_id()));
|
||||
BOOST_CHECK((t.get_id()<=t3.get_id()) == (t3.get_id()>t.get_id()));
|
||||
BOOST_CHECK((t3.get_id()<=t.get_id()) == (t.get_id()>t3.get_id()));
|
||||
BOOST_CHECK((t2.get_id()<=t3.get_id()) == (t3.get_id()>t2.get_id()));
|
||||
BOOST_CHECK((t3.get_id()<=t2.get_id()) == (t2.get_id()>t3.get_id()));
|
||||
|
||||
if((t.get_id()<t2.get_id()) && (t2.get_id()<t3.get_id()))
|
||||
{
|
||||
BOOST_CHECK(t.get_id()<t3.get_id());
|
||||
}
|
||||
else if((t.get_id()<t3.get_id()) && (t3.get_id()<t2.get_id()))
|
||||
{
|
||||
BOOST_CHECK(t.get_id()<t2.get_id());
|
||||
}
|
||||
else if((t2.get_id()<t3.get_id()) && (t3.get_id()<t.get_id()))
|
||||
{
|
||||
BOOST_CHECK(t2.get_id()<t.get_id());
|
||||
}
|
||||
else if((t2.get_id()<t.get_id()) && (t.get_id()<t3.get_id()))
|
||||
{
|
||||
BOOST_CHECK(t2.get_id()<t3.get_id());
|
||||
}
|
||||
else if((t3.get_id()<t.get_id()) && (t.get_id()<t2.get_id()))
|
||||
{
|
||||
BOOST_CHECK(t3.get_id()<t2.get_id());
|
||||
}
|
||||
else if((t3.get_id()<t2.get_id()) && (t2.get_id()<t.get_id()))
|
||||
{
|
||||
BOOST_CHECK(t3.get_id()<t.get_id());
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_CHECK(false);
|
||||
}
|
||||
|
||||
boost::thread::id default_id;
|
||||
|
||||
BOOST_CHECK(default_id < t.get_id());
|
||||
BOOST_CHECK(default_id < t2.get_id());
|
||||
BOOST_CHECK(default_id < t3.get_id());
|
||||
|
||||
BOOST_CHECK(default_id <= t.get_id());
|
||||
BOOST_CHECK(default_id <= t2.get_id());
|
||||
BOOST_CHECK(default_id <= t3.get_id());
|
||||
|
||||
BOOST_CHECK(!(default_id > t.get_id()));
|
||||
BOOST_CHECK(!(default_id > t2.get_id()));
|
||||
BOOST_CHECK(!(default_id > t3.get_id()));
|
||||
|
||||
BOOST_CHECK(!(default_id >= t.get_id()));
|
||||
BOOST_CHECK(!(default_id >= t2.get_id()));
|
||||
BOOST_CHECK(!(default_id >= t3.get_id()));
|
||||
|
||||
t.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
|
||||
void get_thread_id(boost::thread::id* id)
|
||||
{
|
||||
*id=boost::this_thread::get_id();
|
||||
}
|
||||
|
||||
void test_thread_id_of_running_thread_returned_by_this_thread_get_id()
|
||||
{
|
||||
boost::thread::id id;
|
||||
boost::thread t(boost::bind(get_thread_id,&id));
|
||||
boost::thread::id t_id=t.get_id();
|
||||
t.join();
|
||||
BOOST_CHECK(id==t_id);
|
||||
}
|
||||
|
||||
boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
|
||||
{
|
||||
boost::unit_test_framework::test_suite* test =
|
||||
BOOST_TEST_SUITE("Boost.Threads: thread move test suite");
|
||||
|
||||
test->add(BOOST_TEST_CASE(test_thread_id_for_default_constructed_thread_is_default_constructed_id));
|
||||
test->add(BOOST_TEST_CASE(test_thread_id_for_running_thread_is_not_default_constructed_id));
|
||||
test->add(BOOST_TEST_CASE(test_different_threads_have_different_ids));
|
||||
test->add(BOOST_TEST_CASE(test_thread_ids_have_a_total_order));
|
||||
test->add(BOOST_TEST_CASE(test_thread_id_of_running_thread_returned_by_this_thread_get_id));
|
||||
return test;
|
||||
}
|
||||
@@ -187,54 +187,12 @@ void test_tss()
|
||||
timed_test(&do_test_tss, 2);
|
||||
}
|
||||
|
||||
bool tss_cleanup_called=false;
|
||||
|
||||
struct Dummy
|
||||
{};
|
||||
|
||||
void tss_custom_cleanup(Dummy* d)
|
||||
{
|
||||
delete d;
|
||||
tss_cleanup_called=true;
|
||||
}
|
||||
|
||||
boost::thread_specific_ptr<Dummy> tss_with_cleanup(tss_custom_cleanup);
|
||||
|
||||
void tss_thread_with_custom_cleanup()
|
||||
{
|
||||
tss_with_cleanup.reset(new Dummy);
|
||||
}
|
||||
|
||||
void do_test_tss_with_custom_cleanup()
|
||||
{
|
||||
boost::thread t(tss_thread_with_custom_cleanup);
|
||||
try
|
||||
{
|
||||
t.join();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
t.interrupt();
|
||||
t.join();
|
||||
throw;
|
||||
}
|
||||
|
||||
BOOST_CHECK(tss_cleanup_called);
|
||||
}
|
||||
|
||||
|
||||
void test_tss_with_custom_cleanup()
|
||||
{
|
||||
timed_test(&do_test_tss_with_custom_cleanup, 2);
|
||||
}
|
||||
|
||||
boost::unit_test_framework::test_suite* init_unit_test_suite(int, char*[])
|
||||
{
|
||||
boost::unit_test_framework::test_suite* test =
|
||||
BOOST_TEST_SUITE("Boost.Threads: tss test suite");
|
||||
|
||||
test->add(BOOST_TEST_CASE(test_tss));
|
||||
test->add(BOOST_TEST_CASE(test_tss_with_custom_cleanup));
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user