mirror of
https://github.com/boostorg/thread.git
synced 2026-02-03 09:42:16 +00:00
Compare commits
215 Commits
svn-branch
...
svn-branch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af77562a9e | ||
|
|
1e80ccb8d3 | ||
|
|
8ad34a689a | ||
|
|
a421e10e3b | ||
|
|
1c4b42bb95 | ||
|
|
bba3be457b | ||
|
|
3abfbb8ba1 | ||
|
|
331a35070c | ||
|
|
99ad690382 | ||
|
|
4301b21702 | ||
|
|
fceab582fe | ||
|
|
e8a4ed40a5 | ||
|
|
b698c1437b | ||
|
|
14cea92e06 | ||
|
|
3a8e04cac6 | ||
|
|
5b01721440 | ||
|
|
aad2b35ac9 | ||
|
|
f8371daeb8 | ||
|
|
74519977fd | ||
|
|
c0bea158d4 | ||
|
|
70686b4913 | ||
|
|
14502dd715 | ||
|
|
8ee986536b | ||
|
|
8ed82798d2 | ||
|
|
ebfe10b7df | ||
|
|
4aa26180ca | ||
|
|
89496448d9 | ||
|
|
dfa0a3979a | ||
|
|
396cd7db4f | ||
|
|
0351d59060 | ||
|
|
6f0b0e976d | ||
|
|
dd5d687014 | ||
|
|
5d8b0891bd | ||
|
|
7dc95f63d3 | ||
|
|
a7adc5865b | ||
|
|
cdbe5766fa | ||
|
|
b1cac0731c | ||
|
|
fc8de511c6 | ||
|
|
defdb8ff1c | ||
|
|
9a08a8478f | ||
|
|
a6f7a0180b | ||
|
|
5a59df4476 | ||
|
|
1df9d7c575 | ||
|
|
65008b11f7 | ||
|
|
b18314878a | ||
|
|
11a951c679 | ||
|
|
c67e3ff7b9 | ||
|
|
e5a633cc41 | ||
|
|
3724d847cf | ||
|
|
b6063b5c60 | ||
|
|
0d08362291 | ||
|
|
9f120a80a7 | ||
|
|
2eb6fd754e | ||
|
|
9f4a8973d0 | ||
|
|
a4d9355060 | ||
|
|
5a7545afbd | ||
|
|
4d25ea1760 | ||
|
|
6ec8e2ccec | ||
|
|
97d0ae6527 | ||
|
|
50a74d0eda | ||
|
|
f9e03b5eaa | ||
|
|
ad571bd898 | ||
|
|
de8ef9aee4 | ||
|
|
21f75da2f6 | ||
|
|
233dbf8075 | ||
|
|
d8f1ba9b3d | ||
|
|
1241f18215 | ||
|
|
b6604882eb | ||
|
|
a9c9d5c499 | ||
|
|
9a827d937e | ||
|
|
38594f889a | ||
|
|
04c17e45b3 | ||
|
|
730a8de024 | ||
|
|
7eac2fe3e4 | ||
|
|
267243d959 | ||
|
|
f587262c8e | ||
|
|
ebf458dbd0 | ||
|
|
f64b5559dd | ||
|
|
2ddcd5f678 | ||
|
|
cac715937a | ||
|
|
39f43feb11 | ||
|
|
58d65b17ea | ||
|
|
4314f0cac3 | ||
|
|
d4da369930 | ||
|
|
6f1876b618 | ||
|
|
c6e872ceb0 | ||
|
|
72d809819f | ||
|
|
dd09ef3362 | ||
|
|
aa7941fae2 | ||
|
|
35af4a8f35 | ||
|
|
a01fd3dd76 | ||
|
|
d220da89d1 | ||
|
|
55c75e9299 | ||
|
|
616ea87a0a | ||
|
|
319ba2fe75 | ||
|
|
d79eeff779 | ||
|
|
26d38748db | ||
|
|
5c124234bb | ||
|
|
681af396b8 | ||
|
|
cac0eaa6c3 | ||
|
|
a64fa2c18f | ||
|
|
f07640850b | ||
|
|
e43586ffac | ||
|
|
9cc243837d | ||
|
|
de7e3baabc | ||
|
|
5e29afcb57 | ||
|
|
0a1085d9be | ||
|
|
0439d53704 | ||
|
|
5ac2ff4521 | ||
|
|
8565a3e472 | ||
|
|
3648bc8cb0 | ||
|
|
73121eda9d | ||
|
|
768e92b0e9 | ||
|
|
98333b7dcf | ||
|
|
4e0007780c | ||
|
|
10f0c3e08e | ||
|
|
fa2950a04b | ||
|
|
ebfb62ca49 | ||
|
|
96023e81af | ||
|
|
9c07d0ff5d | ||
|
|
72a85b396c | ||
|
|
87786091bb | ||
|
|
784494274b | ||
|
|
68012dd92c | ||
|
|
e40be775fe | ||
|
|
64e6924132 | ||
|
|
4bbf47086d | ||
|
|
7c674bc255 | ||
|
|
6b9a2d791b | ||
|
|
4551e8759b | ||
|
|
9442976bdb | ||
|
|
8d07df176f | ||
|
|
4b22aff33e | ||
|
|
93dee254d0 | ||
|
|
a29b598205 | ||
|
|
e3b20eaae9 | ||
|
|
d369fb0f94 | ||
|
|
d816bca42f | ||
|
|
d6bb11c4e9 | ||
|
|
2fdcefac05 | ||
|
|
044c3cc11e | ||
|
|
bd9223b525 | ||
|
|
347703dab2 | ||
|
|
f9a0e450e1 | ||
|
|
f6b8cdd1f5 | ||
|
|
6727013302 | ||
|
|
cda12a2660 | ||
|
|
c3c2072472 | ||
|
|
bfc226fdc0 | ||
|
|
fd28e1a7fb | ||
|
|
b11911f5e5 | ||
|
|
a1587d070f | ||
|
|
df2f43bc61 | ||
|
|
895e8eea52 | ||
|
|
97d6249f3b | ||
|
|
7a8ed98eb5 | ||
|
|
d611eece19 | ||
|
|
a99320f5a4 | ||
|
|
c97484943a | ||
|
|
547d9bd844 | ||
|
|
1a65aab05a | ||
|
|
2e869aeb86 | ||
|
|
d729776575 | ||
|
|
895c436405 | ||
|
|
4ae2932792 | ||
|
|
a52be2bdbb | ||
|
|
31c4792216 | ||
|
|
39fd9c0b47 | ||
|
|
9c25df3402 | ||
|
|
fb150b5038 | ||
|
|
8cff3a167e | ||
|
|
2be1431f60 | ||
|
|
255b7ed7f6 | ||
|
|
58fd27399e | ||
|
|
5f88ba1e47 | ||
|
|
ab569461d8 | ||
|
|
7093fc670b | ||
|
|
6f2b030253 | ||
|
|
0e61e679af | ||
|
|
b40998e1b5 | ||
|
|
174d701bc3 | ||
|
|
f2143d08b9 | ||
|
|
1273e2620d | ||
|
|
c719f6e37e | ||
|
|
37922d8ce0 | ||
|
|
7b79a31f40 | ||
|
|
9a09406f77 | ||
|
|
9bdb778478 | ||
|
|
9621dafe46 | ||
|
|
d7c9837844 | ||
|
|
27bb7803ae | ||
|
|
c0e1086f2c | ||
|
|
ffa751c617 | ||
|
|
b8ad60a2d6 | ||
|
|
5db0aac816 | ||
|
|
3fae7c5184 | ||
|
|
47889a8f22 | ||
|
|
8d22c3869b | ||
|
|
235ed4afe0 | ||
|
|
627cb7f774 | ||
|
|
09021af350 | ||
|
|
31c280d1fa | ||
|
|
629f344f34 | ||
|
|
db5f924e24 | ||
|
|
9be3eb282a | ||
|
|
effd891a16 | ||
|
|
13db35cbf5 | ||
|
|
0f2d480e3c | ||
|
|
9edc61e37b | ||
|
|
f4dab6aac5 | ||
|
|
9e0550d140 | ||
|
|
0d1701c509 | ||
|
|
f2f62f93ea | ||
|
|
8a329f66fb | ||
|
|
05d4c52918 |
@@ -43,7 +43,16 @@ project boost/thread
|
||||
<link>shared:<define>BOOST_THREAD_BUILD_DLL=1
|
||||
-<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
|
||||
<tag>@$(__name__).tag
|
||||
: default-build <threading>multi
|
||||
<toolset>gcc:<cxxflags>-Wno-long-long
|
||||
<define>BOOST_SYSTEM_NO_DEPRECATED
|
||||
<library>/boost/system//boost_system
|
||||
|
||||
# : default-build <threading>multi
|
||||
: usage-requirements # pass these requirement to dependents (i.e. users)
|
||||
<link>static:<define>BOOST_THREAD_BUILD_LIB=1
|
||||
<link>shared:<define>BOOST_THREAD_BUILD_DLL=1
|
||||
<define>BOOST_SYSTEM_NO_DEPRECATED
|
||||
<library>/boost/system//boost_system
|
||||
;
|
||||
|
||||
local rule default_threadapi ( )
|
||||
@@ -151,6 +160,16 @@ rule usage-requirements ( properties * )
|
||||
# in that case?
|
||||
}
|
||||
}
|
||||
|
||||
if <toolset>vacpp in $(properties)
|
||||
{
|
||||
result += <define>BOOST_THREAD_DONT_USE_CHRONO ;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += <library>/boost/chrono//boost_chrono ;
|
||||
}
|
||||
|
||||
return $(result) ;
|
||||
}
|
||||
|
||||
@@ -174,13 +193,21 @@ rule requirements ( properties * )
|
||||
}
|
||||
}
|
||||
}
|
||||
if <toolset>vacpp in $(properties)
|
||||
{
|
||||
result += <define>BOOST_THREAD_DONT_USE_CHRONO ;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += <library>/boost/chrono//boost_chrono ;
|
||||
}
|
||||
|
||||
return $(result) ;
|
||||
}
|
||||
|
||||
alias thread_sources
|
||||
: ## win32 sources ##
|
||||
win32/thread.cpp
|
||||
win32/exceptions.cpp
|
||||
win32/tss_dll.cpp
|
||||
win32/tss_pe.cpp
|
||||
: ## requirements ##
|
||||
@@ -190,7 +217,6 @@ alias thread_sources
|
||||
alias thread_sources
|
||||
: ## pthread sources ##
|
||||
pthread/thread.cpp
|
||||
pthread/exceptions.cpp
|
||||
pthread/once.cpp
|
||||
: ## requirements ##
|
||||
<threadapi>pthread
|
||||
@@ -199,7 +225,7 @@ alias thread_sources
|
||||
explicit thread_sources ;
|
||||
|
||||
lib boost_thread
|
||||
: thread_sources
|
||||
: thread_sources future.cpp
|
||||
: <conditional>@requirements
|
||||
:
|
||||
: <link>shared:<define>BOOST_THREAD_USE_DLL=1
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# (C) Copyright 2008 Anthony Williams
|
||||
# (C) Copyright 2008-11 Anthony Williams
|
||||
# (C) Copyright 2011-12 Vicente J. Botet Escriba
|
||||
#
|
||||
# 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)
|
||||
@@ -15,41 +16,17 @@ boostbook standalone
|
||||
# Use graphics not text for navigation:
|
||||
<xsl:param>navig.graphics=1
|
||||
# How far down we chunk nested sections, basically all of them:
|
||||
<xsl:param>chunk.section.depth=3
|
||||
<xsl:param>chunk.section.depth=2
|
||||
# Don't put the first section on the same page as the TOC:
|
||||
<xsl:param>chunk.first.sections=1
|
||||
# How far down sections get TOC's
|
||||
<xsl:param>toc.section.depth=10
|
||||
<xsl:param>toc.section.depth=4
|
||||
# Max depth in each TOC:
|
||||
<xsl:param>toc.max.depth=3
|
||||
<xsl:param>toc.max.depth=2
|
||||
# How far down we go with TOC's
|
||||
<xsl:param>generate.section.toc.level=10
|
||||
# Path for links to Boost:
|
||||
<xsl:param>boost.root=../../../..
|
||||
# Path for libraries index:
|
||||
<xsl:param>boost.libraries=../../../../libs/libraries.htm
|
||||
# Use the main Boost stylesheet:
|
||||
<xsl:param>html.stylesheet=../../../../doc/html/boostbook.css
|
||||
|
||||
# PDF Options:
|
||||
# TOC Generation: this is needed for FOP-0.9 and later:
|
||||
#<xsl:param>fop1.extensions=1
|
||||
# Or enable this if you're using XEP:
|
||||
<xsl:param>xep.extensions=1
|
||||
# TOC generation: this is needed for FOP 0.2, but must not be set to zero for FOP-0.9!
|
||||
<xsl:param>fop.extensions=0
|
||||
# No indent on body text:
|
||||
<xsl:param>body.start.indent=0pt
|
||||
# Margin size:
|
||||
<xsl:param>page.margin.inner=0.5in
|
||||
# Margin size:
|
||||
<xsl:param>page.margin.outer=0.5in
|
||||
# Yes, we want graphics for admonishments:
|
||||
<xsl:param>admon.graphics=1
|
||||
# Set this one for PDF generation *only*:
|
||||
# default pnd graphics are awful in PDF form,
|
||||
# better use SVG's instead:
|
||||
<format>pdf:<xsl:param>admon.graphics.extension=".svg"
|
||||
<format>pdf:<xsl:param>admon.graphics.path=$(boost-images)/
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,89 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
(C) Copyright 2007-11 Anthony Williams.
|
||||
(C) Copyright 2011-12 Vicente J. Botet Escriba.
|
||||
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).
|
||||
]
|
||||
|
||||
[section:changes Changes since boost 1.35]
|
||||
[section:changes History]
|
||||
|
||||
[heading Version 2.0.0 - boost 1.50]
|
||||
|
||||
New Features:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2741 #2741] Proposal to manage portable and non portable thread attributes.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6195 #6195] c++11 compliance: Provide the standard time related interface using Boost.Chrono.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6224 #6224] c++11 compliance: Add the use of standard noexcept on compilers supporting them.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6226 #6226] c++11 compliance: Add explicit bool conversion from locks.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6230 #6230] c++11 compliance: Follows the exception reporting mechanism as defined in the c++11.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6272 #6272] c++11 compliance: Add thread::id hash specialization.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6273 #6273] c++11 compliance: Add cv_status enum class and use it on the conditions wait functions.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6194 #6194] Adapt to Boost.Move.
|
||||
|
||||
Fixed Bugs:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2575 #2575] Bug- Boost 1.36.0 on Itanium platform.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4921 #4921] BOOST_THREAD_USE_DLL and BOOST_THREAD_USE_LIB are crucial and need to be documented.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5013 #5013] documentation: boost::thread: pthreas_exit causes terminate().
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5351 #5351] interrupt a future get boost::unknown_exception.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5516 #5516] Upgrade lock is not acquired when previous upgrade lock releases if another read lock is present.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5990 #5990] shared_future<T>::get() has wrong return type.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6174 #6174] packaged_task doesn't correctly handle moving results.
|
||||
|
||||
[/
|
||||
|
||||
Deprecated features since boost 1.50 available only until boost 1.55:
|
||||
|
||||
These deprecated features will be provided by default up to boost 1.52. If you don't want to include the deprecated features you could define BOOST_THREAD_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V2_0_0. Since 1.53 these features will not be included any more by default. Since this version, if you want to include the deprecated features yet you could define BOOST_THREAD_PROVIDE_DEPRECATED_FEATURES_SINCE_V2_0_0. These deprecated features will be only available until boost 1.55, that is you have 1 year and a half to move to the new features.
|
||||
|
||||
* Time related functions don't using the Boost.Chrono library, use the chrono overloads instead.
|
||||
|
||||
Breaking changes:
|
||||
|
||||
There are some new features which share the same interface but with different behavior. These breaking features are not provided by default when BOOST_THREAD_VERSION is 2, but the user can however choose the version 1 behavior by defining the corresponding macro. As for the deprecated features, these broken features will be only available until boost 1.55.
|
||||
|
||||
* #6266 c++11 compliance: thread destructor should call terminate if joinable
|
||||
* #6269 c++11 compliance: thread move assignment should call terminate if joinable
|
||||
]
|
||||
|
||||
[heading boost 1.49]
|
||||
|
||||
Fixed Bugs:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2309 #2309] Lack of g++ symbol visibility support in Boost.Thread.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/2639 #2639] documentation should be extended(defer_lock, try_to_lock, ...).
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3639 #3639] Boost.Thread doesn't build with Sun-5.9 on Linux.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3762 #3762] Thread can't be compiled with winscw (Codewarrior by Nokia).
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3885 #3885] document about mix usage of boost.thread and native thread api.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3975 #3975] Incorrect precondition for promise::set_wait_callback().
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4048 #4048] thread::id formatting involves locale
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4315 #4315] gcc 4.4 Warning: inline ... declared as dllimport: attribute ignored.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4480 #4480] OpenVMS patches for compiler issues workarounds.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4819 #4819] boost.thread's documentation misprints.
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5423 #5423] thread issues with C++0x.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5617 #5617] boost::thread::id copy ctor.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5739 #5739] set-but-not-used warnings with gcc-4.6.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5826 #5826] threads.cpp: resource leak on threads creation failure.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5839 #5839] thread.cpp: ThreadProxy leaks on exceptions.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5859 #5859] win32 shared_mutex constructor leaks on exceptions.
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6100 #6100] Compute hardware_concurrency() using get_nprocs() on GLIBC systems.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6168 #6168] recursive_mutex is using wrong config symbol (possible typo).
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6175 #6175] Compile error with SunStudio.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6200 #6200] patch to have condition_variable and mutex error better handle EINTR.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6207 #6207] shared_lock swap compiler error on clang 3.0 c++11.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6208 #6208] try_lock_wrapper swap compiler error on clang 3.0 c++11.
|
||||
|
||||
[heading Changes since boost 1.40]
|
||||
|
||||
The 1.41.0 release of Boost adds futures to the thread library. There are also a few minor changes.
|
||||
|
||||
[heading Changes since boost 1.35]
|
||||
|
||||
The 1.36.0 release of Boost includes a few new features in the thread library:
|
||||
|
||||
@@ -81,3 +159,18 @@ been moved to __thread_id__.
|
||||
unlocked one level, and not completely. This prior behaviour was not guaranteed and did not feature in the tests.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:future Future]
|
||||
|
||||
The following features will be included in next releases. By order of priority:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4710 #4710] Missing async().
|
||||
* Lock guards
|
||||
* [@http://svn.boost.org/trac/boost/ticket/1850 #1850] request for unlock_guard (and/or unique_unlock) to compliment lock_guard/unique_lock
|
||||
* [@http://svn.boost.org/trac/boost/ticket/3567 #3567] Request for shared_lock_guard
|
||||
* #2880 Request for Thread scheduler support for boost ..
|
||||
* #3696 Boost Thread library lacks any way to set priority of threads
|
||||
* #5956 Add optional stack_size argument to thread::start_thread()
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
101
doc/compliance.qbk
Normal file
101
doc/compliance.qbk
Normal file
@@ -0,0 +1,101 @@
|
||||
[/
|
||||
(C) Copyright 2011-12 Vicente J. Botet Escriba.
|
||||
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).
|
||||
]
|
||||
|
||||
[section:compliance Compliance with standard]
|
||||
|
||||
[section:cpp11 C++11 standard Thread library]
|
||||
|
||||
|
||||
[table Compliance C++11 standard
|
||||
[[Section] [Description] [Status] [Comments] [Ticket]]
|
||||
[[30] [Thread support library] [Partial] [-] [-]]
|
||||
[[30.1] [General] [-] [-] [-]]
|
||||
[[30.2] [Requirements] [-] [-] [-]]
|
||||
[[30.2.1] [Template parameter names] [-] [-] [-]]
|
||||
[[30.2.2] [Exceptions] [Yes] [-] [#6230]]
|
||||
[[30.2.3] [Native handles] [Yes] [-] [-]]
|
||||
[[30.2.4] [Timing specifications] [Yes] [-] [#6195]]
|
||||
[[30.2.5] [Requirements for Lockable types] [Partial] [-] [-]]
|
||||
[[30.2.5.1] [In general] [-] [-] [-]]
|
||||
[[30.2.5.2] [BasicLockable requirements] [No] [-] [#6231]]
|
||||
[[30.2.5.3] [Lockable requirements] [yes] [-] [-]]
|
||||
[[30.2.5.4] [TimedLockable requirements] [Yes] [-] [#6195]]
|
||||
[[30.2.6] [decay_copy] [-] [-] [-]]
|
||||
[[30.3] [Threads] [Partial] [-] [-]]
|
||||
[[30.3.1] [Class thread] [Partial] [move,terminate] [-]]
|
||||
[[30.3.1.1] [Class thread::id] [Yes] [-] [#6224,#6272]]
|
||||
[[30.3.1.2] [thread constructors] [Partial] [move] [#6224,#6194, #6270]]
|
||||
[[30.3.1.3] [thread destructor] [Partial] [terminate] [#6266]]
|
||||
[[30.3.1.4] [thread assignment] [Partial] [move, terminate] [#6269]]
|
||||
[[30.3.1.5] [thread members] [Yes] [-] [#6224,#6195]]
|
||||
[[30.3.1.6] [thread static members] [Yes] [-] [#6224]]
|
||||
[[30.3.1.7] [thread specialized algorithms] [Yes] [-] [-]]
|
||||
|
||||
[[30.3.2] [Namespace this_thread] [Yes] [-] [#6195]]
|
||||
[[30.4] [Mutual exclusion] [Partial] [move] [-]]
|
||||
[[30.4.1] [Mutex requirements] [Yes] [-] [-]]
|
||||
[[30.4.1.1] [In general] [Yes] [-] [-]]
|
||||
[[30.4.1.2] [Mutex types] [Yes] [-] [#6224,#6225]]
|
||||
[[30.4.1.2.1] [Class mutex] [Yes] [-] [#6224,#6225]]
|
||||
[[30.4.1.2.2] [Class recursive_mutex] [Yes] [-] [#6224,#6225]]
|
||||
[[30.4.1.3] [Timed mutex types] [Yes] [-] [#6224,#6195,#6225]]
|
||||
[[30.4.1.3.1] [Class timed_mutex] [Yes] [-] [#6224,#6195,#6225]]
|
||||
[[30.4.1.3.1] [Class recursive_timed_mutex] [Yes] [-] [#6224,#6195,#6225]]
|
||||
[[30.4.2] [Locks] [Partial] [move] [#6224,#6195,#6225,#6227]]
|
||||
[[30.4.2.1] [Class template lock_guard] [Yes] [-] [#6225]]
|
||||
[[30.4.2.2] [Class template unique_lock] [Yes] [move] [#6224,#6195,#6225,#6227]]
|
||||
[[30.4.2.2.1] [unique_lock constructors, destructor, and assignment] [Partial] [move] [#6224,#6195,#6225,#6227]]
|
||||
[[30.4.2.2.2] [unique_lock locking] [Yes] [-] [#6195]]
|
||||
[[30.4.2.2.3] [unique_lock modifiers] [Yes] [-] [-]]
|
||||
[[30.4.2.2.4] [unique_lock observers] [Yes] [] [#6227]]
|
||||
[[30.4.3] [Generic locking algorithms] [Partial] [variadic] [#6227]]
|
||||
[[30.4.4] [Call once] [Partial] [move,variadic,] [#6194,#7]]
|
||||
[[30.4.4.1] [Struct once_flag] [Partial] [interface] [#xx]]
|
||||
[[30.4.4.2] [Function call_once] [Partial] [move,variadic,interface] [#xx]]
|
||||
[[30.5] [Condition variables] [Partial] [notify_all_at_thread_exit] [#6195,#6273,#9]]
|
||||
[[30.5 6-10] [Function notify_all_at_thread_exit] [No] [-] [#9]]
|
||||
[[30.5.1] [Class condition_variable] [Yes] [-] [#6195,#6273]]
|
||||
[[30.5.2] [Class condition_variable_any] [Yes] [-] [#6195,#6273]]
|
||||
[[30.6] [Futures] [Partial] [-] [-]]
|
||||
[[30.6.1] [Overview] [Partial] [-] [-]]
|
||||
[[30.6.2] [Error handling] [No] [-] [-]]
|
||||
[[30.6.3] [Class future_error] [No] [-] [-]]
|
||||
[[30.6.4] [Shared state] [No] [-] [-]]
|
||||
[[30.6.5] [Class template promise] [Partial] [allocator,move] [#6228,#6194,#6225]]
|
||||
[[30.6.6] [Class template future] [No] [unique_future is the closest to future] [##6229,#6228]]
|
||||
[[30.6.7] [Class template shared_future] [Partial] [allocator,move] [#6228,#6194,#6225]]
|
||||
[[30.6.8] [Function template async] [No] [async] [#4710]]
|
||||
[[30.6.8] [Class template packaged_task] [Partial] [move] [#6194]]
|
||||
]
|
||||
|
||||
[/
|
||||
[table Extension
|
||||
[[Section] [Description] [Comments]]
|
||||
[[30.3.1.5.x] [interrupt] [-]]
|
||||
[[30.3.2.x] [Interruption] [-]]
|
||||
[[30.3.2.y] [at_thread_exit] [-]]
|
||||
[[30.4.3.x] [Generic locking algorithms begin/end] [-]]
|
||||
[[30.x] [Barriers] [-]]
|
||||
[[30.y] [Thread Local Storage] [-]]
|
||||
[[30.z] [Class thread_group] [-]]
|
||||
]
|
||||
]
|
||||
[endsect]
|
||||
|
||||
[/
|
||||
[section:shared Shared Mutex library extension]
|
||||
|
||||
[table Clock Requirements
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[XXXX] [DDDD] [SSSS] [CCCC]]
|
||||
[[XXXX] [DDDD] [SSSS] [CCCC]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
@@ -1,5 +1,6 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
(C) Copyright 2007-11 Anthony Williams.
|
||||
(C) Copyright 2011-12 Vicente J. Botet Escriba.
|
||||
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).
|
||||
@@ -9,6 +10,17 @@
|
||||
|
||||
[heading Synopsis]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
enum class cv_status;
|
||||
{
|
||||
no_timeout,
|
||||
timeout
|
||||
};
|
||||
class condition_variable;
|
||||
class condition_variable_any;
|
||||
}
|
||||
|
||||
The classes `condition_variable` and `condition_variable_any` provide a
|
||||
mechanism for one thread to wait for notification from another thread that a
|
||||
particular condition has become true. The general usage pattern is that one
|
||||
@@ -84,31 +96,57 @@ optimizations in some cases, based on the knowledge of the mutex type;
|
||||
condition_variable();
|
||||
~condition_variable();
|
||||
|
||||
void notify_one();
|
||||
void notify_all();
|
||||
void notify_one() noexcept;
|
||||
void notify_all() noexcept;
|
||||
|
||||
void wait(boost::unique_lock<boost::mutex>& lock);
|
||||
|
||||
template<typename predicate_type>
|
||||
void wait(boost::unique_lock<boost::mutex>& lock,predicate_type predicate);
|
||||
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::system_time const& abs_time);
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::system_time const& abs_time); // DEPRECATED V2
|
||||
|
||||
template<typename duration_type>
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,duration_type const& rel_time);
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,duration_type const& rel_time); // DEPRECATED V2
|
||||
|
||||
template<typename predicate_type>
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::system_time const& abs_time,predicate_type predicate);
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::system_time const& abs_time,predicate_type predicate); // DEPRECATED V2
|
||||
|
||||
template<typename duration_type,typename predicate_type>
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,duration_type const& rel_time,predicate_type predicate);
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,duration_type const& rel_time,predicate_type predicate); // DEPRECATED V2
|
||||
|
||||
template <class Clock, class Duration>
|
||||
typename cv_status::type
|
||||
wait_until(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::time_point<Clock, Duration>& t);
|
||||
|
||||
template <class Clock, class Duration, class Predicate>
|
||||
bool
|
||||
wait_until(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::time_point<Clock, Duration>& t,
|
||||
Predicate pred);
|
||||
|
||||
template <class Rep, class Period>
|
||||
typename cv_status::type
|
||||
wait_for(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::duration<Rep, Period>& d);
|
||||
|
||||
template <class Rep, class Period, class Predicate>
|
||||
bool
|
||||
wait_for(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::duration<Rep, Period>& d,
|
||||
Predicate pred);
|
||||
|
||||
// backwards compatibility
|
||||
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::xtime const& abs_time);
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::xtime const& abs_time); // DEPRECATED V2
|
||||
|
||||
template<typename predicate_type>
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::xtime const& abs_time,predicate_type predicate);
|
||||
bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::xtime const& abs_time,predicate_type predicate); // DEPRECATED V2
|
||||
};
|
||||
}
|
||||
|
||||
@@ -208,7 +246,7 @@ while(!pred())
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait `bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::system_time const& abs_time)`]
|
||||
[section:timed_wait `bool timed_wait(boost::unique_lock<boost::mutex>& lock,boost::system_time const& abs_time)` DEPRECATED V2]
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -239,7 +277,7 @@ __interrupt__ on the __thread__ object associated with the current thread of exe
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait_rel `template<typename duration_type> bool timed_wait(boost::unique_lock<boost::mutex>& lock,duration_type const& rel_time)`]
|
||||
[section:timed_wait_rel `template<typename duration_type> bool timed_wait(boost::unique_lock<boost::mutex>& lock,duration_type const& rel_time)` DEPRECATED V2]
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -272,7 +310,7 @@ __interrupt__ on the __thread__ object associated with the current thread of exe
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait_predicate `template<typename predicate_type> bool timed_wait(boost::unique_lock<boost::mutex>& lock, boost::system_time const& abs_time, predicate_type pred)`]
|
||||
[section:timed_wait_predicate `template<typename predicate_type> bool timed_wait(boost::unique_lock<boost::mutex>& lock, boost::system_time const& abs_time, predicate_type pred)` DEPRECATED V2]
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -292,6 +330,114 @@ return true;
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:wait_until `template <class Clock, class Duration> cv_status wait_until(boost::unique_lock<boost::mutex>& lock, const chrono::time_point<Clock, Duration>& abs_time)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [`lock` is locked by the current thread, and either no other
|
||||
thread is currently waiting on `*this`, or the execution of the `mutex()` member
|
||||
function on the `lock` objects supplied in the calls to `wait` or `wait_for` or `wait_until`
|
||||
in all the threads currently waiting on `*this` would return the same value as
|
||||
`lock->mutex()` for this call to `wait`.]]
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, when the time as reported by `Clock::now()`
|
||||
would be equal to or later than the specified `abs_time`, or spuriously. When
|
||||
the thread is unblocked (for whatever reason), the lock is reacquired by
|
||||
invoking `lock.lock()` before the call to `wait` returns. The lock is also
|
||||
reacquired by invoking `lock.lock()` if the function exits with an exception.]]
|
||||
|
||||
[[Returns:] [`cv_status::no_timeout` if the call is returning because the time specified by
|
||||
`abs_time` was reached, `cv_status::timeout` otherwise.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_for `template <class Rep, class Period> cv_status wait_for(boost::unique_lock<boost::mutex>& lock, const chrono::duration<Rep, Period>& rel_time)`]
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [`lock` is locked by the current thread, and either no other
|
||||
thread is currently waiting on `*this`, or the execution of the `mutex()` member
|
||||
function on the `lock` objects supplied in the calls to `wait` or `wait_until` or `wait_for`
|
||||
in all the threads currently waiting on `*this` would return the same value as
|
||||
`lock->mutex()` for this call to `wait`.]]
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, after the period of time indicated by the `rel_time`
|
||||
argument has elapsed, or spuriously. When the thread is unblocked (for whatever
|
||||
reason), the lock is reacquired by invoking `lock.lock()` before the call to
|
||||
`wait` returns. The lock is also reacquired by invoking `lock.lock()` if the
|
||||
function exits with an exception.]]
|
||||
|
||||
[[Returns:] [`cv_status::no_timeout ` if the call is returning because the time period specified
|
||||
by `rel_time` has elapsed, `cv_status::timeout ` otherwise.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[note The duration overload of timed_wait is difficult to use correctly. The overload taking a predicate should be preferred in most cases.]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_until_predicate `template <class Clock, class Duration, class Predicate> bool wait_until(boost::unique_lock<boost::mutex>& lock, const chrono::time_point<Clock, Duration>& abs_time, Predicate pred)`]
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [As-if ``
|
||||
while(!pred())
|
||||
{
|
||||
if(!wait_until(lock,abs_time))
|
||||
{
|
||||
return pred();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
``]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_for_predicate `template <class Rep, class Period, class Predicate> bool wait_for(boost::unique_lock<boost::mutex>& lock, const chrono::duration<Rep, Period>& rel_time, Predicate pred)`]
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [As-if ``
|
||||
while(!pred())
|
||||
{
|
||||
if(!wait_for(lock,rel_time))
|
||||
{
|
||||
return pred();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
``]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:condition_variable_any Class `condition_variable_any`]
|
||||
@@ -316,24 +462,47 @@ return true;
|
||||
void wait(lock_type& lock,predicate_type predicate);
|
||||
|
||||
template<typename lock_type>
|
||||
bool timed_wait(lock_type& lock,boost::system_time const& abs_time);
|
||||
bool timed_wait(lock_type& lock,boost::system_time const& abs_time) // DEPRECATED V2;
|
||||
|
||||
template<typename lock_type,typename duration_type>
|
||||
bool timed_wait(lock_type& lock,duration_type const& rel_time);
|
||||
bool timed_wait(lock_type& lock,duration_type const& rel_time) // DEPRECATED V2;
|
||||
|
||||
template<typename lock_type,typename predicate_type>
|
||||
bool timed_wait(lock_type& lock,boost::system_time const& abs_time,predicate_type predicate);
|
||||
bool timed_wait(lock_type& lock,boost::system_time const& abs_time,predicate_type predicate) // DEPRECATED V2;
|
||||
|
||||
template<typename lock_type,typename duration_type,typename predicate_type>
|
||||
bool timed_wait(lock_type& lock,duration_type const& rel_time,predicate_type predicate);
|
||||
bool timed_wait(lock_type& lock,duration_type const& rel_time,predicate_type predicate) // DEPRECATED V2;
|
||||
|
||||
template <class lock_type, class Clock, class Duration>
|
||||
cv_status wait_until(
|
||||
lock_type& lock,
|
||||
const chrono::time_point<Clock, Duration>& t);
|
||||
|
||||
template <class lock_type, class Clock, class Duration, class Predicate>
|
||||
bool wait_until(
|
||||
lock_type& lock,
|
||||
const chrono::time_point<Clock, Duration>& t,
|
||||
Predicate pred);
|
||||
|
||||
|
||||
template <class lock_type, class Rep, class Period>
|
||||
cv_status wait_for(
|
||||
lock_type& lock,
|
||||
const chrono::duration<Rep, Period>& d);
|
||||
|
||||
template <class lock_type, class Rep, class Period, class Predicate>
|
||||
bool wait_for(
|
||||
lock_type& lock,
|
||||
const chrono::duration<Rep, Period>& d,
|
||||
Predicate pred);
|
||||
|
||||
// backwards compatibility
|
||||
|
||||
template<typename lock_type>
|
||||
bool timed_wait(lock_type>& lock,boost::xtime const& abs_time);
|
||||
bool timed_wait(lock_type>& lock,boost::xtime const& abs_time) // DEPRECATED V2;
|
||||
|
||||
template<typename lock_type,typename predicate_type>
|
||||
bool timed_wait(lock_type& lock,boost::xtime const& abs_time,predicate_type predicate);
|
||||
bool timed_wait(lock_type& lock,boost::xtime const& abs_time,predicate_type predicate) // DEPRECATED V2;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -427,7 +596,7 @@ while(!pred())
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait `template<typename lock_type> bool timed_wait(lock_type& lock,boost::system_time const& abs_time)`]
|
||||
[section:timed_wait `template<typename lock_type> bool timed_wait(lock_type& lock,boost::system_time const& abs_time)` DEPRECATED V2]
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -452,7 +621,7 @@ __interrupt__ on the __thread__ object associated with the current thread of exe
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait_rel `template<typename lock_type,typename duration_type> bool timed_wait(lock_type& lock,duration_type const& rel_time)`]
|
||||
[section:timed_wait_rel `template<typename lock_type,typename duration_type> bool timed_wait(lock_type& lock,duration_type const& rel_time)` DEPRECATED V2]
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -479,7 +648,7 @@ __interrupt__ on the __thread__ object associated with the current thread of exe
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait_predicate `template<typename lock_type,typename predicate_type> bool timed_wait(lock_type& lock, boost::system_time const& abs_time, predicate_type pred)`]
|
||||
[section:timed_wait_predicate `template<typename lock_type,typename predicate_type> bool timed_wait(lock_type& lock, boost::system_time const& abs_time, predicate_type pred)` DEPRECATED V2]
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -498,6 +667,96 @@ return true;
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_until `template <class lock_type, class Clock, class Duration> cv_status wait_until(lock_type& lock, const chrono::time_point<Clock, Duration>& abs_time)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, when the time as reported by `Clock::now()`
|
||||
would be equal to or later than the specified `abs_time`, or spuriously. When
|
||||
the thread is unblocked (for whatever reason), the lock is reacquired by
|
||||
invoking `lock.lock()` before the call to `wait` returns. The lock is also
|
||||
reacquired by invoking `lock.lock()` if the function exits with an exception.]]
|
||||
|
||||
[[Returns:] [`cv_status::timeout` if the call is returning because the time specified by
|
||||
`abs_time` was reached, `cv_status::no_timeout` otherwise.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_for `template <class lock_type, class Rep, class Period> cv_status wait_for(lock_type& lock, const chrono::duration<Rep, Period>& rel_time)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Atomically call `lock.unlock()` and blocks the current thread. The
|
||||
thread will unblock when notified by a call to `this->notify_one()` or
|
||||
`this->notify_all()`, after the period of time indicated by the `rel_time`
|
||||
argument has elapsed, or spuriously. When the thread is unblocked (for whatever
|
||||
reason), the lock is reacquired by invoking `lock.lock()` before the call to
|
||||
`wait` returns. The lock is also reacquired by invoking `lock.lock()` if the
|
||||
function exits with an exception.]]
|
||||
|
||||
[[Returns:] [`cv_status::timeout` if the call is returning because the time specified by
|
||||
`abs_time` was reached, `cv_status::no_timeout` otherwise.]]
|
||||
|
||||
[[Postcondition:] [`lock` is locked by the current thread.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error
|
||||
occurs. __thread_interrupted__ if the wait was interrupted by a call to
|
||||
__interrupt__ on the __thread__ object associated with the current thread of execution.]]
|
||||
|
||||
]
|
||||
|
||||
[note The duration overload of timed_wait is difficult to use correctly. The overload taking a predicate should be preferred in most cases.]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_until_predicate `template <class lock_type, class Clock, class Duration, class Predicate> bool wait_until(lock_type& lock, const chrono::time_point<Clock, Duration>& abs_time, Predicate pred)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [As-if ``
|
||||
while(!pred())
|
||||
{
|
||||
if(!__cvany_wait_until(lock,abs_time))
|
||||
{
|
||||
return pred();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
``]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_for_predicate `template <class lock_type, class Rep, class Period, class Predicate> bool wait_until(lock_type& lock, const chrono::duration<Rep, Period>& rel_time, Predicate pred)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [As-if ``
|
||||
while(!pred())
|
||||
{
|
||||
if(!__cvany_wait_for(lock,rel_time))
|
||||
{
|
||||
return pred();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
``]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:condition Typedef `condition`]
|
||||
|
||||
968
doc/future_ref.qbk
Normal file
968
doc/future_ref.qbk
Normal file
@@ -0,0 +1,968 @@
|
||||
[/
|
||||
(C) Copyright 2008-11 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).
|
||||
]
|
||||
|
||||
[section:reference Futures Reference]
|
||||
|
||||
[section:future_state `state` enum]
|
||||
|
||||
namespace future_state
|
||||
{
|
||||
enum state {uninitialized, waiting, ready};
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:unique_future `unique_future` class template]
|
||||
|
||||
template <typename R>
|
||||
class unique_future
|
||||
{
|
||||
unique_future(unique_future & rhs);// = delete;
|
||||
unique_future& operator=(unique_future& rhs);// = delete;
|
||||
|
||||
public:
|
||||
typedef future_state::state state;
|
||||
|
||||
unique_future();
|
||||
~unique_future();
|
||||
|
||||
// move support
|
||||
unique_future(unique_future && other);
|
||||
unique_future& operator=(unique_future && other);
|
||||
|
||||
void swap(unique_future& other);
|
||||
|
||||
// retrieving the value
|
||||
R&& get();
|
||||
|
||||
// functions to check state
|
||||
state get_state() const;
|
||||
bool is_ready() const;
|
||||
bool has_exception() const;
|
||||
bool has_value() const;
|
||||
|
||||
// waiting for the result to be ready
|
||||
void wait() const;
|
||||
template<typename Duration>
|
||||
bool timed_wait(Duration const& rel_time) const;
|
||||
bool timed_wait_until(boost::system_time const& abs_time) const;
|
||||
};
|
||||
|
||||
[section:default_constructor Default Constructor]
|
||||
|
||||
unique_future();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Constructs an uninitialized future.]]
|
||||
|
||||
[[Postconditions:] [[unique_future_is_ready_link `this->is_ready`] returns `false`. [unique_future_get_state_link
|
||||
`this->get_state()`] returns __uninitialized__.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:destructor Destructor]
|
||||
|
||||
~unique_future();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Destroys `*this`.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_constructor Move Constructor]
|
||||
|
||||
unique_future(unique_future && other);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Constructs a new future, and transfers ownership of the asynchronous result associated with `other` to `*this`.]]
|
||||
|
||||
[[Postconditions:] [[unique_future_get_state_link `this->get_state()`] returns the value of `other->get_state()` prior to the
|
||||
call. `other->get_state()` returns __uninitialized__. If `other` was associated with an asynchronous result, that result is now
|
||||
associated with `*this`. `other` is not associated with any asynchronous result.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
[[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_assignment Move Assignment Operator]
|
||||
|
||||
unique_future& operator=(unique_future && other);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Transfers ownership of the asynchronous result associated with `other` to `*this`.]]
|
||||
|
||||
[[Postconditions:] [[unique_future_get_state_link `this->get_state()`] returns the value of `other->get_state()` prior to the
|
||||
call. `other->get_state()` returns __uninitialized__. If `other` was associated with an asynchronous result, that result is now
|
||||
associated with `*this`. `other` is not associated with any asynchronous result. If `*this` was associated with an asynchronous
|
||||
result prior to the call, that result no longer has an associated __unique_future__ instance.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
[[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:swap Member function `swap()`]
|
||||
|
||||
void swap(unique_future & other);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Swaps ownership of the asynchronous results associated with `other` and `*this`.]]
|
||||
|
||||
[[Postconditions:] [[unique_future_get_state_link `this->get_state()`] returns the value of `other->get_state()` prior to the
|
||||
call. `other->get_state()` returns the value of `this->get_state()` prior to the call. If `other` was associated with an
|
||||
asynchronous result, that result is now associated with `*this`, otherwise `*this` has no associated result. If `*this` was
|
||||
associated with an asynchronous result, that result is now associated with `other`, otherwise `other` has no associated result.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:get Member function `get()`]
|
||||
|
||||
R&& get();
|
||||
R& unique_future<R&>::get();
|
||||
void unique_future<void>::get();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If `*this` is associated with an asynchronous result, waits until the result is ready as-if by a call to
|
||||
__unique_future_wait__, and retrieves the result (whether that is a value or an exception).]]
|
||||
|
||||
[[Returns:] [If the result type `R` is a reference, returns the stored reference. If `R` is `void`, there is no return
|
||||
value. Otherwise, returns an rvalue-reference to the value stored in the asynchronous result.]]
|
||||
|
||||
[[Postconditions:] [[unique_future_is_ready_link `this->is_ready()`] returns `true`. [unique_future_get_state_link
|
||||
`this->get_state()`] returns __ready__.]]
|
||||
|
||||
[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result
|
||||
associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception stored in the
|
||||
asynchronous result in place of a value.]]
|
||||
|
||||
[[Notes:] [`get()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait Member function `wait()`]
|
||||
|
||||
void wait();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If `*this` is associated with an asynchronous result, waits until the result is ready. If the result is not ready on
|
||||
entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]]
|
||||
|
||||
[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result
|
||||
associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the
|
||||
['wait callback] if such a callback is called.]]
|
||||
|
||||
[[Postconditions:] [[unique_future_is_ready_link `this->is_ready()`] returns `true`. [unique_future_get_state_link
|
||||
`this->get_state()`] returns __ready__.]]
|
||||
|
||||
[[Notes:] [`wait()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait_duration Member function `timed_wait()`]
|
||||
|
||||
template<typename Duration>
|
||||
bool timed_wait(Duration const& wait_duration);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If `*this` is associated with an asynchronous result, waits until the result is ready, or the time specified by
|
||||
`wait_duration` has elapsed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is
|
||||
invoked prior to waiting.]]
|
||||
|
||||
[[Returns:] [`true` if `*this` is associated with an asynchronous result, and that result is ready before the specified time has
|
||||
elapsed, `false` otherwise.]]
|
||||
|
||||
[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result
|
||||
associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the
|
||||
['wait callback] if such a callback is called.]]
|
||||
|
||||
[[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and
|
||||
[unique_future_get_state_link `this->get_state()`] returns __ready__.]]
|
||||
|
||||
[[Notes:] [`timed_wait()` is an ['interruption point]. `Duration` must be a type that meets the Boost.DateTime time duration requirements.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait_absolute Member function `timed_wait()`]
|
||||
|
||||
bool timed_wait(boost::system_time const& wait_timeout);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If `*this` is associated with an asynchronous result, waits until the result is ready, or the time point specified by
|
||||
`wait_timeout` has passed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is invoked
|
||||
prior to waiting.]]
|
||||
|
||||
[[Returns:] [`true` if `*this` is associated with an asynchronous result, and that result is ready before the specified time has
|
||||
passed, `false` otherwise.]]
|
||||
|
||||
[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result
|
||||
associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the
|
||||
['wait callback] if such a callback is called.]]
|
||||
|
||||
[[Postconditions:] [If this call returned `true`, then [unique_future_is_ready_link `this->is_ready()`] returns `true` and
|
||||
[unique_future_get_state_link `this->get_state()`] returns __ready__.]]
|
||||
|
||||
[[Notes:] [`timed_wait()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:is_ready Member function `is_ready()`]
|
||||
|
||||
bool is_ready();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Checks to see if the asynchronous result associated with `*this` is set.]]
|
||||
|
||||
[[Returns:] [`true` if `*this` is associated with an asynchronous result, and that result is ready for retrieval, `false`
|
||||
otherwise.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:has_value Member function `has_value()`]
|
||||
|
||||
bool has_value();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Checks to see if the asynchronous result associated with `*this` is set with a value rather than an exception.]]
|
||||
|
||||
[[Returns:] [`true` if `*this` is associated with an asynchronous result, that result is ready for retrieval, and the result is a
|
||||
stored value, `false` otherwise.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:has_exception Member function `has_exception()`]
|
||||
|
||||
bool has_exception();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Checks to see if the asynchronous result associated with `*this` is set with an exception rather than a value.]]
|
||||
|
||||
[[Returns:] [`true` if `*this` is associated with an asynchronous result, that result is ready for retrieval, and the result is a
|
||||
stored exception, `false` otherwise.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:get_state Member function `get_state()`]
|
||||
|
||||
future_state::state get_state();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Determine the state of the asynchronous result associated with `*this`, if any.]]
|
||||
|
||||
[[Returns:] [__uninitialized__ if `*this` is not associated with an asynchronous result. __ready__ if the asynchronous result
|
||||
associated with `*this` is ready for retrieval, __waiting__ otherwise.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:shared_future `shared_future` class template]
|
||||
|
||||
template <typename R>
|
||||
class shared_future
|
||||
{
|
||||
public:
|
||||
typedef future_state::state state;
|
||||
|
||||
shared_future();
|
||||
~shared_future();
|
||||
|
||||
// copy support
|
||||
shared_future(shared_future const& other);
|
||||
shared_future& operator=(shared_future const& other);
|
||||
|
||||
// move support
|
||||
shared_future(shared_future && other);
|
||||
shared_future(unique_future<R> && other);
|
||||
shared_future& operator=(shared_future && other);
|
||||
shared_future& operator=(unique_future<R> && other);
|
||||
|
||||
void swap(shared_future& other);
|
||||
|
||||
// retrieving the value
|
||||
R get();
|
||||
|
||||
// functions to check state, and wait for ready
|
||||
state get_state() const;
|
||||
bool is_ready() const;
|
||||
bool has_exception() const;
|
||||
bool has_value() const;
|
||||
|
||||
// waiting for the result to be ready
|
||||
void wait() const;
|
||||
template<typename Duration>
|
||||
bool timed_wait(Duration const& rel_time) const;
|
||||
bool timed_wait_until(boost::system_time const& abs_time) const;
|
||||
};
|
||||
|
||||
[section:default_constructor Default Constructor]
|
||||
|
||||
shared_future();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Constructs an uninitialized future.]]
|
||||
|
||||
[[Postconditions:] [[shared_future_is_ready_link `this->is_ready`] returns `false`. [shared_future_get_state_link
|
||||
`this->get_state()`] returns __uninitialized__.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:get Member function `get()`]
|
||||
|
||||
const R& get();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If `*this` is associated with an asynchronous result, waits until the result is ready as-if by a call to
|
||||
__shared_future_wait__, and returns a `const` reference to the result.]]
|
||||
|
||||
[[Returns:] [If the result type `R` is a reference, returns the stored reference. If `R` is `void`, there is no return
|
||||
value. Otherwise, returns a `const` reference to the value stored in the asynchronous result.]]
|
||||
|
||||
[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the
|
||||
result associated with `*this` is not ready at the point of the call, and the current thread is interrupted.]]
|
||||
|
||||
[[Notes:] [`get()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait Member function `wait()`]
|
||||
|
||||
void wait();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If `*this` is associated with an asynchronous result, waits until the result is ready. If the result is not ready on
|
||||
entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]]
|
||||
|
||||
[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result
|
||||
associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the
|
||||
['wait callback] if such a callback is called.]]
|
||||
|
||||
[[Postconditions:] [[shared_future_is_ready_link `this->is_ready()`] returns `true`. [shared_future_get_state_link
|
||||
`this->get_state()`] returns __ready__.]]
|
||||
|
||||
[[Notes:] [`wait()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait_duration Member function `timed_wait()`]
|
||||
|
||||
template<typename Duration>
|
||||
bool timed_wait(Duration const& wait_duration);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If `*this` is associated with an asynchronous result, waits until the result is ready, or the time specified by
|
||||
`wait_duration` has elapsed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is
|
||||
invoked prior to waiting.]]
|
||||
|
||||
[[Returns:] [`true` if `*this` is associated with an asynchronous result, and that result is ready before the specified time has
|
||||
elapsed, `false` otherwise.]]
|
||||
|
||||
[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result
|
||||
associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the
|
||||
['wait callback] if such a callback is called.]]
|
||||
|
||||
[[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and
|
||||
[shared_future_get_state_link `this->get_state()`] returns __ready__.]]
|
||||
|
||||
[[Notes:] [`timed_wait()` is an ['interruption point]. `Duration` must be a type that meets the Boost.DateTime time duration requirements.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_wait_absolute Member function `timed_wait()`]
|
||||
|
||||
bool timed_wait(boost::system_time const& wait_timeout);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If `*this` is associated with an asynchronous result, waits until the result is ready, or the time point specified by
|
||||
`wait_timeout` has passed. If the result is not ready on entry, and the result has a ['wait callback] set, that callback is invoked
|
||||
prior to waiting.]]
|
||||
|
||||
[[Returns:] [`true` if `*this` is associated with an asynchronous result, and that result is ready before the specified time has
|
||||
passed, `false` otherwise.]]
|
||||
|
||||
[[Throws:] [__future_uninitialized__ if `*this` is not associated with an asynchronous result. __thread_interrupted__ if the result
|
||||
associated with `*this` is not ready at the point of the call, and the current thread is interrupted. Any exception thrown by the
|
||||
['wait callback] if such a callback is called.]]
|
||||
|
||||
[[Postconditions:] [If this call returned `true`, then [shared_future_is_ready_link `this->is_ready()`] returns `true` and
|
||||
[shared_future_get_state_link `this->get_state()`] returns __ready__.]]
|
||||
|
||||
[[Notes:] [`timed_wait()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:is_ready Member function `is_ready()`]
|
||||
|
||||
bool is_ready();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Checks to see if the asynchronous result associated with `*this` is set.]]
|
||||
|
||||
[[Returns:] [`true` if `*this` is associated with an asynchronous result, and that result is ready for retrieval, `false`
|
||||
otherwise.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:has_value Member function `has_value()`]
|
||||
|
||||
bool has_value();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Checks to see if the asynchronous result associated with `*this` is set with a value rather than an exception.]]
|
||||
|
||||
[[Returns:] [`true` if `*this` is associated with an asynchronous result, that result is ready for retrieval, and the result is a
|
||||
stored value, `false` otherwise.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:has_exception Member function `has_exception()`]
|
||||
|
||||
bool has_exception();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Checks to see if the asynchronous result associated with `*this` is set with an exception rather than a value.]]
|
||||
|
||||
[[Returns:] [`true` if `*this` is associated with an asynchronous result, that result is ready for retrieval, and the result is a
|
||||
stored exception, `false` otherwise.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:get_state Member function `get_state()`]
|
||||
|
||||
future_state::state get_state();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Determine the state of the asynchronous result associated with `*this`, if any.]]
|
||||
|
||||
[[Returns:] [__uninitialized__ if `*this` is not associated with an asynchronous result. __ready__ if the asynchronous result
|
||||
associated with `*this` is ready for retrieval, __waiting__ otherwise.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:promise `promise` class template]
|
||||
|
||||
template <typename R>
|
||||
class promise
|
||||
{
|
||||
promise(promise & rhs);// = delete;
|
||||
promise & operator=(promise & rhs);// = delete;
|
||||
public:
|
||||
// template <class Allocator> explicit promise(Allocator a);
|
||||
|
||||
promise();
|
||||
~promise();
|
||||
|
||||
// Move support
|
||||
promise(promise && rhs);
|
||||
promise & operator=(promise&& rhs);
|
||||
|
||||
void swap(promise& other);
|
||||
// Result retrieval
|
||||
unique_future<R> get_future();
|
||||
|
||||
// Set the value
|
||||
void set_value(R& r);
|
||||
void set_value(R&& r);
|
||||
void set_exception(boost::exception_ptr e);
|
||||
|
||||
template<typename F>
|
||||
void set_wait_callback(F f);
|
||||
};
|
||||
|
||||
[section:default_constructor Default Constructor]
|
||||
|
||||
promise();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Constructs a new __promise__ with no associated result.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_constructor Move Constructor]
|
||||
|
||||
promise(promise && other);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Constructs a new __promise__, and transfers ownership of the result associated with `other` to `*this`, leaving `other`
|
||||
with no associated result.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
[[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_assignment Move Assignment Operator]
|
||||
|
||||
promise& operator=(promise && other);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Transfers ownership of the result associated with `other` to `*this`, leaving `other` with no associated result. If there
|
||||
was already a result associated with `*this`, and that result was not ['ready], sets any futures associated with that result to
|
||||
['ready] with a __broken_promise__ exception as the result. ]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
[[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:destructor Destructor]
|
||||
|
||||
~promise();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Destroys `*this`. If there was a result associated with `*this`, and that result is not ['ready], sets any futures
|
||||
associated with that task to ['ready] with a __broken_promise__ exception as the result.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:get_future Member Function `get_future()`]
|
||||
|
||||
unique_future<R> get_future();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If `*this` was not associated with a result, allocate storage for a new asynchronous result and associate it with
|
||||
`*this`. Returns a __unique_future__ associated with the result associated with `*this`. ]]
|
||||
|
||||
[[Throws:] [__future_already_retrieved__ if the future associated with the task has already been retrieved. `std::bad_alloc` if any
|
||||
memory necessary could not be allocated.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:set_value Member Function `set_value()`]
|
||||
|
||||
void set_value(R&& r);
|
||||
void set_value(const R& r);
|
||||
void promise<R&>::set_value(R& r);
|
||||
void promise<void>::set_value();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If `*this` was not associated with a result, allocate storage for a new asynchronous result and associate it with
|
||||
`*this`. Store the value `r` in the asynchronous result associated with `*this`. Any threads blocked waiting for the asynchronous
|
||||
result are woken.]]
|
||||
|
||||
[[Postconditions:] [All futures waiting on the asynchronous result are ['ready] and __unique_future_has_value__ or
|
||||
__shared_future_has_value__ for those futures shall return `true`.]]
|
||||
|
||||
[[Throws:] [__promise_already_satisfied__ if the result associated with `*this` is already ['ready]. `std::bad_alloc` if the memory
|
||||
required for storage of the result cannot be allocated. Any exception thrown by the copy or move-constructor of `R`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:set_exception Member Function `set_exception()`]
|
||||
|
||||
void set_exception(boost::exception_ptr e);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If `*this` was not associated with a result, allocate storage for a new asynchronous result and associate it with
|
||||
`*this`. Store the exception `e` in the asynchronous result associated with `*this`. Any threads blocked waiting for the asynchronous
|
||||
result are woken.]]
|
||||
|
||||
[[Postconditions:] [All futures waiting on the asynchronous result are ['ready] and __unique_future_has_exception__ or
|
||||
__shared_future_has_exception__ for those futures shall return `true`.]]
|
||||
|
||||
[[Throws:] [__promise_already_satisfied__ if the result associated with `*this` is already ['ready]. `std::bad_alloc` if the memory
|
||||
required for storage of the result cannot be allocated.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:set_wait_callback Member Function `set_wait_callback()`]
|
||||
|
||||
template<typename F>
|
||||
void set_wait_callback(F f);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Preconditions:] [The expression `f(t)` where `t` is a lvalue of type __promise__ shall be well-formed. Invoking a copy of
|
||||
`f` shall have the same effect as invoking `f`]]
|
||||
|
||||
[[Effects:] [Store a copy of `f` with the asynchronous result associated with `*this` as a ['wait callback]. This will replace any
|
||||
existing wait callback store alongside that result. If a thread subsequently calls one of the wait functions on a __unique_future__
|
||||
or __shared_future__ associated with this result, and the result is not ['ready], `f(*this)` shall be invoked.]]
|
||||
|
||||
[[Throws:] [`std::bad_alloc` if memory cannot be allocated for the required storage.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:packaged_task `packaged_task` class template]
|
||||
|
||||
template<typename R>
|
||||
class packaged_task
|
||||
{
|
||||
packaged_task(packaged_task&);// = delete;
|
||||
packaged_task& operator=(packaged_task&);// = delete;
|
||||
|
||||
public:
|
||||
// construction and destruction
|
||||
template <class F>
|
||||
explicit packaged_task(F const& f);
|
||||
|
||||
explicit packaged_task(R(*f)());
|
||||
|
||||
template <class F>
|
||||
explicit packaged_task(F&& f);
|
||||
|
||||
// template <class F, class Allocator>
|
||||
// explicit packaged_task(F const& f, Allocator a);
|
||||
// template <class F, class Allocator>
|
||||
// explicit packaged_task(F&& f, Allocator a);
|
||||
|
||||
~packaged_task()
|
||||
{}
|
||||
|
||||
// move support
|
||||
packaged_task(packaged_task&& other);
|
||||
packaged_task& operator=(packaged_task&& other);
|
||||
|
||||
void swap(packaged_task& other);
|
||||
// result retrieval
|
||||
unique_future<R> get_future();
|
||||
|
||||
// execution
|
||||
void operator()();
|
||||
|
||||
template<typename F>
|
||||
void set_wait_callback(F f);
|
||||
};
|
||||
|
||||
[section:task_constructor Task Constructor]
|
||||
|
||||
template<typename F>
|
||||
packaged_task(F const &f);
|
||||
|
||||
packaged_task(R(*f)());
|
||||
|
||||
template<typename F>
|
||||
packaged_task(F&&f);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Preconditions:] [`f()` is a valid expression with a return type convertible to `R`. Invoking a copy of `f` shall behave the same
|
||||
as invoking `f`.]]
|
||||
|
||||
[[Effects:] [Constructs a new __packaged_task__ with a copy of `f` stored as the associated task.]]
|
||||
|
||||
[[Throws:] [Any exceptions thrown by the copy (or move) constructor of `f`. `std::bad_alloc` if memory for the internal data
|
||||
structures could not be allocated.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_constructor Move Constructor]
|
||||
|
||||
packaged_task(packaged_task && other);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Constructs a new __packaged_task__, and transfers ownership of the task associated with `other` to `*this`, leaving `other`
|
||||
with no associated task.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
[[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_assignment Move Assignment Operator]
|
||||
|
||||
packaged_task& operator=(packaged_task && other);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Transfers ownership of the task associated with `other` to `*this`, leaving `other` with no associated task. If there
|
||||
was already a task associated with `*this`, and that task has not been invoked, sets any futures associated with that task to
|
||||
['ready] with a __broken_promise__ exception as the result. ]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
[[Notes:] [If the compiler does not support rvalue-references, this is implemented using the boost.thread move emulation.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:destructor Destructor]
|
||||
|
||||
~packaged_task();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Destroys `*this`. If there was a task associated with `*this`, and that task has not been invoked, sets any futures
|
||||
associated with that task to ['ready] with a __broken_promise__ exception as the result.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:get_future Member Function `get_future()`]
|
||||
|
||||
unique_future<R> get_future();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Returns a __unique_future__ associated with the result of the task associated with `*this`. ]]
|
||||
|
||||
[[Throws:] [__task_moved__ if ownership of the task associated with `*this` has been moved to another instance of
|
||||
__packaged_task__. __future_already_retrieved__ if the future associated with the task has already been retrieved.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:call_operator Member Function `operator()()`]
|
||||
|
||||
void operator()();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Invoke the task associated with `*this` and store the result in the corresponding future. If the task returns normally,
|
||||
the return value is stored as the asynchronous result, otherwise the exception thrown is stored. Any threads blocked waiting for the
|
||||
asynchronous result associated with this task are woken.]]
|
||||
|
||||
[[Postconditions:] [All futures waiting on the asynchronous result are ['ready]]]
|
||||
|
||||
[[Throws:] [__task_moved__ if ownership of the task associated with `*this` has been moved to another instance of
|
||||
__packaged_task__. __task_already_started__ if the task has already been invoked.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:set_wait_callback Member Function `set_wait_callback()`]
|
||||
|
||||
template<typename F>
|
||||
void set_wait_callback(F f);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Preconditions:] [The expression `f(t)` where `t` is a lvalue of type __packaged_task__ shall be well-formed. Invoking a copy of
|
||||
`f` shall have the same effect as invoking `f`]]
|
||||
|
||||
[[Effects:] [Store a copy of `f` with the task associated with `*this` as a ['wait callback]. This will replace any existing wait
|
||||
callback store alongside that task. If a thread subsequently calls one of the wait functions on a __unique_future__ or
|
||||
__shared_future__ associated with this task, and the result of the task is not ['ready], `f(*this)` shall be invoked.]]
|
||||
|
||||
[[Throws:] [__task_moved__ if ownership of the task associated with `*this` has been moved to another instance of
|
||||
__packaged_task__.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_for_any Non-member function `wait_for_any()`]
|
||||
|
||||
template<typename Iterator>
|
||||
Iterator wait_for_any(Iterator begin,Iterator end);
|
||||
|
||||
template<typename F1,typename F2>
|
||||
unsigned wait_for_any(F1& f1,F2& f2);
|
||||
|
||||
template<typename F1,typename F2,typename F3>
|
||||
unsigned wait_for_any(F1& f1,F2& f2,F3& f3);
|
||||
|
||||
template<typename F1,typename F2,typename F3,typename F4>
|
||||
unsigned wait_for_any(F1& f1,F2& f2,F3& f3,F4& f4);
|
||||
|
||||
template<typename F1,typename F2,typename F3,typename F4,typename F5>
|
||||
unsigned wait_for_any(F1& f1,F2& f2,F3& f3,F4& f4,F5& f5);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Preconditions:] [The types `Fn` shall be specializations of
|
||||
__unique_future__ or __shared_future__, and `Iterator` shall be a
|
||||
forward iterator with a `value_type` which is a specialization of
|
||||
__unique_future__ or __shared_future__.]]
|
||||
|
||||
[[Effects:] [Waits until at least one of the specified futures is ['ready].]]
|
||||
|
||||
[[Returns:] [The range-based overload returns an `Iterator` identifying the first future in the range that was detected as
|
||||
['ready]. The remaining overloads return the zero-based index of the first future that was detected as ['ready] (first parameter =>
|
||||
0, second parameter => 1, etc.).]]
|
||||
|
||||
[[Throws:] [__thread_interrupted__ if the current thread is interrupted. Any exception thrown by the ['wait callback] associated
|
||||
with any of the futures being waited for. `std::bad_alloc` if memory could not be allocated for the internal wait structures.]]
|
||||
|
||||
[[Notes:] [`wait_for_any()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:wait_for_all Non-member function `wait_for_all()`]
|
||||
|
||||
template<typename Iterator>
|
||||
void wait_for_all(Iterator begin,Iterator end);
|
||||
|
||||
template<typename F1,typename F2>
|
||||
void wait_for_all(F1& f1,F2& f2);
|
||||
|
||||
template<typename F1,typename F2,typename F3>
|
||||
void wait_for_all(F1& f1,F2& f2,F3& f3);
|
||||
|
||||
template<typename F1,typename F2,typename F3,typename F4>
|
||||
void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4);
|
||||
|
||||
template<typename F1,typename F2,typename F3,typename F4,typename F5>
|
||||
void wait_for_all(F1& f1,F2& f2,F3& f3,F4& f4,F5& f5);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Preconditions:] [The types `Fn` shall be specializations of
|
||||
__unique_future__ or __shared_future__, and `Iterator` shall be a
|
||||
forward iterator with a `value_type` which is a specialization of
|
||||
__unique_future__ or __shared_future__.]]
|
||||
|
||||
[[Effects:] [Waits until all of the specified futures are ['ready].]]
|
||||
|
||||
[[Throws:] [Any exceptions thrown by a call to `wait()` on the specified futures.]]
|
||||
|
||||
[[Notes:] [`wait_for_all()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect]
|
||||
187
doc/futures.qbk
Executable file
187
doc/futures.qbk
Executable file
@@ -0,0 +1,187 @@
|
||||
[/
|
||||
(C) Copyright 2008-11 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).
|
||||
]
|
||||
|
||||
[section:futures Futures]
|
||||
|
||||
[template future_state_link[link_text] [link thread.synchronization.futures.reference.future_state [link_text]]]
|
||||
[def __uninitialized__ [future_state_link `boost::future_state::uninitialized`]]
|
||||
[def __ready__ [future_state_link `boost::future_state::ready`]]
|
||||
[def __waiting__ [future_state_link `boost::future_state::waiting`]]
|
||||
|
||||
[def __future_uninitialized__ `boost::future_uninitialized`]
|
||||
[def __broken_promise__ `boost::broken_promise`]
|
||||
[def __future_already_retrieved__ `boost::future_already_retrieved`]
|
||||
[def __task_moved__ `boost::task_moved`]
|
||||
[def __task_already_started__ `boost::task_already_started`]
|
||||
[def __promise_already_satisfied__ `boost::promise_already_satisfied`]
|
||||
|
||||
[def __thread_interrupted__ `boost::thread_interrupted`]
|
||||
|
||||
|
||||
[template unique_future_link[link_text] [link thread.synchronization.futures.reference.unique_future [link_text]]]
|
||||
[def __unique_future__ [unique_future_link `boost::unique_future`]]
|
||||
|
||||
[template unique_future_get_link[link_text] [link thread.synchronization.futures.reference.unique_future.get [link_text]]]
|
||||
[def __unique_future_get__ [unique_future_get_link `boost::unique_future<R>::get()`]]
|
||||
|
||||
[template unique_future_wait_link[link_text] [link thread.synchronization.futures.reference.unique_future.wait [link_text]]]
|
||||
[def __unique_future_wait__ [unique_future_wait_link `boost::unique_future<R>::wait()`]]
|
||||
|
||||
[template unique_future_is_ready_link[link_text] [link thread.synchronization.futures.reference.unique_future.is_ready [link_text]]]
|
||||
[def __unique_future_is_ready__ [unique_future_is_ready_link `boost::unique_future<R>::is_ready()`]]
|
||||
|
||||
[template unique_future_has_value_link[link_text] [link thread.synchronization.futures.reference.unique_future.has_value [link_text]]]
|
||||
[def __unique_future_has_value__ [unique_future_has_value_link `boost::unique_future<R>::has_value()`]]
|
||||
|
||||
[template unique_future_has_exception_link[link_text] [link thread.synchronization.futures.reference.unique_future.has_exception [link_text]]]
|
||||
[def __unique_future_has_exception__ [unique_future_has_exception_link `boost::unique_future<R>::has_exception()`]]
|
||||
|
||||
[template unique_future_get_state_link[link_text] [link thread.synchronization.futures.reference.unique_future.get_state [link_text]]]
|
||||
[def __unique_future_get_state__ [unique_future_get_state_link `boost::unique_future<R>::get_state()`]]
|
||||
|
||||
[template shared_future_link[link_text] [link thread.synchronization.futures.reference.shared_future [link_text]]]
|
||||
[def __shared_future__ [shared_future_link `boost::shared_future`]]
|
||||
|
||||
[template shared_future_get_link[link_text] [link thread.synchronization.futures.reference.shared_future.get [link_text]]]
|
||||
[def __shared_future_get__ [shared_future_get_link `boost::shared_future<R>::get()`]]
|
||||
|
||||
[template shared_future_wait_link[link_text] [link thread.synchronization.futures.reference.shared_future.wait [link_text]]]
|
||||
[def __shared_future_wait__ [shared_future_wait_link `boost::shared_future<R>::wait()`]]
|
||||
|
||||
[template shared_future_is_ready_link[link_text] [link thread.synchronization.futures.reference.shared_future.is_ready [link_text]]]
|
||||
[def __shared_future_is_ready__ [shared_future_is_ready_link `boost::shared_future<R>::is_ready()`]]
|
||||
|
||||
[template shared_future_has_value_link[link_text] [link thread.synchronization.futures.reference.shared_future.has_value [link_text]]]
|
||||
[def __shared_future_has_value__ [shared_future_has_value_link `boost::shared_future<R>::has_value()`]]
|
||||
|
||||
[template shared_future_has_exception_link[link_text] [link thread.synchronization.futures.reference.shared_future.has_exception [link_text]]]
|
||||
[def __shared_future_has_exception__ [shared_future_has_exception_link `boost::shared_future<R>::has_exception()`]]
|
||||
|
||||
[template shared_future_get_state_link[link_text] [link thread.synchronization.futures.reference.shared_future.get_state [link_text]]]
|
||||
[def __shared_future_get_state__ [shared_future_get_state_link `boost::shared_future<R>::get_state()`]]
|
||||
|
||||
[template promise_link[link_text] [link thread.synchronization.futures.reference.promise [link_text]]]
|
||||
[def __promise__ [promise_link `boost::promise`]]
|
||||
|
||||
[template packaged_task_link[link_text] [link thread.synchronization.futures.reference.packaged_task [link_text]]]
|
||||
[def __packaged_task__ [packaged_task_link `boost::packaged_task`]]
|
||||
|
||||
[template wait_for_any_link[link_text] [link thread.synchronization.futures.reference.wait_for_any [link_text]]]
|
||||
[def __wait_for_any__ [wait_for_any_link `boost::wait_for_any()`]]
|
||||
|
||||
[template wait_for_all_link[link_text] [link thread.synchronization.futures.reference.wait_for_all [link_text]]]
|
||||
[def __wait_for_all__ [wait_for_all_link `boost::wait_for_all()`]]
|
||||
|
||||
|
||||
[section:overview Overview]
|
||||
|
||||
The futures library provides a means of handling synchronous future values, whether those values are generated by another thread, or
|
||||
on a single thread in response to external stimuli, or on-demand.
|
||||
|
||||
This is done through the provision of four class templates: __unique_future__ and __shared_future__ which are used to retrieve the
|
||||
asynchronous results, and __promise__ and __packaged_task__ which are used to generate the asynchronous results.
|
||||
|
||||
An instance of __unique_future__ holds the one and only reference to a result. Ownership can be transferred between instances using
|
||||
the move constructor or move-assignment operator, but at most one instance holds a reference to a given asynchronous result. When
|
||||
the result is ready, it is returned from __unique_future_get__ by rvalue-reference to allow the result to be moved or copied as
|
||||
appropriate for the type.
|
||||
|
||||
On the other hand, many instances of __shared_future__ may reference the same result. Instances can be freely copied and assigned,
|
||||
and __shared_future_get__ returns a `const` reference so that multiple calls to __shared_future_get__ are safe. You can move an
|
||||
instance of __unique_future__ into an instance of __shared_future__, thus transferring ownership of the associated asynchronous
|
||||
result, but not vice-versa.
|
||||
|
||||
You can wait for futures either individually or with one of the __wait_for_any__ and __wait_for_all__ functions.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:creating Creating asynchronous values]
|
||||
|
||||
You can set the value in a future with either a __promise__ or a __packaged_task__. A __packaged_task__ is a callable object that
|
||||
wraps a function or callable object. When the packaged task is invoked, it invokes the contained function in turn, and populates a
|
||||
future with the return value. This is an answer to the perennial question: "how do I return a value from a thread?": package the
|
||||
function you wish to run as a __packaged_task__ and pass the packaged task to the thread constructor. The future retrieved from the
|
||||
packaged task can then be used to obtain the return value. If the function throws an exception, that is stored in the future in
|
||||
place of the return value.
|
||||
|
||||
int calculate_the_answer_to_life_the_universe_and_everything()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
boost::packaged_task<int> pt(calculate_the_answer_to_life_the_universe_and_everything);
|
||||
boost::unique_future<int> fi=pt.get_future();
|
||||
|
||||
boost::thread task(boost::move(pt)); // launch task on a thread
|
||||
|
||||
fi.wait(); // wait for it to finish
|
||||
|
||||
assert(fi.is_ready());
|
||||
assert(fi.has_value());
|
||||
assert(!fi.has_exception());
|
||||
assert(fi.get_state()==boost::future_state::ready);
|
||||
assert(fi.get()==42);
|
||||
|
||||
|
||||
A __promise__ is a bit more low level: it just provides explicit functions to store a value or an exception in the associated
|
||||
future. A promise can therefore be used where the value may come from more than one possible source, or where a single operation may
|
||||
produce multiple values.
|
||||
|
||||
boost::promise<int> pi;
|
||||
boost::unique_future<int> fi;
|
||||
fi=pi.get_future();
|
||||
|
||||
pi.set_value(42);
|
||||
|
||||
assert(fi.is_ready());
|
||||
assert(fi.has_value());
|
||||
assert(!fi.has_exception());
|
||||
assert(fi.get_state()==boost::future_state::ready);
|
||||
assert(fi.get()==42);
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:lazy_futures Wait Callbacks and Lazy Futures]
|
||||
|
||||
Both __promise__ and __packaged_task__ support ['wait callbacks] that are invoked when a thread blocks in a call to `wait()` or
|
||||
`timed_wait()` on a future that is waiting for the result from the __promise__ or __packaged_task__, in the thread that is doing the
|
||||
waiting. These can be set using the `set_wait_callback()` member function on the __promise__ or __packaged_task__ in question.
|
||||
|
||||
This allows ['lazy futures] where the result is not actually computed until it is needed by some thread. In the example below, the
|
||||
call to `f.get()` invokes the callback `invoke_lazy_task`, which runs the task to set the value. If you remove the call to
|
||||
`f.get()`, the task is not ever run.
|
||||
|
||||
int calculate_the_answer_to_life_the_universe_and_everything()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
void invoke_lazy_task(boost::packaged_task<int>& task)
|
||||
{
|
||||
try
|
||||
{
|
||||
task();
|
||||
}
|
||||
catch(boost::task_already_started&)
|
||||
{}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::packaged_task<int> task(calculate_the_answer_to_life_the_universe_and_everything);
|
||||
task.set_wait_callback(invoke_lazy_task);
|
||||
boost::unique_future<int> f(task.get_future());
|
||||
|
||||
assert(f.get()==42);
|
||||
}
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[include future_ref.qbk]
|
||||
|
||||
[endsect]
|
||||
@@ -1,5 +1,6 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
(C) Copyright 2011-12 Vicente J. Botet Escriba.
|
||||
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).
|
||||
@@ -38,6 +39,16 @@ Lock ownership acquired through a call to __lock_ref__ or __try_lock_ref__ must
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error occurs.]]
|
||||
|
||||
[[Error Conditions:] [
|
||||
|
||||
[*operation_not_permitted]: if the thread does not have the privilege to perform the operation.
|
||||
|
||||
[*resource_deadlock_would_occur]: if the implementation detects that a deadlock would occur.
|
||||
|
||||
[*device_or_resource_busy]: if the mutex is already locked and blocking is not possible.
|
||||
|
||||
]]
|
||||
|
||||
]
|
||||
[endsect]
|
||||
|
||||
@@ -51,7 +62,7 @@ Lock ownership acquired through a call to __lock_ref__ or __try_lock_ref__ must
|
||||
|
||||
[[Postcondition:] [If the call returns `true`, the current thread owns the `*this`.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error occurs.]]
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
[endsect]
|
||||
@@ -66,7 +77,7 @@ Lock ownership acquired through a call to __lock_ref__ or __try_lock_ref__ must
|
||||
|
||||
[[Postcondition:] [The current thread no longer owns `*this`.]]
|
||||
|
||||
[[Throws:] [Nothing]]
|
||||
[[Throws:] [Nothing.]]
|
||||
]
|
||||
[endsect]
|
||||
[endsect]
|
||||
@@ -80,12 +91,17 @@ A type that implements the __timed_lockable_concept__ shall meet the requirement
|
||||
of the __lockable_concept__. In addition, the following member functions must be
|
||||
provided:
|
||||
|
||||
* [timed_lock_ref_link `bool timed_lock(boost::system_time const& abs_time);`]
|
||||
* [timed_lock_duration_ref_link `template<typename DurationType> bool timed_lock(DurationType const& rel_time);`]
|
||||
* [timed_lock_ref_link `bool timed_lock(boost::system_time const& abs_time);` DEPRECATED V2]
|
||||
* [timed_lock_duration_ref_link `template<typename DurationType> bool timed_lock(DurationType const& rel_time);` DEPRECATED V2]
|
||||
|
||||
Lock ownership acquired through a call to __timed_lock_ref__ must be released through a call to __unlock_ref__.
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& t);
|
||||
|
||||
[section:timed_lock `bool timed_lock(boost::system_time const& abs_time)`]
|
||||
Lock ownership acquired through a call to __timed_lock_ref__, __try_lock_for or __try_lock_until must be released through a call to __unlock_ref__.
|
||||
|
||||
[section:timed_lock `bool timed_lock(boost::system_time const& abs_time)` DEPRECATED V2]
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -101,7 +117,7 @@ reached. If the specified time has already passed, behaves as __try_lock_ref__.]
|
||||
[endsect]
|
||||
|
||||
[section:timed_lock_duration `template<typename DurationType> bool
|
||||
timed_lock(DurationType const& rel_time)`]
|
||||
timed_lock(DurationType const& rel_time)` DEPRECATED V2]
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -111,6 +127,32 @@ timed_lock(DurationType const& rel_time)`]
|
||||
]
|
||||
[endsect]
|
||||
|
||||
[section:try_lock_until `template <class Clock, class Duration> bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Attempt to obtain ownership for the current thread. Blocks until ownership can be obtained, or the specified time is
|
||||
reached. If the specified time has already passed, behaves as __try_lock_ref__.]]
|
||||
|
||||
[[Returns:] [`true` if ownership was obtained for the current thread, `false` otherwise.]]
|
||||
|
||||
[[Postcondition:] [If the call returns `true`, the current thread owns `*this`.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
]
|
||||
[endsect]
|
||||
|
||||
[section:try_lock_for `template <class Rep, class Period> bool
|
||||
try_lock_for(const chrono::duration<Rep, Period>& rel_time)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [As-if `__try_lock_until(chrono::steady_clock::now() + rel_time)`.]]
|
||||
|
||||
]
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:shared_lockable `SharedLockable` Concept]
|
||||
@@ -310,6 +352,25 @@ without blocking.]]
|
||||
|
||||
[section:locks Lock Types]
|
||||
|
||||
[section:lock_tags Lock option tags]
|
||||
|
||||
#include <boost/thread/locks.hpp>
|
||||
|
||||
struct defer_lock_t {};
|
||||
struct try_to_lock_t {};
|
||||
struct adopt_lock_t {};
|
||||
const defer_lock_t defer_lock;
|
||||
const try_to_lock_t try_to_lock;
|
||||
const adopt_lock_t adopt_lock;
|
||||
|
||||
These tags are used in scoped locks constructors to specify a specific behavior.
|
||||
|
||||
*`defer_lock_t`: is used to construct the scoped lock without locking it.
|
||||
*`try_to_lock_t`: is used to construct the scoped lock trying to lock it.
|
||||
*`adopt_lock_t`: is used to construct the scoped lock without locking it but adopting ownership.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:lock_guard Class template `lock_guard`]
|
||||
|
||||
#include <boost/thread/locks.hpp>
|
||||
@@ -384,41 +445,53 @@ object passed to the constructor.]]
|
||||
class unique_lock
|
||||
{
|
||||
public:
|
||||
unique_lock();
|
||||
typedef Lockable mutex_type;
|
||||
unique_lock() noexcept;
|
||||
explicit unique_lock(Lockable& m_);
|
||||
unique_lock(Lockable& m_,adopt_lock_t);
|
||||
unique_lock(Lockable& m_,defer_lock_t);
|
||||
unique_lock(Lockable& m_,defer_lock_t) noexcept;
|
||||
unique_lock(Lockable& m_,try_to_lock_t);
|
||||
unique_lock(Lockable& m_,system_time const& target_time);
|
||||
unique_lock(Lockable& m_,system_time const& target_time); // DEPRECATED V2
|
||||
|
||||
template <class Clock, class Duration>
|
||||
unique_lock(Mutex& mtx, const chrono::time_point<Clock, Duration>& t);
|
||||
template <class Rep, class Period>
|
||||
unique_lock(Mutex& mtx, const chrono::duration<Rep, Period>& d);
|
||||
~unique_lock();
|
||||
|
||||
unique_lock(detail::thread_move_t<unique_lock<Lockable> > other);
|
||||
unique_lock(detail::thread_move_t<upgrade_lock<Lockable> > other);
|
||||
unique_lock(unique_lock const&) = delete;
|
||||
unique_lock& operator=(unique_lock const&) = delete;
|
||||
unique_lock(unique_lock<Lockable>&& other) noexcept;
|
||||
unique_lock(upgrade_lock<Lockable>&& other) noexcept;
|
||||
|
||||
operator detail::thread_move_t<unique_lock<Lockable> >();
|
||||
detail::thread_move_t<unique_lock<Lockable> > move();
|
||||
unique_lock& operator=(detail::thread_move_t<unique_lock<Lockable> > other);
|
||||
unique_lock& operator=(detail::thread_move_t<upgrade_lock<Lockable> > other);
|
||||
unique_lock& operator=(unique_lock<Lockable>&& other) noexcept;
|
||||
unique_lock& operator=(upgrade_lock<Lockable>&& other) noexcept;
|
||||
|
||||
void swap(unique_lock& other);
|
||||
void swap(detail::thread_move_t<unique_lock<Lockable> > other);
|
||||
void swap(unique_lock& other) noexcept;
|
||||
Lockable* release() noexcept;
|
||||
|
||||
void lock();
|
||||
bool try_lock();
|
||||
|
||||
template<typename TimeDuration>
|
||||
bool timed_lock(TimeDuration const& relative_time);
|
||||
bool timed_lock(::boost::system_time const& absolute_time);
|
||||
bool timed_lock(TimeDuration const& relative_time); // DEPRECATED V2
|
||||
bool timed_lock(::boost::system_time const& absolute_time); // DEPRECATED V2
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
|
||||
void unlock();
|
||||
|
||||
bool owns_lock() const;
|
||||
operator ``['unspecified-bool-type]``() const;
|
||||
bool operator!() const;
|
||||
bool owns_lock() const noexcept;
|
||||
#if defined(BOOST_NO_EXPLICIT_CONVERSION_OPERATORS)
|
||||
operator ``['unspecified-bool-type]``() const noexcept;
|
||||
bool operator!() const noexcept;
|
||||
#else
|
||||
explicit operator bool() const noexcept;
|
||||
#endif
|
||||
|
||||
Lockable* mutex() const;
|
||||
Lockable* release();
|
||||
Lockable* mutex() const noexcept;
|
||||
};
|
||||
|
||||
__unique_lock__ is more complex than __lock_guard__: not only does it provide for RAII-style locking, it also allows for deferring
|
||||
@@ -426,7 +499,7 @@ acquiring the lock until the __lock_ref__ member function is called explicitly,
|
||||
fashion, or with a timeout. Consequently, __unlock_ref__ is only called in the destructor if the lock object has locked the
|
||||
__lockable_concept_type__ object, or otherwise adopted a lock on the __lockable_concept_type__ object.
|
||||
|
||||
Specializations of __unique_lock__ model the __timed_lockable_concept__ if the supplied __lockable_concept_type__ type itself models
|
||||
Specializations of __unique_lock__ model the __timed_lockable_concept__ if the supplied Lockable type itself models
|
||||
__timed_lockable_concept__ (e.g. `boost::unique_lock<boost::timed_mutex>`), or the __lockable_concept__ otherwise
|
||||
(e.g. `boost::unique_lock<boost::mutex>`).
|
||||
|
||||
@@ -514,7 +587,7 @@ returns `false`.]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:constructor_abs_time `unique_lock(Lockable & m,boost::system_time const& abs_time)`]
|
||||
[section:constructor_abs_time `unique_lock(Lockable & m,boost::system_time const& abs_time)` // DEPRECATED V2]
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -532,6 +605,47 @@ returns `false`.]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:constructor_time_point `template <class Clock, class Duration> unique_lock(Lockable & m,const chrono::time_point<Clock, Duration>& abs_time)`]
|
||||
|
||||
template <class Rep, class Period>
|
||||
unique_lock(Mutex& mtx, const chrono::duration<Rep, Period>& d);
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Stores a reference to `m`. Invokes
|
||||
`m.__try_lock_until(abs_time)`, and takes ownership of the lock state if the call
|
||||
returns `true`.]]
|
||||
|
||||
[[Postcondition:] [__mutex_func_ref__ returns `&m`. If the call to __try_lock_until
|
||||
returned `true`, then __owns_lock_ref__ returns `true`, otherwise __owns_lock_ref__
|
||||
returns `false`.]]
|
||||
|
||||
[[Throws:] [Any exceptions thrown by the call to `m.__try_lock_until(abs_time)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:constructor_duration `template <class Rep, class Period> unique_lock(Lockable & m,const chrono::duration<Rep, Period>& abs_time)`]
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Stores a reference to `m`. Invokes
|
||||
`m.__try_lock_for(rel_time)`, and takes ownership of the lock state if the call
|
||||
returns `true`.]]
|
||||
|
||||
[[Postcondition:] [__mutex_func_ref__ returns `&m`. If the call to __try_lock_for
|
||||
returned `true`, then __owns_lock_ref__ returns `true`, otherwise __owns_lock_ref__
|
||||
returns `false`.]]
|
||||
|
||||
[[Throws:] [Any exceptions thrown by the call to `m.__try_lock_for(rel_time)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:destructor `~unique_lock()`]
|
||||
|
||||
[variablelist
|
||||
@@ -571,6 +685,18 @@ object associated with `*this`.]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:explicit_bool_conversion `explicit operator bool() const`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [`__owns_lock_ref__()`.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:bool_conversion `operator unspecified-bool-type() const`]
|
||||
|
||||
[variablelist
|
||||
@@ -585,6 +711,7 @@ boolean contexts.]]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:operator_not `bool operator!() const`]
|
||||
|
||||
[variablelist
|
||||
@@ -627,24 +754,25 @@ __owns_lock_ref__ returns `false`.]]
|
||||
class shared_lock
|
||||
{
|
||||
public:
|
||||
typedef Lockable mutex_type;
|
||||
shared_lock();
|
||||
explicit shared_lock(Lockable& m_);
|
||||
shared_lock(Lockable& m_,adopt_lock_t);
|
||||
shared_lock(Lockable& m_,defer_lock_t);
|
||||
shared_lock(Lockable& m_,try_to_lock_t);
|
||||
shared_lock(Lockable& m_,system_time const& target_time);
|
||||
shared_lock(detail::thread_move_t<shared_lock<Lockable> > other);
|
||||
shared_lock(detail::thread_move_t<unique_lock<Lockable> > other);
|
||||
shared_lock(detail::thread_move_t<upgrade_lock<Lockable> > other);
|
||||
|
||||
~shared_lock();
|
||||
|
||||
operator detail::thread_move_t<shared_lock<Lockable> >();
|
||||
detail::thread_move_t<shared_lock<Lockable> > move();
|
||||
shared_lock(shared_lock const&) = delete;
|
||||
shared_lock& operator=(shared_lock const&) = delete;
|
||||
|
||||
shared_lock& operator=(detail::thread_move_t<shared_lock<Lockable> > other);
|
||||
shared_lock& operator=(detail::thread_move_t<unique_lock<Lockable> > other);
|
||||
shared_lock& operator=(detail::thread_move_t<upgrade_lock<Lockable> > other);
|
||||
shared_lock(shared_lock<Lockable> && other);
|
||||
shared_lock(unique_lock<Lockable> && other);
|
||||
shared_lock(upgrade_lock<Lockable> && other);
|
||||
|
||||
shared_lock& operator=(shared_lock<Lockable> && other);
|
||||
shared_lock& operator=(unique_lock<Lockable> && other);
|
||||
shared_lock& operator=(upgrade_lock<Lockable> && other);
|
||||
void swap(shared_lock& other);
|
||||
|
||||
void lock();
|
||||
@@ -652,8 +780,12 @@ __owns_lock_ref__ returns `false`.]]
|
||||
bool timed_lock(boost::system_time const& target_time);
|
||||
void unlock();
|
||||
|
||||
#if defined(BOOST_NO_EXPLICIT_CONVERSION_OPERATORS)
|
||||
operator ``['unspecified-bool-type]``() const;
|
||||
bool operator!() const;
|
||||
#else
|
||||
explicit operator bool() const;
|
||||
#endif
|
||||
bool owns_lock() const;
|
||||
};
|
||||
|
||||
@@ -832,6 +964,18 @@ boolean contexts.]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:explicit_operator_bool `explicit operator bool() const`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [__owns_lock_shared_ref__.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:release `Lockable* release()`]
|
||||
|
||||
[variablelist
|
||||
@@ -862,26 +1006,31 @@ __owns_lock_shared_ref__ returns `false`.]]
|
||||
class upgrade_lock
|
||||
{
|
||||
public:
|
||||
typedef Lockable mutex_type;
|
||||
explicit upgrade_lock(Lockable& m_);
|
||||
|
||||
upgrade_lock(detail::thread_move_t<upgrade_lock<Lockable> > other);
|
||||
upgrade_lock(detail::thread_move_t<unique_lock<Lockable> > other);
|
||||
upgrade_lock(upgrade_lock<Lockable> && other);
|
||||
upgrade_lock(unique_lock<Lockable> && other);
|
||||
|
||||
~upgrade_lock();
|
||||
|
||||
operator detail::thread_move_t<upgrade_lock<Lockable> >();
|
||||
detail::thread_move_t<upgrade_lock<Lockable> > move();
|
||||
upgrade_lock(const upgrade_lock& other) = delete;
|
||||
upgrade_lock& operator=(const upgrade_lock<Lockable> & other) = delete;
|
||||
|
||||
upgrade_lock& operator=(detail::thread_move_t<upgrade_lock<Lockable> > other);
|
||||
upgrade_lock& operator=(detail::thread_move_t<unique_lock<Lockable> > other);
|
||||
upgrade_lock& operator=(upgrade_lock<Lockable> && other);
|
||||
upgrade_lock& operator=(unique_lock<Lockable> && other);
|
||||
|
||||
void swap(upgrade_lock& other);
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
#if defined(BOOST_NO_EXPLICIT_CONVERSION_OPERATORS)
|
||||
operator ``['unspecified-bool-type]``() const;
|
||||
bool operator!() const;
|
||||
#else
|
||||
explicit operator bool() const;
|
||||
#endif
|
||||
bool owns_lock() const;
|
||||
};
|
||||
|
||||
@@ -911,16 +1060,24 @@ state (including the destructor) must be called by the same thread that acquired
|
||||
class upgrade_to_unique_lock
|
||||
{
|
||||
public:
|
||||
typedef Lockable mutex_type;
|
||||
explicit upgrade_to_unique_lock(upgrade_lock<Lockable>& m_);
|
||||
|
||||
~upgrade_to_unique_lock();
|
||||
|
||||
upgrade_to_unique_lock(detail::thread_move_t<upgrade_to_unique_lock<Lockable> > other);
|
||||
upgrade_to_unique_lock& operator=(detail::thread_move_t<upgrade_to_unique_lock<Lockable> > other);
|
||||
upgrade_to_unique_lock(upgrade_to_unique_lock const& other) = delete;
|
||||
upgrade_to_unique_lock& operator=(upgrade_to_unique_lock<Lockable> const& other) = delete;
|
||||
|
||||
upgrade_to_unique_lock(upgrade_to_unique_lock<Lockable> && other);
|
||||
upgrade_to_unique_lock& operator=(upgrade_to_unique_lock<Lockable> && other);
|
||||
|
||||
void swap(upgrade_to_unique_lock& other);
|
||||
|
||||
#if defined(BOOST_NO_EXPLICIT_CONVERSION_OPERATORS)
|
||||
operator ``['unspecified-bool-type]``() const;
|
||||
bool operator!() const;
|
||||
#else
|
||||
explicit operator bool() const;
|
||||
#endif
|
||||
bool owns_lock() const;
|
||||
};
|
||||
|
||||
@@ -957,10 +1114,13 @@ __lockable_concept_type__ is downgraded back to ['upgrade ownership].
|
||||
|
||||
MutexType* mutex() const;
|
||||
MutexType* release();
|
||||
bool operator!() const;
|
||||
|
||||
typedef ``['unspecified-bool-type]`` bool_type;
|
||||
operator bool_type() const;
|
||||
#if defined(BOOST_NO_EXPLICIT_CONVERSION_OPERATORS)
|
||||
operator ``['unspecified-bool-type]``() const;
|
||||
bool operator!() const;
|
||||
#else
|
||||
explicit operator bool() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
The member typedef `scoped_try_lock` is provided for each distinct
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
(C) Copyright 2007-11 Anthony Williams
|
||||
(C) Copyright 2011-12 Vicente J. Botet Escriba
|
||||
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).
|
||||
@@ -75,10 +76,14 @@ __try_mutex__ is a `typedef` to __mutex__, provided for backwards compatibility
|
||||
void lock();
|
||||
void unlock();
|
||||
bool try_lock();
|
||||
bool timed_lock(system_time const & abs_time);
|
||||
|
||||
bool timed_lock(system_time const & abs_time); // DEPRECATED V2
|
||||
template<typename TimeDuration>
|
||||
bool timed_lock(TimeDuration const & relative_time);
|
||||
bool timed_lock(TimeDuration const & relative_time); // DEPRECATED V2
|
||||
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& t);
|
||||
|
||||
typedef platform-specific-type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
@@ -181,10 +186,14 @@ __recursive_try_mutex__ is a `typedef` to __recursive_mutex__, provided for back
|
||||
bool try_lock();
|
||||
void unlock();
|
||||
|
||||
bool timed_lock(system_time const & abs_time);
|
||||
|
||||
bool timed_lock(system_time const & abs_time); // DEPRECATED V2
|
||||
template<typename TimeDuration>
|
||||
bool timed_lock(TimeDuration const & relative_time);
|
||||
bool timed_lock(TimeDuration const & relative_time); // DEPRECATED V2
|
||||
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& t);
|
||||
|
||||
typedef platform-specific-type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
|
||||
@@ -45,6 +45,15 @@ all subsequent `call_once` invocations on the same `once_flag` object. ]]
|
||||
|
||||
[[Throws:] [`thread_resource_error` when the effects cannot be achieved. or any exception propagated from `func`.]]
|
||||
|
||||
[[Note:] [The function passed to `call_once` must not also call
|
||||
`call_once` passing the same `once_flag` object. This may cause
|
||||
deadlock, or invoking the passed function a second time. The
|
||||
alternative is to allow the second call to return immediately, but
|
||||
that assumes the code knows it has been called recursively, and can
|
||||
proceed even though the call to `call_once` didn't actually call the
|
||||
function, in which case it could also avoid calling `call_once`
|
||||
recursively.]]
|
||||
|
||||
]
|
||||
|
||||
void call_once(void (*func)(),once_flag& flag);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
(C) Copyright 2007-12 Anthony Williams.
|
||||
(C) Copyright 20012 Vicente J. Botet Escriba.
|
||||
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).
|
||||
@@ -11,13 +12,14 @@ __boost_thread__ enables the use of multiple threads of execution with shared da
|
||||
functions for managing the threads themselves, along with others for synchronizing data between the threads or providing separate
|
||||
copies of data specific to individual threads.
|
||||
|
||||
The __boost_thread__ library was originally written and designed by William E. Kempf. This version is a major rewrite designed to
|
||||
The __boost_thread__ library was originally written and designed by William E. Kempf (version 0). Anthony Williams version (version 1) was a major rewrite designed to
|
||||
closely follow the proposals presented to the C++ Standards Committee, in particular
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html N2497],
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2320.html N2320],
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2184.html N2184],
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2139.html N2139], and
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2094.html N2094]
|
||||
Vicente J. Botet Escriba started in version 2 the adaptation to comply with the accepted Thread C++11 library.
|
||||
|
||||
In order to use the classes and functions described here, you can
|
||||
either include the specific headers specified by the descriptions of
|
||||
@@ -28,3 +30,15 @@ each class or function, or include the master thread library header:
|
||||
which includes all the other headers in turn.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:build Using and building the library]
|
||||
|
||||
Boost.Thread is configured following the conventions used to build [@http://www.boost.org/doc/libs/1_48_0/libs/config/doc/html/boost_config/boost_macro_reference.html#boost_config.boost_macro_reference.macros_for_libraries_with_separate_source_code libraries with separate source code]. Boost.Thread will import/export the code only if the user has specifically asked for it, by defining either BOOST_ALL_DYN_LINK if they want all boost libraries to be dynamically linked, or BOOST_THREAD_DYN_LINK if they want just this one to be dynamically liked.
|
||||
|
||||
The definition of these macros determines whether BOOST_THREAD_USE_DLL is defined. If BOOST_THREAD_USE_DLL is not defined, the library will define BOOST_THREAD_USE_DLL or BOOST_THREAD_USE_LIB depending on whether the platform. On non windows platforms BOOST_THREAD_USE_LIB is defined if is not defined. In windows platforms, BOOST_THREAD_USE_LIB is defined if BOOST_THREAD_USE_DLL and the compiler supports auto-tss cleanup with Boost.Threads (for the time been Msvc and Intel)
|
||||
|
||||
The source code compiled when building the library defines a macros BOOST_THREAD_SOURCE that is used to import or export it. The user must not define this macro in any case.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
(C) Copyright 2008-11 Anthony Williams
|
||||
(C) Copyright 2011-12 Vicente J. Botet Escriba
|
||||
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).
|
||||
]
|
||||
|
||||
[article Thread
|
||||
[quickbook 1.4]
|
||||
[authors [Williams, Anthony]]
|
||||
[copyright 2007-8 Anthony Williams]
|
||||
[quickbook 1.5]
|
||||
[authors [Williams, Anthony] [Botet Escriba, Vicente J.]]
|
||||
[copyright 2007-11 Anthony Williams]
|
||||
[copyright 2011-12 Vicente J. Botet Escriba]
|
||||
[purpose C++ Library for launching threads and synchronizing data between them]
|
||||
[category text]
|
||||
[license
|
||||
@@ -53,6 +55,9 @@
|
||||
[template timed_lock_ref_link[link_text] [link thread.synchronization.mutex_concepts.timed_lockable.timed_lock [link_text]]]
|
||||
[def __timed_lock_ref__ [timed_lock_ref_link `timed_lock()`]]
|
||||
|
||||
[def __try_lock_for [link thread.synchronization.mutex_concepts.timed_lockable.try_lock_for `try_lock_for`]]
|
||||
[def __try_lock_until [link thread.synchronization.mutex_concepts.timed_lockable.try_lock_until `try_lock_until`]]
|
||||
|
||||
[template timed_lock_duration_ref_link[link_text] [link thread.synchronization.mutex_concepts.timed_lockable.timed_lock_duration [link_text]]]
|
||||
[def __timed_lock_duration_ref__ [timed_lock_duration_ref_link `timed_lock()`]]
|
||||
|
||||
@@ -117,14 +122,22 @@
|
||||
|
||||
|
||||
[def __thread__ [link thread.thread_management.thread `boost::thread`]]
|
||||
[def __thread [link thread.thread_management.thread `boost::thread`]]
|
||||
[def __thread_id__ [link thread.thread_management.thread.id `boost::thread::id`]]
|
||||
[template join_link[link_text] [link thread.thread_management.thread.join [link_text]]]
|
||||
[def __join__ [join_link `join()`]]
|
||||
|
||||
[def __try_join_for [link thread.thread_management.thread.try_join_for `try_join_for`]]
|
||||
[def __try_join_until [link thread.thread_management.thread.try_join_until `try_join_until`]]
|
||||
|
||||
|
||||
[template timed_join_link[link_text] [link thread.thread_management.thread.timed_join [link_text]]]
|
||||
[def __timed_join__ [timed_join_link `timed_join()`]]
|
||||
[def __detach__ [link thread.thread_management.thread.detach `detach()`]]
|
||||
[def __interrupt__ [link thread.thread_management.thread.interrupt `interrupt()`]]
|
||||
[def __sleep__ [link thread.thread_management.this_thread.sleep `boost::this_thread::sleep()`]]
|
||||
[def __sleep_for [link thread.thread_management.this_thread.sleep_for `sleep_for`]]
|
||||
[def __sleep_until [link thread.thread_management.this_thread.sleep_until `sleep_until`]]
|
||||
|
||||
[def __interruption_enabled__ [link thread.thread_management.this_thread.interruption_enabled `boost::this_thread::interruption_enabled()`]]
|
||||
[def __interruption_requested__ [link thread.thread_management.this_thread.interruption_requested `boost::this_thread::interruption_requested()`]]
|
||||
@@ -140,11 +153,21 @@
|
||||
[def __cond_wait__ [cond_wait_link `wait()`]]
|
||||
[template cond_timed_wait_link[link_text] [link thread.synchronization.condvar_ref.condition_variable.timed_wait [link_text]]]
|
||||
[def __cond_timed_wait__ [cond_timed_wait_link `timed_wait()`]]
|
||||
|
||||
[def __condition_variable [link thread.synchronization.condvar_ref.condition_variable `condition_variable`]]
|
||||
[def __wait_for [link thread.synchronization.condvar_ref.condition_variable.wait_for `wait_for`]]
|
||||
[def __wait_until [link thread.synchronization.condvar_ref.condition_variable.wait_until `wait_until`]]
|
||||
|
||||
|
||||
[template cond_any_wait_link[link_text] [link thread.synchronization.condvar_ref.condition_variable_any.wait [link_text]]]
|
||||
[def __cond_any_wait__ [cond_any_wait_link `wait()`]]
|
||||
[template cond_any_timed_wait_link[link_text] [link thread.synchronization.condvar_ref.condition_variable_any.timed_wait [link_text]]]
|
||||
[def __cond_any_timed_wait__ [cond_any_timed_wait_link `timed_wait()`]]
|
||||
|
||||
[def __condition_variable_any [link thread.synchronization.condvar_ref.condition_variable_any `condition_variable_any`]]
|
||||
[def __cvany_wait_for [link thread.synchronization.condvar_ref.condition_variable_any.wait_for `wait_for`]]
|
||||
[def __cvany_wait_until [link thread.synchronization.condvar_ref.condition_variable_any.wait_until `wait_until`]]
|
||||
|
||||
[def __blocked__ ['blocked]]
|
||||
|
||||
[include overview.qbk]
|
||||
@@ -158,6 +181,7 @@
|
||||
[include condition_variables.qbk]
|
||||
[include once.qbk]
|
||||
[include barrier.qbk]
|
||||
[include futures.qbk]
|
||||
[endsect]
|
||||
|
||||
[include tss.qbk]
|
||||
@@ -165,3 +189,5 @@
|
||||
[include time.qbk]
|
||||
|
||||
[include acknowledgements.qbk]
|
||||
|
||||
[include compliance.qbk]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
(C) Copyright 2011-12 Vicente J. Botet Escriba.
|
||||
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).
|
||||
@@ -7,7 +8,35 @@
|
||||
|
||||
[section:thread_management Thread Management]
|
||||
|
||||
[heading Synopsis]
|
||||
[section:synopsis Synopsis]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class thread;
|
||||
void swap(thread& lhs,thread& rhs);
|
||||
namespace this_thread
|
||||
{
|
||||
thread::id get_id() noexcept;
|
||||
template<typename TimeDuration>
|
||||
void sleep(TimeDuration const& rel_time); // DEPRECATED
|
||||
void sleep(system_time const& abs_time) // DEPRECATED
|
||||
void yield() noexcept;
|
||||
template <class Clock, class Duration>
|
||||
void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
template <class Rep, class Period>
|
||||
void sleep_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
|
||||
void interruption_point();
|
||||
bool interruption_requested();
|
||||
bool interruption_enabled();
|
||||
class disable_interruption;
|
||||
class restore_interruption;
|
||||
}
|
||||
}
|
||||
|
||||
[endsect] [/section:synopsis Synopsis]
|
||||
|
||||
[section:tutorial Tutorial]
|
||||
|
||||
The __thread__ class is responsible for launching and managing threads. Each __thread__ object represents a single thread of execution,
|
||||
or __not_a_thread__, and at most one __thread__ object represents a given thread of execution: objects of type __thread__ are not
|
||||
@@ -24,14 +53,14 @@ allows the details of thread creation to be wrapped in a function.
|
||||
some_thread.join();
|
||||
}
|
||||
|
||||
[Note: On compilers that support rvalue references, __thread__ provides a proper move constructor and move-assignment operator, and
|
||||
[note On compilers that support rvalue references, __thread__ provides a proper move constructor and move-assignment operator, and
|
||||
therefore meets the C++0x ['MoveConstructible] and ['MoveAssignable] concepts. With such compilers, __thread__ can therefore be used
|
||||
with containers that support those concepts.
|
||||
|
||||
For other compilers, move support is provided with a move emulation layer, so containers must explicitly detect that move emulation
|
||||
layer. See <boost/thread/detail/move.hpp> for details.]
|
||||
|
||||
[heading Launching threads]
|
||||
[section:launching Launching threads]
|
||||
|
||||
A new thread is launched by passing an object of a callable type that can be invoked with no parameters to the constructor. The
|
||||
object is then copied into internal storage, and invoked on the newly-created thread of execution. If the object must not (or
|
||||
@@ -68,12 +97,99 @@ to callable functions.
|
||||
|
||||
There is an unspecified limit on the number of additional arguments that can be passed.
|
||||
|
||||
[heading Exceptions in thread functions]
|
||||
[endsect]
|
||||
|
||||
[section:attributes Thread attributes]
|
||||
|
||||
Thread launched in this way are created with implementation defined thread attributes as stack size, scheduling,
|
||||
priority, ... or any platform specific attributes. It is not evident how to provide a portable interface that allows
|
||||
the user to set the platform specific attributes. Boost.Thread stay in the middle road through the class
|
||||
thread::attributes which allows to set at least in a portable way the stack size as follows:
|
||||
|
||||
boost::thread::attributes attrs;
|
||||
attrs.set_size(4096*10);
|
||||
boost::thread deep_thought_2(attrs, find_the_question, 42);
|
||||
|
||||
Even for this simple attribute there could be portable issues as some platforms could require that the stack size
|
||||
should have a minimal size and/or be a multiple of a given page size.
|
||||
The library adapts the requested size to the platform constraints so that the user doesn't need to take care of it.
|
||||
|
||||
This is the single attribute that is provided in a portable way. In order to set any other thread attribute at
|
||||
construction time the user needs to use non portable code.
|
||||
|
||||
On PThread platforms the user will need to get the thread attributes handle and use it for whatever attribute.
|
||||
|
||||
Next follows how the user could set the stack size and the scheduling policy on PThread platforms.
|
||||
|
||||
boost::thread::attributes attrs;
|
||||
// set portable attributes
|
||||
// ...
|
||||
attr.set_stack_size(4096*10);
|
||||
#if defined(BOOST_THREAD_PLATFORM_WIN32)
|
||||
// ... window version
|
||||
#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
|
||||
// ... pthread version
|
||||
pthread_attr_setschedpolicy(attr.get_native_handle(), SCHED_RR);
|
||||
#else
|
||||
#error "Boost threads unavailable on this platform"
|
||||
#endif
|
||||
boost::thread th(attrs, find_the_question, 42);
|
||||
|
||||
On Windows platforms it is not so simple as there is no type that compiles the thread attributes.
|
||||
There is a linked to the creation of a thread on Windows that is emulated via the thread::attributes class. This is the LPSECURITY_ATTRIBUTES lpThreadAttributes.
|
||||
Boost.Thread provides a non portable set_security function so that the user can provide it before the thread creation as follows
|
||||
|
||||
[/Boost.Thread creates Windows threads that are suspended. Then it calls to the virtual function set_attributes and last it resumes the thread.
|
||||
The user needs to define a class that inherits from the class thread::attributes that defines a virtual function set_attributes to set any specific Windows thread attribute.
|
||||
|
||||
|
||||
class MyWinTthreadAttributes : boost::thread::attributes
|
||||
{
|
||||
public:
|
||||
void set_attributes(boost::thread::native_handle_type h)
|
||||
{
|
||||
// use any specific windows thread setting
|
||||
|
||||
}
|
||||
};
|
||||
#if defined(BOOST_THREAD_PLATFORM_WIN32)
|
||||
|
||||
MyWinTthreadAttributes attrs;
|
||||
// set portable attributes
|
||||
// ...
|
||||
attr.set_stack_size(4096*10);
|
||||
boost::thread th(attrs, find_the_question, 42);
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
|
||||
]
|
||||
|
||||
#if defined(BOOST_THREAD_PLATFORM_WIN32)
|
||||
boost::thread::attributes attrs;
|
||||
// set portable attributes
|
||||
attr.set_stack_size(4096*10);
|
||||
// set non portable attribute
|
||||
LPSECURITY_ATTRIBUTES sec;
|
||||
// init sec
|
||||
attr.set_security(sec);
|
||||
boost::thread th(attrs, find_the_question, 42);
|
||||
// Set other thread attributes using the native_handle_type.
|
||||
//...
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:exceptions Exceptions in thread functions]
|
||||
|
||||
If the function or callable object passed to the __thread__ constructor propagates an exception when invoked that is not of type
|
||||
__thread_interrupted__, `std::terminate()` is called.
|
||||
|
||||
[heading Joining and detaching]
|
||||
[endsect]
|
||||
|
||||
[section:join Joining and detaching]
|
||||
|
||||
When the __thread__ object that represents a thread of execution is destroyed the thread becomes ['detached]. Once a thread is
|
||||
detached, it will continue executing until the invocation of the function or callable object supplied on construction has completed,
|
||||
@@ -86,7 +202,9 @@ execution represented by the __thread__ object has already completed, or the __t
|
||||
returns immediately. __timed_join__ is similar, except that a call to __timed_join__ will also return if the thread being waited for
|
||||
does not complete when the specified time has elapsed.
|
||||
|
||||
[heading Interruption]
|
||||
[endsect]
|
||||
|
||||
[section:interruption Interruption]
|
||||
|
||||
A running thread can be ['interrupted] by invoking the __interrupt__ member function of the corresponding __thread__ object. When the
|
||||
interrupted thread next executes one of the specified __interruption_points__ (or if it is currently __blocked__ whilst executing one)
|
||||
@@ -142,16 +260,25 @@ The following functions are ['interruption points], which will throw __thread_in
|
||||
current thread, and interruption is requested for the current thread:
|
||||
|
||||
* [join_link `boost::thread::join()`]
|
||||
* [timed_join_link `boost::thread::timed_join()`]
|
||||
* [timed_join_link `boost::thread::timed_join()` DEPRECATED V2]
|
||||
* `boost::__thread::__try_join_for()`,
|
||||
* `boost::__thread::__try_join_until()`,
|
||||
* [cond_wait_link `boost::condition_variable::wait()`]
|
||||
* [cond_timed_wait_link `boost::condition_variable::timed_wait()`]
|
||||
* [cond_timed_wait_link `boost::condition_variable::timed_wait()` DEPRECATED V2]
|
||||
* `boost::__condition_variable::__wait_for()`
|
||||
* `boost::__condition_variable::__wait_until()`
|
||||
* [cond_any_wait_link `boost::condition_variable_any::wait()`]
|
||||
* [cond_any_timed_wait_link `boost::condition_variable_any::timed_wait()`]
|
||||
* [link thread.thread_management.thread.sleep `boost::thread::sleep()`]
|
||||
* __sleep__
|
||||
* [cond_any_timed_wait_link `boost::condition_variable_any::timed_wait()` DEPRECATED V2]
|
||||
* `boost::__condition_variable_any::__cvany_wait_for()`
|
||||
* `boost::__condition_variable_any::__cvany_wait_until()`
|
||||
* [link thread.thread_management.thread.sleep `boost::thread::sleep()` DEPRECATED V2]
|
||||
* `boost::this_thread::__sleep_for()`
|
||||
* `boost::this_thread::__sleep_until()`
|
||||
* __interruption_point__
|
||||
|
||||
[heading Thread IDs]
|
||||
[endsect]
|
||||
|
||||
[section:id Thread IDs]
|
||||
|
||||
Objects of class __thread_id__ can be used to identify threads. Each running thread of execution has a unique ID obtainable
|
||||
from the corresponding __thread__ by calling the `get_id()` member function, or by calling `boost::this_thread::get_id()` from
|
||||
@@ -163,6 +290,57 @@ Each instance of __thread_id__ either refers to some thread, or __not_a_thread__
|
||||
compare equal to each other, but not equal to any instances that refer to an actual thread of execution. The comparison operators on
|
||||
__thread_id__ yield a total order for every non-equal thread ID.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:native_in Using native interfaces with Boost.Thread resources]
|
||||
|
||||
|
||||
__thread__ class has members `native_handle_type` and `native_handle` providing access to the underlying native handle.
|
||||
|
||||
This native handle can be used to change for example the scheduling.
|
||||
|
||||
In general, it is not safe to use this handle with operations that can conflict with the ones provided by Boost.Thread. An example of bad usage could be detaching a thread directly as it will not change the internals of the __thread__ instance, so for example the joinable function will continue to return true, while the native thread is no more joinable.
|
||||
|
||||
thread t(fct);
|
||||
thread::native_handle_type hnd=t.native_handle();
|
||||
pthread_detach(hnd);
|
||||
assert(t.joinable());
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:native_from Using Boost.Thread interfaces in a native thread]
|
||||
|
||||
|
||||
Any thread of execution created using the native interface is called a native thread in this documentation.
|
||||
|
||||
The first example of a native thread of execution is the main thread.
|
||||
|
||||
The user can access to some synchronization functions related to the native current thread using the `boost::this_thread` `yield`, `sleep`, __sleep_for, __sleep_until, functions.
|
||||
|
||||
|
||||
int main() {
|
||||
// ...
|
||||
boost::this_thread::sleep_for(boost::chrono::milliseconds(10));
|
||||
// ...
|
||||
}
|
||||
|
||||
|
||||
Of course all the synchronization facilities provided by Boost.Thread are also available on native threads.
|
||||
|
||||
The `boost::this_thread` interrupt related functions behave in a degraded mode when called from a thread created using the native interface, i.e. `boost::this_thread::interruption_enabled()` returns false. As consequence the use of `boost::this_thread::disable_interruption` and `boost::this_thread::restore_interruption` will do nothing and calls to `boost::this_thread::interrupt_point()` will be just ignored.
|
||||
|
||||
As the single way to interrupt a thread is through a __thread__ instance, `interruption_request()` wiil returns false for the native threads.
|
||||
|
||||
[heading `pthread_exit` POSIX limitation]
|
||||
|
||||
`pthread_exit` in glibc/NPTL causes a "forced unwind" that is almost like a C++ exception, but not quite. On Mac OS X, for example, `pthread_exit` unwinds without calling C++ destructors.
|
||||
|
||||
This behavior is incompatible with the current Boost.Thread design, so the use of this function in a POSIX thread result in undefined behavior of any Boost.Thread function.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect] [/section:tutorial Tutorial]
|
||||
|
||||
[section:thread Class `thread`]
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
@@ -170,7 +348,12 @@ __thread_id__ yield a total order for every non-equal thread ID.
|
||||
class thread
|
||||
{
|
||||
public:
|
||||
thread();
|
||||
thread() noexcept;
|
||||
thread(const thread&) = delete;
|
||||
thread& operator=(const thread&) = delete;
|
||||
|
||||
thread(thread&&) noexcept;
|
||||
thread& operator=(thread&&) noexcept;
|
||||
~thread();
|
||||
|
||||
template <class F>
|
||||
@@ -180,29 +363,32 @@ __thread_id__ yield a total order for every non-equal thread ID.
|
||||
thread(F f,A1 a1,A2 a2,...);
|
||||
|
||||
template <class F>
|
||||
thread(detail::thread_move_t<F> f);
|
||||
thread(F &&f);
|
||||
|
||||
template <class F, class ...Args> explicit thread(F&& f, Args&&... args);
|
||||
|
||||
// move support
|
||||
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();
|
||||
thread(thread && x);
|
||||
thread& operator=(thread && x);
|
||||
|
||||
void swap(thread& x);
|
||||
void swap(thread& x) noexcept;
|
||||
|
||||
class id;
|
||||
id get_id() const;
|
||||
id get_id() const noexcept;
|
||||
|
||||
bool joinable() const;
|
||||
bool joinable() const noexcept;
|
||||
void join();
|
||||
bool timed_join(const system_time& wait_until);
|
||||
|
||||
bool timed_join(const system_time& wait_until); // DEPRECATED V2
|
||||
template<typename TimeDuration>
|
||||
bool timed_join(TimeDuration const& rel_time);
|
||||
bool timed_join(TimeDuration const& rel_time); // DEPRECATED V2
|
||||
template <class Rep, class Period>
|
||||
bool try_join_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_join_until(const chrono::time_point<Clock, Duration>& t);
|
||||
|
||||
void detach();
|
||||
|
||||
static unsigned hardware_concurrency();
|
||||
static unsigned hardware_concurrency() noexcept;
|
||||
|
||||
typedef platform-specific-type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
@@ -211,18 +397,19 @@ __thread_id__ yield a total order for every non-equal thread ID.
|
||||
bool interruption_requested() const;
|
||||
|
||||
// backwards compatibility
|
||||
bool operator==(const thread& other) const;
|
||||
bool operator!=(const thread& other) const;
|
||||
bool operator==(const thread& other) const; // DEPRECATED V2
|
||||
bool operator!=(const thread& other) const; // DEPRECATED V2
|
||||
|
||||
static void yield(); // DEPRECATED V2
|
||||
static void sleep(const system_time& xt); // DEPRECATED V2
|
||||
|
||||
static void yield();
|
||||
static void sleep(const system_time& xt);
|
||||
};
|
||||
|
||||
void swap(thread& lhs,thread& rhs);
|
||||
void swap(thread& lhs,thread& rhs) noexcep;
|
||||
|
||||
[section:default_constructor Default Constructor]
|
||||
|
||||
thread();
|
||||
thread() noexcep;
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -234,6 +421,40 @@ __thread_id__ yield a total order for every non-equal thread ID.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_constructor Move Constructor]
|
||||
|
||||
thread(thread&& other) noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Transfers ownership of the thread managed by `other` (if any) to the newly constructed __thread__ instance.]]
|
||||
|
||||
[[Postconditions:] [`other->get_id()==thread::id()`]]
|
||||
|
||||
[[Throws:] [Nothing]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_assignment Move assignment operator]
|
||||
|
||||
thread& operator=(thread&& other) noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Transfers ownership of the thread managed by `other` (if
|
||||
any) to `*this`. If there was a thread previously associated with
|
||||
`*this` then that thread is detached.]]
|
||||
|
||||
[[Postconditions:] [`other->get_id()==thread::id()`]]
|
||||
|
||||
[[Throws:] [Nothing]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:callable_constructor Thread Constructor]
|
||||
|
||||
template<typename Callable>
|
||||
@@ -249,7 +470,13 @@ not of type __thread_interrupted__, then `std::terminate()` will be called.]]
|
||||
|
||||
[[Postconditions:] [`*this` refers to the newly created thread of execution.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error occurs.]]
|
||||
[[Throws:] [__thread_resource_error__ if an error occurs. ]]
|
||||
|
||||
[[Error Conditions:] [
|
||||
|
||||
[*resource_unavailable_try_again] : the system lacked the necessary resources to create an- other thread, or the system-imposed limit on the number of threads in a process would be exceeded.
|
||||
|
||||
]]
|
||||
|
||||
]
|
||||
|
||||
@@ -273,6 +500,12 @@ are copied into internal storage for access by the new thread.]]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error occurs.]]
|
||||
|
||||
[[Error Conditions:] [
|
||||
|
||||
[*resource_unavailable_try_again] : the system lacked the necessary resources to create an- other thread, or the system-imposed limit on the number of threads in a process would be exceeded.
|
||||
|
||||
]]
|
||||
|
||||
[[Note:] [Currently up to nine additional arguments `a1` to `a9` can be specified in addition to the function `f`.]]
|
||||
|
||||
]
|
||||
@@ -295,7 +528,7 @@ are copied into internal storage for access by the new thread.]]]
|
||||
|
||||
[section:joinable Member function `joinable()`]
|
||||
|
||||
bool joinable() const;
|
||||
bool joinable() const noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -320,7 +553,19 @@ are copied into internal storage for access by the new thread.]]]
|
||||
|
||||
[[Postconditions:] [If `*this` refers to a thread of execution on entry, that thread of execution has completed. `*this` no longer refers to any thread of execution.]]
|
||||
|
||||
[[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted.]]
|
||||
[[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted or `system_error`]]
|
||||
|
||||
[[Error Conditions:] [
|
||||
|
||||
[*resource_deadlock_would_occur]: if deadlock is detected or this->get_id() == std::this_thread::get_id().
|
||||
|
||||
[/
|
||||
[*no_such_process]: if the thread is not valid.
|
||||
|
||||
[*invalid_argument]: if the thread is not joinable.
|
||||
]
|
||||
|
||||
]]
|
||||
|
||||
[[Notes:] [`join()` is one of the predefined __interruption_points__.]]
|
||||
|
||||
@@ -328,7 +573,7 @@ are copied into internal storage for access by the new thread.]]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:timed_join Member function `timed_join()`]
|
||||
[section:timed_join Member function `timed_join()` DEPRECATED V2]
|
||||
|
||||
bool timed_join(const system_time& wait_until);
|
||||
|
||||
@@ -349,7 +594,19 @@ times out, `false` otherwise.]]
|
||||
has completed, and `*this` no longer refers to any thread of execution. If this call to `timed_join` returns `false`, `*this` is
|
||||
unchanged.]]
|
||||
|
||||
[[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted.]]
|
||||
[[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted or `system_error`]]
|
||||
|
||||
[[Error Conditions:] [
|
||||
|
||||
[*resource_deadlock_would_occur]: if deadlock is detected or this->get_id() == std::this_thread::get_id().
|
||||
|
||||
[/
|
||||
[*no_such_process]: if the thread is not valid.
|
||||
|
||||
[*invalid_argument]: if the thread is not joinable.
|
||||
]
|
||||
|
||||
]]
|
||||
|
||||
[[Notes:] [`timed_join()` is one of the predefined __interruption_points__.]]
|
||||
|
||||
@@ -357,6 +614,86 @@ unchanged.]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:try_join_for Member function `try_join_for()`]
|
||||
|
||||
template <class Rep, class Period>
|
||||
bool try_join_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Preconditions:] [`this->get_id()!=boost::this_thread::get_id()`]]
|
||||
|
||||
[[Effects:] [If `*this` refers to a thread of execution, waits for that thread of execution to complete,
|
||||
the specified duration `rel_time` has elapsed. If `*this` doesn't refer to a thread of execution, returns immediately.]]
|
||||
|
||||
[[Returns:] [`true` if `*this` refers to a thread of execution on entry, and that thread of execution has completed before the call
|
||||
times out, `false` otherwise.]]
|
||||
|
||||
[[Postconditions:] [If `*this` refers to a thread of execution on entry, and `try_join_for` returns `true`, that thread of execution
|
||||
has completed, and `*this` no longer refers to any thread of execution. If this call to `try_join_for` returns `false`, `*this` is
|
||||
unchanged.]]
|
||||
|
||||
[[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted or `system_error`]]
|
||||
|
||||
[[Error Conditions:] [
|
||||
|
||||
[*resource_deadlock_would_occur]: if deadlock is detected or this->get_id() == std::this_thread::get_id().
|
||||
|
||||
[/
|
||||
[*no_such_process]: if the thread is not valid.
|
||||
|
||||
[*invalid_argument]: if the thread is not joinable.
|
||||
]
|
||||
|
||||
]]
|
||||
|
||||
[[Notes:] [`try_join_for()` is one of the predefined __interruption_points__.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:try_join_until Member function `try_join_until()`]
|
||||
|
||||
template <class Clock, class Duration>
|
||||
bool try_join_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Preconditions:] [`this->get_id()!=boost::this_thread::get_id()`]]
|
||||
|
||||
[[Effects:] [If `*this` refers to a thread of execution, waits for that thread of execution to complete, the time `abs_time` has
|
||||
been reach. If `*this` doesn't refer to a thread of execution, returns immediately.]]
|
||||
|
||||
[[Returns:] [`true` if `*this` refers to a thread of execution on entry, and that thread of execution has completed before the call
|
||||
times out, `false` otherwise.]]
|
||||
|
||||
[[Postconditions:] [If `*this` refers to a thread of execution on entry, and `try_join_until` returns `true`, that thread of execution
|
||||
has completed, and `*this` no longer refers to any thread of execution. If this call to `try_join_until` returns `false`, `*this` is
|
||||
unchanged.]]
|
||||
|
||||
[[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted or `system_error`]]
|
||||
|
||||
[[Error Conditions:] [
|
||||
|
||||
[*resource_deadlock_would_occur]: if deadlock is detected or this->get_id() == std::this_thread::get_id().
|
||||
|
||||
[/
|
||||
[*no_such_process]: if the thread is not valid.
|
||||
|
||||
[*invalid_argument]: if the thread is not joinable.
|
||||
]
|
||||
|
||||
]]
|
||||
|
||||
[[Notes:] [`try_join_until()` is one of the predefined __interruption_points__.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
[section:detach Member function `detach()`]
|
||||
|
||||
void detach();
|
||||
@@ -376,7 +713,7 @@ unchanged.]]
|
||||
|
||||
[section:get_id Member function `get_id()`]
|
||||
|
||||
thread::id get_id() const;
|
||||
thread::id get_id() const noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -408,7 +745,7 @@ predefined __interruption_points__ with interruption enabled .]]
|
||||
|
||||
[section:hardware_concurrency Static member function `hardware_concurrency()`]
|
||||
|
||||
unsigned hardware_concurrency();
|
||||
unsigned hardware_concurrency() noexecpt;
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -461,7 +798,7 @@ implementation. If no such instance exists, `native_handle()` and `native_handle
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:sleep Static member function `sleep()`]
|
||||
[section:sleep Static member function `sleep()` DEPRECATED V2]
|
||||
|
||||
void sleep(system_time const& abs_time);
|
||||
|
||||
@@ -477,7 +814,7 @@ implementation. If no such instance exists, `native_handle()` and `native_handle
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:yield Static member function `yield()`]
|
||||
[section:yield Static member function `yield()` DEPRECATED V2]
|
||||
|
||||
void yield();
|
||||
|
||||
@@ -491,7 +828,7 @@ implementation. If no such instance exists, `native_handle()` and `native_handle
|
||||
|
||||
[section:swap Member function `swap()`]
|
||||
|
||||
void swap(thread& other);
|
||||
void swap(thread& other) noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -511,7 +848,7 @@ value as `this->get_id()` prior to the call.]]
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
void swap(thread& lhs,thread& rhs);
|
||||
void swap(thread& lhs,thread& rhs) noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -521,6 +858,27 @@ value as `this->get_id()` prior to the call.]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[/
|
||||
[section:non_member_move Non-member function `move()`]
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
detail::thread_move_t<thread> move(detail::thread_move_t<thread> t)
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [`t`.]]
|
||||
|
||||
]
|
||||
|
||||
Enables moving thread objects. e.g.
|
||||
|
||||
extern void some_func();
|
||||
boost::thread t(some_func);
|
||||
boost::thread t2(boost::move(t)); // transfer thread from t to t2
|
||||
|
||||
[endsect]
|
||||
]
|
||||
|
||||
[section:id Class `boost::thread::id`]
|
||||
|
||||
@@ -529,14 +887,14 @@ value as `this->get_id()` prior to the call.]]
|
||||
class thread::id
|
||||
{
|
||||
public:
|
||||
id();
|
||||
id() noexcept;
|
||||
|
||||
bool operator==(const id& y) const;
|
||||
bool operator!=(const id& y) const;
|
||||
bool operator<(const id& y) const;
|
||||
bool operator>(const id& y) const;
|
||||
bool operator<=(const id& y) const;
|
||||
bool operator>=(const id& y) const;
|
||||
bool operator==(const id& y) const noexcept;
|
||||
bool operator!=(const id& y) const noexcept;
|
||||
bool operator<(const id& y) const noexcept;
|
||||
bool operator>(const id& y) const noexcept;
|
||||
bool operator<=(const id& y) const noexcept;
|
||||
bool operator>=(const id& y) const noexcept;
|
||||
|
||||
template<class charT, class traits>
|
||||
friend std::basic_ostream<charT, traits>&
|
||||
@@ -545,7 +903,7 @@ value as `this->get_id()` prior to the call.]]
|
||||
|
||||
[section:constructor Default constructor]
|
||||
|
||||
id();
|
||||
id() noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -559,7 +917,7 @@ value as `this->get_id()` prior to the call.]]
|
||||
|
||||
[section:is_equal `operator==`]
|
||||
|
||||
bool operator==(const id& y) const;
|
||||
bool operator==(const id& y) const noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -574,7 +932,7 @@ otherwise.]]
|
||||
|
||||
[section:not_equal `operator!=`]
|
||||
|
||||
bool operator!=(const id& y) const;
|
||||
bool operator!=(const id& y) const noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -589,7 +947,7 @@ the other represent __not_a_thread__, `false` otherwise.]]
|
||||
|
||||
[section:less_than `operator<`]
|
||||
|
||||
bool operator<(const id& y) const;
|
||||
bool operator<(const id& y) const noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -608,7 +966,7 @@ execution.]]
|
||||
|
||||
[section:greater_than `operator>`]
|
||||
|
||||
bool operator>(const id& y) const;
|
||||
bool operator>(const id& y) const noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -620,9 +978,9 @@ execution.]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:less_than_or_equal `operator>=`]
|
||||
[section:less_than_or_equal `operator<=`]
|
||||
|
||||
bool operator<=(const id& y) const;
|
||||
bool operator<=(const id& y) const noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -636,7 +994,7 @@ execution.]]
|
||||
|
||||
[section:greater_than_or_equal `operator>=`]
|
||||
|
||||
bool operator>=(const id& y) const;
|
||||
bool operator>=(const id& y) const noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -672,13 +1030,34 @@ instances of __thread_id__ `a` and `b` is the same if `a==b`, and different if `
|
||||
|
||||
[section:this_thread Namespace `this_thread`]
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace this_thread {
|
||||
thread::id get_id() noexcept;
|
||||
template<typename TimeDuration>
|
||||
void sleep(TimeDuration const& rel_time); // DEPRECATED V2
|
||||
void sleep(system_time const& abs_time) // DEPRECATED V2
|
||||
void yield() noexcept;
|
||||
template <class Clock, class Duration>
|
||||
void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
template <class Rep, class Period>
|
||||
void sleep_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
|
||||
void interruption_point();
|
||||
bool interruption_requested();
|
||||
bool interruption_enabled();
|
||||
class disable_interruption;
|
||||
class restore_interruption;
|
||||
}
|
||||
}
|
||||
|
||||
[section:get_id Non-member function `get_id()`]
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
namespace this_thread
|
||||
{
|
||||
thread::id get_id();
|
||||
thread::id get_id() noexcept;
|
||||
}
|
||||
|
||||
[variablelist
|
||||
@@ -748,7 +1127,7 @@ instances of __thread_id__ `a` and `b` is the same if `a==b`, and different if `
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:sleep Non-member function `sleep()`]
|
||||
[section:sleep Non-member function `sleep()` DEPRECATED V2]
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
@@ -756,11 +1135,14 @@ instances of __thread_id__ `a` and `b` is the same if `a==b`, and different if `
|
||||
{
|
||||
template<typename TimeDuration>
|
||||
void sleep(TimeDuration const& rel_time);
|
||||
void sleep(system_time const& abs_time)
|
||||
}
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Suspends the current thread until the specified time has elapsed.]]
|
||||
[[Effects:] [Suspends the current thread until the time period
|
||||
specified by `rel_time` has elapsed or the time point specified by
|
||||
`abs_time` has been reached.]]
|
||||
|
||||
[[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted.]]
|
||||
|
||||
@@ -770,6 +1152,55 @@ instances of __thread_id__ `a` and `b` is the same if `a==b`, and different if `
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:sleep_until Non-member function `sleep_until()`]
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
namespace this_thread
|
||||
{
|
||||
template <class Clock, class Duration>
|
||||
void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
}
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Suspends the current thread until the time period
|
||||
specified by `rel_time` has elapsed or the time point specified by
|
||||
`abs_time` has been reached.]]
|
||||
|
||||
[[Throws:] [Nothing if Clock satisfies the TrivialClock requirements and operations of Duration
|
||||
do not throw exceptions. __thread_interrupted__ if the current thread of execution is interrupted. ]]
|
||||
|
||||
[[Notes:] [`sleep_until()` is one of the predefined __interruption_points__.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:sleep_for Non-member function `sleep_for()`]
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
|
||||
namespace this_thread
|
||||
{
|
||||
template <class Rep, class Period>
|
||||
void sleep_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
}
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Suspends the current thread until the time point specified by
|
||||
`abs_time` has been reached.]]
|
||||
|
||||
[[Throws:] [Nothing if operations of chrono::duration<Rep, Period> do not throw exceptions. __thread_interrupted__ if the current thread of execution is interrupted.]]
|
||||
|
||||
[[Notes:] [`sleep_for()` is one of the predefined __interruption_points__.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:yield Non-member function `yield()`]
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
@@ -916,6 +1347,13 @@ exits (even if the thread has been interrupted).]]
|
||||
[[Throws:] [`std::bad_alloc` if memory cannot be allocated for the copy of the function, __thread_resource_error__ if any other
|
||||
error occurs within the thread library. Any exception thrown whilst copying `func` into internal storage.]]
|
||||
|
||||
[[Note:] [This function is *not* called if the thread was terminated
|
||||
forcefully using platform-specific APIs, or if the thread is
|
||||
terminated due to a call to `exit()`, `abort()` or
|
||||
`std::terminate()`. In particular, returning from `main()` is
|
||||
equivalent to call to `exit()`, so will not call any functions
|
||||
registered with `at_thread_exit()`]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -41,6 +41,11 @@ order. If a cleanup routine sets the value of associated with an instance of `bo
|
||||
cleaned up, that value is added to the cleanup list. Cleanup finishes when there are no outstanding instances of
|
||||
`boost::thread_specific_ptr` with values.
|
||||
|
||||
Note: on some platforms, cleanup of thread-specific data is not
|
||||
performed for threads created with the platform's native API. On those
|
||||
platforms such cleanup is only done for threads that are started with
|
||||
`boost::thread` unless `boost::on_thread_exit()` is called manually
|
||||
from that thread.
|
||||
|
||||
[section:thread_specific_ptr Class `thread_specific_ptr`]
|
||||
|
||||
|
||||
@@ -50,8 +50,9 @@ boost::mutex io_mutex;
|
||||
|
||||
void sender() {
|
||||
int n = 0;
|
||||
while (n < 100) {
|
||||
while (n < 1000000) {
|
||||
buf.send(n);
|
||||
if(!(n%10000))
|
||||
{
|
||||
boost::mutex::scoped_lock io_lock(io_mutex);
|
||||
std::cout << "sent: " << n << std::endl;
|
||||
@@ -65,18 +66,24 @@ void receiver() {
|
||||
int n;
|
||||
do {
|
||||
n = buf.receive();
|
||||
if(!(n%10000))
|
||||
{
|
||||
boost::mutex::scoped_lock io_lock(io_mutex);
|
||||
std::cout << "received: " << n << std::endl;
|
||||
}
|
||||
} while (n != -1); // -1 indicates end of buffer
|
||||
buf.send(-1);
|
||||
}
|
||||
|
||||
int main(int, char*[])
|
||||
{
|
||||
boost::thread thrd1(&sender);
|
||||
boost::thread thrd2(&receiver);
|
||||
boost::thread thrd3(&receiver);
|
||||
boost::thread thrd4(&receiver);
|
||||
thrd1.join();
|
||||
thrd2.join();
|
||||
thrd3.join();
|
||||
thrd4.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
136
example/shared_monitor.cpp
Normal file
136
example/shared_monitor.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
// Copyright (C) 2012 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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 <iostream>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/chrono/chrono_io.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
#define EXCLUSIVE 1
|
||||
#define SHARED 2
|
||||
|
||||
#define MODE SHARED
|
||||
|
||||
class A
|
||||
{
|
||||
#if MODE == EXCLUSIVE
|
||||
typedef boost::mutex mutex_type;
|
||||
#elif MODE == SHARED
|
||||
typedef boost::shared_mutex mutex_type;
|
||||
#else
|
||||
#error MODE not set
|
||||
#endif
|
||||
typedef std::vector<double> C;
|
||||
mutable mutex_type mut_;
|
||||
C data_;
|
||||
public:
|
||||
A() : data_(10000000) {}
|
||||
A(const A& a);
|
||||
A& operator=(const A& a);
|
||||
|
||||
void compute(const A& x, const A& y);
|
||||
};
|
||||
|
||||
A::A(const A& a)
|
||||
{
|
||||
#if MODE == EXCLUSIVE
|
||||
boost::unique_lock<mutex_type> lk(a.mut_);
|
||||
#elif MODE == SHARED
|
||||
boost::shared_lock<mutex_type> lk(a.mut_);
|
||||
#else
|
||||
#error MODE not set
|
||||
#endif
|
||||
data_ = a.data_;
|
||||
}
|
||||
|
||||
A&
|
||||
A::operator=(const A& a)
|
||||
{
|
||||
if (this != &a)
|
||||
{
|
||||
boost::unique_lock<mutex_type> lk1(mut_, boost::defer_lock);
|
||||
#if MODE == EXCLUSIVE
|
||||
boost::unique_lock<mutex_type> lk2(a.mut_, boost::defer_lock);
|
||||
#elif MODE == SHARED
|
||||
boost::shared_lock<mutex_type> lk2(a.mut_, boost::defer_lock);
|
||||
#else
|
||||
#error MODE not set
|
||||
#endif
|
||||
boost::lock(lk1, lk2);
|
||||
data_ = a.data_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
A::compute(const A& x, const A& y)
|
||||
{
|
||||
boost::unique_lock<mutex_type> lk1(mut_, boost::defer_lock);
|
||||
#if MODE == EXCLUSIVE
|
||||
boost::unique_lock<mutex_type> lk2(x.mut_, boost::defer_lock);
|
||||
boost::unique_lock<mutex_type> lk3(y.mut_, boost::defer_lock);
|
||||
#elif MODE == SHARED
|
||||
boost::shared_lock<mutex_type> lk2(x.mut_, boost::defer_lock);
|
||||
boost::shared_lock<mutex_type> lk3(y.mut_, boost::defer_lock);
|
||||
#else
|
||||
#error MODE not set
|
||||
#endif
|
||||
boost::lock(lk1, lk2, lk3);
|
||||
assert(data_.size() == x.data_.size());
|
||||
assert(data_.size() == y.data_.size());
|
||||
for (unsigned i = 0; i < data_.size(); ++i)
|
||||
data_[i] = (x.data_[i] + y.data_[i]) / 2;
|
||||
}
|
||||
|
||||
A a1;
|
||||
A a2;
|
||||
|
||||
void test_s()
|
||||
{
|
||||
A la3 = a1;
|
||||
for (int i = 0; i < 150; ++i)
|
||||
{
|
||||
la3.compute(a1, a2);
|
||||
}
|
||||
}
|
||||
|
||||
void test_w()
|
||||
{
|
||||
A la3 = a1;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
la3.compute(a1, a2);
|
||||
a1 = la3;
|
||||
a2 = la3;
|
||||
// boost::this_thread::sleep_for(boost::chrono::seconds(1));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::chrono::high_resolution_clock Clock;
|
||||
typedef boost::chrono::duration<double> sec;
|
||||
Clock::time_point t0 = Clock::now();
|
||||
std::vector<boost::thread*> v;
|
||||
boost::thread thw(test_w);
|
||||
v.push_back(&thw);
|
||||
boost::thread thr0(test_w);
|
||||
v.push_back(&thr0);
|
||||
boost::thread thr1(test_w);
|
||||
v.push_back(&thr1);
|
||||
boost::thread thr2(test_w);
|
||||
v.push_back(&thr2);
|
||||
boost::thread thr3(test_w);
|
||||
v.push_back(&thr3);
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
v[i]->join();
|
||||
Clock::time_point t1 = Clock::now();
|
||||
std::cout << sec(t1-t0) << '\n';
|
||||
return 0;
|
||||
}
|
||||
722
example/shared_mutex.cpp
Normal file
722
example/shared_mutex.cpp
Normal file
@@ -0,0 +1,722 @@
|
||||
// Copyright (C) 2012 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
#define BOOST_THREAD_SHARED_MUTEX_PROVIDES_UPWARDS_CONVERSION
|
||||
#define BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/chrono/chrono_io.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
enum {reading, writing};
|
||||
int state = reading;
|
||||
|
||||
#if 1
|
||||
|
||||
boost::mutex&
|
||||
cout_mut()
|
||||
{
|
||||
static boost::mutex m;
|
||||
return m;
|
||||
}
|
||||
|
||||
void
|
||||
print(const char* tag, unsigned count, char ch)
|
||||
{
|
||||
boost::lock_guard<boost::mutex> _(cout_mut());
|
||||
std::cout << tag << count << ch;
|
||||
}
|
||||
|
||||
#elif 0
|
||||
|
||||
boost::recursive_mutex&
|
||||
cout_mut()
|
||||
{
|
||||
static boost::recursive_mutex m;
|
||||
return m;
|
||||
}
|
||||
|
||||
void print() {}
|
||||
|
||||
template <class A0, class ...Args>
|
||||
void
|
||||
print(const A0& a0, const Args& ...args)
|
||||
{
|
||||
boost::lock_guard<boost::recursive_mutex> _(cout_mut());
|
||||
std::cout << a0;
|
||||
print(args...);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template <class A0, class A1, class A2>
|
||||
void
|
||||
print(const A0&, const A1& a1, const A2&)
|
||||
{
|
||||
assert(a1 > 10000);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
namespace S
|
||||
{
|
||||
|
||||
boost::shared_mutex mut;
|
||||
|
||||
void reader()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock_shared();
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_shared();
|
||||
}
|
||||
print("reader = ", count, '\n');
|
||||
}
|
||||
|
||||
void writer()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock();
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
++count;
|
||||
mut.unlock();
|
||||
}
|
||||
print("writer = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_reader()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_shared())
|
||||
{
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_shared();
|
||||
}
|
||||
}
|
||||
print("try_reader = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_writer()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock())
|
||||
{
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
++count;
|
||||
mut.unlock();
|
||||
}
|
||||
}
|
||||
print("try_writer = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_reader()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_shared_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_shared();
|
||||
}
|
||||
}
|
||||
print("try_for_reader = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_writer()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
++count;
|
||||
mut.unlock();
|
||||
}
|
||||
}
|
||||
print("try_for_writer = ", count, '\n');
|
||||
}
|
||||
|
||||
void
|
||||
test_shared_mutex()
|
||||
{
|
||||
{
|
||||
boost::thread t1(reader);
|
||||
boost::thread t2(writer);
|
||||
boost::thread t3(reader);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
{
|
||||
boost::thread t1(try_reader);
|
||||
boost::thread t2(try_writer);
|
||||
boost::thread t3(try_reader);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
{
|
||||
boost::thread t1(try_for_reader);
|
||||
boost::thread t2(try_for_writer);
|
||||
boost::thread t3(try_for_reader);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace U
|
||||
{
|
||||
|
||||
boost::upgrade_mutex mut;
|
||||
|
||||
void reader()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock_shared();
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_shared();
|
||||
}
|
||||
print("reader = ", count, '\n');
|
||||
}
|
||||
|
||||
void writer()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock();
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
++count;
|
||||
mut.unlock();
|
||||
}
|
||||
print("writer = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_reader()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_shared())
|
||||
{
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_shared();
|
||||
}
|
||||
}
|
||||
print("try_reader = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_writer()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock())
|
||||
{
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
++count;
|
||||
mut.unlock();
|
||||
}
|
||||
}
|
||||
print("try_writer = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_reader()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_shared_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_shared();
|
||||
}
|
||||
}
|
||||
print("try_for_reader = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_writer()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
++count;
|
||||
mut.unlock();
|
||||
}
|
||||
}
|
||||
print("try_for_writer = ", count, '\n');
|
||||
}
|
||||
|
||||
void upgradable()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock_upgrade();
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_upgrade();
|
||||
}
|
||||
print("upgradable = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_upgradable()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_upgrade())
|
||||
{
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_upgrade();
|
||||
}
|
||||
}
|
||||
print("try_upgradable = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_upgradable()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_upgrade_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
++count;
|
||||
mut.unlock_upgrade();
|
||||
}
|
||||
}
|
||||
print("try_for_upgradable = ", count, '\n');
|
||||
}
|
||||
|
||||
void clockwise()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock_shared();
|
||||
assert(state == reading);
|
||||
if (mut.try_unlock_shared_and_lock())
|
||||
{
|
||||
state = writing;
|
||||
}
|
||||
else if (mut.try_unlock_shared_and_lock_upgrade())
|
||||
{
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock();
|
||||
state = writing;
|
||||
}
|
||||
else
|
||||
{
|
||||
mut.unlock_shared();
|
||||
continue;
|
||||
}
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
mut.unlock_and_lock_upgrade();
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock_shared();
|
||||
assert(state == reading);
|
||||
mut.unlock_shared();
|
||||
++count;
|
||||
}
|
||||
print("clockwise = ", count, '\n');
|
||||
}
|
||||
|
||||
void counter_clockwise()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
mut.lock_upgrade();
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock();
|
||||
assert(state == reading);
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
mut.unlock_and_lock_shared();
|
||||
assert(state == reading);
|
||||
mut.unlock_shared();
|
||||
++count;
|
||||
}
|
||||
print("counter_clockwise = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_clockwise()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_shared())
|
||||
{
|
||||
assert(state == reading);
|
||||
if (mut.try_unlock_shared_and_lock())
|
||||
{
|
||||
state = writing;
|
||||
}
|
||||
else if (mut.try_unlock_shared_and_lock_upgrade())
|
||||
{
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock();
|
||||
state = writing;
|
||||
}
|
||||
else
|
||||
{
|
||||
mut.unlock_shared();
|
||||
continue;
|
||||
}
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
mut.unlock_and_lock_upgrade();
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock_shared();
|
||||
assert(state == reading);
|
||||
mut.unlock_shared();
|
||||
++count;
|
||||
}
|
||||
}
|
||||
print("try_clockwise = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_clockwise()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_shared_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
if (mut.try_unlock_shared_and_lock_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
state = writing;
|
||||
}
|
||||
else if (mut.try_unlock_shared_and_lock_upgrade_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock();
|
||||
state = writing;
|
||||
}
|
||||
else
|
||||
{
|
||||
mut.unlock_shared();
|
||||
continue;
|
||||
}
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
mut.unlock_and_lock_upgrade();
|
||||
assert(state == reading);
|
||||
mut.unlock_upgrade_and_lock_shared();
|
||||
assert(state == reading);
|
||||
mut.unlock_shared();
|
||||
++count;
|
||||
}
|
||||
}
|
||||
print("try_for_clockwise = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_counter_clockwise()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_upgrade())
|
||||
{
|
||||
assert(state == reading);
|
||||
if (mut.try_unlock_upgrade_and_lock())
|
||||
{
|
||||
assert(state == reading);
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
mut.unlock_and_lock_shared();
|
||||
assert(state == reading);
|
||||
mut.unlock_shared();
|
||||
++count;
|
||||
}
|
||||
else
|
||||
{
|
||||
mut.unlock_upgrade();
|
||||
}
|
||||
}
|
||||
}
|
||||
print("try_counter_clockwise = ", count, '\n');
|
||||
}
|
||||
|
||||
void try_for_counter_clockwise()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
unsigned count = 0;
|
||||
Clock::time_point until = Clock::now() + boost::chrono::seconds(3);
|
||||
while (Clock::now() < until)
|
||||
{
|
||||
if (mut.try_lock_upgrade_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
if (mut.try_unlock_upgrade_and_lock_for(boost::chrono::microseconds(5)))
|
||||
{
|
||||
assert(state == reading);
|
||||
state = writing;
|
||||
assert(state == writing);
|
||||
state = reading;
|
||||
mut.unlock_and_lock_shared();
|
||||
assert(state == reading);
|
||||
mut.unlock_shared();
|
||||
++count;
|
||||
}
|
||||
else
|
||||
{
|
||||
mut.unlock_upgrade();
|
||||
}
|
||||
}
|
||||
}
|
||||
print("try_for_counter_clockwise = ", count, '\n');
|
||||
}
|
||||
|
||||
void
|
||||
test_upgrade_mutex()
|
||||
{
|
||||
{
|
||||
boost::thread t1(reader);
|
||||
boost::thread t2(writer);
|
||||
boost::thread t3(reader);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
{
|
||||
boost::thread t1(try_reader);
|
||||
boost::thread t2(try_writer);
|
||||
boost::thread t3(try_reader);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
{
|
||||
boost::thread t1(try_for_reader);
|
||||
boost::thread t2(try_for_writer);
|
||||
boost::thread t3(try_for_reader);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
{
|
||||
boost::thread t1(reader);
|
||||
boost::thread t2(writer);
|
||||
boost::thread t3(upgradable);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
{
|
||||
boost::thread t1(reader);
|
||||
boost::thread t2(writer);
|
||||
boost::thread t3(try_upgradable);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
{
|
||||
boost::thread t1(reader);
|
||||
boost::thread t2(writer);
|
||||
boost::thread t3(try_for_upgradable);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
}
|
||||
{
|
||||
state = reading;
|
||||
boost::thread t1(clockwise);
|
||||
boost::thread t2(counter_clockwise);
|
||||
boost::thread t3(clockwise);
|
||||
boost::thread t4(counter_clockwise);
|
||||
t1.join();
|
||||
t2.join();
|
||||
t3.join();
|
||||
t4.join();
|
||||
}
|
||||
{
|
||||
state = reading;
|
||||
boost::thread t1(try_clockwise);
|
||||
boost::thread t2(try_counter_clockwise);
|
||||
t1.join();
|
||||
t2.join();
|
||||
}
|
||||
{
|
||||
state = reading;
|
||||
boost::thread t1(try_for_clockwise);
|
||||
boost::thread t2(try_for_counter_clockwise);
|
||||
t1.join();
|
||||
t2.join();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Assignment
|
||||
{
|
||||
|
||||
class A
|
||||
{
|
||||
typedef boost::upgrade_mutex mutex_type;
|
||||
typedef boost::shared_lock<mutex_type> SharedLock;
|
||||
typedef boost::upgrade_lock<mutex_type> UpgradeLock;
|
||||
typedef boost::unique_lock<mutex_type> Lock;
|
||||
|
||||
mutable mutex_type mut_;
|
||||
std::vector<double> data_;
|
||||
|
||||
public:
|
||||
|
||||
A(const A& a)
|
||||
{
|
||||
SharedLock _(a.mut_);
|
||||
data_ = a.data_;
|
||||
}
|
||||
|
||||
A& operator=(const A& a)
|
||||
{
|
||||
if (this != &a)
|
||||
{
|
||||
Lock this_lock(mut_, boost::defer_lock);
|
||||
SharedLock that_lock(a.mut_, boost::defer_lock);
|
||||
boost::lock(this_lock, that_lock);
|
||||
data_ = a.data_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(A& a)
|
||||
{
|
||||
Lock this_lock(mut_, boost::defer_lock);
|
||||
Lock that_lock(a.mut_, boost::defer_lock);
|
||||
boost::lock(this_lock, that_lock);
|
||||
data_.swap(a.data_);
|
||||
}
|
||||
|
||||
void average(A& a)
|
||||
{
|
||||
assert(data_.size() == a.data_.size());
|
||||
assert(this != &a);
|
||||
|
||||
Lock this_lock(mut_, boost::defer_lock);
|
||||
UpgradeLock share_that_lock(a.mut_, boost::defer_lock);
|
||||
boost::lock(this_lock, share_that_lock);
|
||||
|
||||
for (unsigned i = 0; i < data_.size(); ++i)
|
||||
data_[i] = (data_[i] + a.data_[i]) / 2;
|
||||
|
||||
SharedLock share_this_lock(boost::move(this_lock));
|
||||
Lock that_lock(boost::move(share_that_lock));
|
||||
a.data_ = data_;
|
||||
}
|
||||
};
|
||||
|
||||
} // Assignment
|
||||
|
||||
void temp()
|
||||
{
|
||||
using namespace boost;
|
||||
static upgrade_mutex mut;
|
||||
unique_lock<upgrade_mutex> ul(mut);
|
||||
shared_lock<upgrade_mutex> sl;
|
||||
sl = shared_lock<upgrade_mutex>(boost::move(ul));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::chrono::high_resolution_clock Clock;
|
||||
typedef boost::chrono::duration<double> sec;
|
||||
Clock::time_point t0 = Clock::now();
|
||||
|
||||
S::test_shared_mutex();
|
||||
U::test_upgrade_mutex();
|
||||
Clock::time_point t1 = Clock::now();
|
||||
std::cout << sec(t1 - t0) << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ int main(int argc, char* argv[])
|
||||
std::cout << "---Noise ON..." << std::endl;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1000000; ++i)
|
||||
for (int i = 0; i < 1000000000; ++i)
|
||||
cond.notify_all();
|
||||
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
// (C) Copyright 2008 Anthony Williams
|
||||
// (C) Copyright 2008-9 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)
|
||||
@@ -21,5 +21,6 @@
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/barrier.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
// David Moore, William E. Kempf
|
||||
// Copyright (C) 2007-8 Anthony Williams
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_BARRIER_JDM030602_HPP
|
||||
#define BOOST_BARRIER_JDM030602_HPP
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
@@ -27,14 +28,14 @@ namespace boost
|
||||
: m_threshold(count), m_count(count), m_generation(0)
|
||||
{
|
||||
if (count == 0)
|
||||
throw std::invalid_argument("count cannot be zero.");
|
||||
boost::throw_exception(thread_exception(system::errc::invalid_argument, "barrier constructor: count cannot be zero."));
|
||||
}
|
||||
|
||||
|
||||
bool wait()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_mutex);
|
||||
unsigned int gen = m_generation;
|
||||
|
||||
|
||||
if (--m_count == 0)
|
||||
{
|
||||
m_generation++;
|
||||
|
||||
26
include/boost/thread/cv_status.hpp
Normal file
26
include/boost/thread/cv_status.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// cv_status.hpp
|
||||
//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_THREAD_CV_STATUS_HPP
|
||||
#define BOOST_THREAD_CV_STATUS_HPP
|
||||
|
||||
#include <boost/thread/detail/scoped_enum.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
// enum class cv_status;
|
||||
BOOST_SCOPED_ENUM_DECLARE_BEGIN(cv_status)
|
||||
{
|
||||
no_timeout,
|
||||
timeout
|
||||
}
|
||||
BOOST_SCOPED_ENUM_DECLARE_END(cv_status)
|
||||
}
|
||||
|
||||
#endif // header
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_THREAD_CONFIG_WEK01032003_HPP
|
||||
@@ -10,6 +10,40 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#if !defined BOOST_THREAD_VERSION
|
||||
#define BOOST_THREAD_VERSION 1
|
||||
#else
|
||||
#if BOOST_THREAD_VERSION!=1 && BOOST_THREAD_VERSION!=2
|
||||
#error "BOOST_THREAD_VERSION must be 1 or 2"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ! defined BOOST_THREAD_DONT_USE_SYSTEM
|
||||
#define BOOST_THREAD_USES_SYSTEM
|
||||
#endif
|
||||
|
||||
#if ! defined BOOST_THREAD_DONT_USE_CHRONO && ! defined BOOST_THREAD_DONT_USE_SYSTEM
|
||||
#define BOOST_THREAD_USES_CHRONO
|
||||
#endif
|
||||
|
||||
//#if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100)
|
||||
//#define BOOST_THREAD_DONT_USE_MOVE
|
||||
//#endif
|
||||
|
||||
//#define BOOST_THREAD_SHARED_MUTEX_PROVIDES_UPWARDS_CONVERSION
|
||||
//#define BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION
|
||||
#define BOOST_THREAD_EXPLICIT_LOCK_CONVERSION explicit
|
||||
#else
|
||||
#define BOOST_THREAD_EXPLICIT_LOCK_CONVERSION
|
||||
#endif
|
||||
|
||||
|
||||
#if ! defined BOOST_THREAD_DONT_USE_MOVE
|
||||
#define BOOST_THREAD_USES_MOVE
|
||||
#endif
|
||||
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
|
||||
# pragma warn -8008 // Condition always true/false
|
||||
# pragma warn -8080 // Identifier declared but never used
|
||||
@@ -19,8 +53,14 @@
|
||||
|
||||
#include "platform.hpp"
|
||||
|
||||
// provided for backwards compatibility, since this
|
||||
// macro was used for several releases by mistake.
|
||||
#if defined(BOOST_THREAD_DYN_DLL)
|
||||
# define BOOST_THREAD_DYN_LINK
|
||||
#endif
|
||||
|
||||
// compatibility with the rest of Boost's auto-linking code:
|
||||
#if defined(BOOST_THREAD_DYN_DLL) || defined(BOOST_ALL_DYN_LINK)
|
||||
#if defined(BOOST_THREAD_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)
|
||||
# undef BOOST_THREAD_USE_LIB
|
||||
# define BOOST_THREAD_USE_DLL
|
||||
#endif
|
||||
@@ -47,12 +87,18 @@
|
||||
|
||||
#if defined(BOOST_HAS_DECLSPEC)
|
||||
# if defined(BOOST_THREAD_BUILD_DLL) //Build dll
|
||||
# define BOOST_THREAD_DECL __declspec(dllexport)
|
||||
# define BOOST_THREAD_DECL BOOST_SYMBOL_EXPORT
|
||||
//# define BOOST_THREAD_DECL __declspec(dllexport)
|
||||
|
||||
# elif defined(BOOST_THREAD_USE_DLL) //Use dll
|
||||
# define BOOST_THREAD_DECL __declspec(dllimport)
|
||||
# define BOOST_THREAD_DECL BOOST_SYMBOL_IMPORT
|
||||
//# define BOOST_THREAD_DECL __declspec(dllimport)
|
||||
# else
|
||||
# define BOOST_THREAD_DECL
|
||||
# endif
|
||||
#elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
|
||||
# define BOOST_THREAD_DECL BOOST_SYMBOL_VISIBLE
|
||||
|
||||
#else
|
||||
# define BOOST_THREAD_DECL
|
||||
#endif // BOOST_HAS_DECLSPEC
|
||||
@@ -63,7 +109,7 @@
|
||||
#if !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_THREAD_NO_LIB) && !defined(BOOST_THREAD_BUILD_DLL) && !defined(BOOST_THREAD_BUILD_LIB)
|
||||
//
|
||||
// Tell the autolink to link dynamically, this will get undef'ed by auto_link.hpp
|
||||
// once it's done with it:
|
||||
// once it's done with it:
|
||||
//
|
||||
#if defined(BOOST_THREAD_USE_DLL)
|
||||
# define BOOST_DYN_LINK
|
||||
|
||||
@@ -6,15 +6,20 @@
|
||||
#ifndef BOOST_THREAD_MOVE_HPP
|
||||
#define BOOST_THREAD_MOVE_HPP
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/move/move.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template<typename T>
|
||||
@@ -41,18 +46,19 @@ namespace boost
|
||||
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
template<typename T>
|
||||
typename enable_if<boost::is_convertible<T&,detail::thread_move_t<T> >, detail::thread_move_t<T> >::type move(T& t)
|
||||
typename enable_if<boost::is_convertible<T&,boost::detail::thread_move_t<T> >, boost::detail::thread_move_t<T> >::type move(T& t)
|
||||
{
|
||||
return t;
|
||||
return boost::detail::thread_move_t<T>(t);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
template<typename T>
|
||||
detail::thread_move_t<T> move(detail::thread_move_t<T> t)
|
||||
boost::detail::thread_move_t<T> move(boost::detail::thread_move_t<T> t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
# define BOOST_THREAD_HPUX
|
||||
#elif defined(__CYGWIN__)
|
||||
# define BOOST_THREAD_CYGWIN
|
||||
#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
||||
#elif (defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) && !defined(BOOST_DISABLE_WIN32)
|
||||
# define BOOST_THREAD_WIN32
|
||||
#elif defined(__BEOS__)
|
||||
# define BOOST_THREAD_BEOS
|
||||
|
||||
113
include/boost/thread/detail/scoped_enum.hpp
Normal file
113
include/boost/thread/detail/scoped_enum.hpp
Normal file
@@ -0,0 +1,113 @@
|
||||
// Copyright (C) 2012
|
||||
// Vicente J. Botet Escriba
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_THREAD_DETAIL_SCOPED_ENUM_HPP
|
||||
#define BOOST_THREAD_DETAIL_SCOPED_ENUM_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
#ifdef BOOST_NO_SCOPED_ENUMS
|
||||
template <typename NT>
|
||||
struct underlying_type
|
||||
{
|
||||
typedef typename NT::underlying_type type;
|
||||
};
|
||||
|
||||
template <typename UT, typename NT>
|
||||
UT underlying_cast(NT v)
|
||||
{
|
||||
return v.underlying();
|
||||
}
|
||||
|
||||
template <typename EC>
|
||||
inline
|
||||
typename EC::enum_type native_value(EC e)
|
||||
{
|
||||
return e.native();
|
||||
}
|
||||
|
||||
#else // BOOST_NO_SCOPED_ENUMS
|
||||
|
||||
template <typename NT>
|
||||
struct underlying_type
|
||||
{
|
||||
//typedef typename std::underlying_type<NT>::type type;
|
||||
};
|
||||
|
||||
template <typename UT, typename NT>
|
||||
UT underlying_cast(NT v)
|
||||
{
|
||||
return static_cast<UT>(v);
|
||||
}
|
||||
|
||||
template <typename EC>
|
||||
inline
|
||||
EC native_value(EC e)
|
||||
{
|
||||
return e;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef BOOST_NO_SCOPED_ENUMS
|
||||
|
||||
#ifndef BOOST_NO_EXPLICIT_CONVERSION_OPERATORS
|
||||
|
||||
#define BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR \
|
||||
explicit operator underlying_type() const { return underlying(); }
|
||||
|
||||
#else
|
||||
|
||||
#define BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR
|
||||
|
||||
#endif
|
||||
|
||||
#define BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(NT, UT) \
|
||||
struct NT { \
|
||||
typedef UT underlying_type; \
|
||||
enum enum_type
|
||||
|
||||
#define BOOST_SCOPED_ENUM_DECLARE_END(NT) \
|
||||
; \
|
||||
NT() {} \
|
||||
NT(enum_type v) : v_(v) {} \
|
||||
explicit NT(underlying_type v) : v_(v) {} \
|
||||
underlying_type underlying() const { return v_; } \
|
||||
enum_type native() const { return enum_type(v_); } \
|
||||
BOOST_SCOPED_ENUM_UT_DECLARE_CONVERSION_OPERATOR \
|
||||
friend bool operator ==(NT lhs, enum_type rhs) { return enum_type(lhs.v_)==rhs; } \
|
||||
friend bool operator ==(enum_type lhs, NT rhs) { return lhs==enum_type(rhs.v_); } \
|
||||
friend bool operator !=(NT lhs, enum_type rhs) { return enum_type(lhs.v_)!=rhs; } \
|
||||
friend bool operator !=(enum_type lhs, NT rhs) { return lhs!=enum_type(rhs.v_); } \
|
||||
private: \
|
||||
underlying_type v_; \
|
||||
};
|
||||
|
||||
#define BOOST_SCOPED_ENUM_DECLARE_BEGIN(NT) \
|
||||
BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(NT,int)
|
||||
|
||||
#define BOOST_SCOPED_ENUM_NATIVE(NT) NT::enum_type
|
||||
#define BOOST_SCOPED_ENUM_FORWARD_DECLARE(NT) struct NT
|
||||
|
||||
#else // BOOST_NO_SCOPED_ENUMS
|
||||
|
||||
#define BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(NT,UT) enum class NT:UT
|
||||
#define BOOST_SCOPED_ENUM_DECLARE_BEGIN(NT) enum class NT
|
||||
#define BOOST_SCOPED_ENUM_DECLARE_END(NT) ;
|
||||
|
||||
#define BOOST_SCOPED_ENUM_NATIVE(NT) NT
|
||||
#define BOOST_SCOPED_ENUM_FORWARD_DECLARE(NT) enum class NT
|
||||
|
||||
#endif // BOOST_NO_SCOPED_ENUMS
|
||||
|
||||
|
||||
#endif // BOOST_THREAD_DETAIL_SCOPED_ENUM_HPP
|
||||
@@ -3,11 +3,19 @@
|
||||
// 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
|
||||
|
||||
// (C) Copyright 2007-10 Anthony Williams
|
||||
// (C) Copyright 20011-12 Vicente J. Botet Escriba
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/thread/exceptions.hpp>
|
||||
#ifndef BOOST_NO_IOSTREAM
|
||||
#include <ostream>
|
||||
#endif
|
||||
#if defined BOOST_THREAD_USES_MOVE
|
||||
#include <boost/move/move.hpp>
|
||||
#else
|
||||
#include <boost/thread/detail/move.hpp>
|
||||
#endif
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
#include <boost/thread/detail/thread_heap_alloc.hpp>
|
||||
@@ -22,6 +30,14 @@
|
||||
#include <memory>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/io/ios_state.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/decay.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#include <boost/chrono/ceil.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
@@ -32,6 +48,19 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
#ifndef BOOST_NO_RVALUE_REFERENCES
|
||||
namespace thread_detail
|
||||
{
|
||||
template <class T>
|
||||
typename decay<T>::type
|
||||
decay_copy(T&& t)
|
||||
{
|
||||
return boost::forward<T>(t);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template<typename F>
|
||||
@@ -39,18 +68,28 @@ namespace boost
|
||||
public detail::thread_data_base
|
||||
{
|
||||
public:
|
||||
#ifdef BOOST_HAS_RVALUE_REFS
|
||||
#ifndef BOOST_NO_RVALUE_REFERENCES
|
||||
thread_data(F&& f_):
|
||||
f(static_cast<F&&>(f_))
|
||||
f(boost::forward<F>(f_))
|
||||
{}
|
||||
// This overloading must be removed if we want the packaged_task's tests to pass.
|
||||
// thread_data(F& f_):
|
||||
// f(f_)
|
||||
// {}
|
||||
#else
|
||||
thread_data(F f_):
|
||||
f(f_)
|
||||
{}
|
||||
#if defined BOOST_THREAD_USES_MOVE
|
||||
thread_data(boost::rv<F>& f_):
|
||||
f(boost::move(f_))
|
||||
{}
|
||||
#else
|
||||
thread_data(detail::thread_move_t<F> f_):
|
||||
f(f_)
|
||||
{}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
void run()
|
||||
{
|
||||
f();
|
||||
@@ -75,7 +114,7 @@ namespace boost
|
||||
thread_data(boost::reference_wrapper<F> f_):
|
||||
f(f_)
|
||||
{}
|
||||
|
||||
|
||||
void run()
|
||||
{
|
||||
f();
|
||||
@@ -94,40 +133,53 @@ namespace boost
|
||||
thread_data(const boost::reference_wrapper<F> f_):
|
||||
f(f_)
|
||||
{}
|
||||
|
||||
|
||||
void run()
|
||||
{
|
||||
f();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
class BOOST_THREAD_DECL thread
|
||||
{
|
||||
public:
|
||||
//typedef int boost_move_emulation_t;
|
||||
typedef thread_attributes attributes;
|
||||
|
||||
#ifndef BOOST_NO_DELETED_FUNCTIONS
|
||||
public:
|
||||
thread(thread const&) = delete;
|
||||
thread& operator=(thread const&) = delete;
|
||||
#else // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
thread(thread&);
|
||||
thread& operator=(thread&);
|
||||
#endif // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
thread(thread&);
|
||||
thread& operator=(thread&);
|
||||
|
||||
void release_handle();
|
||||
|
||||
mutable boost::mutex thread_info_mutex;
|
||||
|
||||
detail::thread_data_ptr thread_info;
|
||||
|
||||
void start_thread();
|
||||
|
||||
void start_thread(const attributes& attr);
|
||||
|
||||
explicit thread(detail::thread_data_ptr data);
|
||||
|
||||
detail::thread_data_ptr get_thread_info() const;
|
||||
detail::thread_data_ptr get_thread_info BOOST_PREVENT_MACRO_SUBSTITUTION () const;
|
||||
|
||||
#ifdef BOOST_HAS_RVALUE_REFS
|
||||
#ifndef BOOST_NO_RVALUE_REFERENCES
|
||||
template<typename F>
|
||||
static inline detail::thread_data_ptr make_thread_info(F&& f)
|
||||
{
|
||||
return detail::thread_data_ptr(detail::heap_new<detail::thread_data<typename boost::remove_reference<F>::type> >(static_cast<F&&>(f)));
|
||||
return detail::thread_data_ptr(detail::heap_new<detail::thread_data<typename boost::remove_reference<F>::type> >(
|
||||
boost::forward<F>(f)));
|
||||
}
|
||||
static inline detail::thread_data_ptr make_thread_info(void (*f)())
|
||||
{
|
||||
return detail::thread_data_ptr(detail::heap_new<detail::thread_data<void(*)()> >(f));
|
||||
return detail::thread_data_ptr(detail::heap_new<detail::thread_data<void(*)()> >(
|
||||
boost::forward<void(*)()>(f)));
|
||||
}
|
||||
#else
|
||||
template<typename F>
|
||||
@@ -135,43 +187,80 @@ namespace boost
|
||||
{
|
||||
return detail::thread_data_ptr(detail::heap_new<detail::thread_data<F> >(f));
|
||||
}
|
||||
#if defined BOOST_THREAD_USES_MOVE
|
||||
template<typename F>
|
||||
static inline detail::thread_data_ptr make_thread_info(boost::rv<F>& f)
|
||||
{
|
||||
return detail::thread_data_ptr(detail::heap_new<detail::thread_data<F> >(boost::move(f)));
|
||||
}
|
||||
|
||||
#else
|
||||
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<detail::thread_data<F> >(f));
|
||||
}
|
||||
|
||||
struct dummy;
|
||||
#endif
|
||||
#endif
|
||||
struct dummy;
|
||||
public:
|
||||
thread();
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100)
|
||||
thread(const volatile thread&);
|
||||
#endif
|
||||
thread() BOOST_NOEXCEPT;
|
||||
~thread();
|
||||
|
||||
#ifdef BOOST_HAS_RVALUE_REFS
|
||||
#ifndef BOOST_NO_RVALUE_REFERENCES
|
||||
#ifdef BOOST_MSVCXX
|
||||
template <class F>
|
||||
thread(F&& f):
|
||||
explicit thread(F f,typename disable_if<boost::is_convertible<F&,detail::thread_move_t<F> >, dummy* >::type=0):
|
||||
thread_info(make_thread_info(static_cast<F&&>(f)))
|
||||
{
|
||||
start_thread();
|
||||
}
|
||||
#else
|
||||
template <
|
||||
class F
|
||||
//, class Dummy = typename disable_if< is_same<typename decay<F>::type, thread> >::type
|
||||
>
|
||||
explicit thread(F&& f
|
||||
, typename disable_if<is_same<typename decay<F>::type, thread>, dummy* >::type=0
|
||||
):
|
||||
thread_info(make_thread_info(thread_detail::decay_copy(boost::forward<F>(f))))
|
||||
{
|
||||
start_thread();
|
||||
}
|
||||
template <
|
||||
class F
|
||||
//, class Dummy = typename disable_if< is_same<typename decay<F>::type, thread> >::type
|
||||
>
|
||||
thread(attributes& attrs, F&& f
|
||||
, typename disable_if<is_same<typename decay<F>::type, thread>, dummy* >::type=0
|
||||
):
|
||||
thread_info(make_thread_info(thread_detail::decay_copy(boost::forward<F>(f))))
|
||||
{
|
||||
start_thread(attrs);
|
||||
}
|
||||
#endif
|
||||
|
||||
thread(thread&& other)
|
||||
thread(thread&& other) BOOST_NOEXCEPT
|
||||
{
|
||||
thread_info.swap(other.thread_info);
|
||||
}
|
||||
|
||||
thread& operator=(thread&& other)
|
||||
|
||||
thread& operator=(thread&& other) BOOST_NOEXCEPT
|
||||
{
|
||||
thread_info=other.thread_info;
|
||||
other.thread_info.reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
thread&& move()
|
||||
{
|
||||
return static_cast<thread&&>(*this);
|
||||
}
|
||||
|
||||
// thread&& move()
|
||||
// {
|
||||
// return static_cast<thread&&>(*this);
|
||||
// }
|
||||
|
||||
#else
|
||||
#ifdef BOOST_NO_SFINAE
|
||||
template <class F>
|
||||
@@ -180,6 +269,26 @@ namespace boost
|
||||
{
|
||||
start_thread();
|
||||
}
|
||||
template <class F>
|
||||
thread(attributes& attrs, F f):
|
||||
thread_info(make_thread_info(f))
|
||||
{
|
||||
start_thread(attrs);
|
||||
}
|
||||
#else
|
||||
#if defined BOOST_THREAD_USES_MOVE
|
||||
template <class F>
|
||||
explicit thread(F f,typename disable_if<boost::is_convertible<F&,boost::rv<F>& >, dummy* >::type=0):
|
||||
thread_info(make_thread_info(f))
|
||||
{
|
||||
start_thread();
|
||||
}
|
||||
template <class F>
|
||||
thread(attributes& attrs, F f,typename disable_if<boost::is_convertible<F&,boost::rv<F>& >, dummy* >::type=0):
|
||||
thread_info(make_thread_info(f))
|
||||
{
|
||||
start_thread(attrs);
|
||||
}
|
||||
#else
|
||||
template <class F>
|
||||
explicit thread(F f,typename disable_if<boost::is_convertible<F&,detail::thread_move_t<F> >, dummy* >::type=0):
|
||||
@@ -187,8 +296,52 @@ namespace boost
|
||||
{
|
||||
start_thread();
|
||||
}
|
||||
template <class F>
|
||||
thread(attributes& attrs, F f,typename disable_if<boost::is_convertible<F&,detail::thread_move_t<F> >, dummy* >::type=0):
|
||||
thread_info(make_thread_info(f))
|
||||
{
|
||||
start_thread(attrs);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined BOOST_THREAD_USES_MOVE
|
||||
template <class F>
|
||||
explicit thread(boost::rv<F>& f):
|
||||
thread_info(make_thread_info(boost::move(f)))
|
||||
{
|
||||
start_thread();
|
||||
}
|
||||
|
||||
|
||||
// explicit thread(void (*f)()):
|
||||
// thread_info(make_thread_info(f))
|
||||
// {
|
||||
// start_thread();
|
||||
// }
|
||||
//
|
||||
// template <class F>
|
||||
// explicit thread(BOOST_FWD_REF(F) f):
|
||||
// thread_info(make_thread_info(boost::forward<F>(f)))
|
||||
// {
|
||||
// start_thread();
|
||||
// }
|
||||
|
||||
template <class F>
|
||||
thread(attributes& attrs, boost::rv<F>& f):
|
||||
thread_info(make_thread_info(boost::move(f)))
|
||||
{
|
||||
start_thread(attrs);
|
||||
}
|
||||
|
||||
|
||||
thread(boost::rv<thread>& x)
|
||||
//thread(BOOST_RV_REF(thread) x)
|
||||
{
|
||||
thread_info=x.thread_info;
|
||||
x.thread_info.reset();
|
||||
}
|
||||
#else
|
||||
template <class F>
|
||||
explicit thread(detail::thread_move_t<F> f):
|
||||
thread_info(make_thread_info(f))
|
||||
@@ -196,34 +349,79 @@ namespace boost
|
||||
start_thread();
|
||||
}
|
||||
|
||||
template <class F>
|
||||
thread(attributes& attrs, detail::thread_move_t<F> f):
|
||||
thread_info(make_thread_info(f))
|
||||
{
|
||||
start_thread(attrs);
|
||||
}
|
||||
|
||||
thread(detail::thread_move_t<thread> x)
|
||||
{
|
||||
thread_info=x->thread_info;
|
||||
x->thread_info.reset();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100)
|
||||
thread& operator=(thread x)
|
||||
{
|
||||
swap(x);
|
||||
return *this;
|
||||
}
|
||||
#else
|
||||
#if defined BOOST_THREAD_USES_MOVE
|
||||
thread& operator=(boost::rv<thread>& x)
|
||||
{
|
||||
thread new_thread(boost::move(x));
|
||||
swap(new_thread);
|
||||
return *this;
|
||||
}
|
||||
#else
|
||||
thread& operator=(detail::thread_move_t<thread> x)
|
||||
{
|
||||
thread new_thread(x);
|
||||
swap(new_thread);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined BOOST_THREAD_USES_MOVE
|
||||
::boost::rv<thread>& move()
|
||||
{
|
||||
return *static_cast< ::boost::rv<thread>* >(this);
|
||||
}
|
||||
const ::boost::rv<thread>& move() const
|
||||
{
|
||||
return *static_cast<const ::boost::rv<thread>* >(this);
|
||||
}
|
||||
|
||||
operator ::boost::rv<thread>&()
|
||||
{
|
||||
return *static_cast< ::boost::rv<thread>* >(this);
|
||||
}
|
||||
operator const ::boost::rv<thread>&() const
|
||||
{
|
||||
return *static_cast<const ::boost::rv<thread>* >(this);
|
||||
}
|
||||
#else
|
||||
operator detail::thread_move_t<thread>()
|
||||
{
|
||||
return move();
|
||||
}
|
||||
|
||||
|
||||
detail::thread_move_t<thread> move()
|
||||
{
|
||||
detail::thread_move_t<thread> x(*this);
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
template <class F,class A1>
|
||||
thread(F f,A1 a1):
|
||||
thread(F f,A1 a1,typename disable_if<boost::is_convertible<F&,thread_attributes >, dummy* >::type=0):
|
||||
thread_info(make_thread_info(boost::bind(boost::type<void>(),f,a1)))
|
||||
{
|
||||
start_thread();
|
||||
@@ -284,28 +482,99 @@ namespace boost
|
||||
start_thread();
|
||||
}
|
||||
|
||||
void swap(thread& x)
|
||||
void swap(thread& x) BOOST_NOEXCEPT
|
||||
{
|
||||
thread_info.swap(x.thread_info);
|
||||
}
|
||||
|
||||
class id;
|
||||
id get_id() const;
|
||||
class BOOST_SYMBOL_VISIBLE id;
|
||||
id get_id() const BOOST_NOEXCEPT;
|
||||
|
||||
|
||||
bool joinable() const;
|
||||
bool joinable() const BOOST_NOEXCEPT;
|
||||
void join();
|
||||
bool timed_join(const system_time& wait_until);
|
||||
#if defined(BOOST_THREAD_PLATFORM_WIN32)
|
||||
bool timed_join(const system_time& abs_time);
|
||||
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_join_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
return try_join_until(chrono::steady_clock::now() + rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool try_join_until(const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
system_clock::time_point s_now = system_clock::now();
|
||||
typename Clock::time_point c_now = Clock::now();
|
||||
return try_join_until(s_now + ceil<nanoseconds>(t - c_now));
|
||||
}
|
||||
template <class Duration>
|
||||
bool try_join_until(const chrono::time_point<chrono::system_clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
typedef time_point<system_clock, nanoseconds> nano_sys_tmpt;
|
||||
return try_join_until(nano_sys_tmpt(ceil<nanoseconds>(t.time_since_epoch())));
|
||||
}
|
||||
bool try_join_until(const chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp);
|
||||
#endif
|
||||
public:
|
||||
|
||||
#else
|
||||
bool timed_join(const system_time& abs_time) {
|
||||
struct timespec const ts=detail::get_timespec(abs_time);
|
||||
return do_try_join_until(ts);
|
||||
}
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_join_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
return try_join_until(chrono::steady_clock::now() + rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool try_join_until(const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
system_clock::time_point s_now = system_clock::now();
|
||||
typename Clock::time_point c_now = Clock::now();
|
||||
return try_join_until(s_now + ceil<nanoseconds>(t - c_now));
|
||||
}
|
||||
template <class Duration>
|
||||
bool try_join_until(const chrono::time_point<chrono::system_clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
typedef time_point<system_clock, nanoseconds> nano_sys_tmpt;
|
||||
return try_join_until(nano_sys_tmpt(ceil<nanoseconds>(t.time_since_epoch())));
|
||||
}
|
||||
bool try_join_until(const chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp)
|
||||
{
|
||||
using namespace chrono;
|
||||
nanoseconds d = tp.time_since_epoch();
|
||||
timespec ts;
|
||||
seconds s = duration_cast<seconds>(d);
|
||||
ts.tv_sec = static_cast<long>(s.count());
|
||||
ts.tv_nsec = static_cast<long>((d - s).count());
|
||||
return do_try_join_until(ts);
|
||||
}
|
||||
#endif
|
||||
private:
|
||||
bool do_try_join_until(struct timespec const &timeout);
|
||||
public:
|
||||
|
||||
#endif
|
||||
|
||||
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();
|
||||
static unsigned hardware_concurrency() BOOST_NOEXCEPT;
|
||||
|
||||
#define BOOST_THREAD_DEFINES_THREAD_NATIVE_HANDLE
|
||||
typedef detail::thread_data_base::native_handle_type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
|
||||
@@ -313,11 +582,11 @@ namespace boost
|
||||
bool operator==(const thread& other) const;
|
||||
bool operator!=(const thread& other) const;
|
||||
|
||||
static inline void yield()
|
||||
static inline void yield() BOOST_NOEXCEPT
|
||||
{
|
||||
this_thread::yield();
|
||||
}
|
||||
|
||||
|
||||
static inline void sleep(const system_time& xt)
|
||||
{
|
||||
this_thread::sleep(xt);
|
||||
@@ -328,156 +597,193 @@ namespace boost
|
||||
bool interruption_requested() const;
|
||||
};
|
||||
|
||||
inline void swap(thread& lhs,thread& rhs)
|
||||
inline void swap(thread& lhs,thread& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
return lhs.swap(rhs);
|
||||
}
|
||||
|
||||
#ifdef BOOST_HAS_RVALUE_REFS
|
||||
|
||||
#ifndef BOOST_NO_RVALUE_REFERENCES
|
||||
inline thread&& move(thread& t)
|
||||
{
|
||||
return static_cast<thread&&>(t);
|
||||
}
|
||||
inline thread&& move(thread&& t)
|
||||
{
|
||||
return t;
|
||||
return static_cast<thread&&>(t);
|
||||
}
|
||||
#else
|
||||
#if !defined BOOST_THREAD_USES_MOVE
|
||||
inline detail::thread_move_t<thread> move(detail::thread_move_t<thread> t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_NO_RVALUE_REFERENCES
|
||||
#if !defined BOOST_THREAD_USES_MOVE
|
||||
template <>
|
||||
struct has_move_emulation_enabled_aux<thread>
|
||||
: BOOST_MOVE_BOOST_NS::integral_constant<bool, true>
|
||||
{};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
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();
|
||||
thread::id BOOST_THREAD_DECL get_id() BOOST_NOEXCEPT;
|
||||
|
||||
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)
|
||||
inline BOOST_SYMBOL_VISIBLE void sleep(xtime const& abs_time)
|
||||
{
|
||||
sleep(system_time(abs_time));
|
||||
}
|
||||
}
|
||||
|
||||
class thread::id
|
||||
class BOOST_SYMBOL_VISIBLE thread::id
|
||||
{
|
||||
private:
|
||||
friend inline
|
||||
std::size_t
|
||||
hash_value(const thread::id &v)
|
||||
{
|
||||
return hash_value(v.thread_data.get());
|
||||
}
|
||||
|
||||
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();
|
||||
friend id BOOST_THREAD_DECL this_thread::get_id() BOOST_NOEXCEPT;
|
||||
public:
|
||||
id():
|
||||
id() BOOST_NOEXCEPT:
|
||||
thread_data()
|
||||
{}
|
||||
|
||||
bool operator==(const id& y) const
|
||||
|
||||
id(const id& other) BOOST_NOEXCEPT :
|
||||
thread_data(other.thread_data)
|
||||
{}
|
||||
|
||||
bool operator==(const id& y) const BOOST_NOEXCEPT
|
||||
{
|
||||
return thread_data==y.thread_data;
|
||||
}
|
||||
|
||||
bool operator!=(const id& y) const
|
||||
|
||||
bool operator!=(const id& y) const BOOST_NOEXCEPT
|
||||
{
|
||||
return thread_data!=y.thread_data;
|
||||
}
|
||||
|
||||
bool operator<(const id& y) const
|
||||
|
||||
bool operator<(const id& y) const BOOST_NOEXCEPT
|
||||
{
|
||||
return thread_data<y.thread_data;
|
||||
}
|
||||
|
||||
bool operator>(const id& y) const
|
||||
|
||||
bool operator>(const id& y) const BOOST_NOEXCEPT
|
||||
{
|
||||
return y.thread_data<thread_data;
|
||||
}
|
||||
|
||||
bool operator<=(const id& y) const
|
||||
|
||||
bool operator<=(const id& y) const BOOST_NOEXCEPT
|
||||
{
|
||||
return !(y.thread_data<thread_data);
|
||||
}
|
||||
|
||||
bool operator>=(const id& y) const
|
||||
|
||||
bool operator>=(const id& y) const BOOST_NOEXCEPT
|
||||
{
|
||||
return !(thread_data<y.thread_data);
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_IOSTREAM
|
||||
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
||||
template<class charT, class traits>
|
||||
friend std::basic_ostream<charT, traits>&
|
||||
friend BOOST_SYMBOL_VISIBLE
|
||||
std::basic_ostream<charT, traits>&
|
||||
operator<<(std::basic_ostream<charT, traits>& os, const id& x)
|
||||
{
|
||||
if(x.thread_data)
|
||||
{
|
||||
return os<<x.thread_data;
|
||||
io::ios_flags_saver ifs( os );
|
||||
return os<< std::hex << x.thread_data;
|
||||
}
|
||||
else
|
||||
{
|
||||
return os<<"{Not-any-thread}";
|
||||
}
|
||||
}
|
||||
#else
|
||||
template<class charT, class traits>
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
std::basic_ostream<charT, traits>&
|
||||
print(std::basic_ostream<charT, traits>& os) const
|
||||
{
|
||||
if(thread_data)
|
||||
{
|
||||
return os<<thread_data;
|
||||
}
|
||||
else
|
||||
{
|
||||
return os<<"{Not-any-thread}";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_IOSTREAM) && defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
|
||||
template<class charT, class traits>
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
std::basic_ostream<charT, traits>&
|
||||
operator<<(std::basic_ostream<charT, traits>& os, const thread::id& x)
|
||||
{
|
||||
return x.print(os);
|
||||
}
|
||||
#endif
|
||||
|
||||
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;
|
||||
virtual void operator()()=0;
|
||||
};
|
||||
|
||||
|
||||
template<typename F>
|
||||
struct thread_exit_function:
|
||||
thread_exit_function_base
|
||||
{
|
||||
F f;
|
||||
|
||||
|
||||
thread_exit_function(F f_):
|
||||
f(f_)
|
||||
{}
|
||||
|
||||
void operator()() const
|
||||
|
||||
void operator()()
|
||||
{
|
||||
f();
|
||||
}
|
||||
};
|
||||
|
||||
void add_thread_exit_function(thread_exit_function_base*);
|
||||
|
||||
void BOOST_THREAD_DECL add_thread_exit_function(thread_exit_function_base*);
|
||||
}
|
||||
|
||||
|
||||
namespace this_thread
|
||||
{
|
||||
template<typename F>
|
||||
@@ -487,83 +793,6 @@ namespace boost
|
||||
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
|
||||
|
||||
108
include/boost/thread/detail/thread_group.hpp
Normal file
108
include/boost/thread/detail/thread_group.hpp
Normal file
@@ -0,0 +1,108 @@
|
||||
#ifndef BOOST_THREAD_DETAIL_THREAD_GROUP_HPP
|
||||
#define BOOST_THREAD_DETAIL_THREAD_GROUP_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-9 Anthony Williams
|
||||
|
||||
#include <list>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4251)
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class thread_group
|
||||
{
|
||||
private:
|
||||
thread_group(thread_group const&);
|
||||
thread_group& operator=(thread_group const&);
|
||||
public:
|
||||
thread_group() {}
|
||||
~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<shared_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<shared_mutex> guard(m);
|
||||
threads.push_back(thrd);
|
||||
}
|
||||
}
|
||||
|
||||
void remove_thread(thread* thrd)
|
||||
{
|
||||
boost::lock_guard<shared_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::shared_lock<shared_mutex> guard(m);
|
||||
|
||||
for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
|
||||
it!=end;
|
||||
++it)
|
||||
{
|
||||
(*it)->join();
|
||||
}
|
||||
}
|
||||
|
||||
void interrupt_all()
|
||||
{
|
||||
boost::shared_lock<shared_mutex> guard(m);
|
||||
|
||||
for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
|
||||
it!=end;
|
||||
++it)
|
||||
{
|
||||
(*it)->interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
boost::shared_lock<shared_mutex> guard(m);
|
||||
return threads.size();
|
||||
}
|
||||
|
||||
private:
|
||||
std::list<thread*> threads;
|
||||
mutable shared_mutex m;
|
||||
};
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif
|
||||
35
include/boost/thread/detail/thread_interruption.hpp
Normal file
35
include/boost/thread/detail/thread_interruption.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef BOOST_THREAD_DETAIL_THREAD_INTERRUPTION_HPP
|
||||
#define BOOST_THREAD_DETAIL_THREAD_INTERRUPTION_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-9 Anthony Williams
|
||||
|
||||
namespace boost
|
||||
{
|
||||
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();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -12,27 +12,9 @@
|
||||
|
||||
#if defined(BOOST_HAS_WINTHREADS)
|
||||
|
||||
typedef void (__cdecl *thread_exit_handler)(void);
|
||||
|
||||
extern "C" BOOST_THREAD_DECL int at_thread_exit(
|
||||
thread_exit_handler exit_handler
|
||||
);
|
||||
//Add a function to the list of functions that will
|
||||
//be called when a thread is about to exit.
|
||||
//Currently only implemented for Win32, but should
|
||||
//later be implemented for all platforms.
|
||||
//Used by Win32 implementation of Boost.Threads
|
||||
//tss to perform cleanup.
|
||||
//Like the C runtime library atexit() function,
|
||||
//which it mimics, at_thread_exit() returns
|
||||
//zero if successful and a nonzero
|
||||
//value if an error occurs.
|
||||
|
||||
#endif //defined(BOOST_HAS_WINTHREADS)
|
||||
|
||||
#if defined(BOOST_HAS_WINTHREADS)
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_process_enter(void);
|
||||
namespace boost
|
||||
{
|
||||
BOOST_THREAD_DECL void __cdecl on_process_enter(void);
|
||||
//Function to be called when the exe or dll
|
||||
//that uses Boost.Threads first starts
|
||||
//or is first loaded.
|
||||
@@ -42,7 +24,7 @@
|
||||
//a method for doing so has been discovered.
|
||||
//May be omitted; may be called multiple times.
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_process_exit(void);
|
||||
BOOST_THREAD_DECL void __cdecl on_process_exit(void);
|
||||
//Function to be called when the exe or dll
|
||||
//that uses Boost.Threads first starts
|
||||
//or is first loaded.
|
||||
@@ -52,7 +34,7 @@
|
||||
//a method for doing so has been discovered.
|
||||
//Must not be omitted; may be called multiple times.
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_thread_enter(void);
|
||||
BOOST_THREAD_DECL void __cdecl on_thread_enter(void);
|
||||
//Function to be called just after a thread starts
|
||||
//in an exe or dll that uses Boost.Threads.
|
||||
//Must be called in the context of the thread
|
||||
@@ -61,7 +43,7 @@
|
||||
//a method for doing so has been discovered.
|
||||
//May be omitted; may be called multiple times.
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void __cdecl on_thread_exit(void);
|
||||
BOOST_THREAD_DECL void __cdecl on_thread_exit(void);
|
||||
//Function to be called just be fore a thread ends
|
||||
//in an exe or dll that uses Boost.Threads.
|
||||
//Must be called in the context of the thread
|
||||
@@ -70,10 +52,11 @@
|
||||
//a method for doing so has been discovered.
|
||||
//Must not be omitted; may be called multiple times.
|
||||
|
||||
extern "C" void tss_cleanup_implemented(void);
|
||||
void tss_cleanup_implemented();
|
||||
//Dummy function used both to detect whether tss cleanup
|
||||
//cleanup has been implemented and to force
|
||||
//it to be linked into the Boost.Threads library.
|
||||
}
|
||||
|
||||
#endif //defined(BOOST_HAS_WINTHREADS)
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
// Copyright (C) 2007-8 Anthony Williams
|
||||
// Copyright (C) 2007-9 Anthony Williams
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_THREAD_EXCEPTIONS_PDM070801_H
|
||||
@@ -18,97 +18,205 @@
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <boost/system/system_error.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
class BOOST_THREAD_DECL thread_interrupted
|
||||
class BOOST_SYMBOL_VISIBLE thread_interrupted
|
||||
{};
|
||||
|
||||
class BOOST_THREAD_DECL thread_exception : public std::exception
|
||||
{
|
||||
protected:
|
||||
thread_exception();
|
||||
thread_exception(int sys_err_code);
|
||||
|
||||
public:
|
||||
~thread_exception() throw();
|
||||
|
||||
int native_error() const;
|
||||
|
||||
private:
|
||||
int m_sys_err;
|
||||
};
|
||||
|
||||
class condition_error:
|
||||
public std::exception
|
||||
class BOOST_SYMBOL_VISIBLE thread_exception:
|
||||
public system::system_error
|
||||
//public std::exception
|
||||
{
|
||||
typedef system::system_error base_type;
|
||||
public:
|
||||
const char* what() const throw()
|
||||
thread_exception()
|
||||
: base_type(0,system::system_category())
|
||||
{}
|
||||
|
||||
thread_exception(int sys_error_code)
|
||||
: base_type(sys_error_code, system::system_category())
|
||||
{}
|
||||
|
||||
thread_exception( int ev, const char * what_arg )
|
||||
: base_type(system::error_code(ev, system::system_category()), what_arg)
|
||||
{
|
||||
return "Condition error";
|
||||
}
|
||||
thread_exception( int ev, const std::string & what_arg )
|
||||
: base_type(system::error_code(ev, system::system_category()), what_arg)
|
||||
{
|
||||
}
|
||||
|
||||
~thread_exception() throw()
|
||||
{}
|
||||
|
||||
|
||||
int native_error() const
|
||||
{
|
||||
return code().value();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class BOOST_THREAD_DECL lock_error : public thread_exception
|
||||
{
|
||||
public:
|
||||
lock_error();
|
||||
lock_error(int sys_err_code);
|
||||
~lock_error() throw();
|
||||
class BOOST_SYMBOL_VISIBLE condition_error:
|
||||
public system::system_error
|
||||
//public std::exception
|
||||
{
|
||||
typedef system::system_error base_type;
|
||||
public:
|
||||
condition_error()
|
||||
: base_type(system::error_code(0, system::system_category()), "Condition error")
|
||||
{}
|
||||
condition_error( int ev )
|
||||
: base_type(system::error_code(ev, system::system_category()), "Condition error")
|
||||
{
|
||||
}
|
||||
condition_error( int ev, const char * what_arg )
|
||||
: base_type(system::error_code(ev, system::system_category()), what_arg)
|
||||
{
|
||||
}
|
||||
condition_error( int ev, const std::string & what_arg )
|
||||
: base_type(system::error_code(ev, system::system_category()), what_arg)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
virtual const char* what() const throw();
|
||||
};
|
||||
|
||||
class BOOST_THREAD_DECL thread_resource_error : public thread_exception
|
||||
{
|
||||
public:
|
||||
thread_resource_error();
|
||||
thread_resource_error(int sys_err_code);
|
||||
~thread_resource_error() throw();
|
||||
class BOOST_SYMBOL_VISIBLE lock_error:
|
||||
public thread_exception
|
||||
{
|
||||
typedef thread_exception base_type;
|
||||
public:
|
||||
lock_error()
|
||||
: base_type(0, "boost::lock_error")
|
||||
{}
|
||||
|
||||
virtual const char* what() const throw();
|
||||
};
|
||||
lock_error( int ev )
|
||||
: base_type(ev, "boost::lock_error")
|
||||
{
|
||||
}
|
||||
lock_error( int ev, const char * what_arg )
|
||||
: base_type(ev, what_arg)
|
||||
{
|
||||
}
|
||||
lock_error( int ev, const std::string & what_arg )
|
||||
: base_type(ev, what_arg)
|
||||
{
|
||||
}
|
||||
|
||||
class BOOST_THREAD_DECL unsupported_thread_option : public thread_exception
|
||||
{
|
||||
public:
|
||||
unsupported_thread_option();
|
||||
unsupported_thread_option(int sys_err_code);
|
||||
~unsupported_thread_option() throw();
|
||||
~lock_error() throw()
|
||||
{}
|
||||
|
||||
virtual const char* what() const throw();
|
||||
};
|
||||
};
|
||||
|
||||
class BOOST_THREAD_DECL invalid_thread_argument : public thread_exception
|
||||
{
|
||||
public:
|
||||
invalid_thread_argument();
|
||||
invalid_thread_argument(int sys_err_code);
|
||||
~invalid_thread_argument() throw();
|
||||
class BOOST_SYMBOL_VISIBLE thread_resource_error:
|
||||
public thread_exception
|
||||
{
|
||||
typedef thread_exception base_type;
|
||||
public:
|
||||
thread_resource_error()
|
||||
: base_type(system::errc::resource_unavailable_try_again, "boost::thread_resource_error")
|
||||
{}
|
||||
|
||||
virtual const char* what() const throw();
|
||||
};
|
||||
thread_resource_error( int ev )
|
||||
: base_type(ev, "boost::thread_resource_error")
|
||||
{
|
||||
}
|
||||
thread_resource_error( int ev, const char * what_arg )
|
||||
: base_type(ev, what_arg)
|
||||
{
|
||||
}
|
||||
thread_resource_error( int ev, const std::string & what_arg )
|
||||
: base_type(ev, what_arg)
|
||||
{
|
||||
}
|
||||
|
||||
class BOOST_THREAD_DECL thread_permission_error : public thread_exception
|
||||
{
|
||||
public:
|
||||
thread_permission_error();
|
||||
thread_permission_error(int sys_err_code);
|
||||
~thread_permission_error() throw();
|
||||
|
||||
virtual const char* what() const throw();
|
||||
};
|
||||
~thread_resource_error() throw()
|
||||
{}
|
||||
|
||||
};
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE unsupported_thread_option:
|
||||
public thread_exception
|
||||
{
|
||||
typedef thread_exception base_type;
|
||||
public:
|
||||
unsupported_thread_option()
|
||||
: base_type(system::errc::invalid_argument, "boost::unsupported_thread_option")
|
||||
{}
|
||||
|
||||
unsupported_thread_option( int ev )
|
||||
: base_type(ev, "boost::unsupported_thread_option")
|
||||
{
|
||||
}
|
||||
unsupported_thread_option( int ev, const char * what_arg )
|
||||
: base_type(ev, what_arg)
|
||||
{
|
||||
}
|
||||
unsupported_thread_option( int ev, const std::string & what_arg )
|
||||
: base_type(ev, what_arg)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE invalid_thread_argument:
|
||||
public thread_exception
|
||||
{
|
||||
typedef thread_exception base_type;
|
||||
public:
|
||||
invalid_thread_argument()
|
||||
: base_type(system::errc::invalid_argument, "boost::invalid_thread_argument")
|
||||
{}
|
||||
|
||||
invalid_thread_argument( int ev )
|
||||
: base_type(ev, "boost::invalid_thread_argument")
|
||||
{
|
||||
}
|
||||
invalid_thread_argument( int ev, const char * what_arg )
|
||||
: base_type(ev, what_arg)
|
||||
{
|
||||
}
|
||||
invalid_thread_argument( int ev, const std::string & what_arg )
|
||||
: base_type(ev, what_arg)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE thread_permission_error:
|
||||
public thread_exception
|
||||
{
|
||||
typedef thread_exception base_type;
|
||||
public:
|
||||
thread_permission_error()
|
||||
: base_type(system::errc::permission_denied, "boost::thread_permission_error")
|
||||
{}
|
||||
|
||||
thread_permission_error( int ev )
|
||||
: base_type(ev, "boost::thread_permission_error")
|
||||
{
|
||||
}
|
||||
thread_permission_error( int ev, const char * what_arg )
|
||||
: base_type(ev, what_arg)
|
||||
{
|
||||
}
|
||||
thread_permission_error( int ev, const std::string & what_arg )
|
||||
: base_type(ev, what_arg)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif // BOOST_THREAD_CONFIG_PDM070801_H
|
||||
|
||||
// Change log:
|
||||
// 3 Jan 03 WEKEMPF Modified for DLL implementation.
|
||||
|
||||
#endif
|
||||
|
||||
1940
include/boost/thread/future.hpp
Normal file
1940
include/boost/thread/future.hpp
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@
|
||||
|
||||
// once.hpp
|
||||
//
|
||||
// (C) Copyright 2006-7 Anthony Williams
|
||||
// (C) Copyright 2006-7 Anthony Williams
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
// template<class Callable, class ...Args> void call_once(once_flag& flag, Callable func, Args&&... args);
|
||||
inline void call_once(void (*func)(),once_flag& flag)
|
||||
{
|
||||
call_once(flag,func);
|
||||
|
||||
@@ -3,53 +3,123 @@
|
||||
// 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
|
||||
// (C) Copyright 2007-10 Anthony Williams
|
||||
// (C) Copyright 2011 Vicente J. Botet Escriba
|
||||
|
||||
#include "timespec.hpp"
|
||||
#include "pthread_mutex_scoped_lock.hpp"
|
||||
#include "thread_data.hpp"
|
||||
#include "condition_variable_fwd.hpp"
|
||||
#include <boost/thread/pthread/timespec.hpp>
|
||||
#include <boost/thread/pthread/pthread_mutex_scoped_lock.hpp>
|
||||
#include <boost/thread/pthread/thread_data.hpp>
|
||||
#include <boost/thread/pthread/condition_variable_fwd.hpp>
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#include <boost/chrono/ceil.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
inline void condition_variable::wait(unique_lock<mutex>& m)
|
||||
namespace this_thread
|
||||
{
|
||||
detail::interruption_checker check_for_interruption(&cond);
|
||||
BOOST_VERIFY(!pthread_cond_wait(&cond,m.mutex()->native_handle()));
|
||||
void BOOST_THREAD_DECL interruption_point();
|
||||
}
|
||||
|
||||
inline bool condition_variable::timed_wait(unique_lock<mutex>& m,boost::system_time const& wait_until)
|
||||
namespace thread_cv_detail
|
||||
{
|
||||
detail::interruption_checker check_for_interruption(&cond);
|
||||
struct timespec const timeout=detail::get_timespec(wait_until);
|
||||
int const cond_res=pthread_cond_timedwait(&cond,m.mutex()->native_handle(),&timeout);
|
||||
template<typename MutexType>
|
||||
struct lock_on_exit
|
||||
{
|
||||
MutexType* m;
|
||||
|
||||
lock_on_exit():
|
||||
m(0)
|
||||
{}
|
||||
|
||||
void activate(MutexType& m_)
|
||||
{
|
||||
m_.unlock();
|
||||
m=&m_;
|
||||
}
|
||||
~lock_on_exit()
|
||||
{
|
||||
if(m)
|
||||
{
|
||||
m->lock();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
inline void condition_variable::wait(unique_lock<mutex>& m)
|
||||
{
|
||||
int res=0;
|
||||
{
|
||||
thread_cv_detail::lock_on_exit<unique_lock<mutex> > guard;
|
||||
detail::interruption_checker check_for_interruption(&internal_mutex,&cond);
|
||||
guard.activate(m);
|
||||
do {
|
||||
res = pthread_cond_wait(&cond,&internal_mutex);
|
||||
} while (res == EINTR);
|
||||
}
|
||||
this_thread::interruption_point();
|
||||
if(res)
|
||||
{
|
||||
boost::throw_exception(condition_error(res, "boost:: condition_variable constructor failed in pthread_cond_wait"));
|
||||
}
|
||||
}
|
||||
|
||||
inline bool condition_variable::do_timed_wait(
|
||||
unique_lock<mutex>& m,
|
||||
struct timespec const &timeout)
|
||||
{
|
||||
if (!m.owns_lock())
|
||||
boost::throw_exception(condition_error(EPERM, "condition_variable do_timed_wait: mutex not locked"));
|
||||
|
||||
thread_cv_detail::lock_on_exit<unique_lock<mutex> > guard;
|
||||
int cond_res;
|
||||
{
|
||||
detail::interruption_checker check_for_interruption(&internal_mutex,&cond);
|
||||
guard.activate(m);
|
||||
cond_res=pthread_cond_timedwait(&cond,&internal_mutex,&timeout);
|
||||
}
|
||||
this_thread::interruption_point();
|
||||
if(cond_res==ETIMEDOUT)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
BOOST_ASSERT(!cond_res);
|
||||
if(cond_res)
|
||||
{
|
||||
boost::throw_exception(condition_error(cond_res, "condition_variable failed in pthread_cond_timedwait"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void condition_variable::notify_one()
|
||||
inline void condition_variable::notify_one() BOOST_NOEXCEPT
|
||||
{
|
||||
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
|
||||
BOOST_VERIFY(!pthread_cond_signal(&cond));
|
||||
}
|
||||
|
||||
inline void condition_variable::notify_all()
|
||||
|
||||
inline void condition_variable::notify_all() BOOST_NOEXCEPT
|
||||
{
|
||||
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&cond));
|
||||
}
|
||||
|
||||
|
||||
class condition_variable_any
|
||||
{
|
||||
pthread_mutex_t internal_mutex;
|
||||
pthread_cond_t cond;
|
||||
|
||||
condition_variable_any(condition_variable&);
|
||||
condition_variable_any& operator=(condition_variable&);
|
||||
#ifndef BOOST_NO_DELETED_FUNCTIONS
|
||||
public:
|
||||
condition_variable_any(condition_variable_any const&) = delete;
|
||||
condition_variable_any& operator=(condition_variable_any const&) = delete;
|
||||
#else // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
condition_variable_any(condition_variable_any&);
|
||||
condition_variable_any& operator=(condition_variable_any&);
|
||||
#endif // BOOST_NO_DELETED_FUNCTIONS
|
||||
|
||||
public:
|
||||
condition_variable_any()
|
||||
@@ -57,13 +127,13 @@ namespace boost
|
||||
int const res=pthread_mutex_init(&internal_mutex,NULL);
|
||||
if(res)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error(res, "condition_variable_any failed in pthread_mutex_init"));
|
||||
}
|
||||
int const res2=pthread_cond_init(&cond,NULL);
|
||||
if(res2)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error(res, "condition_variable_any failed in pthread_cond_init"));
|
||||
}
|
||||
}
|
||||
~condition_variable_any()
|
||||
@@ -71,23 +141,21 @@ namespace boost
|
||||
BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
|
||||
BOOST_VERIFY(!pthread_cond_destroy(&cond));
|
||||
}
|
||||
|
||||
|
||||
template<typename lock_type>
|
||||
void wait(lock_type& m)
|
||||
{
|
||||
int res=0;
|
||||
{
|
||||
detail::interruption_checker check_for_interruption(&cond);
|
||||
{
|
||||
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
|
||||
m.unlock();
|
||||
res=pthread_cond_wait(&cond,&internal_mutex);
|
||||
}
|
||||
m.lock();
|
||||
thread_cv_detail::lock_on_exit<lock_type> guard;
|
||||
detail::interruption_checker check_for_interruption(&internal_mutex,&cond);
|
||||
guard.activate(m);
|
||||
res=pthread_cond_wait(&cond,&internal_mutex);
|
||||
}
|
||||
this_thread::interruption_point();
|
||||
if(res)
|
||||
{
|
||||
throw condition_error();
|
||||
boost::throw_exception(condition_error(res, "condition_variable_any failed in pthread_cond_wait"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,30 +164,12 @@ namespace boost
|
||||
{
|
||||
while(!pred()) wait(m);
|
||||
}
|
||||
|
||||
|
||||
template<typename lock_type>
|
||||
bool timed_wait(lock_type& m,boost::system_time const& wait_until)
|
||||
{
|
||||
struct timespec const timeout=detail::get_timespec(wait_until);
|
||||
int res=0;
|
||||
{
|
||||
detail::interruption_checker check_for_interruption(&cond);
|
||||
{
|
||||
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
|
||||
m.unlock();
|
||||
res=pthread_cond_timedwait(&cond,&internal_mutex,&timeout);
|
||||
}
|
||||
m.lock();
|
||||
}
|
||||
if(res==ETIMEDOUT)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(res)
|
||||
{
|
||||
throw condition_error();
|
||||
}
|
||||
return true;
|
||||
return do_timed_wait(m, timeout);
|
||||
}
|
||||
template<typename lock_type>
|
||||
bool timed_wait(lock_type& m,xtime const& wait_until)
|
||||
@@ -156,17 +206,134 @@ namespace boost
|
||||
return timed_wait(m,get_system_time()+wait_duration,pred);
|
||||
}
|
||||
|
||||
void notify_one()
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class lock_type,class Duration>
|
||||
cv_status
|
||||
wait_until(
|
||||
lock_type& lock,
|
||||
const chrono::time_point<chrono::system_clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
typedef time_point<system_clock, nanoseconds> nano_sys_tmpt;
|
||||
wait_until(lock,
|
||||
nano_sys_tmpt(ceil<nanoseconds>(t.time_since_epoch())));
|
||||
return system_clock::now() < t ? cv_status::no_timeout :
|
||||
cv_status::timeout;
|
||||
}
|
||||
|
||||
template <class lock_type, class Clock, class Duration>
|
||||
cv_status
|
||||
wait_until(
|
||||
lock_type& lock,
|
||||
const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
system_clock::time_point s_now = system_clock::now();
|
||||
typename Clock::time_point c_now = Clock::now();
|
||||
wait_until(lock, s_now + ceil<nanoseconds>(t - c_now));
|
||||
return Clock::now() < t ? cv_status::no_timeout : cv_status::timeout;
|
||||
}
|
||||
|
||||
template <class lock_type, class Clock, class Duration, class Predicate>
|
||||
bool
|
||||
wait_until(
|
||||
lock_type& lock,
|
||||
const chrono::time_point<Clock, Duration>& t,
|
||||
Predicate pred)
|
||||
{
|
||||
while (!pred())
|
||||
{
|
||||
if (wait_until(lock, t) == cv_status::timeout)
|
||||
return pred();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class lock_type, class Rep, class Period>
|
||||
cv_status
|
||||
wait_for(
|
||||
lock_type& lock,
|
||||
const chrono::duration<Rep, Period>& d)
|
||||
{
|
||||
using namespace chrono;
|
||||
system_clock::time_point s_now = system_clock::now();
|
||||
steady_clock::time_point c_now = steady_clock::now();
|
||||
wait_until(lock, s_now + ceil<nanoseconds>(d));
|
||||
return steady_clock::now() - c_now < d ? cv_status::no_timeout :
|
||||
cv_status::timeout;
|
||||
|
||||
}
|
||||
|
||||
|
||||
template <class lock_type, class Rep, class Period, class Predicate>
|
||||
bool
|
||||
wait_for(
|
||||
lock_type& lock,
|
||||
const chrono::duration<Rep, Period>& d,
|
||||
Predicate pred)
|
||||
{
|
||||
while (!pred())
|
||||
{
|
||||
if (wait_for(lock, d) == cv_status::timeout)
|
||||
return pred();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class lock_type>
|
||||
inline void wait_until(
|
||||
lock_type& lk,
|
||||
chrono::time_point<chrono::system_clock, chrono::nanoseconds> tp)
|
||||
{
|
||||
using namespace chrono;
|
||||
nanoseconds d = tp.time_since_epoch();
|
||||
timespec ts;
|
||||
seconds s = duration_cast<seconds>(d);
|
||||
ts.tv_sec = static_cast<long>(s.count());
|
||||
ts.tv_nsec = static_cast<long>((d - s).count());
|
||||
do_timed_wait(lk, ts);
|
||||
}
|
||||
#endif
|
||||
|
||||
void notify_one() BOOST_NOEXCEPT
|
||||
{
|
||||
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
|
||||
BOOST_VERIFY(!pthread_cond_signal(&cond));
|
||||
}
|
||||
|
||||
void notify_all()
|
||||
|
||||
void notify_all() BOOST_NOEXCEPT
|
||||
{
|
||||
boost::pthread::pthread_mutex_scoped_lock internal_lock(&internal_mutex);
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&cond));
|
||||
}
|
||||
private: // used by boost::thread::try_join_until
|
||||
|
||||
template <class lock_type>
|
||||
inline bool do_timed_wait(
|
||||
lock_type& m,
|
||||
struct timespec const &timeout)
|
||||
{
|
||||
int res=0;
|
||||
{
|
||||
thread_cv_detail::lock_on_exit<lock_type> guard;
|
||||
detail::interruption_checker check_for_interruption(&internal_mutex,&cond);
|
||||
guard.activate(m);
|
||||
res=pthread_cond_timedwait(&cond,&internal_mutex,&timeout);
|
||||
}
|
||||
this_thread::interruption_point();
|
||||
if(res==ETIMEDOUT)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(res)
|
||||
{
|
||||
boost::throw_exception(condition_error(res, "condition_variable_any failed in pthread_cond_timedwait"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -4,38 +4,65 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
// (C) Copyright 2007-8 Anthony Williams
|
||||
// (C) Copyright 2011 Vicente J. Botet Escriba
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <pthread.h>
|
||||
#include <boost/thread/cv_status.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/thread_time.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#include <boost/chrono/ceil.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
class condition_variable
|
||||
{
|
||||
private:
|
||||
pthread_mutex_t internal_mutex;
|
||||
pthread_cond_t cond;
|
||||
|
||||
condition_variable(condition_variable&);
|
||||
condition_variable& operator=(condition_variable&);
|
||||
|
||||
#ifndef BOOST_NO_DELETED_FUNCTIONS
|
||||
public:
|
||||
condition_variable(condition_variable const&) = delete;
|
||||
condition_variable& operator=(condition_variable const&) = delete;
|
||||
#else // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
condition_variable(condition_variable const&);
|
||||
condition_variable& operator=(condition_variable const&);
|
||||
#endif // BOOST_NO_DELETED_FUNCTIONS
|
||||
|
||||
public:
|
||||
condition_variable()
|
||||
{
|
||||
int const res=pthread_cond_init(&cond,NULL);
|
||||
int const res=pthread_mutex_init(&internal_mutex,NULL);
|
||||
if(res)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error(res, "boost:: condition_variable constructor failed in pthread_mutex_init"));
|
||||
}
|
||||
int const res2=pthread_cond_init(&cond,NULL);
|
||||
if(res2)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
|
||||
boost::throw_exception(thread_resource_error(res2, "boost:: condition_variable constructor failed in pthread_cond_init"));
|
||||
}
|
||||
}
|
||||
~condition_variable()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_cond_destroy(&cond));
|
||||
BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
|
||||
int ret;
|
||||
do {
|
||||
ret = pthread_cond_destroy(&cond);
|
||||
} while (ret == EINTR);
|
||||
BOOST_VERIFY(!ret);
|
||||
}
|
||||
|
||||
void wait(unique_lock<mutex>& m);
|
||||
@@ -46,20 +73,32 @@ namespace boost
|
||||
while(!pred()) wait(m);
|
||||
}
|
||||
|
||||
bool timed_wait(unique_lock<mutex>& m,boost::system_time const& wait_until);
|
||||
bool timed_wait(unique_lock<mutex>& m,xtime const& wait_until)
|
||||
inline bool timed_wait(
|
||||
unique_lock<mutex>& m,
|
||||
boost::system_time const& wait_until)
|
||||
{
|
||||
struct timespec const timeout=detail::get_timespec(wait_until);
|
||||
return do_timed_wait(m, timeout);
|
||||
}
|
||||
bool timed_wait(
|
||||
unique_lock<mutex>& m,
|
||||
xtime const& wait_until)
|
||||
{
|
||||
return timed_wait(m,system_time(wait_until));
|
||||
}
|
||||
|
||||
template<typename duration_type>
|
||||
bool timed_wait(unique_lock<mutex>& m,duration_type const& wait_duration)
|
||||
bool timed_wait(
|
||||
unique_lock<mutex>& m,
|
||||
duration_type const& wait_duration)
|
||||
{
|
||||
return timed_wait(m,get_system_time()+wait_duration);
|
||||
}
|
||||
|
||||
template<typename predicate_type>
|
||||
bool timed_wait(unique_lock<mutex>& m,boost::system_time const& wait_until,predicate_type pred)
|
||||
bool timed_wait(
|
||||
unique_lock<mutex>& m,
|
||||
boost::system_time const& wait_until,predicate_type pred)
|
||||
{
|
||||
while (!pred())
|
||||
{
|
||||
@@ -70,25 +109,127 @@ namespace boost
|
||||
}
|
||||
|
||||
template<typename predicate_type>
|
||||
bool timed_wait(unique_lock<mutex>& m,xtime const& wait_until,predicate_type pred)
|
||||
bool timed_wait(
|
||||
unique_lock<mutex>& m,
|
||||
xtime const& wait_until,predicate_type pred)
|
||||
{
|
||||
return timed_wait(m,system_time(wait_until),pred);
|
||||
}
|
||||
|
||||
template<typename duration_type,typename predicate_type>
|
||||
bool timed_wait(unique_lock<mutex>& m,duration_type const& wait_duration,predicate_type pred)
|
||||
bool timed_wait(
|
||||
unique_lock<mutex>& m,
|
||||
duration_type const& wait_duration,predicate_type pred)
|
||||
{
|
||||
return timed_wait(m,get_system_time()+wait_duration,pred);
|
||||
}
|
||||
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
|
||||
template <class Duration>
|
||||
cv_status
|
||||
wait_until(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::time_point<chrono::system_clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
typedef time_point<system_clock, nanoseconds> nano_sys_tmpt;
|
||||
wait_until(lock,
|
||||
nano_sys_tmpt(ceil<nanoseconds>(t.time_since_epoch())));
|
||||
return system_clock::now() < t ? cv_status::no_timeout :
|
||||
cv_status::timeout;
|
||||
}
|
||||
|
||||
template <class Clock, class Duration>
|
||||
cv_status
|
||||
wait_until(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
system_clock::time_point s_now = system_clock::now();
|
||||
typename Clock::time_point c_now = Clock::now();
|
||||
wait_until(lock, s_now + ceil<nanoseconds>(t - c_now));
|
||||
return Clock::now() < t ? cv_status::no_timeout : cv_status::timeout;
|
||||
}
|
||||
|
||||
template <class Clock, class Duration, class Predicate>
|
||||
bool
|
||||
wait_until(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::time_point<Clock, Duration>& t,
|
||||
Predicate pred)
|
||||
{
|
||||
while (!pred())
|
||||
{
|
||||
if (wait_until(lock, t) == cv_status::timeout)
|
||||
return pred();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <class Rep, class Period>
|
||||
cv_status
|
||||
wait_for(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::duration<Rep, Period>& d)
|
||||
{
|
||||
using namespace chrono;
|
||||
system_clock::time_point s_now = system_clock::now();
|
||||
steady_clock::time_point c_now = steady_clock::now();
|
||||
wait_until(lock, s_now + ceil<nanoseconds>(d));
|
||||
return steady_clock::now() - c_now < d ? cv_status::no_timeout :
|
||||
cv_status::timeout;
|
||||
|
||||
}
|
||||
|
||||
|
||||
template <class Rep, class Period, class Predicate>
|
||||
bool
|
||||
wait_for(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::duration<Rep, Period>& d,
|
||||
Predicate pred)
|
||||
{
|
||||
while (!pred())
|
||||
{
|
||||
if (wait_for(lock, d) == cv_status::timeout)
|
||||
return pred();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define BOOST_THREAD_DEFINES_CONDITION_VARIABLE_NATIVE_HANDLE
|
||||
typedef pthread_cond_t* native_handle_type;
|
||||
native_handle_type native_handle()
|
||||
{
|
||||
return &cond;
|
||||
}
|
||||
|
||||
void notify_one();
|
||||
void notify_all();
|
||||
void notify_one() BOOST_NOEXCEPT;
|
||||
void notify_all() BOOST_NOEXCEPT;
|
||||
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
inline void wait_until(
|
||||
unique_lock<mutex>& lk,
|
||||
chrono::time_point<chrono::system_clock, chrono::nanoseconds> tp)
|
||||
{
|
||||
using namespace chrono;
|
||||
nanoseconds d = tp.time_since_epoch();
|
||||
timespec ts;
|
||||
seconds s = duration_cast<seconds>(d);
|
||||
ts.tv_sec = static_cast<long>(s.count());
|
||||
ts.tv_nsec = static_cast<long>((d - s).count());
|
||||
do_timed_wait(lk, ts);
|
||||
}
|
||||
#endif
|
||||
//private: // used by boost::thread::try_join_until
|
||||
|
||||
inline bool do_timed_wait(
|
||||
unique_lock<mutex>& lock,
|
||||
struct timespec const &timeout);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,29 @@
|
||||
#ifndef BOOST_THREAD_PTHREAD_MUTEX_HPP
|
||||
#define BOOST_THREAD_PTHREAD_MUTEX_HPP
|
||||
// (C) Copyright 2007-8 Anthony Williams
|
||||
// (C) Copyright 2011-2012 Vicente J. Botet Escriba
|
||||
// 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 <pthread.h>
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/thread/exceptions.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/thread_time.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <errno.h>
|
||||
#include "timespec.hpp"
|
||||
#include "pthread_mutex_scoped_lock.hpp"
|
||||
#include <boost/thread/pthread/timespec.hpp>
|
||||
#include <boost/thread/pthread/pthread_mutex_scoped_lock.hpp>
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#include <boost/chrono/ceil.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef _POSIX_TIMEOUTS
|
||||
#if _POSIX_TIMEOUTS >= 0
|
||||
#if _POSIX_TIMEOUTS >= 0 && _POSIX_C_SOURCE>=200112L
|
||||
#define BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
#endif
|
||||
#endif
|
||||
@@ -26,9 +32,17 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class mutex:
|
||||
boost::noncopyable
|
||||
class mutex
|
||||
{
|
||||
#ifndef BOOST_NO_DELETED_FUNCTIONS
|
||||
public:
|
||||
mutex(mutex const&) = delete;
|
||||
mutex& operator=(mutex const&) = delete;
|
||||
#else // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
mutex(mutex const&);
|
||||
mutex& operator=(mutex const&);
|
||||
#endif // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
pthread_mutex_t m;
|
||||
public:
|
||||
@@ -37,31 +51,61 @@ namespace boost
|
||||
int const res=pthread_mutex_init(&m,NULL);
|
||||
if(res)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error(res, "boost:: mutex constructor failed in pthread_mutex_init"));
|
||||
}
|
||||
}
|
||||
~mutex()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_destroy(&m));
|
||||
int ret;
|
||||
do
|
||||
{
|
||||
ret = pthread_mutex_destroy(&m);
|
||||
} while (ret == EINTR);
|
||||
}
|
||||
|
||||
|
||||
void lock()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_lock(&m));
|
||||
int res;
|
||||
do
|
||||
{
|
||||
res = pthread_mutex_lock(&m);
|
||||
} while (res == EINTR);
|
||||
if (res)
|
||||
{
|
||||
boost::throw_exception(lock_error(res,"boost: mutex lock failed in pthread_mutex_lock"));
|
||||
}
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_unlock(&m));
|
||||
int ret;
|
||||
do
|
||||
{
|
||||
ret = pthread_mutex_unlock(&m);
|
||||
} while (ret == EINTR);
|
||||
BOOST_VERIFY(!ret);
|
||||
}
|
||||
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
int const res=pthread_mutex_trylock(&m);
|
||||
BOOST_ASSERT(!res || res==EBUSY);
|
||||
int res;
|
||||
do
|
||||
{
|
||||
res = pthread_mutex_trylock(&m);
|
||||
} while (res == EINTR);
|
||||
if(res && (res!=EBUSY))
|
||||
{
|
||||
// The following throw_exception has been replaced by an assertion and just return false,
|
||||
// as this is an internal error and the user can do nothing with the exception.
|
||||
//boost::throw_exception(lock_error(res,"boost: mutex try_lock failed in pthread_mutex_trylock"));
|
||||
BOOST_ASSERT_MSG(false ,"boost: mutex try_lock failed in pthread_mutex_trylock");
|
||||
return false;
|
||||
}
|
||||
|
||||
return !res;
|
||||
}
|
||||
|
||||
#define BOOST_THREAD_DEFINES_MUTEX_NATIVE_HANDLE
|
||||
typedef pthread_mutex_t* native_handle_type;
|
||||
native_handle_type native_handle()
|
||||
{
|
||||
@@ -74,9 +118,18 @@ namespace boost
|
||||
|
||||
typedef mutex try_mutex;
|
||||
|
||||
class timed_mutex:
|
||||
boost::noncopyable
|
||||
class timed_mutex
|
||||
{
|
||||
#ifndef BOOST_NO_DELETED_FUNCTIONS
|
||||
public:
|
||||
timed_mutex(timed_mutex const&) = delete;
|
||||
timed_mutex& operator=(timed_mutex const&) = delete;
|
||||
#else // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
timed_mutex(timed_mutex const&);
|
||||
timed_mutex& operator=(timed_mutex const&);
|
||||
public:
|
||||
#endif // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
pthread_mutex_t m;
|
||||
#ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
@@ -89,14 +142,14 @@ namespace boost
|
||||
int const res=pthread_mutex_init(&m,NULL);
|
||||
if(res)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error(res, "boost:: timed_mutex constructor failed in pthread_mutex_init"));
|
||||
}
|
||||
#ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
int const res2=pthread_cond_init(&cond,NULL);
|
||||
if(res2)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_destroy(&m));
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error(res2, "boost:: timed_mutex constructor failed in pthread_cond_init"));
|
||||
}
|
||||
is_locked=false;
|
||||
#endif
|
||||
@@ -129,26 +182,23 @@ namespace boost
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_unlock(&m));
|
||||
}
|
||||
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
int const res=pthread_mutex_trylock(&m);
|
||||
BOOST_ASSERT(!res || res==EBUSY);
|
||||
return !res;
|
||||
}
|
||||
bool timed_lock(system_time const & abs_time)
|
||||
{
|
||||
struct timespec const timeout=detail::get_timespec(abs_time);
|
||||
int const res=pthread_mutex_timedlock(&m,&timeout);
|
||||
BOOST_ASSERT(!res || res==ETIMEDOUT);
|
||||
return !res;
|
||||
}
|
||||
|
||||
typedef pthread_mutex_t* native_handle_type;
|
||||
native_handle_type native_handle()
|
||||
|
||||
private:
|
||||
bool do_try_lock_until(struct timespec const &timeout)
|
||||
{
|
||||
return &m;
|
||||
int const res=pthread_mutex_timedlock(&m,&timeout);
|
||||
BOOST_ASSERT(!res || res==ETIMEDOUT);
|
||||
return !res;
|
||||
}
|
||||
public:
|
||||
|
||||
#else
|
||||
void lock()
|
||||
@@ -167,7 +217,7 @@ namespace boost
|
||||
is_locked=false;
|
||||
BOOST_VERIFY(!pthread_cond_signal(&cond));
|
||||
}
|
||||
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
|
||||
@@ -179,9 +229,9 @@ namespace boost
|
||||
return true;
|
||||
}
|
||||
|
||||
bool timed_lock(system_time const & abs_time)
|
||||
private:
|
||||
bool do_try_lock_until(struct timespec const &timeout)
|
||||
{
|
||||
struct timespec const timeout=detail::get_timespec(abs_time);
|
||||
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
|
||||
while(is_locked)
|
||||
{
|
||||
@@ -195,8 +245,55 @@ namespace boost
|
||||
is_locked=true;
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
#endif
|
||||
|
||||
bool timed_lock(system_time const & abs_time)
|
||||
{
|
||||
struct timespec const ts=detail::get_timespec(abs_time);
|
||||
return do_try_lock_until(ts);
|
||||
}
|
||||
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
return try_lock_until(chrono::steady_clock::now() + rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
system_clock::time_point s_now = system_clock::now();
|
||||
typename Clock::time_point c_now = Clock::now();
|
||||
return try_lock_until(s_now + ceil<nanoseconds>(t - c_now));
|
||||
}
|
||||
template <class Duration>
|
||||
bool try_lock_until(const chrono::time_point<chrono::system_clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
typedef time_point<system_clock, nanoseconds> nano_sys_tmpt;
|
||||
return try_lock_until(nano_sys_tmpt(ceil<nanoseconds>(t.time_since_epoch())));
|
||||
}
|
||||
bool try_lock_until(const chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp)
|
||||
{
|
||||
using namespace chrono;
|
||||
nanoseconds d = tp.time_since_epoch();
|
||||
timespec ts;
|
||||
seconds s = duration_cast<seconds>(d);
|
||||
ts.tv_sec = static_cast<long>(s.count());
|
||||
ts.tv_nsec = static_cast<long>((d - s).count());
|
||||
return do_try_lock_until(ts);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define BOOST_THREAD_DEFINES_TIMED_MUTEX_NATIVE_HANDLE
|
||||
typedef pthread_mutex_t* native_handle_type;
|
||||
native_handle_type native_handle()
|
||||
{
|
||||
return &m;
|
||||
}
|
||||
|
||||
typedef unique_lock<timed_mutex> scoped_timed_lock;
|
||||
typedef detail::try_lock_wrapper<timed_mutex> scoped_try_lock;
|
||||
typedef scoped_timed_lock scoped_lock;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
// once.hpp
|
||||
//
|
||||
// (C) Copyright 2007-8 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
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
#include <pthread.h>
|
||||
#include <boost/assert.hpp>
|
||||
#include "pthread_mutex_scoped_lock.hpp"
|
||||
#include <boost/thread/pthread/pthread_mutex_scoped_lock.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
@@ -22,11 +21,39 @@
|
||||
namespace boost
|
||||
{
|
||||
|
||||
#if BOOST_THREAD_VERSION==3
|
||||
|
||||
struct once_flag
|
||||
{
|
||||
BOOST_CONSTEXPR once_flag() BOOST_NOEXCEPT
|
||||
: epoch(0)
|
||||
{}
|
||||
#ifndef BOOST_NO_DELETED_FUNCTIONS
|
||||
once_flag(const once_flag&) = delete;
|
||||
once_flag& operator=(const once_flag&) = delete;
|
||||
#else // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
once_flag(const once_flag&);
|
||||
once_flag& operator=(const once_flag&);
|
||||
public:
|
||||
#endif // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
boost::uintmax_t epoch;
|
||||
|
||||
};
|
||||
|
||||
#else // BOOST_THREAD_VERSION==3
|
||||
|
||||
struct once_flag
|
||||
{
|
||||
boost::uintmax_t epoch;
|
||||
};
|
||||
|
||||
#define BOOST_ONCE_INITIAL_FLAG_VALUE 0
|
||||
#define BOOST_ONCE_INIT {BOOST_ONCE_INITIAL_FLAG_VALUE}
|
||||
|
||||
#endif // BOOST_THREAD_VERSION==3
|
||||
|
||||
namespace detail
|
||||
{
|
||||
BOOST_THREAD_DECL boost::uintmax_t& get_once_per_thread_epoch();
|
||||
@@ -34,10 +61,6 @@ namespace boost
|
||||
BOOST_THREAD_DECL extern pthread_mutex_t once_epoch_mutex;
|
||||
BOOST_THREAD_DECL extern pthread_cond_t once_epoch_cv;
|
||||
}
|
||||
|
||||
#define BOOST_ONCE_INITIAL_FLAG_VALUE 0
|
||||
#define BOOST_ONCE_INIT {BOOST_ONCE_INITIAL_FLAG_VALUE}
|
||||
|
||||
|
||||
// Based on Mike Burrows fast_pthread_once algorithm as described in
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2444.html
|
||||
@@ -48,7 +71,7 @@ namespace boost
|
||||
static boost::uintmax_t const being_initialized=uninitialized_flag+1;
|
||||
boost::uintmax_t const epoch=flag.epoch;
|
||||
boost::uintmax_t& this_thread_epoch=detail::get_once_per_thread_epoch();
|
||||
|
||||
|
||||
if(epoch<this_thread_epoch)
|
||||
{
|
||||
pthread::pthread_mutex_scoped_lock lk(&detail::once_epoch_mutex);
|
||||
@@ -58,10 +81,13 @@ namespace boost
|
||||
if(flag.epoch==uninitialized_flag)
|
||||
{
|
||||
flag.epoch=being_initialized;
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try
|
||||
{
|
||||
#endif
|
||||
pthread::pthread_mutex_scoped_unlock relocker(&detail::once_epoch_mutex);
|
||||
f();
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
@@ -69,6 +95,7 @@ namespace boost
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&detail::once_epoch_cv));
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
flag.epoch=--detail::once_global_epoch;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&detail::once_epoch_cv));
|
||||
}
|
||||
|
||||
@@ -18,15 +18,25 @@ namespace boost
|
||||
class pthread_mutex_scoped_lock
|
||||
{
|
||||
pthread_mutex_t* m;
|
||||
bool locked;
|
||||
public:
|
||||
explicit pthread_mutex_scoped_lock(pthread_mutex_t* m_):
|
||||
m(m_)
|
||||
m(m_),locked(true)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_lock(m));
|
||||
}
|
||||
~pthread_mutex_scoped_lock()
|
||||
void unlock()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_unlock(m));
|
||||
locked=false;
|
||||
}
|
||||
|
||||
~pthread_mutex_scoped_lock()
|
||||
{
|
||||
if(locked)
|
||||
{
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <pthread.h>
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/thread/exceptions.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/thread_time.hpp>
|
||||
@@ -16,8 +17,12 @@
|
||||
#endif
|
||||
#include <boost/date_time/posix_time/conversion.hpp>
|
||||
#include <errno.h>
|
||||
#include "timespec.hpp"
|
||||
#include "pthread_mutex_scoped_lock.hpp"
|
||||
#include <boost/thread/pthread/timespec.hpp>
|
||||
#include <boost/thread/pthread/pthread_mutex_scoped_lock.hpp>
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#include <boost/chrono/ceil.hpp>
|
||||
#endif
|
||||
|
||||
#ifdef _POSIX_TIMEOUTS
|
||||
#if _POSIX_TIMEOUTS >= 0
|
||||
@@ -25,138 +30,83 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE) && defined(BOOST_PTHREAD_HAS_TIMEDLOCK)
|
||||
#define BOOST_USE_PTHREAD_RECURSIVE_TIMEDLOCK
|
||||
#endif
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class recursive_mutex:
|
||||
boost::noncopyable
|
||||
class recursive_mutex
|
||||
{
|
||||
private:
|
||||
pthread_mutex_t m;
|
||||
#ifndef BOOST_NO_DELETED_FUNCTIONS
|
||||
public:
|
||||
recursive_mutex()
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
int const init_attr_res=pthread_mutexattr_init(&attr);
|
||||
if(init_attr_res)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
}
|
||||
int const set_attr_res=pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
|
||||
if(set_attr_res)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
}
|
||||
|
||||
int const res=pthread_mutex_init(&m,&attr);
|
||||
if(res)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
}
|
||||
BOOST_VERIFY(!pthread_mutexattr_destroy(&attr));
|
||||
}
|
||||
~recursive_mutex()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_destroy(&m));
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_lock(&m));
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_unlock(&m));
|
||||
}
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
int const res=pthread_mutex_trylock(&m);
|
||||
BOOST_ASSERT(!res || res==EBUSY);
|
||||
return !res;
|
||||
}
|
||||
|
||||
typedef pthread_mutex_t* native_handle_type;
|
||||
native_handle_type native_handle()
|
||||
{
|
||||
return &m;
|
||||
}
|
||||
|
||||
typedef unique_lock<recursive_mutex> scoped_lock;
|
||||
typedef detail::try_lock_wrapper<recursive_mutex> scoped_try_lock;
|
||||
};
|
||||
|
||||
typedef recursive_mutex recursive_try_mutex;
|
||||
|
||||
class recursive_timed_mutex:
|
||||
boost::noncopyable
|
||||
{
|
||||
recursive_mutex(recursive_mutex const&) = delete;
|
||||
recursive_mutex& operator=(recursive_mutex const&) = delete;
|
||||
#else // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
recursive_mutex(recursive_mutex const&);
|
||||
recursive_mutex& operator=(recursive_mutex const&);
|
||||
#endif // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
pthread_mutex_t m;
|
||||
#ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
#ifndef BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE
|
||||
pthread_cond_t cond;
|
||||
bool is_locked;
|
||||
pthread_t owner;
|
||||
unsigned count;
|
||||
#endif
|
||||
public:
|
||||
recursive_timed_mutex()
|
||||
recursive_mutex()
|
||||
{
|
||||
#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
#ifdef BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
|
||||
int const init_attr_res=pthread_mutexattr_init(&attr);
|
||||
if(init_attr_res)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error(init_attr_res, "boost:: recursive_mutex constructor failed in pthread_mutexattr_init"));
|
||||
}
|
||||
int const set_attr_res=pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
|
||||
if(set_attr_res)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
BOOST_VERIFY(!pthread_mutexattr_destroy(&attr));
|
||||
boost::throw_exception(thread_resource_error(set_attr_res, "boost:: recursive_mutex constructor failed in pthread_mutexattr_settype"));
|
||||
}
|
||||
|
||||
|
||||
int const res=pthread_mutex_init(&m,&attr);
|
||||
if(res)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutexattr_destroy(&attr));
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error(res, "boost:: recursive_mutex constructor failed in pthread_mutex_init"));
|
||||
}
|
||||
BOOST_VERIFY(!pthread_mutexattr_destroy(&attr));
|
||||
#else
|
||||
int const res=pthread_mutex_init(&m,NULL);
|
||||
if(res)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error(res, "boost:: recursive_mutex constructor failed in pthread_mutex_init"));
|
||||
}
|
||||
int const res2=pthread_cond_init(&cond,NULL);
|
||||
if(res2)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_destroy(&m));
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error(res2, "boost:: recursive_mutex constructor failed in pthread_cond_init"));
|
||||
}
|
||||
is_locked=false;
|
||||
count=0;
|
||||
#endif
|
||||
}
|
||||
~recursive_timed_mutex()
|
||||
~recursive_mutex()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_destroy(&m));
|
||||
#ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
#ifndef BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE
|
||||
BOOST_VERIFY(!pthread_cond_destroy(&cond));
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename TimeDuration>
|
||||
bool timed_lock(TimeDuration const & relative_time)
|
||||
{
|
||||
return timed_lock(get_system_time()+relative_time);
|
||||
}
|
||||
|
||||
#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
#ifdef BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE
|
||||
void lock()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_lock(&m));
|
||||
@@ -166,21 +116,14 @@ namespace boost
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_unlock(&m));
|
||||
}
|
||||
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
int const res=pthread_mutex_trylock(&m);
|
||||
BOOST_ASSERT(!res || res==EBUSY);
|
||||
return !res;
|
||||
}
|
||||
bool timed_lock(system_time const & abs_time)
|
||||
{
|
||||
struct timespec const timeout=detail::get_timespec(abs_time);
|
||||
int const res=pthread_mutex_timedlock(&m,&timeout);
|
||||
BOOST_ASSERT(!res || res==EBUSY);
|
||||
return !res;
|
||||
}
|
||||
|
||||
#define BOOST_THREAD_DEFINES_RECURSIVE_MUTEX_NATIVE_HANDLE
|
||||
typedef pthread_mutex_t* native_handle_type;
|
||||
native_handle_type native_handle()
|
||||
{
|
||||
@@ -196,7 +139,7 @@ namespace boost
|
||||
++count;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
while(is_locked)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_cond_wait(&cond,&m));
|
||||
@@ -215,7 +158,7 @@ namespace boost
|
||||
}
|
||||
BOOST_VERIFY(!pthread_cond_signal(&cond));
|
||||
}
|
||||
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
|
||||
@@ -229,9 +172,159 @@ namespace boost
|
||||
return true;
|
||||
}
|
||||
|
||||
bool timed_lock(system_time const & abs_time)
|
||||
#endif
|
||||
|
||||
typedef unique_lock<recursive_mutex> scoped_lock;
|
||||
typedef detail::try_lock_wrapper<recursive_mutex> scoped_try_lock;
|
||||
};
|
||||
|
||||
typedef recursive_mutex recursive_try_mutex;
|
||||
|
||||
class recursive_timed_mutex
|
||||
{
|
||||
#ifndef BOOST_NO_DELETED_FUNCTIONS
|
||||
public:
|
||||
recursive_timed_mutex(recursive_timed_mutex const&) = delete;
|
||||
recursive_timed_mutex& operator=(recursive_timed_mutex const&) = delete;
|
||||
#else // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
recursive_timed_mutex(recursive_timed_mutex const&);
|
||||
recursive_timed_mutex& operator=(recursive_timed_mutex const&);
|
||||
#endif // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
pthread_mutex_t m;
|
||||
#ifndef BOOST_USE_PTHREAD_RECURSIVE_TIMEDLOCK
|
||||
pthread_cond_t cond;
|
||||
bool is_locked;
|
||||
pthread_t owner;
|
||||
unsigned count;
|
||||
#endif
|
||||
public:
|
||||
recursive_timed_mutex()
|
||||
{
|
||||
#ifdef BOOST_USE_PTHREAD_RECURSIVE_TIMEDLOCK
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
int const init_attr_res=pthread_mutexattr_init(&attr);
|
||||
if(init_attr_res)
|
||||
{
|
||||
boost::throw_exception(thread_resource_error(init_attr_res, "boost:: recursive_timed_mutex constructor failed in pthread_mutexattr_init"));
|
||||
}
|
||||
int const set_attr_res=pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
|
||||
if(set_attr_res)
|
||||
{
|
||||
boost::throw_exception(thread_resource_error(set_attr_res, "boost:: recursive_timed_mutex constructor failed in pthread_mutexattr_settype"));
|
||||
}
|
||||
|
||||
int const res=pthread_mutex_init(&m,&attr);
|
||||
if(res)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutexattr_destroy(&attr));
|
||||
boost::throw_exception(thread_resource_error(res, "boost:: recursive_timed_mutex constructor failed in pthread_mutex_init"));
|
||||
}
|
||||
BOOST_VERIFY(!pthread_mutexattr_destroy(&attr));
|
||||
#else
|
||||
int const res=pthread_mutex_init(&m,NULL);
|
||||
if(res)
|
||||
{
|
||||
boost::throw_exception(thread_resource_error(res, "boost:: recursive_timed_mutex constructor failed in pthread_mutex_init"));
|
||||
}
|
||||
int const res2=pthread_cond_init(&cond,NULL);
|
||||
if(res2)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_destroy(&m));
|
||||
boost::throw_exception(thread_resource_error(res2, "boost:: recursive_timed_mutex constructor failed in pthread_cond_init"));
|
||||
}
|
||||
is_locked=false;
|
||||
count=0;
|
||||
#endif
|
||||
}
|
||||
~recursive_timed_mutex()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_destroy(&m));
|
||||
#ifndef BOOST_USE_PTHREAD_RECURSIVE_TIMEDLOCK
|
||||
BOOST_VERIFY(!pthread_cond_destroy(&cond));
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename TimeDuration>
|
||||
bool timed_lock(TimeDuration const & relative_time)
|
||||
{
|
||||
return timed_lock(get_system_time()+relative_time);
|
||||
}
|
||||
|
||||
#ifdef BOOST_USE_PTHREAD_RECURSIVE_TIMEDLOCK
|
||||
void lock()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_lock(&m));
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_unlock(&m));
|
||||
}
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
int const res=pthread_mutex_trylock(&m);
|
||||
BOOST_ASSERT(!res || res==EBUSY);
|
||||
return !res;
|
||||
}
|
||||
private:
|
||||
bool do_try_lock_until(struct timespec const &timeout)
|
||||
{
|
||||
int const res=pthread_mutex_timedlock(&m,&timeout);
|
||||
BOOST_ASSERT(!res || res==ETIMEDOUT);
|
||||
return !res;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
#else
|
||||
void lock()
|
||||
{
|
||||
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
|
||||
if(is_locked && pthread_equal(owner,pthread_self()))
|
||||
{
|
||||
++count;
|
||||
return;
|
||||
}
|
||||
|
||||
while(is_locked)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_cond_wait(&cond,&m));
|
||||
}
|
||||
is_locked=true;
|
||||
++count;
|
||||
owner=pthread_self();
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
|
||||
if(!--count)
|
||||
{
|
||||
is_locked=false;
|
||||
}
|
||||
BOOST_VERIFY(!pthread_cond_signal(&cond));
|
||||
}
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
|
||||
if(is_locked && !pthread_equal(owner,pthread_self()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
is_locked=true;
|
||||
++count;
|
||||
owner=pthread_self();
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
bool do_try_lock_until(struct timespec const &timeout)
|
||||
{
|
||||
struct timespec const timeout=detail::get_timespec(abs_time);
|
||||
boost::pthread::pthread_mutex_scoped_lock const local_lock(&m);
|
||||
if(is_locked && pthread_equal(owner,pthread_self()))
|
||||
{
|
||||
@@ -252,8 +345,56 @@ namespace boost
|
||||
owner=pthread_self();
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
|
||||
#endif
|
||||
|
||||
bool timed_lock(system_time const & abs_time)
|
||||
{
|
||||
struct timespec const ts=detail::get_timespec(abs_time);
|
||||
return do_try_lock_until(ts);
|
||||
}
|
||||
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
return try_lock_until(chrono::steady_clock::now() + rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
system_clock::time_point s_now = system_clock::now();
|
||||
typename Clock::time_point c_now = Clock::now();
|
||||
return try_lock_until(s_now + ceil<nanoseconds>(t - c_now));
|
||||
}
|
||||
template <class Duration>
|
||||
bool try_lock_until(const chrono::time_point<chrono::system_clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
typedef time_point<system_clock, nanoseconds> nano_sys_tmpt;
|
||||
return try_lock_until(nano_sys_tmpt(ceil<nanoseconds>(t.time_since_epoch())));
|
||||
}
|
||||
bool try_lock_until(const chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp)
|
||||
{
|
||||
using namespace chrono;
|
||||
nanoseconds d = tp.time_since_epoch();
|
||||
timespec ts;
|
||||
seconds s = duration_cast<seconds>(d);
|
||||
ts.tv_sec = static_cast<long>(s.count());
|
||||
ts.tv_nsec = static_cast<long>((d - s).count());
|
||||
return do_try_lock_until(ts);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define BOOST_THREAD_DEFINES_RECURSIVE_TIMED_MUTEX_NATIVE_HANDLE
|
||||
typedef pthread_mutex_t* native_handle_type;
|
||||
native_handle_type native_handle()
|
||||
{
|
||||
return &m;
|
||||
}
|
||||
|
||||
typedef unique_lock<recursive_timed_mutex> scoped_timed_lock;
|
||||
typedef detail::try_lock_wrapper<recursive_timed_mutex> scoped_try_lock;
|
||||
typedef scoped_timed_lock scoped_lock;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define BOOST_THREAD_PTHREAD_SHARED_MUTEX_HPP
|
||||
|
||||
// (C) Copyright 2006-8 Anthony Williams
|
||||
// (C) Copyright 2012 Vicente J. Botet Escriba
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -10,8 +11,12 @@
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/detail/thread_interruption.hpp>
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#include <boost/chrono/ceil.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
@@ -27,7 +32,7 @@ namespace boost
|
||||
bool upgrade;
|
||||
bool exclusive_waiting_blocked;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
state_data state;
|
||||
@@ -41,9 +46,19 @@ namespace boost
|
||||
exclusive_cond.notify_one();
|
||||
shared_cond.notify_all();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifndef BOOST_NO_DELETED_FUNCTIONS
|
||||
public:
|
||||
shared_mutex(shared_mutex const&) = delete;
|
||||
shared_mutex& operator=(shared_mutex const&) = delete;
|
||||
#else // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
shared_mutex(shared_mutex const&);
|
||||
shared_mutex& operator=(shared_mutex const&);
|
||||
#endif // BOOST_NO_DELETED_FUNCTIONS
|
||||
public:
|
||||
|
||||
shared_mutex()
|
||||
{
|
||||
state_data state_={0,0,0,0};
|
||||
@@ -57,19 +72,19 @@ namespace boost
|
||||
void lock_shared()
|
||||
{
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
|
||||
while(state.exclusive || state.exclusive_waiting_blocked)
|
||||
{
|
||||
shared_cond.wait(lock);
|
||||
shared_cond.wait(lk);
|
||||
}
|
||||
++state.shared_count;
|
||||
}
|
||||
|
||||
bool try_lock_shared()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
|
||||
if(state.exclusive || state.exclusive_waiting_blocked)
|
||||
{
|
||||
return false;
|
||||
@@ -84,11 +99,11 @@ namespace boost
|
||||
bool timed_lock_shared(system_time const& timeout)
|
||||
{
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
|
||||
while(state.exclusive || state.exclusive_waiting_blocked)
|
||||
{
|
||||
if(!shared_cond.timed_wait(lock,timeout))
|
||||
if(!shared_cond.timed_wait(lk,timeout))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -102,12 +117,34 @@ namespace boost
|
||||
{
|
||||
return timed_lock_shared(get_system_time()+relative_time);
|
||||
}
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
return try_lock_shared_until(chrono::steady_clock::now() + rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time)
|
||||
{
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
|
||||
while(state.exclusive || state.exclusive_waiting_blocked)
|
||||
{
|
||||
if(cv_status::timeout==shared_cond.wait_until(lk,abs_time))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
++state.shared_count;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
void unlock_shared()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
bool const last_reader=!--state.shared_count;
|
||||
|
||||
|
||||
if(last_reader)
|
||||
{
|
||||
if(state.upgrade)
|
||||
@@ -127,12 +164,12 @@ namespace boost
|
||||
void lock()
|
||||
{
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
|
||||
while(state.shared_count || state.exclusive)
|
||||
{
|
||||
state.exclusive_waiting_blocked=true;
|
||||
exclusive_cond.wait(lock);
|
||||
exclusive_cond.wait(lk);
|
||||
}
|
||||
state.exclusive=true;
|
||||
}
|
||||
@@ -140,17 +177,17 @@ namespace boost
|
||||
bool timed_lock(system_time const& timeout)
|
||||
{
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
|
||||
while(state.shared_count || state.exclusive)
|
||||
{
|
||||
state.exclusive_waiting_blocked=true;
|
||||
if(!exclusive_cond.timed_wait(lock,timeout))
|
||||
if(!exclusive_cond.timed_wait(lk,timeout))
|
||||
{
|
||||
if(state.shared_count || state.exclusive)
|
||||
{
|
||||
state.exclusive_waiting_blocked=false;
|
||||
exclusive_cond.notify_one();
|
||||
release_waiters();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
@@ -166,10 +203,41 @@ namespace boost
|
||||
return timed_lock(get_system_time()+relative_time);
|
||||
}
|
||||
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
return try_lock_until(chrono::steady_clock::now() + rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time)
|
||||
{
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
|
||||
while(state.shared_count || state.exclusive)
|
||||
{
|
||||
state.exclusive_waiting_blocked=true;
|
||||
if(cv_status::timeout == exclusive_cond.wait_until(lk,abs_time))
|
||||
{
|
||||
if(state.shared_count || state.exclusive)
|
||||
{
|
||||
state.exclusive_waiting_blocked=false;
|
||||
release_waiters();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
state.exclusive=true;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
|
||||
if(state.shared_count || state.exclusive)
|
||||
{
|
||||
return false;
|
||||
@@ -179,12 +247,12 @@ namespace boost
|
||||
state.exclusive=true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
state.exclusive=false;
|
||||
state.exclusive_waiting_blocked=false;
|
||||
release_waiters();
|
||||
@@ -193,10 +261,10 @@ namespace boost
|
||||
void lock_upgrade()
|
||||
{
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
while(state.exclusive || state.exclusive_waiting_blocked || state.upgrade)
|
||||
{
|
||||
shared_cond.wait(lock);
|
||||
shared_cond.wait(lk);
|
||||
}
|
||||
++state.shared_count;
|
||||
state.upgrade=true;
|
||||
@@ -205,10 +273,10 @@ namespace boost
|
||||
bool timed_lock_upgrade(system_time const& timeout)
|
||||
{
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
while(state.exclusive || state.exclusive_waiting_blocked || state.upgrade)
|
||||
{
|
||||
if(!shared_cond.timed_wait(lock,timeout))
|
||||
if(!shared_cond.timed_wait(lk,timeout))
|
||||
{
|
||||
if(state.exclusive || state.exclusive_waiting_blocked || state.upgrade)
|
||||
{
|
||||
@@ -225,12 +293,39 @@ namespace boost
|
||||
template<typename TimeDuration>
|
||||
bool timed_lock_upgrade(TimeDuration const & relative_time)
|
||||
{
|
||||
return timed_lock(get_system_time()+relative_time);
|
||||
return timed_lock_upgrade(get_system_time()+relative_time);
|
||||
}
|
||||
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
return try_lock_upgrade_until(chrono::steady_clock::now() + rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time)
|
||||
{
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
while(state.exclusive || state.exclusive_waiting_blocked || state.upgrade)
|
||||
{
|
||||
if(cv_status::timeout == shared_cond.wait_until(lk,abs_time))
|
||||
{
|
||||
if(state.exclusive || state.exclusive_waiting_blocked || state.upgrade)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
++state.shared_count;
|
||||
state.upgrade=true;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
bool try_lock_upgrade()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
if(state.exclusive || state.exclusive_waiting_blocked || state.upgrade)
|
||||
{
|
||||
return false;
|
||||
@@ -245,25 +340,28 @@ namespace boost
|
||||
|
||||
void unlock_upgrade()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
state.upgrade=false;
|
||||
bool const last_reader=!--state.shared_count;
|
||||
|
||||
|
||||
if(last_reader)
|
||||
{
|
||||
state.exclusive_waiting_blocked=false;
|
||||
release_waiters();
|
||||
} else {
|
||||
shared_cond.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
// Upgrade <-> Exclusive
|
||||
void unlock_upgrade_and_lock()
|
||||
{
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
--state.shared_count;
|
||||
while(state.shared_count)
|
||||
{
|
||||
upgrade_cond.wait(lock);
|
||||
upgrade_cond.wait(lk);
|
||||
}
|
||||
state.upgrade=false;
|
||||
state.exclusive=true;
|
||||
@@ -271,31 +369,86 @@ namespace boost
|
||||
|
||||
void unlock_and_lock_upgrade()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
state.exclusive=false;
|
||||
state.upgrade=true;
|
||||
++state.shared_count;
|
||||
state.exclusive_waiting_blocked=false;
|
||||
release_waiters();
|
||||
}
|
||||
|
||||
|
||||
bool try_unlock_upgrade_and_lock()
|
||||
{
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
if( !state.exclusive
|
||||
&& !state.exclusive_waiting_blocked
|
||||
&& state.upgrade
|
||||
&& state.shared_count==1)
|
||||
{
|
||||
state.shared_count=0;
|
||||
state.exclusive=true;
|
||||
state.upgrade=false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool
|
||||
try_unlock_upgrade_and_lock_for(
|
||||
const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
return try_unlock_upgrade_and_lock_until(
|
||||
chrono::steady_clock::now() + rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool
|
||||
try_unlock_upgrade_and_lock_until(
|
||||
const chrono::time_point<Clock, Duration>& abs_time)
|
||||
{
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
if (state.shared_count != 1)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
cv_status status = shared_cond.wait_until(lk,abs_time);
|
||||
if (state.shared_count == 1)
|
||||
break;
|
||||
if(status == cv_status::timeout)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
state.upgrade=false;
|
||||
state.exclusive=true;
|
||||
state.exclusive_waiting_blocked=false;
|
||||
state.shared_count=0;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Shared <-> Exclusive
|
||||
void unlock_and_lock_shared()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
state.exclusive=false;
|
||||
++state.shared_count;
|
||||
state.exclusive_waiting_blocked=false;
|
||||
release_waiters();
|
||||
}
|
||||
|
||||
|
||||
// Shared <-> Upgrade
|
||||
void unlock_upgrade_and_lock_shared()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(state_change);
|
||||
boost::mutex::scoped_lock lk(state_change);
|
||||
state.upgrade=false;
|
||||
state.exclusive_waiting_blocked=false;
|
||||
release_waiters();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef shared_mutex upgrade_mutex;
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
@@ -12,22 +12,78 @@
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <pthread.h>
|
||||
#include "condition_variable_fwd.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/thread/pthread/condition_variable_fwd.hpp>
|
||||
#include <map>
|
||||
#include <unistd.h>
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#endif
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class thread_attributes {
|
||||
public:
|
||||
thread_attributes() {
|
||||
int res = pthread_attr_init(&val_);
|
||||
BOOST_VERIFY(!res && "pthread_attr_init failed");
|
||||
}
|
||||
~thread_attributes() {
|
||||
int res = pthread_attr_destroy(&val_);
|
||||
BOOST_VERIFY(!res && "pthread_attr_destroy failed");
|
||||
}
|
||||
// stack
|
||||
void set_stack_size(std::size_t size) {
|
||||
if (size==0) return;
|
||||
std::size_t page_size = getpagesize();
|
||||
#ifdef PTHREAD_STACK_MIN
|
||||
if (size<PTHREAD_STACK_MIN) size=PTHREAD_STACK_MIN;
|
||||
#endif
|
||||
size = ((size+page_size-1)/page_size)*page_size;
|
||||
int res = pthread_attr_setstacksize(&val_, size);
|
||||
BOOST_VERIFY(!res && "pthread_attr_setstacksize failed");
|
||||
}
|
||||
|
||||
std::size_t get_stack_size() const {
|
||||
std::size_t size;
|
||||
int res = pthread_attr_getstacksize(&val_, &size);
|
||||
BOOST_VERIFY(!res && "pthread_attr_getstacksize failed");
|
||||
return size;
|
||||
}
|
||||
|
||||
typedef pthread_attr_t native_handle_type;
|
||||
native_handle_type* native_handle() {
|
||||
return &val_;
|
||||
}
|
||||
const native_handle_type* native_handle() const {
|
||||
return &val_;
|
||||
}
|
||||
|
||||
private:
|
||||
pthread_attr_t val_;
|
||||
};
|
||||
|
||||
class thread;
|
||||
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct tss_cleanup_function;
|
||||
struct thread_exit_callback_node;
|
||||
struct tss_data_node;
|
||||
struct tss_data_node
|
||||
{
|
||||
boost::shared_ptr<boost::detail::tss_cleanup_function> func;
|
||||
void* value;
|
||||
|
||||
tss_data_node(boost::shared_ptr<boost::detail::tss_cleanup_function> func_,
|
||||
void* value_):
|
||||
func(func_),value(value_)
|
||||
{}
|
||||
};
|
||||
|
||||
struct thread_data_base;
|
||||
typedef boost::shared_ptr<thread_data_base> thread_data_ptr;
|
||||
|
||||
|
||||
struct BOOST_THREAD_DECL thread_data_base:
|
||||
enable_shared_from_this<thread_data_base>
|
||||
{
|
||||
@@ -41,14 +97,15 @@ namespace boost
|
||||
bool join_started;
|
||||
bool joined;
|
||||
boost::detail::thread_exit_callback_node* thread_exit_callbacks;
|
||||
boost::detail::tss_data_node* tss_data;
|
||||
std::map<void const*,boost::detail::tss_data_node> tss_data;
|
||||
bool interrupt_enabled;
|
||||
bool interrupt_requested;
|
||||
pthread_mutex_t* cond_mutex;
|
||||
pthread_cond_t* current_cond;
|
||||
|
||||
thread_data_base():
|
||||
done(false),join_started(false),joined(false),
|
||||
thread_exit_callbacks(0),tss_data(0),
|
||||
thread_exit_callbacks(0),
|
||||
interrupt_enabled(true),
|
||||
interrupt_requested(false),
|
||||
current_cond(0)
|
||||
@@ -65,6 +122,8 @@ namespace boost
|
||||
class interruption_checker
|
||||
{
|
||||
thread_data_base* const thread_info;
|
||||
pthread_mutex_t* m;
|
||||
bool set;
|
||||
|
||||
void check_for_interruption()
|
||||
{
|
||||
@@ -74,26 +133,38 @@ namespace boost
|
||||
throw thread_interrupted();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void operator=(interruption_checker&);
|
||||
public:
|
||||
explicit interruption_checker(pthread_cond_t* cond):
|
||||
thread_info(detail::get_current_thread_data())
|
||||
explicit interruption_checker(pthread_mutex_t* cond_mutex,pthread_cond_t* cond):
|
||||
thread_info(detail::get_current_thread_data()),m(cond_mutex),
|
||||
set(thread_info && thread_info->interrupt_enabled)
|
||||
{
|
||||
if(thread_info && thread_info->interrupt_enabled)
|
||||
if(set)
|
||||
{
|
||||
lock_guard<mutex> guard(thread_info->data_mutex);
|
||||
check_for_interruption();
|
||||
thread_info->cond_mutex=cond_mutex;
|
||||
thread_info->current_cond=cond;
|
||||
BOOST_VERIFY(!pthread_mutex_lock(m));
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_lock(m));
|
||||
}
|
||||
}
|
||||
~interruption_checker()
|
||||
{
|
||||
if(thread_info && thread_info->interrupt_enabled)
|
||||
if(set)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_unlock(m));
|
||||
lock_guard<mutex> guard(thread_info->data_mutex);
|
||||
thread_info->cond_mutex=NULL;
|
||||
thread_info->current_cond=NULL;
|
||||
check_for_interruption();
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_unlock(m));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -101,15 +172,30 @@ namespace boost
|
||||
|
||||
namespace this_thread
|
||||
{
|
||||
void BOOST_THREAD_DECL yield();
|
||||
|
||||
void BOOST_THREAD_DECL sleep(system_time const& abs_time);
|
||||
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds& ns);
|
||||
#endif
|
||||
void BOOST_THREAD_DECL yield() BOOST_NOEXCEPT;
|
||||
|
||||
#ifdef __DECXXX
|
||||
/// Workaround of DECCXX issue of incorrect template substitution
|
||||
template<typename TimeDuration>
|
||||
inline void sleep(TimeDuration const& rel_time)
|
||||
{
|
||||
this_thread::sleep(get_system_time()+rel_time);
|
||||
}
|
||||
|
||||
template<>
|
||||
void BOOST_THREAD_DECL sleep(system_time const& abs_time);
|
||||
#else
|
||||
void BOOST_THREAD_DECL sleep(system_time const& abs_time);
|
||||
|
||||
template<typename TimeDuration>
|
||||
inline BOOST_SYMBOL_VISIBLE void sleep(TimeDuration const& rel_time)
|
||||
{
|
||||
this_thread::sleep(get_system_time()+rel_time);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace boost
|
||||
return new T();
|
||||
}
|
||||
|
||||
#ifdef BOOST_HAS_RVALUE_REFS
|
||||
#ifndef BOOST_NO_RVALUE_REFERENCES
|
||||
template<typename T,typename A1>
|
||||
inline T* heap_new(A1&& a1)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
// thread.hpp
|
||||
//
|
||||
// (C) Copyright 2007-8 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
|
||||
@@ -20,6 +20,9 @@
|
||||
#endif
|
||||
|
||||
#include <boost/thread/detail/thread.hpp>
|
||||
#include <boost/thread/detail/thread_interruption.hpp>
|
||||
#include <boost/thread/detail/thread_group.hpp>
|
||||
#include <boost/thread/v2/thread.hpp>
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/date_time/time_clock.hpp>
|
||||
#include <boost/date_time/microsec_time_clock.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
|
||||
@@ -17,7 +18,11 @@ namespace boost
|
||||
|
||||
inline system_time get_system_time()
|
||||
{
|
||||
#if defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
|
||||
return boost::date_time::microsec_clock<system_time>::universal_time();
|
||||
#else // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
|
||||
return boost::date_time::second_clock<system_time>::universal_time();
|
||||
#endif // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
|
||||
}
|
||||
|
||||
namespace detail
|
||||
|
||||
@@ -1,111 +1,113 @@
|
||||
#ifndef BOOST_THREAD_TSS_HPP
|
||||
#define BOOST_THREAD_TSS_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/detail/config.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/thread/detail/thread_heap_alloc.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
struct tss_cleanup_function
|
||||
{
|
||||
virtual ~tss_cleanup_function()
|
||||
{}
|
||||
|
||||
virtual void operator()(void* data)=0;
|
||||
};
|
||||
|
||||
BOOST_THREAD_DECL void set_tss_data(void const* key,boost::shared_ptr<tss_cleanup_function> func,void* tss_data,bool cleanup_existing);
|
||||
BOOST_THREAD_DECL void* get_tss_data(void const* key);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class thread_specific_ptr
|
||||
{
|
||||
private:
|
||||
thread_specific_ptr(thread_specific_ptr&);
|
||||
thread_specific_ptr& operator=(thread_specific_ptr&);
|
||||
|
||||
struct delete_data:
|
||||
detail::tss_cleanup_function
|
||||
{
|
||||
void operator()(void* data)
|
||||
{
|
||||
delete static_cast<T*>(data);
|
||||
}
|
||||
};
|
||||
|
||||
struct run_custom_cleanup_function:
|
||||
detail::tss_cleanup_function
|
||||
{
|
||||
void (*cleanup_function)(T*);
|
||||
|
||||
explicit run_custom_cleanup_function(void (*cleanup_function_)(T*)):
|
||||
cleanup_function(cleanup_function_)
|
||||
{}
|
||||
|
||||
void operator()(void* data)
|
||||
{
|
||||
cleanup_function(static_cast<T*>(data));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
boost::shared_ptr<detail::tss_cleanup_function> cleanup;
|
||||
|
||||
public:
|
||||
thread_specific_ptr():
|
||||
cleanup(detail::heap_new<delete_data>(),detail::do_heap_delete<delete_data>())
|
||||
{}
|
||||
explicit thread_specific_ptr(void (*func_)(T*))
|
||||
{
|
||||
if(func_)
|
||||
{
|
||||
cleanup.reset(detail::heap_new<run_custom_cleanup_function>(func_),detail::do_heap_delete<run_custom_cleanup_function>());
|
||||
}
|
||||
}
|
||||
~thread_specific_ptr()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
T* get() const
|
||||
{
|
||||
return static_cast<T*>(detail::get_tss_data(this));
|
||||
}
|
||||
T* operator->() const
|
||||
{
|
||||
return get();
|
||||
}
|
||||
T& operator*() const
|
||||
{
|
||||
return *get();
|
||||
}
|
||||
T* release()
|
||||
{
|
||||
T* const temp=get();
|
||||
detail::set_tss_data(this,boost::shared_ptr<detail::tss_cleanup_function>(),0,false);
|
||||
return temp;
|
||||
}
|
||||
void reset(T* new_value=0)
|
||||
{
|
||||
T* const current_value=get();
|
||||
if(current_value!=new_value)
|
||||
{
|
||||
detail::set_tss_data(this,cleanup,new_value,true);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif
|
||||
#ifndef BOOST_THREAD_TSS_HPP
|
||||
#define BOOST_THREAD_TSS_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/detail/config.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/thread/detail/thread_heap_alloc.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
struct tss_cleanup_function
|
||||
{
|
||||
virtual ~tss_cleanup_function()
|
||||
{}
|
||||
|
||||
virtual void operator()(void* data)=0;
|
||||
};
|
||||
|
||||
BOOST_THREAD_DECL void set_tss_data(void const* key,boost::shared_ptr<tss_cleanup_function> func,void* tss_data,bool cleanup_existing);
|
||||
BOOST_THREAD_DECL void* get_tss_data(void const* key);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class thread_specific_ptr
|
||||
{
|
||||
private:
|
||||
thread_specific_ptr(thread_specific_ptr&);
|
||||
thread_specific_ptr& operator=(thread_specific_ptr&);
|
||||
|
||||
struct delete_data:
|
||||
detail::tss_cleanup_function
|
||||
{
|
||||
void operator()(void* data)
|
||||
{
|
||||
delete static_cast<T*>(data);
|
||||
}
|
||||
};
|
||||
|
||||
struct run_custom_cleanup_function:
|
||||
detail::tss_cleanup_function
|
||||
{
|
||||
void (*cleanup_function)(T*);
|
||||
|
||||
explicit run_custom_cleanup_function(void (*cleanup_function_)(T*)):
|
||||
cleanup_function(cleanup_function_)
|
||||
{}
|
||||
|
||||
void operator()(void* data)
|
||||
{
|
||||
cleanup_function(static_cast<T*>(data));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
boost::shared_ptr<detail::tss_cleanup_function> cleanup;
|
||||
|
||||
public:
|
||||
typedef T element_type;
|
||||
|
||||
thread_specific_ptr():
|
||||
cleanup(detail::heap_new<delete_data>(),detail::do_heap_delete<delete_data>())
|
||||
{}
|
||||
explicit thread_specific_ptr(void (*func_)(T*))
|
||||
{
|
||||
if(func_)
|
||||
{
|
||||
cleanup.reset(detail::heap_new<run_custom_cleanup_function>(func_),detail::do_heap_delete<run_custom_cleanup_function>());
|
||||
}
|
||||
}
|
||||
~thread_specific_ptr()
|
||||
{
|
||||
detail::set_tss_data(this,boost::shared_ptr<detail::tss_cleanup_function>(),0,true);
|
||||
}
|
||||
|
||||
T* get() const
|
||||
{
|
||||
return static_cast<T*>(detail::get_tss_data(this));
|
||||
}
|
||||
T* operator->() const
|
||||
{
|
||||
return get();
|
||||
}
|
||||
T& operator*() const
|
||||
{
|
||||
return *get();
|
||||
}
|
||||
T* release()
|
||||
{
|
||||
T* const temp=get();
|
||||
detail::set_tss_data(this,boost::shared_ptr<detail::tss_cleanup_function>(),0,false);
|
||||
return temp;
|
||||
}
|
||||
void reset(T* new_value=0)
|
||||
{
|
||||
T* const current_value=get();
|
||||
if(current_value!=new_value)
|
||||
{
|
||||
detail::set_tss_data(this,cleanup,new_value,true);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
56
include/boost/thread/v2/thread.hpp
Normal file
56
include/boost/thread/v2/thread.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
// 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 2011 Vicente J. Botet Escriba
|
||||
|
||||
#ifndef BOOST_THREAD_V2_THREAD_HPP
|
||||
#define BOOST_THREAD_V2_THREAD_HPP
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#endif
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace this_thread
|
||||
{
|
||||
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
|
||||
template <class Rep, class Period>
|
||||
void sleep_for(const chrono::duration<Rep, Period>& d)
|
||||
{
|
||||
using namespace chrono;
|
||||
nanoseconds ns = duration_cast<nanoseconds> (d);
|
||||
if (ns < d) ++ns;
|
||||
sleep_for(ns);
|
||||
}
|
||||
|
||||
template <class Clock, class Duration>
|
||||
void sleep_until(const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
mutex mut;
|
||||
condition_variable cv;
|
||||
unique_lock<mutex> lk(mut);
|
||||
while (Clock::now() < t)
|
||||
cv.wait_until(lk, t);
|
||||
}
|
||||
|
||||
template <class Duration>
|
||||
inline BOOST_SYMBOL_VISIBLE
|
||||
void sleep_until(const chrono::time_point<chrono::steady_clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
sleep_for(t - steady_clock::now());
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -3,14 +3,18 @@
|
||||
|
||||
// basic_recursive_mutex.hpp
|
||||
//
|
||||
// (C) Copyright 2006-8 Anthony Williams
|
||||
// (C) Copyright 2006-8 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 "thread_primitives.hpp"
|
||||
#include "basic_timed_mutex.hpp"
|
||||
#include <boost/thread/win32/thread_primitives.hpp>
|
||||
#include <boost/thread/win32/basic_timed_mutex.hpp>
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#include <boost/chrono/ceil.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
@@ -42,7 +46,7 @@ namespace boost
|
||||
long const current_thread_id=win32::GetCurrentThreadId();
|
||||
return try_recursive_lock(current_thread_id) || try_basic_lock(current_thread_id);
|
||||
}
|
||||
|
||||
|
||||
void lock()
|
||||
{
|
||||
long const current_thread_id=win32::GetCurrentThreadId();
|
||||
@@ -64,6 +68,20 @@ namespace boost
|
||||
return timed_lock(get_system_time()+timeout);
|
||||
}
|
||||
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
long const current_thread_id=win32::GetCurrentThreadId();
|
||||
return try_recursive_lock(current_thread_id) || try_timed_lock_for(current_thread_id,rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
long const current_thread_id=win32::GetCurrentThreadId();
|
||||
return try_recursive_lock(current_thread_id) || try_timed_lock_until(current_thread_id,t);
|
||||
}
|
||||
#endif
|
||||
void unlock()
|
||||
{
|
||||
if(!--recursion_count)
|
||||
@@ -83,7 +101,7 @@ namespace boost
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool try_basic_lock(long current_thread_id)
|
||||
{
|
||||
if(mutex.try_lock())
|
||||
@@ -94,7 +112,7 @@ namespace boost
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool try_timed_lock(long current_thread_id,::boost::system_time const& target)
|
||||
{
|
||||
if(mutex.timed_lock(target))
|
||||
@@ -105,7 +123,28 @@ namespace boost
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename TP>
|
||||
bool try_timed_lock_until(long current_thread_id,TP const& target)
|
||||
{
|
||||
if(mutex.try_lock_until(target))
|
||||
{
|
||||
BOOST_INTERLOCKED_EXCHANGE(&locking_thread_id,current_thread_id);
|
||||
recursion_count=1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
template <typename D>
|
||||
bool try_timed_lock_for(long current_thread_id,D const& target)
|
||||
{
|
||||
if(mutex.try_lock_for(target))
|
||||
{
|
||||
BOOST_INTERLOCKED_EXCHANGE(&locking_thread_id,current_thread_id);
|
||||
recursion_count=1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
typedef basic_recursive_mutex_impl<basic_timed_mutex> basic_recursive_mutex;
|
||||
|
||||
@@ -3,19 +3,22 @@
|
||||
|
||||
// basic_timed_mutex_win32.hpp
|
||||
//
|
||||
// (C) Copyright 2006-8 Anthony Williams
|
||||
// (C) Copyright 2006-8 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/assert.hpp>
|
||||
#include "thread_primitives.hpp"
|
||||
#include "interlocked_read.hpp"
|
||||
#include <boost/thread/win32/thread_primitives.hpp>
|
||||
#include <boost/thread/win32/interlocked_read.hpp>
|
||||
#include <boost/thread/thread_time.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
#include <boost/detail/interlocked.hpp>
|
||||
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#include <boost/chrono/ceil.hpp>
|
||||
#endif
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
@@ -52,24 +55,39 @@ namespace boost
|
||||
win32::CloseHandle(old_event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
return !win32::interlocked_bit_test_and_set(&active_count,lock_flag_bit);
|
||||
}
|
||||
|
||||
|
||||
void lock()
|
||||
{
|
||||
BOOST_VERIFY(timed_lock(::boost::detail::get_system_time_sentinel()));
|
||||
}
|
||||
bool timed_lock(::boost::system_time const& wait_until)
|
||||
{
|
||||
if(!win32::interlocked_bit_test_and_set(&active_count,lock_flag_bit))
|
||||
if(try_lock())
|
||||
{
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
long old_count=active_count;
|
||||
mark_waiting_and_try_lock(old_count);
|
||||
|
||||
if(old_count&lock_flag_value)
|
||||
{
|
||||
bool lock_acquired=false;
|
||||
void* const sem=get_event();
|
||||
|
||||
do
|
||||
{
|
||||
BOOST_VERIFY(win32::WaitForSingleObject(
|
||||
sem,::boost::detail::win32::infinite)==0);
|
||||
clear_waiting_and_try_lock(old_count);
|
||||
lock_acquired=!(old_count&lock_flag_value);
|
||||
}
|
||||
while(!lock_acquired);
|
||||
}
|
||||
}
|
||||
void mark_waiting_and_try_lock(long& old_count)
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
long const new_count=(old_count&lock_flag_value)?(old_count+1):(old_count|lock_flag_value);
|
||||
@@ -80,6 +98,33 @@ namespace boost
|
||||
}
|
||||
old_count=current;
|
||||
}
|
||||
}
|
||||
|
||||
void clear_waiting_and_try_lock(long& old_count)
|
||||
{
|
||||
old_count&=~lock_flag_value;
|
||||
old_count|=event_set_flag_value;
|
||||
for(;;)
|
||||
{
|
||||
long const new_count=((old_count&lock_flag_value)?old_count:((old_count-1)|lock_flag_value))&~event_set_flag_value;
|
||||
long const current=BOOST_INTERLOCKED_COMPARE_EXCHANGE(&active_count,new_count,old_count);
|
||||
if(current==old_count)
|
||||
{
|
||||
break;
|
||||
}
|
||||
old_count=current;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool timed_lock(::boost::system_time const& wait_until)
|
||||
{
|
||||
if(try_lock())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
long old_count=active_count;
|
||||
mark_waiting_and_try_lock(old_count);
|
||||
|
||||
if(old_count&lock_flag_value)
|
||||
{
|
||||
@@ -93,18 +138,7 @@ namespace boost
|
||||
BOOST_INTERLOCKED_DECREMENT(&active_count);
|
||||
return false;
|
||||
}
|
||||
old_count&=~lock_flag_value;
|
||||
old_count|=event_set_flag_value;
|
||||
for(;;)
|
||||
{
|
||||
long const new_count=((old_count&lock_flag_value)?old_count:((old_count-1)|lock_flag_value))&~event_set_flag_value;
|
||||
long const current=BOOST_INTERLOCKED_COMPARE_EXCHANGE(&active_count,new_count,old_count);
|
||||
if(current==old_count)
|
||||
{
|
||||
break;
|
||||
}
|
||||
old_count=current;
|
||||
}
|
||||
clear_waiting_and_try_lock(old_count);
|
||||
lock_acquired=!(old_count&lock_flag_value);
|
||||
}
|
||||
while(!lock_acquired);
|
||||
@@ -112,6 +146,7 @@ namespace boost
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<typename Duration>
|
||||
bool timed_lock(Duration const& timeout)
|
||||
{
|
||||
@@ -123,6 +158,57 @@ namespace boost
|
||||
return timed_lock(system_time(timeout));
|
||||
}
|
||||
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
return try_lock_until(chrono::steady_clock::now() + rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
system_clock::time_point s_now = system_clock::now();
|
||||
typename Clock::time_point c_now = Clock::now();
|
||||
return try_lock_until(s_now + ceil<system_clock::duration>(t - c_now));
|
||||
}
|
||||
template <class Duration>
|
||||
bool try_lock_until(const chrono::time_point<chrono::system_clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
typedef time_point<chrono::system_clock, chrono::system_clock::duration> sys_tmpt;
|
||||
return try_lock_until(sys_tmpt(chrono::ceil<chrono::system_clock::duration>(t.time_since_epoch())));
|
||||
}
|
||||
bool try_lock_until(const chrono::time_point<chrono::system_clock, chrono::system_clock::duration>& tp)
|
||||
{
|
||||
if(try_lock())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
long old_count=active_count;
|
||||
mark_waiting_and_try_lock(old_count);
|
||||
|
||||
if(old_count&lock_flag_value)
|
||||
{
|
||||
bool lock_acquired=false;
|
||||
void* const sem=get_event();
|
||||
|
||||
do
|
||||
{
|
||||
chrono::milliseconds rel_time= chrono::ceil<chrono::milliseconds>(tp-chrono::system_clock::now());
|
||||
|
||||
if(win32::WaitForSingleObject(sem,static_cast<unsigned long>(rel_time.count()))!=0)
|
||||
{
|
||||
BOOST_INTERLOCKED_DECREMENT(&active_count);
|
||||
return false;
|
||||
}
|
||||
clear_waiting_and_try_lock(old_count);
|
||||
lock_acquired=!(old_count&lock_flag_value);
|
||||
}
|
||||
while(!lock_acquired);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
long const offset=lock_flag_value;
|
||||
@@ -140,7 +226,7 @@ namespace boost
|
||||
void* get_event()
|
||||
{
|
||||
void* current_event=::boost::detail::interlocked_read_acquire(&event);
|
||||
|
||||
|
||||
if(!current_event)
|
||||
{
|
||||
void* const new_event=win32::create_anonymous_event(win32::auto_reset_event,win32::event_initially_reset);
|
||||
@@ -165,9 +251,9 @@ namespace boost
|
||||
}
|
||||
return current_event;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,16 +6,22 @@
|
||||
// (C) Copyright 2007-8 Anthony Williams
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include "thread_primitives.hpp"
|
||||
#include <boost/thread/win32/thread_primitives.hpp>
|
||||
#include <limits.h>
|
||||
#include <boost/assert.hpp>
|
||||
#include <algorithm>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/cv_status.hpp>
|
||||
//#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/win32/thread_data.hpp>
|
||||
#include <boost/thread/thread_time.hpp>
|
||||
#include "interlocked_read.hpp"
|
||||
#include <boost/thread/win32/interlocked_read.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
#include <vector>
|
||||
#include <boost/intrusive_ptr.hpp>
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#include <boost/chrono/ceil.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
@@ -26,7 +32,7 @@ namespace boost
|
||||
class basic_cv_list_entry;
|
||||
void intrusive_ptr_add_ref(basic_cv_list_entry * p);
|
||||
void intrusive_ptr_release(basic_cv_list_entry * p);
|
||||
|
||||
|
||||
class basic_cv_list_entry
|
||||
{
|
||||
private:
|
||||
@@ -38,7 +44,7 @@ namespace boost
|
||||
|
||||
basic_cv_list_entry(basic_cv_list_entry&);
|
||||
void operator=(basic_cv_list_entry&);
|
||||
|
||||
|
||||
public:
|
||||
explicit basic_cv_list_entry(detail::win32::handle_manager const& wake_sem_):
|
||||
semaphore(detail::win32::create_anonymous_semaphore(0,LONG_MAX)),
|
||||
@@ -55,7 +61,7 @@ namespace boost
|
||||
{
|
||||
BOOST_INTERLOCKED_INCREMENT(&waiters);
|
||||
}
|
||||
|
||||
|
||||
void remove_waiter()
|
||||
{
|
||||
BOOST_INTERLOCKED_DECREMENT(&waiters);
|
||||
@@ -97,7 +103,7 @@ namespace boost
|
||||
{
|
||||
BOOST_INTERLOCKED_INCREMENT(&p->references);
|
||||
}
|
||||
|
||||
|
||||
inline void intrusive_ptr_release(basic_cv_list_entry * p)
|
||||
{
|
||||
if(!BOOST_INTERLOCKED_DECREMENT(&p->references))
|
||||
@@ -125,13 +131,13 @@ namespace boost
|
||||
detail::interlocked_write_release(&total_count,total_count-count_to_wake);
|
||||
detail::win32::ReleaseSemaphore(wake_sem,count_to_wake,0);
|
||||
}
|
||||
|
||||
|
||||
template<typename lock_type>
|
||||
struct relocker
|
||||
{
|
||||
lock_type& lock;
|
||||
bool unlocked;
|
||||
|
||||
|
||||
relocker(lock_type& lock_):
|
||||
lock(lock_),unlocked(false)
|
||||
{}
|
||||
@@ -146,13 +152,13 @@ namespace boost
|
||||
{
|
||||
lock.lock();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
private:
|
||||
relocker(relocker&);
|
||||
void operator=(relocker&);
|
||||
};
|
||||
|
||||
|
||||
|
||||
entry_ptr get_wait_entry()
|
||||
{
|
||||
@@ -177,15 +183,15 @@ namespace boost
|
||||
return generations.back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct entry_manager
|
||||
{
|
||||
entry_ptr const entry;
|
||||
|
||||
|
||||
entry_manager(entry_ptr const& entry_):
|
||||
entry(entry_)
|
||||
{}
|
||||
|
||||
|
||||
~entry_manager()
|
||||
{
|
||||
entry->remove_waiter();
|
||||
@@ -200,14 +206,14 @@ namespace boost
|
||||
void operator=(entry_manager&);
|
||||
entry_manager(entry_manager&);
|
||||
};
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
template<typename lock_type>
|
||||
bool do_wait(lock_type& lock,timeout wait_until)
|
||||
{
|
||||
relocker<lock_type> locker(lock);
|
||||
|
||||
|
||||
entry_manager entry(get_wait_entry());
|
||||
|
||||
locker.unlock();
|
||||
@@ -219,7 +225,7 @@ namespace boost
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
woken=entry->woken();
|
||||
}
|
||||
return woken;
|
||||
@@ -235,7 +241,7 @@ namespace boost
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
basic_condition_variable(const basic_condition_variable& other);
|
||||
basic_condition_variable& operator=(const basic_condition_variable& other);
|
||||
|
||||
@@ -243,11 +249,11 @@ namespace boost
|
||||
basic_condition_variable():
|
||||
total_count(0),active_generation_count(0),wake_sem(0)
|
||||
{}
|
||||
|
||||
|
||||
~basic_condition_variable()
|
||||
{}
|
||||
|
||||
void notify_one()
|
||||
void notify_one() BOOST_NOEXCEPT
|
||||
{
|
||||
if(detail::interlocked_read_acquire(&total_count))
|
||||
{
|
||||
@@ -267,8 +273,8 @@ namespace boost
|
||||
generations.erase(std::remove_if(generations.begin(),generations.end(),&basic_cv_list_entry::no_waiters),generations.end());
|
||||
}
|
||||
}
|
||||
|
||||
void notify_all()
|
||||
|
||||
void notify_all() BOOST_NOEXCEPT
|
||||
{
|
||||
if(detail::interlocked_read_acquire(&total_count))
|
||||
{
|
||||
@@ -288,7 +294,7 @@ namespace boost
|
||||
wake_sem=detail::win32::handle(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -301,10 +307,10 @@ namespace boost
|
||||
public:
|
||||
condition_variable()
|
||||
{}
|
||||
|
||||
|
||||
using detail::basic_condition_variable::notify_one;
|
||||
using detail::basic_condition_variable::notify_all;
|
||||
|
||||
|
||||
void wait(unique_lock<mutex>& m)
|
||||
{
|
||||
do_wait(m,detail::timeout::sentinel());
|
||||
@@ -315,7 +321,7 @@ namespace boost
|
||||
{
|
||||
while(!pred()) wait(m);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool timed_wait(unique_lock<mutex>& m,boost::system_time const& wait_until)
|
||||
{
|
||||
@@ -347,8 +353,60 @@ namespace boost
|
||||
{
|
||||
return do_wait(m,wait_duration.total_milliseconds(),pred);
|
||||
}
|
||||
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
|
||||
template <class Clock, class Duration>
|
||||
cv_status
|
||||
wait_until(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
do_wait(lock, ceil<milliseconds>(t-Clock::now()).count());
|
||||
return Clock::now() < t ? cv_status::no_timeout :
|
||||
cv_status::timeout;
|
||||
}
|
||||
|
||||
template <class Rep, class Period>
|
||||
cv_status
|
||||
wait_for(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::duration<Rep, Period>& d)
|
||||
{
|
||||
using namespace chrono;
|
||||
steady_clock::time_point c_now = steady_clock::now();
|
||||
do_wait(lock, ceil<milliseconds>(d).count());
|
||||
return steady_clock::now() - c_now < d ? cv_status::no_timeout :
|
||||
cv_status::timeout;
|
||||
}
|
||||
|
||||
template <class Clock, class Duration, class Predicate>
|
||||
bool
|
||||
wait_until(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::time_point<Clock, Duration>& t,
|
||||
Predicate pred)
|
||||
{
|
||||
while (!pred())
|
||||
{
|
||||
if (wait_until(lock, t) == cv_status::timeout)
|
||||
return pred();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
template <class Rep, class Period, class Predicate>
|
||||
bool
|
||||
wait_for(
|
||||
unique_lock<mutex>& lock,
|
||||
const chrono::duration<Rep, Period>& d,
|
||||
Predicate pred)
|
||||
{
|
||||
return wait_until(lock, chrono::steady_clock::now() + d, pred);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
class condition_variable_any:
|
||||
private detail::basic_condition_variable
|
||||
{
|
||||
@@ -358,10 +416,10 @@ namespace boost
|
||||
public:
|
||||
condition_variable_any()
|
||||
{}
|
||||
|
||||
|
||||
using detail::basic_condition_variable::notify_one;
|
||||
using detail::basic_condition_variable::notify_all;
|
||||
|
||||
|
||||
template<typename lock_type>
|
||||
void wait(lock_type& m)
|
||||
{
|
||||
@@ -373,7 +431,7 @@ namespace boost
|
||||
{
|
||||
while(!pred()) wait(m);
|
||||
}
|
||||
|
||||
|
||||
template<typename lock_type>
|
||||
bool timed_wait(lock_type& m,boost::system_time const& wait_until)
|
||||
{
|
||||
@@ -409,6 +467,58 @@ namespace boost
|
||||
{
|
||||
return do_wait(m,wait_duration.total_milliseconds(),pred);
|
||||
}
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
|
||||
template <class lock_type, class Clock, class Duration>
|
||||
cv_status
|
||||
wait_until(
|
||||
lock_type& lock,
|
||||
const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
do_wait(lock, ceil<milliseconds>(t-Clock::now()).count());
|
||||
return Clock::now() < t ? cv_status::no_timeout :
|
||||
cv_status::timeout;
|
||||
}
|
||||
|
||||
template <class lock_type, class Rep, class Period>
|
||||
cv_status
|
||||
wait_for(
|
||||
lock_type& lock,
|
||||
const chrono::duration<Rep, Period>& d)
|
||||
{
|
||||
using namespace chrono;
|
||||
steady_clock::time_point c_now = steady_clock::now();
|
||||
do_wait(lock, ceil<milliseconds>(d).count());
|
||||
return steady_clock::now() - c_now < d ? cv_status::no_timeout :
|
||||
cv_status::timeout;
|
||||
}
|
||||
|
||||
template <class lock_type, class Clock, class Duration, class Predicate>
|
||||
bool
|
||||
wait_until(
|
||||
lock_type& lock,
|
||||
const chrono::time_point<Clock, Duration>& t,
|
||||
Predicate pred)
|
||||
{
|
||||
while (!pred())
|
||||
{
|
||||
if (wait_until(lock, t) == cv_status::timeout)
|
||||
return pred();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class lock_type, class Rep, class Period, class Predicate>
|
||||
bool
|
||||
wait_for(
|
||||
lock_type& lock,
|
||||
const chrono::duration<Rep, Period>& d,
|
||||
Predicate pred)
|
||||
{
|
||||
return wait_until(lock, chrono::steady_clock::now() + d, pred);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "basic_timed_mutex.hpp"
|
||||
#include <boost/thread/win32/basic_timed_mutex.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/thread/exceptions.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
@@ -20,9 +20,11 @@ namespace boost
|
||||
}
|
||||
|
||||
class mutex:
|
||||
boost::noncopyable,
|
||||
public ::boost::detail::underlying_mutex
|
||||
{
|
||||
private:
|
||||
mutex(mutex const&);
|
||||
mutex& operator=(mutex const&);
|
||||
public:
|
||||
mutex()
|
||||
{
|
||||
@@ -40,9 +42,11 @@ namespace boost
|
||||
typedef mutex try_mutex;
|
||||
|
||||
class timed_mutex:
|
||||
boost::noncopyable,
|
||||
public ::boost::detail::basic_timed_mutex
|
||||
{
|
||||
private:
|
||||
timed_mutex(timed_mutex const&);
|
||||
timed_mutex& operator=(timed_mutex const&);
|
||||
public:
|
||||
timed_mutex()
|
||||
{
|
||||
|
||||
@@ -30,81 +30,90 @@ namespace std
|
||||
|
||||
namespace boost
|
||||
{
|
||||
typedef long once_flag;
|
||||
struct once_flag
|
||||
{
|
||||
long status;
|
||||
long count;
|
||||
};
|
||||
|
||||
#define BOOST_ONCE_INIT 0
|
||||
#define BOOST_ONCE_INIT {0,0}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct win32_mutex_scoped_lock
|
||||
{
|
||||
void* const mutex_handle;
|
||||
explicit win32_mutex_scoped_lock(void* mutex_handle_):
|
||||
mutex_handle(mutex_handle_)
|
||||
{
|
||||
BOOST_VERIFY(!win32::WaitForSingleObject(mutex_handle,win32::infinite));
|
||||
}
|
||||
~win32_mutex_scoped_lock()
|
||||
{
|
||||
BOOST_VERIFY(win32::ReleaseMutex(mutex_handle)!=0);
|
||||
}
|
||||
private:
|
||||
void operator=(win32_mutex_scoped_lock&);
|
||||
};
|
||||
|
||||
#ifdef BOOST_NO_ANSI_APIS
|
||||
typedef wchar_t once_char_type;
|
||||
#else
|
||||
typedef char once_char_type;
|
||||
#endif
|
||||
unsigned const once_mutex_name_fixed_length=54;
|
||||
unsigned const once_mutex_name_length=once_mutex_name_fixed_length+
|
||||
sizeof(void*)*2+sizeof(unsigned long)*2+1;
|
||||
|
||||
template <class I>
|
||||
void int_to_string(I p, wchar_t* buf)
|
||||
void int_to_string(I p, once_char_type* buf)
|
||||
{
|
||||
for(unsigned i=0; i < sizeof(I)*2; ++i,++buf)
|
||||
{
|
||||
*buf = L'A' + static_cast<wchar_t>((p >> (i*4)) & 0x0f);
|
||||
}
|
||||
*buf = 0;
|
||||
}
|
||||
#else
|
||||
template <class I>
|
||||
void int_to_string(I p, char* buf)
|
||||
{
|
||||
for(unsigned i=0; i < sizeof(I)*2; ++i,++buf)
|
||||
{
|
||||
*buf = 'A' + static_cast<char>((p >> (i*4)) & 0x0f);
|
||||
}
|
||||
*buf = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// create a named mutex. It doesn't really matter what this name is
|
||||
// as long as it is unique both to this process, and to the address of "flag":
|
||||
inline void* create_once_mutex(void* flag_address)
|
||||
{
|
||||
|
||||
#ifdef BOOST_NO_ANSI_APIS
|
||||
typedef wchar_t char_type;
|
||||
static const char_type fixed_mutex_name[]=L"{C15730E2-145C-4c5e-B005-3BC753F42475}-once-flag";
|
||||
once_char_type const a=L'A';
|
||||
#else
|
||||
typedef char char_type;
|
||||
static const char_type fixed_mutex_name[]="{C15730E2-145C-4c5e-B005-3BC753F42475}-once-flag";
|
||||
once_char_type const a='A';
|
||||
#endif
|
||||
unsigned const once_mutex_name_fixed_buffer_size=sizeof(fixed_mutex_name)/sizeof(char_type);
|
||||
unsigned const once_mutex_name_fixed_length=once_mutex_name_fixed_buffer_size-1;
|
||||
unsigned const once_mutex_name_length=once_mutex_name_fixed_buffer_size+sizeof(void*)*2+sizeof(unsigned long)*2;
|
||||
char_type mutex_name[once_mutex_name_length];
|
||||
*buf = a + static_cast<once_char_type>((p >> (i*4)) & 0x0f);
|
||||
}
|
||||
*buf = 0;
|
||||
}
|
||||
|
||||
inline void name_once_mutex(once_char_type* mutex_name,void* flag_address)
|
||||
{
|
||||
#ifdef BOOST_NO_ANSI_APIS
|
||||
static const once_char_type fixed_mutex_name[]=L"Local\\{C15730E2-145C-4c5e-B005-3BC753F42475}-once-flag";
|
||||
#else
|
||||
static const once_char_type fixed_mutex_name[]="Local\\{C15730E2-145C-4c5e-B005-3BC753F42475}-once-flag";
|
||||
#endif
|
||||
BOOST_STATIC_ASSERT(sizeof(fixed_mutex_name) ==
|
||||
(sizeof(once_char_type)*(once_mutex_name_fixed_length+1)));
|
||||
|
||||
std::memcpy(mutex_name,fixed_mutex_name,sizeof(fixed_mutex_name));
|
||||
|
||||
BOOST_STATIC_ASSERT(sizeof(void*) == sizeof(std::ptrdiff_t));
|
||||
detail::int_to_string(reinterpret_cast<std::ptrdiff_t>(flag_address), mutex_name + once_mutex_name_fixed_length);
|
||||
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);
|
||||
detail::int_to_string(reinterpret_cast<std::ptrdiff_t>(flag_address),
|
||||
mutex_name + once_mutex_name_fixed_length);
|
||||
detail::int_to_string(win32::GetCurrentProcessId(),
|
||||
mutex_name + once_mutex_name_fixed_length + sizeof(void*)*2);
|
||||
}
|
||||
|
||||
inline void* open_once_event(once_char_type* mutex_name,void* flag_address)
|
||||
{
|
||||
if(!*mutex_name)
|
||||
{
|
||||
name_once_mutex(mutex_name,flag_address);
|
||||
}
|
||||
|
||||
#ifdef BOOST_NO_ANSI_APIS
|
||||
return ::boost::detail::win32::OpenEventW(
|
||||
#else
|
||||
return win32::CreateMutexA(0, 0, mutex_name);
|
||||
return ::boost::detail::win32::OpenEventA(
|
||||
#endif
|
||||
::boost::detail::win32::synchronize |
|
||||
::boost::detail::win32::event_modify_state,
|
||||
false,
|
||||
mutex_name);
|
||||
}
|
||||
|
||||
|
||||
inline void* create_once_event(once_char_type* mutex_name,void* flag_address)
|
||||
{
|
||||
if(!*mutex_name)
|
||||
{
|
||||
name_once_mutex(mutex_name,flag_address);
|
||||
}
|
||||
#ifdef BOOST_NO_ANSI_APIS
|
||||
return ::boost::detail::win32::CreateEventW(
|
||||
#else
|
||||
return ::boost::detail::win32::CreateEventA(
|
||||
#endif
|
||||
0,::boost::detail::win32::manual_reset_event,
|
||||
::boost::detail::win32::event_initially_reset,
|
||||
mutex_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -114,19 +123,79 @@ namespace boost
|
||||
// Try for a quick win: if the procedure has already been called
|
||||
// just skip through:
|
||||
long const function_complete_flag_value=0xc15730e2;
|
||||
long const running_value=0x7f0725e3;
|
||||
long status;
|
||||
bool counted=false;
|
||||
detail::win32::handle_manager event_handle;
|
||||
detail::once_char_type mutex_name[detail::once_mutex_name_length];
|
||||
mutex_name[0]=0;
|
||||
|
||||
if(::boost::detail::interlocked_read_acquire(&flag)!=function_complete_flag_value)
|
||||
while((status=::boost::detail::interlocked_read_acquire(&flag.status))
|
||||
!=function_complete_flag_value)
|
||||
{
|
||||
void* const mutex_handle(::boost::detail::create_once_mutex(&flag));
|
||||
BOOST_ASSERT(mutex_handle);
|
||||
detail::win32::handle_manager const closer(mutex_handle);
|
||||
detail::win32_mutex_scoped_lock const lock(mutex_handle);
|
||||
|
||||
if(flag!=function_complete_flag_value)
|
||||
status=BOOST_INTERLOCKED_COMPARE_EXCHANGE(&flag.status,running_value,0);
|
||||
if(!status)
|
||||
{
|
||||
f();
|
||||
BOOST_INTERLOCKED_EXCHANGE(&flag,function_complete_flag_value);
|
||||
try
|
||||
{
|
||||
if(!event_handle)
|
||||
{
|
||||
event_handle=detail::open_once_event(mutex_name,&flag);
|
||||
}
|
||||
if(event_handle)
|
||||
{
|
||||
::boost::detail::win32::ResetEvent(event_handle);
|
||||
}
|
||||
f();
|
||||
if(!counted)
|
||||
{
|
||||
BOOST_INTERLOCKED_INCREMENT(&flag.count);
|
||||
counted=true;
|
||||
}
|
||||
BOOST_INTERLOCKED_EXCHANGE(&flag.status,function_complete_flag_value);
|
||||
if(!event_handle &&
|
||||
(::boost::detail::interlocked_read_acquire(&flag.count)>1))
|
||||
{
|
||||
event_handle=detail::create_once_event(mutex_name,&flag);
|
||||
}
|
||||
if(event_handle)
|
||||
{
|
||||
::boost::detail::win32::SetEvent(event_handle);
|
||||
}
|
||||
break;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
BOOST_INTERLOCKED_EXCHANGE(&flag.status,0);
|
||||
if(!event_handle)
|
||||
{
|
||||
event_handle=detail::open_once_event(mutex_name,&flag);
|
||||
}
|
||||
if(event_handle)
|
||||
{
|
||||
::boost::detail::win32::SetEvent(event_handle);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
if(!counted)
|
||||
{
|
||||
BOOST_INTERLOCKED_INCREMENT(&flag.count);
|
||||
counted=true;
|
||||
status=::boost::detail::interlocked_read_acquire(&flag.status);
|
||||
if(status==function_complete_flag_value)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if(!event_handle)
|
||||
{
|
||||
event_handle=detail::create_once_event(mutex_name,&flag);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObject(
|
||||
event_handle,::boost::detail::win32::infinite));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
// recursive_mutex.hpp
|
||||
//
|
||||
// (C) Copyright 2006-7 Anthony Williams
|
||||
// (C) Copyright 2006-7 Anthony Williams
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
|
||||
#include <boost/utility.hpp>
|
||||
#include "basic_recursive_mutex.hpp"
|
||||
#include <boost/thread/win32/basic_recursive_mutex.hpp>
|
||||
#include <boost/thread/exceptions.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
|
||||
@@ -20,9 +20,11 @@
|
||||
namespace boost
|
||||
{
|
||||
class recursive_mutex:
|
||||
boost::noncopyable,
|
||||
public ::boost::detail::basic_recursive_mutex
|
||||
{
|
||||
private:
|
||||
recursive_mutex(recursive_mutex const&);
|
||||
recursive_mutex& operator=(recursive_mutex const&);
|
||||
public:
|
||||
recursive_mutex()
|
||||
{
|
||||
@@ -40,9 +42,11 @@ namespace boost
|
||||
typedef recursive_mutex recursive_try_mutex;
|
||||
|
||||
class recursive_timed_mutex:
|
||||
boost::noncopyable,
|
||||
public ::boost::detail::basic_recursive_timed_mutex
|
||||
{
|
||||
private:
|
||||
recursive_timed_mutex(recursive_timed_mutex const&);
|
||||
recursive_timed_mutex& operator=(recursive_timed_mutex const&);
|
||||
public:
|
||||
recursive_timed_mutex()
|
||||
{
|
||||
|
||||
@@ -14,14 +14,26 @@
|
||||
#include <limits.h>
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/thread/thread_time.hpp>
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#include <boost/chrono/ceil.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class shared_mutex:
|
||||
private boost::noncopyable
|
||||
class shared_mutex
|
||||
{
|
||||
#ifndef BOOST_NO_DELETED_FUNCTIONS
|
||||
public:
|
||||
shared_mutex(shared_mutex const&) = delete;
|
||||
shared_mutex& operator=(shared_mutex const&) = delete;
|
||||
#else // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
shared_mutex(shared_mutex const&);
|
||||
shared_mutex& operator=(shared_mutex const&);
|
||||
#endif // BOOST_NO_DELETED_FUNCTIONS
|
||||
private:
|
||||
struct state_data
|
||||
{
|
||||
@@ -37,7 +49,7 @@ namespace boost
|
||||
return *reinterpret_cast<unsigned const*>(&lhs)==*reinterpret_cast<unsigned const*>(&rhs);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename T>
|
||||
T interlocked_compare_exchange(T* target,T new_value,T comparand)
|
||||
@@ -49,34 +61,47 @@ namespace boost
|
||||
return *reinterpret_cast<T const*>(&res);
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
unlock_sem = 0,
|
||||
exclusive_sem = 1
|
||||
};
|
||||
|
||||
state_data state;
|
||||
detail::win32::handle semaphores[2];
|
||||
detail::win32::handle &unlock_sem;
|
||||
detail::win32::handle &exclusive_sem;
|
||||
detail::win32::handle upgrade_sem;
|
||||
|
||||
void release_waiters(state_data old_state)
|
||||
{
|
||||
if(old_state.exclusive_waiting)
|
||||
{
|
||||
BOOST_VERIFY(detail::win32::ReleaseSemaphore(exclusive_sem,1,0)!=0);
|
||||
BOOST_VERIFY(detail::win32::ReleaseSemaphore(semaphores[exclusive_sem],1,0)!=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(semaphores[unlock_sem],old_state.shared_waiting + (old_state.exclusive_waiting?1:0),0)!=0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public:
|
||||
shared_mutex():
|
||||
unlock_sem(semaphores[0]),
|
||||
exclusive_sem(semaphores[1])
|
||||
shared_mutex()
|
||||
{
|
||||
unlock_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX);
|
||||
exclusive_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX);
|
||||
upgrade_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX);
|
||||
semaphores[unlock_sem]=detail::win32::create_anonymous_semaphore(0,LONG_MAX);
|
||||
semaphores[exclusive_sem]=detail::win32::create_anonymous_semaphore_nothrow(0,LONG_MAX);
|
||||
if (!semaphores[exclusive_sem])
|
||||
{
|
||||
detail::win32::release_semaphore(semaphores[unlock_sem],LONG_MAX);
|
||||
boost::throw_exception(thread_resource_error());
|
||||
}
|
||||
upgrade_sem=detail::win32::create_anonymous_semaphore_nothrow(0,LONG_MAX);
|
||||
if (!upgrade_sem)
|
||||
{
|
||||
detail::win32::release_semaphore(semaphores[unlock_sem],LONG_MAX);
|
||||
detail::win32::release_semaphore(semaphores[exclusive_sem],LONG_MAX);
|
||||
boost::throw_exception(thread_resource_error());
|
||||
}
|
||||
state_data state_={0};
|
||||
state=state_;
|
||||
}
|
||||
@@ -84,8 +109,8 @@ namespace boost
|
||||
~shared_mutex()
|
||||
{
|
||||
detail::win32::CloseHandle(upgrade_sem);
|
||||
detail::win32::CloseHandle(unlock_sem);
|
||||
detail::win32::CloseHandle(exclusive_sem);
|
||||
detail::win32::CloseHandle(semaphores[unlock_sem]);
|
||||
detail::win32::CloseHandle(semaphores[exclusive_sem]);
|
||||
}
|
||||
|
||||
bool try_lock_shared()
|
||||
@@ -97,8 +122,12 @@ namespace boost
|
||||
if(!new_state.exclusive && !new_state.exclusive_waiting_blocked)
|
||||
{
|
||||
++new_state.shared_count;
|
||||
if(!new_state.shared_count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
if(current_state==old_state)
|
||||
{
|
||||
@@ -131,10 +160,18 @@ namespace boost
|
||||
if(new_state.exclusive || new_state.exclusive_waiting_blocked)
|
||||
{
|
||||
++new_state.shared_waiting;
|
||||
if(!new_state.shared_waiting)
|
||||
{
|
||||
boost::throw_exception(boost::lock_error());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++new_state.shared_count;
|
||||
if(!new_state.shared_count)
|
||||
{
|
||||
boost::throw_exception(boost::lock_error());
|
||||
}
|
||||
}
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
@@ -149,8 +186,8 @@ namespace boost
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned long const res=detail::win32::WaitForSingleObject(unlock_sem,::boost::detail::get_milliseconds_until(wait_until));
|
||||
|
||||
unsigned long const res=detail::win32::WaitForSingleObject(semaphores[unlock_sem],::boost::detail::get_milliseconds_until(wait_until));
|
||||
if(res==detail::win32::timeout)
|
||||
{
|
||||
for(;;)
|
||||
@@ -166,6 +203,10 @@ namespace boost
|
||||
else
|
||||
{
|
||||
++new_state.shared_count;
|
||||
if(!new_state.shared_count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
@@ -182,11 +223,118 @@ namespace boost
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
BOOST_ASSERT(res==0);
|
||||
}
|
||||
}
|
||||
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
return try_lock_shared_until(chrono::steady_clock::now() + rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
system_clock::time_point s_now = system_clock::now();
|
||||
typename Clock::time_point c_now = Clock::now();
|
||||
return try_lock_shared_until(s_now + ceil<system_clock::duration>(t - c_now));
|
||||
}
|
||||
template <class Duration>
|
||||
bool try_lock_shared_until(const chrono::time_point<chrono::system_clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
typedef time_point<chrono::system_clock, chrono::system_clock::duration> sys_tmpt;
|
||||
return try_lock_shared_until(sys_tmpt(chrono::ceil<chrono::system_clock::duration>(t.time_since_epoch())));
|
||||
}
|
||||
bool try_lock_shared_until(const chrono::time_point<chrono::system_clock, chrono::system_clock::duration>& tp)
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
state_data old_state=state;
|
||||
for(;;)
|
||||
{
|
||||
state_data new_state=old_state;
|
||||
if(new_state.exclusive || new_state.exclusive_waiting_blocked)
|
||||
{
|
||||
++new_state.shared_waiting;
|
||||
if(!new_state.shared_waiting)
|
||||
{
|
||||
boost::throw_exception(boost::lock_error());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++new_state.shared_count;
|
||||
if(!new_state.shared_count)
|
||||
{
|
||||
boost::throw_exception(boost::lock_error());
|
||||
}
|
||||
}
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
if(current_state==old_state)
|
||||
{
|
||||
break;
|
||||
}
|
||||
old_state=current_state;
|
||||
}
|
||||
|
||||
if(!(old_state.exclusive| old_state.exclusive_waiting_blocked))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
chrono::system_clock::time_point n = chrono::system_clock::now();
|
||||
unsigned long res;
|
||||
if (tp>n) {
|
||||
chrono::milliseconds rel_time= chrono::ceil<chrono::milliseconds>(tp-n);
|
||||
res=detail::win32::WaitForSingleObject(semaphores[unlock_sem],
|
||||
static_cast<unsigned long>(rel_time.count()));
|
||||
} else {
|
||||
res=detail::win32::timeout;
|
||||
}
|
||||
if(res==detail::win32::timeout)
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
state_data new_state=old_state;
|
||||
if(new_state.exclusive || new_state.exclusive_waiting_blocked)
|
||||
{
|
||||
if(new_state.shared_waiting)
|
||||
{
|
||||
--new_state.shared_waiting;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++new_state.shared_count;
|
||||
if(!new_state.shared_count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
if(current_state==old_state)
|
||||
{
|
||||
break;
|
||||
}
|
||||
old_state=current_state;
|
||||
}
|
||||
|
||||
if(!(old_state.exclusive| old_state.exclusive_waiting_blocked))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
BOOST_ASSERT(res==0);
|
||||
}
|
||||
}
|
||||
|
||||
void unlock_shared()
|
||||
{
|
||||
state_data old_state=state;
|
||||
@@ -194,7 +342,7 @@ namespace boost
|
||||
{
|
||||
state_data new_state=old_state;
|
||||
bool const last_reader=!--new_state.shared_count;
|
||||
|
||||
|
||||
if(last_reader)
|
||||
{
|
||||
if(new_state.upgrade)
|
||||
@@ -212,7 +360,7 @@ namespace boost
|
||||
new_state.shared_waiting=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
if(current_state==old_state)
|
||||
{
|
||||
@@ -258,7 +406,7 @@ namespace boost
|
||||
{
|
||||
new_state.exclusive=true;
|
||||
}
|
||||
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
if(current_state==old_state)
|
||||
{
|
||||
@@ -282,6 +430,11 @@ namespace boost
|
||||
if(new_state.shared_count || new_state.exclusive)
|
||||
{
|
||||
++new_state.exclusive_waiting;
|
||||
if(!new_state.exclusive_waiting)
|
||||
{
|
||||
boost::throw_exception(boost::lock_error());
|
||||
}
|
||||
|
||||
new_state.exclusive_waiting_blocked=true;
|
||||
}
|
||||
else
|
||||
@@ -301,7 +454,12 @@ namespace boost
|
||||
{
|
||||
return true;
|
||||
}
|
||||
unsigned long const wait_res=detail::win32::WaitForMultipleObjects(2,semaphores,true,::boost::detail::get_milliseconds_until(wait_until));
|
||||
#ifndef UNDER_CE
|
||||
const bool wait_all = true;
|
||||
#else
|
||||
const bool wait_all = false;
|
||||
#endif
|
||||
unsigned long const wait_res=detail::win32::WaitForMultipleObjects(2,semaphores,wait_all,::boost::detail::get_milliseconds_until(wait_until));
|
||||
if(wait_res==detail::win32::timeout)
|
||||
{
|
||||
for(;;)
|
||||
@@ -339,6 +497,115 @@ namespace boost
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
return try_lock_until(chrono::steady_clock::now() + rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
system_clock::time_point s_now = system_clock::now();
|
||||
typename Clock::time_point c_now = Clock::now();
|
||||
return try_lock_until(s_now + ceil<system_clock::duration>(t - c_now));
|
||||
}
|
||||
template <class Duration>
|
||||
bool try_lock_until(const chrono::time_point<chrono::system_clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
typedef time_point<chrono::system_clock, chrono::system_clock::duration> sys_tmpt;
|
||||
return try_lock_until(sys_tmpt(chrono::ceil<chrono::system_clock::duration>(t.time_since_epoch())));
|
||||
}
|
||||
bool try_lock_until(const chrono::time_point<chrono::system_clock, chrono::system_clock::duration>& tp)
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
state_data old_state=state;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
state_data new_state=old_state;
|
||||
if(new_state.shared_count || new_state.exclusive)
|
||||
{
|
||||
++new_state.exclusive_waiting;
|
||||
if(!new_state.exclusive_waiting)
|
||||
{
|
||||
boost::throw_exception(boost::lock_error());
|
||||
}
|
||||
|
||||
new_state.exclusive_waiting_blocked=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_state.exclusive=true;
|
||||
}
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
if(current_state==old_state)
|
||||
{
|
||||
break;
|
||||
}
|
||||
old_state=current_state;
|
||||
}
|
||||
|
||||
if(!old_state.shared_count && !old_state.exclusive)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#ifndef UNDER_CE
|
||||
const bool wait_all = true;
|
||||
#else
|
||||
const bool wait_all = false;
|
||||
#endif
|
||||
|
||||
chrono::system_clock::time_point n = chrono::system_clock::now();
|
||||
unsigned long wait_res;
|
||||
if (tp>n) {
|
||||
chrono::milliseconds rel_time= chrono::ceil<chrono::milliseconds>(tp-chrono::system_clock::now());
|
||||
wait_res=detail::win32::WaitForMultipleObjects(2,semaphores,wait_all,
|
||||
static_cast<unsigned long>(rel_time.count()));
|
||||
} else {
|
||||
wait_res=detail::win32::timeout;
|
||||
}
|
||||
if(wait_res==detail::win32::timeout)
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
state_data new_state=old_state;
|
||||
if(new_state.shared_count || new_state.exclusive)
|
||||
{
|
||||
if(new_state.exclusive_waiting)
|
||||
{
|
||||
if(!--new_state.exclusive_waiting)
|
||||
{
|
||||
new_state.exclusive_waiting_blocked=false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
new_state.exclusive=true;
|
||||
}
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
if(current_state==old_state)
|
||||
{
|
||||
break;
|
||||
}
|
||||
old_state=current_state;
|
||||
}
|
||||
if(!old_state.shared_count && !old_state.exclusive)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
BOOST_ASSERT(wait_res<2);
|
||||
}
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
state_data old_state=state;
|
||||
@@ -374,10 +641,18 @@ namespace boost
|
||||
if(new_state.exclusive || new_state.exclusive_waiting_blocked || new_state.upgrade)
|
||||
{
|
||||
++new_state.shared_waiting;
|
||||
if(!new_state.shared_waiting)
|
||||
{
|
||||
boost::throw_exception(boost::lock_error());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++new_state.shared_count;
|
||||
if(!new_state.shared_count)
|
||||
{
|
||||
boost::throw_exception(boost::lock_error());
|
||||
}
|
||||
new_state.upgrade=true;
|
||||
}
|
||||
|
||||
@@ -393,8 +668,8 @@ namespace boost
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BOOST_VERIFY(!detail::win32::WaitForSingleObject(unlock_sem,detail::win32::infinite));
|
||||
|
||||
BOOST_VERIFY(!detail::win32::WaitForSingleObject(semaphores[unlock_sem],detail::win32::infinite));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,9 +686,13 @@ namespace boost
|
||||
else
|
||||
{
|
||||
++new_state.shared_count;
|
||||
if(!new_state.shared_count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
new_state.upgrade=true;
|
||||
}
|
||||
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
if(current_state==old_state)
|
||||
{
|
||||
@@ -432,7 +711,7 @@ namespace boost
|
||||
state_data new_state=old_state;
|
||||
new_state.upgrade=false;
|
||||
bool const last_reader=!--new_state.shared_count;
|
||||
|
||||
|
||||
if(last_reader)
|
||||
{
|
||||
if(new_state.exclusive_waiting)
|
||||
@@ -442,13 +721,15 @@ namespace boost
|
||||
}
|
||||
new_state.shared_waiting=0;
|
||||
}
|
||||
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
if(current_state==old_state)
|
||||
{
|
||||
if(last_reader)
|
||||
{
|
||||
release_waiters(old_state);
|
||||
} else {
|
||||
release_waiters(old_state);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -463,13 +744,13 @@ namespace boost
|
||||
{
|
||||
state_data new_state=old_state;
|
||||
bool const last_reader=!--new_state.shared_count;
|
||||
|
||||
|
||||
if(last_reader)
|
||||
{
|
||||
new_state.upgrade=false;
|
||||
new_state.exclusive=true;
|
||||
}
|
||||
|
||||
|
||||
state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
|
||||
if(current_state==old_state)
|
||||
{
|
||||
@@ -508,7 +789,28 @@ namespace boost
|
||||
}
|
||||
release_waiters(old_state);
|
||||
}
|
||||
|
||||
// bool try_unlock_upgrade_and_lock()
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//#ifdef BOOST_THREAD_USES_CHRONO
|
||||
// template <class Rep, class Period>
|
||||
// bool
|
||||
// try_unlock_upgrade_and_lock_for(
|
||||
// const chrono::duration<Rep, Period>& rel_time)
|
||||
// {
|
||||
// return try_unlock_upgrade_and_lock_until(
|
||||
// chrono::steady_clock::now() + rel_time);
|
||||
// }
|
||||
// template <class Clock, class Duration>
|
||||
// bool
|
||||
// try_unlock_upgrade_and_lock_until(
|
||||
// const chrono::time_point<Clock, Duration>& abs_time)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//#endif
|
||||
|
||||
void unlock_and_lock_shared()
|
||||
{
|
||||
state_data old_state=state;
|
||||
@@ -533,7 +835,6 @@ namespace boost
|
||||
}
|
||||
release_waiters(old_state);
|
||||
}
|
||||
|
||||
void unlock_upgrade_and_lock_shared()
|
||||
{
|
||||
state_data old_state=state;
|
||||
@@ -557,8 +858,10 @@ namespace boost
|
||||
}
|
||||
release_waiters(old_state);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
typedef shared_mutex upgrade_mutex;
|
||||
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
@@ -8,13 +8,53 @@
|
||||
#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"
|
||||
|
||||
#include <boost/thread/win32/thread_primitives.hpp>
|
||||
#include <boost/thread/win32/thread_heap_alloc.hpp>
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#endif
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class thread_attributes {
|
||||
public:
|
||||
thread_attributes() {
|
||||
val_.stack_size = 0;
|
||||
//val_.lpThreadAttributes=0;
|
||||
}
|
||||
~thread_attributes() {
|
||||
}
|
||||
// stack size
|
||||
void set_stack_size(std::size_t size) {
|
||||
val_.stack_size = size;
|
||||
}
|
||||
|
||||
std::size_t get_stack_size() const {
|
||||
return val_.stack_size;
|
||||
}
|
||||
|
||||
//void set_security(LPSECURITY_ATTRIBUTES lpThreadAttributes)
|
||||
//{
|
||||
// val_.lpThreadAttributes=lpThreadAttributes;
|
||||
//}
|
||||
//LPSECURITY_ATTRIBUTES get_security()
|
||||
//{
|
||||
// return val_.lpThreadAttributes;
|
||||
//}
|
||||
|
||||
struct win_attrs {
|
||||
std::size_t stack_size;
|
||||
//LPSECURITY_ATTRIBUTES lpThreadAttributes;
|
||||
};
|
||||
typedef win_attrs native_handle_type;
|
||||
native_handle_type* native_handle() {return &val_;}
|
||||
const native_handle_type* native_handle() const {return &val_;}
|
||||
|
||||
private:
|
||||
win_attrs val_;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct thread_exit_callback_node;
|
||||
@@ -23,8 +63,8 @@ namespace boost
|
||||
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
|
||||
|
||||
struct BOOST_SYMBOL_VISIBLE thread_data_base
|
||||
{
|
||||
long count;
|
||||
detail::win32::handle_manager thread_handle;
|
||||
@@ -48,7 +88,7 @@ namespace boost
|
||||
{
|
||||
BOOST_INTERLOCKED_INCREMENT(&p->count);
|
||||
}
|
||||
|
||||
|
||||
friend void intrusive_ptr_release(thread_data_base * p)
|
||||
{
|
||||
if(!BOOST_INTERLOCKED_DECREMENT(&p->count))
|
||||
@@ -61,7 +101,7 @@ namespace boost
|
||||
{
|
||||
BOOST_VERIFY(detail::win32::SetEvent(interruption_handle)!=0);
|
||||
}
|
||||
|
||||
|
||||
typedef detail::win32::handle native_handle_type;
|
||||
|
||||
virtual void run()=0;
|
||||
@@ -69,7 +109,7 @@ namespace boost
|
||||
|
||||
typedef boost::intrusive_ptr<detail::thread_data_base> thread_data_ptr;
|
||||
|
||||
struct timeout
|
||||
struct BOOST_SYMBOL_VISIBLE timeout
|
||||
{
|
||||
unsigned long start;
|
||||
uintmax_t milliseconds;
|
||||
@@ -92,7 +132,7 @@ namespace boost
|
||||
abs_time(abs_time_)
|
||||
{}
|
||||
|
||||
struct remaining_time
|
||||
struct BOOST_SYMBOL_VISIBLE remaining_time
|
||||
{
|
||||
bool more;
|
||||
unsigned long milliseconds;
|
||||
@@ -130,7 +170,7 @@ namespace boost
|
||||
{
|
||||
return milliseconds==~uintmax_t(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static timeout sentinel()
|
||||
{
|
||||
@@ -139,38 +179,49 @@ namespace boost
|
||||
private:
|
||||
struct sentinel_type
|
||||
{};
|
||||
|
||||
|
||||
explicit timeout(sentinel_type):
|
||||
start(0),milliseconds(~uintmax_t(0)),relative(true)
|
||||
{}
|
||||
};
|
||||
|
||||
inline uintmax_t pin_to_zero(intmax_t value)
|
||||
{
|
||||
return (value<0)?0u:(uintmax_t)value;
|
||||
}
|
||||
}
|
||||
|
||||
namespace this_thread
|
||||
{
|
||||
void BOOST_THREAD_DECL yield();
|
||||
void BOOST_THREAD_DECL yield() BOOST_NOEXCEPT;
|
||||
|
||||
bool BOOST_THREAD_DECL interruptible_wait(detail::win32::handle handle_to_wait_for,detail::timeout target_time);
|
||||
inline void interruptible_wait(unsigned long milliseconds)
|
||||
inline void interruptible_wait(uintmax_t milliseconds)
|
||||
{
|
||||
interruptible_wait(detail::win32::invalid_handle_value,milliseconds);
|
||||
}
|
||||
inline void interruptible_wait(system_time const& abs_time)
|
||||
inline BOOST_SYMBOL_VISIBLE 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)
|
||||
inline BOOST_SYMBOL_VISIBLE void sleep(TimeDuration const& rel_time)
|
||||
{
|
||||
interruptible_wait(static_cast<unsigned long>(rel_time.total_milliseconds()));
|
||||
interruptible_wait(detail::pin_to_zero(rel_time.total_milliseconds()));
|
||||
}
|
||||
inline void sleep(system_time const& abs_time)
|
||||
inline BOOST_SYMBOL_VISIBLE void sleep(system_time const& abs_time)
|
||||
{
|
||||
interruptible_wait(abs_time);
|
||||
}
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
inline void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds& ns)
|
||||
{
|
||||
interruptible_wait(chrono::duration_cast<chrono::milliseconds>(ns).count());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
#ifndef THREAD_HEAP_ALLOC_HPP
|
||||
#define THREAD_HEAP_ALLOC_HPP
|
||||
#include <new>
|
||||
#include "thread_primitives.hpp"
|
||||
#include <boost/thread/win32/thread_primitives.hpp>
|
||||
#include <stdexcept>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#if defined( BOOST_USE_WINDOWS_H )
|
||||
# include <windows.h>
|
||||
@@ -55,21 +56,21 @@ namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
inline BOOST_THREAD_DECL void* allocate_raw_heap_memory(unsigned size)
|
||||
inline void* allocate_raw_heap_memory(unsigned size)
|
||||
{
|
||||
void* const heap_memory=detail::win32::HeapAlloc(detail::win32::GetProcessHeap(),0,size);
|
||||
if(!heap_memory)
|
||||
{
|
||||
throw std::bad_alloc();
|
||||
boost::throw_exception(std::bad_alloc());
|
||||
}
|
||||
return heap_memory;
|
||||
}
|
||||
|
||||
inline BOOST_THREAD_DECL void free_raw_heap_memory(void* heap_memory)
|
||||
inline void free_raw_heap_memory(void* heap_memory)
|
||||
{
|
||||
BOOST_VERIFY(detail::win32::HeapFree(detail::win32::GetProcessHeap(),0,heap_memory)!=0);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline T* heap_new()
|
||||
{
|
||||
@@ -86,7 +87,7 @@ namespace boost
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BOOST_HAS_RVALUE_REFS
|
||||
#ifndef BOOST_NO_RVALUE_REFERENCES
|
||||
template<typename T,typename A1>
|
||||
inline T* heap_new(A1&& a1)
|
||||
{
|
||||
@@ -225,7 +226,7 @@ namespace boost
|
||||
{
|
||||
return heap_new_impl<T,A1&>(a1);
|
||||
}
|
||||
|
||||
|
||||
template<typename T,typename A1,typename A2>
|
||||
inline T* heap_new(A1 const& a1,A2 const& a2)
|
||||
{
|
||||
@@ -371,8 +372,8 @@ namespace boost
|
||||
{
|
||||
return heap_new_impl<T,A1&,A2&,A3&,A4&>(a1,a2,a3,a4);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
template<typename T>
|
||||
inline void heap_delete(T* data)
|
||||
{
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
|
||||
// win32_thread_primitives.hpp
|
||||
//
|
||||
// (C) Copyright 2005-7 Anthony Williams
|
||||
// (C) Copyright 2007 David Deakins
|
||||
// (C) Copyright 2005-7 Anthony Williams
|
||||
// (C) Copyright 2007 David Deakins
|
||||
//
|
||||
// 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/config.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/thread/exceptions.hpp>
|
||||
#include <boost/detail/interlocked.hpp>
|
||||
@@ -30,14 +31,18 @@ namespace boost
|
||||
unsigned const infinite=INFINITE;
|
||||
unsigned const timeout=WAIT_TIMEOUT;
|
||||
handle const invalid_handle_value=INVALID_HANDLE_VALUE;
|
||||
unsigned const event_modify_state=EVENT_MODIFY_STATE;
|
||||
unsigned const synchronize=SYNCHRONIZE;
|
||||
|
||||
# ifdef BOOST_NO_ANSI_APIS
|
||||
using ::CreateMutexW;
|
||||
using ::CreateEventW;
|
||||
using ::OpenEventW;
|
||||
using ::CreateSemaphoreW;
|
||||
# else
|
||||
using ::CreateMutexA;
|
||||
using ::CreateEventA;
|
||||
using ::OpenEventA;
|
||||
using ::CreateSemaphoreA;
|
||||
# endif
|
||||
using ::CloseHandle;
|
||||
@@ -89,7 +94,7 @@ namespace boost
|
||||
{
|
||||
namespace win32
|
||||
{
|
||||
|
||||
|
||||
# ifdef _WIN64
|
||||
typedef unsigned __int64 ulong_ptr;
|
||||
# else
|
||||
@@ -99,6 +104,8 @@ namespace boost
|
||||
unsigned const infinite=~0U;
|
||||
unsigned const timeout=258U;
|
||||
handle const invalid_handle_value=(handle)(-1);
|
||||
unsigned const event_modify_state=2;
|
||||
unsigned const synchronize=0x100000u;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -107,10 +114,12 @@ namespace boost
|
||||
__declspec(dllimport) void* __stdcall CreateMutexW(_SECURITY_ATTRIBUTES*,int,wchar_t const*);
|
||||
__declspec(dllimport) void* __stdcall CreateSemaphoreW(_SECURITY_ATTRIBUTES*,long,long,wchar_t const*);
|
||||
__declspec(dllimport) void* __stdcall CreateEventW(_SECURITY_ATTRIBUTES*,int,int,wchar_t const*);
|
||||
__declspec(dllimport) void* __stdcall OpenEventW(unsigned long,int,wchar_t const*);
|
||||
# else
|
||||
__declspec(dllimport) void* __stdcall CreateMutexA(_SECURITY_ATTRIBUTES*,int,char const*);
|
||||
__declspec(dllimport) void* __stdcall CreateSemaphoreA(_SECURITY_ATTRIBUTES*,long,long,char const*);
|
||||
__declspec(dllimport) void* __stdcall CreateEventA(_SECURITY_ATTRIBUTES*,int,int,char const*);
|
||||
__declspec(dllimport) void* __stdcall OpenEventA(unsigned long,int,char const*);
|
||||
# endif
|
||||
__declspec(dllimport) int __stdcall CloseHandle(void*);
|
||||
__declspec(dllimport) int __stdcall ReleaseMutex(void*);
|
||||
@@ -161,40 +170,49 @@ namespace boost
|
||||
auto_reset_event=false,
|
||||
manual_reset_event=true
|
||||
};
|
||||
|
||||
|
||||
enum initial_event_state
|
||||
{
|
||||
event_initially_reset=false,
|
||||
event_initially_set=true
|
||||
};
|
||||
|
||||
|
||||
inline handle create_anonymous_event(event_type type,initial_event_state state)
|
||||
{
|
||||
#if !defined(BOOST_NO_ANSI_APIS)
|
||||
#if !defined(BOOST_NO_ANSI_APIS)
|
||||
handle const res=win32::CreateEventA(0,type,state,0);
|
||||
#else
|
||||
handle const res=win32::CreateEventW(0,type,state,0);
|
||||
#endif
|
||||
#endif
|
||||
if(!res)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
inline handle create_anonymous_semaphore(long initial_count,long max_count)
|
||||
{
|
||||
#if !defined(BOOST_NO_ANSI_APIS)
|
||||
#if !defined(BOOST_NO_ANSI_APIS)
|
||||
handle const res=CreateSemaphoreA(0,initial_count,max_count,0);
|
||||
#else
|
||||
handle const res=CreateSemaphoreW(0,initial_count,max_count,0);
|
||||
#endif
|
||||
#endif
|
||||
if(!res)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
inline handle create_anonymous_semaphore_nothrow(long initial_count,long max_count)
|
||||
{
|
||||
#if !defined(BOOST_NO_ANSI_APIS)
|
||||
handle const res=CreateSemaphoreA(0,initial_count,max_count,0);
|
||||
#else
|
||||
handle const res=CreateSemaphoreW(0,initial_count,max_count,0);
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
inline handle duplicate_handle(handle source)
|
||||
{
|
||||
@@ -204,7 +222,7 @@ namespace boost
|
||||
bool const success=DuplicateHandle(current_process,source,current_process,&new_handle,0,false,same_access_flag)!=0;
|
||||
if(!success)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error());
|
||||
}
|
||||
return new_handle;
|
||||
}
|
||||
@@ -228,7 +246,7 @@ namespace boost
|
||||
BOOST_VERIFY(CloseHandle(handle_to_manage));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
explicit handle_manager(handle handle_to_manage_):
|
||||
handle_to_manage(handle_to_manage_)
|
||||
@@ -236,7 +254,7 @@ namespace boost
|
||||
handle_manager():
|
||||
handle_to_manage(0)
|
||||
{}
|
||||
|
||||
|
||||
handle_manager& operator=(handle new_handle)
|
||||
{
|
||||
cleanup();
|
||||
@@ -270,13 +288,13 @@ namespace boost
|
||||
{
|
||||
return !handle_to_manage;
|
||||
}
|
||||
|
||||
|
||||
~handle_manager()
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -309,7 +327,7 @@ namespace boost
|
||||
{
|
||||
return _interlockedbittestandreset(x,bit)!=0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,7 +346,7 @@ namespace boost
|
||||
mov edx,x;
|
||||
lock bts [edx],eax;
|
||||
setc al;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
inline bool interlocked_bit_test_and_reset(long* x,long bit)
|
||||
@@ -338,9 +356,9 @@ namespace boost
|
||||
mov edx,x;
|
||||
lock btr [edx],eax;
|
||||
setc al;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
56
src/future.cpp
Executable file
56
src/future.cpp
Executable file
@@ -0,0 +1,56 @@
|
||||
// (C) Copyright 2012 Vicente J. Botet Escriba
|
||||
// Use, modification and distribution are subject to 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/future.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace thread_detail
|
||||
{
|
||||
|
||||
class future_error_category :
|
||||
public boost::system::error_category
|
||||
{
|
||||
public:
|
||||
virtual const char* name() const; //BOOST_NOEXCEPT;
|
||||
virtual std::string message(int ev) const;
|
||||
};
|
||||
|
||||
const char*
|
||||
future_error_category::name() const //BOOST_NOEXCEPT
|
||||
{
|
||||
return "future";
|
||||
}
|
||||
|
||||
std::string
|
||||
future_error_category::message(int ev) const
|
||||
{
|
||||
switch (BOOST_SCOPED_ENUM_NATIVE(future_errc)(ev))
|
||||
{
|
||||
case future_errc::broken_promise:
|
||||
return std::string("The associated promise has been destructed prior "
|
||||
"to the associated state becoming ready.");
|
||||
case future_errc::future_already_retrieved:
|
||||
return std::string("The future has already been retrieved from "
|
||||
"the promise or packaged_task.");
|
||||
case future_errc::promise_already_satisfied:
|
||||
return std::string("The state of the promise has already been set.");
|
||||
case future_errc::no_state:
|
||||
return std::string("Operation not permitted on an object without "
|
||||
"an associated state.");
|
||||
}
|
||||
return std::string("unspecified future_errc value\n");
|
||||
}
|
||||
}
|
||||
|
||||
const system::error_category&
|
||||
future_category()
|
||||
{
|
||||
static thread_detail::future_error_category f;
|
||||
return f;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
|
||||
#include <boost/thread/exceptions.hpp>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
namespace boost {
|
||||
|
||||
thread_exception::thread_exception()
|
||||
: m_sys_err(0)
|
||||
{
|
||||
}
|
||||
|
||||
thread_exception::thread_exception(int sys_err_code)
|
||||
: m_sys_err(sys_err_code)
|
||||
{
|
||||
}
|
||||
|
||||
thread_exception::~thread_exception() throw()
|
||||
{
|
||||
}
|
||||
|
||||
int thread_exception::native_error() const
|
||||
{
|
||||
return m_sys_err;
|
||||
}
|
||||
|
||||
lock_error::lock_error()
|
||||
{
|
||||
}
|
||||
|
||||
lock_error::lock_error(int sys_err_code)
|
||||
: thread_exception(sys_err_code)
|
||||
{
|
||||
}
|
||||
|
||||
lock_error::~lock_error() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char* lock_error::what() const throw()
|
||||
{
|
||||
return "boost::lock_error";
|
||||
}
|
||||
|
||||
thread_resource_error::thread_resource_error()
|
||||
{
|
||||
}
|
||||
|
||||
thread_resource_error::thread_resource_error(int sys_err_code)
|
||||
: thread_exception(sys_err_code)
|
||||
{
|
||||
}
|
||||
|
||||
thread_resource_error::~thread_resource_error() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char* thread_resource_error::what() const throw()
|
||||
{
|
||||
return "boost::thread_resource_error";
|
||||
}
|
||||
|
||||
unsupported_thread_option::unsupported_thread_option()
|
||||
{
|
||||
}
|
||||
|
||||
unsupported_thread_option::unsupported_thread_option(int sys_err_code)
|
||||
: thread_exception(sys_err_code)
|
||||
{
|
||||
}
|
||||
|
||||
unsupported_thread_option::~unsupported_thread_option() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char* unsupported_thread_option::what() const throw()
|
||||
{
|
||||
return "boost::unsupported_thread_option";
|
||||
}
|
||||
|
||||
invalid_thread_argument::invalid_thread_argument()
|
||||
{
|
||||
}
|
||||
|
||||
invalid_thread_argument::invalid_thread_argument(int sys_err_code)
|
||||
: thread_exception(sys_err_code)
|
||||
{
|
||||
}
|
||||
|
||||
invalid_thread_argument::~invalid_thread_argument() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char* invalid_thread_argument::what() const throw()
|
||||
{
|
||||
return "boost::invalid_thread_argument";
|
||||
}
|
||||
|
||||
thread_permission_error::thread_permission_error()
|
||||
{
|
||||
}
|
||||
|
||||
thread_permission_error::thread_permission_error(int sys_err_code)
|
||||
: thread_exception(sys_err_code)
|
||||
{
|
||||
}
|
||||
|
||||
thread_permission_error::~thread_permission_error() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char* thread_permission_error::what() const throw()
|
||||
{
|
||||
return "boost::thread_permission_error";
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
41
src/pthread/once.cpp
Executable file → Normal file
41
src/pthread/once.cpp
Executable file → Normal file
@@ -1,6 +1,6 @@
|
||||
// Copyright (C) 2007 Anthony Williams
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// 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)
|
||||
|
||||
#define __STDC_CONSTANT_MACROS
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <boost/assert.hpp>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@@ -21,19 +22,39 @@ namespace boost
|
||||
{
|
||||
pthread_key_t epoch_tss_key;
|
||||
pthread_once_t epoch_tss_key_flag=PTHREAD_ONCE_INIT;
|
||||
|
||||
extern "C" void delete_epoch_tss_data(void* data)
|
||||
|
||||
extern "C"
|
||||
{
|
||||
free(data);
|
||||
static void delete_epoch_tss_data(void* data)
|
||||
{
|
||||
free(data);
|
||||
}
|
||||
|
||||
static void create_epoch_tss_key()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_key_create(&epoch_tss_key,delete_epoch_tss_data));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void create_epoch_tss_key()
|
||||
#if defined BOOST_THREAD_PATCH
|
||||
const pthread_once_t pthread_once_init_value=PTHREAD_ONCE_INIT;
|
||||
struct BOOST_THREAD_DECL delete_epoch_tss_key_on_dlclose_t
|
||||
{
|
||||
BOOST_VERIFY(!pthread_key_create(&epoch_tss_key,delete_epoch_tss_data));
|
||||
}
|
||||
|
||||
delete_epoch_tss_key_on_dlclose_t()
|
||||
{
|
||||
}
|
||||
~delete_epoch_tss_key_on_dlclose_t()
|
||||
{
|
||||
if(memcmp(&epoch_tss_key_flag, &pthread_once_init_value, sizeof(pthread_once_t)))
|
||||
{
|
||||
pthread_key_delete(epoch_tss_key);
|
||||
}
|
||||
}
|
||||
};
|
||||
delete_epoch_tss_key_on_dlclose_t delete_epoch_tss_key_on_dlclose;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
boost::uintmax_t& get_once_per_thread_epoch()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_once(&epoch_tss_key_flag,create_epoch_tss_key));
|
||||
@@ -47,5 +68,5 @@ namespace boost
|
||||
return *static_cast<boost::uintmax_t*>(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
// Copyright (C) 2007-8 Anthony Williams
|
||||
// (C) Copyright 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// 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>
|
||||
@@ -13,7 +14,8 @@
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/once.hpp>
|
||||
#include <boost/thread/tss.hpp>
|
||||
#ifdef __linux__
|
||||
#include <boost/throw_exception.hpp>
|
||||
#ifdef __GLIBC__
|
||||
#include <sys/sysinfo.h>
|
||||
#elif defined(__APPLE__) || defined(__FreeBSD__)
|
||||
#include <sys/types.h>
|
||||
@@ -42,19 +44,6 @@ namespace boost
|
||||
{}
|
||||
};
|
||||
|
||||
struct tss_data_node
|
||||
{
|
||||
void const* key;
|
||||
boost::shared_ptr<boost::detail::tss_cleanup_function> func;
|
||||
void* value;
|
||||
tss_data_node* next;
|
||||
|
||||
tss_data_node(void const* key_,boost::shared_ptr<boost::detail::tss_cleanup_function> func_,void* value_,
|
||||
tss_data_node* next_):
|
||||
key(key_),func(func_),value(value_),next(next_)
|
||||
{}
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
boost::once_flag current_thread_tls_init_flag=BOOST_ONCE_INIT;
|
||||
@@ -62,12 +51,12 @@ namespace boost
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void tls_destructor(void* data)
|
||||
static void tls_destructor(void* data)
|
||||
{
|
||||
boost::detail::thread_data_base* thread_info=static_cast<boost::detail::thread_data_base*>(data);
|
||||
if(thread_info)
|
||||
{
|
||||
while(thread_info->tss_data || thread_info->thread_exit_callbacks)
|
||||
while(!thread_info->tss_data.empty() || thread_info->thread_exit_callbacks)
|
||||
{
|
||||
while(thread_info->thread_exit_callbacks)
|
||||
{
|
||||
@@ -80,29 +69,49 @@ namespace boost
|
||||
}
|
||||
delete current_node;
|
||||
}
|
||||
while(thread_info->tss_data)
|
||||
for(std::map<void const*,tss_data_node>::iterator next=thread_info->tss_data.begin(),
|
||||
current,
|
||||
end=thread_info->tss_data.end();
|
||||
next!=end;)
|
||||
{
|
||||
detail::tss_data_node* const current_node=thread_info->tss_data;
|
||||
thread_info->tss_data=current_node->next;
|
||||
if(current_node->func)
|
||||
current=next;
|
||||
++next;
|
||||
if(current->second.func && (current->second.value!=0))
|
||||
{
|
||||
(*current_node->func)(current_node->value);
|
||||
(*current->second.func)(current->second.value);
|
||||
}
|
||||
delete current_node;
|
||||
thread_info->tss_data.erase(current);
|
||||
}
|
||||
}
|
||||
thread_info->self.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if defined BOOST_THREAD_PATCH
|
||||
|
||||
struct delete_current_thread_tls_key_on_dlclose_t
|
||||
{
|
||||
delete_current_thread_tls_key_on_dlclose_t()
|
||||
{
|
||||
}
|
||||
~delete_current_thread_tls_key_on_dlclose_t()
|
||||
{
|
||||
if (current_thread_tls_init_flag.epoch!=BOOST_ONCE_INITIAL_FLAG_VALUE)
|
||||
{
|
||||
pthread_key_delete(current_thread_tls_key);
|
||||
}
|
||||
}
|
||||
};
|
||||
delete_current_thread_tls_key_on_dlclose_t delete_current_thread_tls_key_on_dlclose;
|
||||
#endif
|
||||
|
||||
void create_current_thread_tls_key()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_key_create(¤t_thread_tls_key,&tls_destructor));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::detail::thread_data_base* get_current_thread_data()
|
||||
{
|
||||
boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key);
|
||||
@@ -115,12 +124,12 @@ namespace boost
|
||||
BOOST_VERIFY(!pthread_setspecific(current_thread_tls_key,new_data));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
void* thread_proxy(void* param)
|
||||
static void* thread_proxy(void* param)
|
||||
{
|
||||
boost::detail::thread_data_ptr thread_info = static_cast<boost::detail::thread_data_base*>(param)->self;
|
||||
thread_info->self.reset();
|
||||
@@ -132,10 +141,12 @@ namespace boost
|
||||
catch(thread_interrupted const&)
|
||||
{
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
std::terminate();
|
||||
}
|
||||
// Removed as it stops the debugger identifying the cause of the exception
|
||||
// Unhandled exceptions still cause the application to terminate
|
||||
// catch(...)
|
||||
// {
|
||||
// std::terminate();
|
||||
// }
|
||||
|
||||
detail::tls_destructor(thread_info.get());
|
||||
detail::set_current_thread_data(0);
|
||||
@@ -153,7 +164,7 @@ namespace boost
|
||||
{
|
||||
interrupt_enabled=false;
|
||||
}
|
||||
|
||||
|
||||
void run()
|
||||
{}
|
||||
|
||||
@@ -184,7 +195,7 @@ namespace boost
|
||||
}
|
||||
|
||||
|
||||
thread::thread()
|
||||
thread::thread() BOOST_NOEXCEPT
|
||||
{}
|
||||
|
||||
void thread::start_thread()
|
||||
@@ -192,10 +203,45 @@ namespace boost
|
||||
thread_info->self=thread_info;
|
||||
int const res = pthread_create(&thread_info->thread_handle, 0, &thread_proxy, thread_info.get());
|
||||
if (res != 0)
|
||||
{
|
||||
thread_info->self.reset();
|
||||
boost::throw_exception(thread_resource_error(res, "boost thread: failed in pthread_create"));
|
||||
}
|
||||
}
|
||||
|
||||
void thread::start_thread(const attributes& attr)
|
||||
{
|
||||
thread_info->self=thread_info;
|
||||
const attributes::native_handle_type* h = attr.native_handle();
|
||||
int res = pthread_create(&thread_info->thread_handle, h, &thread_proxy, thread_info.get());
|
||||
if (res != 0)
|
||||
{
|
||||
thread_info->self.reset();
|
||||
throw thread_resource_error();
|
||||
}
|
||||
int detached_state;
|
||||
res = pthread_attr_getdetachstate(h, &detached_state);
|
||||
if (res != 0)
|
||||
{
|
||||
thread_info->self.reset();
|
||||
throw thread_resource_error();
|
||||
}
|
||||
if (PTHREAD_CREATE_DETACHED==detached_state)
|
||||
{
|
||||
detail::thread_data_ptr local_thread_info;
|
||||
thread_info.swap(local_thread_info);
|
||||
|
||||
if(local_thread_info)
|
||||
{
|
||||
//lock_guard<mutex> lock(local_thread_info->data_mutex);
|
||||
if(!local_thread_info->join_started)
|
||||
{
|
||||
//BOOST_VERIFY(!pthread_detach(local_thread_info->thread_handle));
|
||||
local_thread_info->join_started=true;
|
||||
local_thread_info->joined=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
thread::~thread()
|
||||
@@ -203,19 +249,22 @@ namespace boost
|
||||
detach();
|
||||
}
|
||||
|
||||
detail::thread_data_ptr thread::get_thread_info() const
|
||||
detail::thread_data_ptr thread::get_thread_info BOOST_PREVENT_MACRO_SUBSTITUTION () const
|
||||
{
|
||||
lock_guard<mutex> l(thread_info_mutex);
|
||||
return thread_info;
|
||||
}
|
||||
|
||||
void thread::join()
|
||||
{
|
||||
detail::thread_data_ptr const local_thread_info=get_thread_info();
|
||||
if (this_thread::get_id() == get_id())
|
||||
{
|
||||
boost::throw_exception(thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself"));
|
||||
}
|
||||
detail::thread_data_ptr const local_thread_info=(get_thread_info)();
|
||||
if(local_thread_info)
|
||||
{
|
||||
bool do_join=false;
|
||||
|
||||
|
||||
{
|
||||
unique_lock<mutex> lock(local_thread_info->data_mutex);
|
||||
while(!local_thread_info->done)
|
||||
@@ -223,7 +272,7 @@ namespace boost
|
||||
local_thread_info->done_condition.wait(lock);
|
||||
}
|
||||
do_join=!local_thread_info->join_started;
|
||||
|
||||
|
||||
if(do_join)
|
||||
{
|
||||
local_thread_info->join_started=true;
|
||||
@@ -244,8 +293,7 @@ namespace boost
|
||||
local_thread_info->joined=true;
|
||||
local_thread_info->done_condition.notify_all();
|
||||
}
|
||||
|
||||
lock_guard<mutex> l1(thread_info_mutex);
|
||||
|
||||
if(thread_info==local_thread_info)
|
||||
{
|
||||
thread_info.reset();
|
||||
@@ -253,24 +301,28 @@ namespace boost
|
||||
}
|
||||
}
|
||||
|
||||
bool thread::timed_join(system_time const& wait_until)
|
||||
bool thread::do_try_join_until(struct timespec const &timeout)
|
||||
{
|
||||
detail::thread_data_ptr const local_thread_info=get_thread_info();
|
||||
if (this_thread::get_id() == get_id())
|
||||
{
|
||||
boost::throw_exception(thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself"));
|
||||
}
|
||||
detail::thread_data_ptr const local_thread_info=(get_thread_info)();
|
||||
if(local_thread_info)
|
||||
{
|
||||
bool do_join=false;
|
||||
|
||||
|
||||
{
|
||||
unique_lock<mutex> lock(local_thread_info->data_mutex);
|
||||
while(!local_thread_info->done)
|
||||
{
|
||||
if(!local_thread_info->done_condition.timed_wait(lock,wait_until))
|
||||
if(!local_thread_info->done_condition.do_timed_wait(lock,timeout))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
do_join=!local_thread_info->join_started;
|
||||
|
||||
|
||||
if(do_join)
|
||||
{
|
||||
local_thread_info->join_started=true;
|
||||
@@ -291,8 +343,7 @@ namespace boost
|
||||
local_thread_info->joined=true;
|
||||
local_thread_info->done_condition.notify_all();
|
||||
}
|
||||
|
||||
lock_guard<mutex> l1(thread_info_mutex);
|
||||
|
||||
if(thread_info==local_thread_info)
|
||||
{
|
||||
thread_info.reset();
|
||||
@@ -301,20 +352,17 @@ namespace boost
|
||||
return true;
|
||||
}
|
||||
|
||||
bool thread::joinable() const
|
||||
bool thread::joinable() const BOOST_NOEXCEPT
|
||||
{
|
||||
return get_thread_info();
|
||||
return (get_thread_info)();
|
||||
}
|
||||
|
||||
|
||||
void thread::detach()
|
||||
{
|
||||
detail::thread_data_ptr local_thread_info;
|
||||
{
|
||||
lock_guard<mutex> l1(thread_info_mutex);
|
||||
thread_info.swap(local_thread_info);
|
||||
}
|
||||
|
||||
thread_info.swap(local_thread_info);
|
||||
|
||||
if(local_thread_info)
|
||||
{
|
||||
lock_guard<mutex> lock(local_thread_info->data_mutex);
|
||||
@@ -329,11 +377,15 @@ namespace boost
|
||||
|
||||
namespace this_thread
|
||||
{
|
||||
|
||||
|
||||
#ifdef __DECXXX
|
||||
/// Workaround of DECCXX issue of incorrect template substitution
|
||||
template<>
|
||||
#endif
|
||||
void sleep(const system_time& st)
|
||||
{
|
||||
detail::thread_data_base* const thread_info=detail::get_current_thread_data();
|
||||
|
||||
|
||||
if(thread_info)
|
||||
{
|
||||
unique_lock<mutex> lk(thread_info->sleep_mutex);
|
||||
@@ -342,7 +394,7 @@ namespace boost
|
||||
else
|
||||
{
|
||||
xtime const xt=get_xtime(st);
|
||||
|
||||
|
||||
for (int foo=0; foo < 5; ++foo)
|
||||
{
|
||||
# if defined(BOOST_HAS_PTHREAD_DELAY_NP)
|
||||
@@ -352,7 +404,7 @@ namespace boost
|
||||
# elif defined(BOOST_HAS_NANOSLEEP)
|
||||
timespec ts;
|
||||
to_timespec_duration(xt, ts);
|
||||
|
||||
|
||||
// nanosleep takes a timespec that is an offset, not
|
||||
// an absolute time.
|
||||
nanosleep(&ts, 0);
|
||||
@@ -370,7 +422,34 @@ namespace boost
|
||||
}
|
||||
}
|
||||
|
||||
void yield()
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
void
|
||||
sleep_for(const chrono::nanoseconds& ns)
|
||||
{
|
||||
using namespace chrono;
|
||||
if (ns >= nanoseconds::zero())
|
||||
{
|
||||
timespec ts;
|
||||
ts.tv_sec = static_cast<long>(duration_cast<seconds>(ns).count());
|
||||
ts.tv_nsec = static_cast<long>((ns - seconds(ts.tv_sec)).count());
|
||||
|
||||
# if defined(BOOST_HAS_PTHREAD_DELAY_NP)
|
||||
BOOST_VERIFY(!pthread_delay_np(&ts));
|
||||
# elif defined(BOOST_HAS_NANOSLEEP)
|
||||
// nanosleep takes a timespec that is an offset, not
|
||||
// an absolute time.
|
||||
nanosleep(&ts, 0);
|
||||
# else
|
||||
mutex mx;
|
||||
mutex::scoped_lock lock(mx);
|
||||
condition_variable cond;
|
||||
cond.wait_for(lock, ns);
|
||||
# endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void yield() BOOST_NOEXCEPT
|
||||
{
|
||||
# if defined(BOOST_HAS_SCHED_YIELD)
|
||||
BOOST_VERIFY(!sched_yield());
|
||||
@@ -383,13 +462,10 @@ namespace boost
|
||||
# endif
|
||||
}
|
||||
}
|
||||
|
||||
unsigned thread::hardware_concurrency()
|
||||
unsigned thread::hardware_concurrency() BOOST_NOEXCEPT
|
||||
{
|
||||
#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);
|
||||
@@ -397,14 +473,16 @@ namespace boost
|
||||
#elif defined(BOOST_HAS_UNISTD_H) && defined(_SC_NPROCESSORS_ONLN)
|
||||
int const count=sysconf(_SC_NPROCESSORS_ONLN);
|
||||
return (count>0)?count:0;
|
||||
#elif defined(__GLIBC__)
|
||||
return get_nprocs();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
thread::id thread::get_id() const
|
||||
thread::id thread::get_id() const BOOST_NOEXCEPT
|
||||
{
|
||||
detail::thread_data_ptr const local_thread_info=get_thread_info();
|
||||
detail::thread_data_ptr const local_thread_info=(get_thread_info)();
|
||||
if(local_thread_info)
|
||||
{
|
||||
return id(local_thread_info);
|
||||
@@ -417,13 +495,14 @@ namespace boost
|
||||
|
||||
void thread::interrupt()
|
||||
{
|
||||
detail::thread_data_ptr const local_thread_info=get_thread_info();
|
||||
detail::thread_data_ptr const local_thread_info=(get_thread_info)();
|
||||
if(local_thread_info)
|
||||
{
|
||||
lock_guard<mutex> lk(local_thread_info->data_mutex);
|
||||
local_thread_info->interrupt_requested=true;
|
||||
if(local_thread_info->current_cond)
|
||||
{
|
||||
boost::pthread::pthread_mutex_scoped_lock internal_lock(local_thread_info->cond_mutex);
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(local_thread_info->current_cond));
|
||||
}
|
||||
}
|
||||
@@ -431,7 +510,7 @@ namespace boost
|
||||
|
||||
bool thread::interruption_requested() const
|
||||
{
|
||||
detail::thread_data_ptr const local_thread_info=get_thread_info();
|
||||
detail::thread_data_ptr const local_thread_info=(get_thread_info)();
|
||||
if(local_thread_info)
|
||||
{
|
||||
lock_guard<mutex> lk(local_thread_info->data_mutex);
|
||||
@@ -445,7 +524,7 @@ namespace boost
|
||||
|
||||
thread::native_handle_type thread::native_handle()
|
||||
{
|
||||
detail::thread_data_ptr const local_thread_info=get_thread_info();
|
||||
detail::thread_data_ptr const local_thread_info=(get_thread_info)();
|
||||
if(local_thread_info)
|
||||
{
|
||||
lock_guard<mutex> lk(local_thread_info->data_mutex);
|
||||
@@ -456,12 +535,12 @@ namespace boost
|
||||
return pthread_t();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace this_thread
|
||||
{
|
||||
thread::id get_id()
|
||||
thread::id get_id() BOOST_NOEXCEPT
|
||||
{
|
||||
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());
|
||||
@@ -480,13 +559,13 @@ namespace boost
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool interruption_enabled()
|
||||
{
|
||||
boost::detail::thread_data_base* const thread_info=detail::get_current_thread_data();
|
||||
return thread_info && thread_info->interrupt_enabled;
|
||||
}
|
||||
|
||||
|
||||
bool interruption_requested()
|
||||
{
|
||||
boost::detail::thread_data_base* const thread_info=detail::get_current_thread_data();
|
||||
@@ -509,7 +588,7 @@ namespace boost
|
||||
detail::get_current_thread_data()->interrupt_enabled=false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
disable_interruption::~disable_interruption()
|
||||
{
|
||||
if(detail::get_current_thread_data())
|
||||
@@ -525,7 +604,7 @@ namespace boost
|
||||
detail::get_current_thread_data()->interrupt_enabled=true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
restore_interruption::~restore_interruption()
|
||||
{
|
||||
if(detail::get_current_thread_data())
|
||||
@@ -550,14 +629,11 @@ namespace boost
|
||||
detail::thread_data_base* const current_thread_data(get_current_thread_data());
|
||||
if(current_thread_data)
|
||||
{
|
||||
detail::tss_data_node* current_node=current_thread_data->tss_data;
|
||||
while(current_node)
|
||||
std::map<void const*,tss_data_node>::iterator current_node=
|
||||
current_thread_data->tss_data.find(key);
|
||||
if(current_node!=current_thread_data->tss_data.end())
|
||||
{
|
||||
if(current_node->key==key)
|
||||
{
|
||||
return current_node;
|
||||
}
|
||||
current_node=current_node->next;
|
||||
return ¤t_node->second;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
@@ -571,106 +647,47 @@ namespace boost
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void set_tss_data(void const* key,boost::shared_ptr<tss_cleanup_function> func,void* tss_data,bool cleanup_existing)
|
||||
|
||||
void add_new_tss_node(void const* key,
|
||||
boost::shared_ptr<tss_cleanup_function> func,
|
||||
void* tss_data)
|
||||
{
|
||||
detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data());
|
||||
current_thread_data->tss_data.insert(std::make_pair(key,tss_data_node(func,tss_data)));
|
||||
}
|
||||
|
||||
void erase_tss_node(void const* key)
|
||||
{
|
||||
detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data());
|
||||
current_thread_data->tss_data.erase(key);
|
||||
}
|
||||
|
||||
void set_tss_data(void const* key,
|
||||
boost::shared_ptr<tss_cleanup_function> func,
|
||||
void* tss_data,bool cleanup_existing)
|
||||
{
|
||||
if(tss_data_node* const current_node=find_tss_data(key))
|
||||
{
|
||||
if(cleanup_existing && current_node->func)
|
||||
if(cleanup_existing && current_node->func && (current_node->value!=0))
|
||||
{
|
||||
(*current_node->func)(current_node->value);
|
||||
}
|
||||
current_node->func=func;
|
||||
current_node->value=tss_data;
|
||||
if(func || (tss_data!=0))
|
||||
{
|
||||
current_node->func=func;
|
||||
current_node->value=tss_data;
|
||||
}
|
||||
else
|
||||
{
|
||||
erase_tss_node(key);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data());
|
||||
tss_data_node* const new_node=new tss_data_node(key,func,tss_data,current_thread_data->tss_data);
|
||||
current_thread_data->tss_data=new_node;
|
||||
add_new_tss_node(key,func,tss_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// size_t thread_group::size() const
|
||||
// {
|
||||
// return m_threads.size();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
// Copyright (C) 2009 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)
|
||||
|
||||
// boostinspect:nounnamed
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace {
|
||||
const int MILLISECONDS_PER_SECOND = 1000;
|
||||
const int NANOSECONDS_PER_SECOND = 1000000000;
|
||||
@@ -18,7 +21,7 @@ inline void to_time(int milliseconds, boost::xtime& xt)
|
||||
{
|
||||
int res = 0;
|
||||
res = boost::xtime_get(&xt, boost::TIME_UTC);
|
||||
assert(res == boost::TIME_UTC);
|
||||
BOOST_ASSERT(res == boost::TIME_UTC); (void)res;
|
||||
|
||||
xt.sec += (milliseconds / MILLISECONDS_PER_SECOND);
|
||||
xt.nsec += ((milliseconds % MILLISECONDS_PER_SECOND) *
|
||||
@@ -30,7 +33,6 @@ inline void to_time(int milliseconds, boost::xtime& xt)
|
||||
xt.nsec -= NANOSECONDS_PER_SECOND;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(BOOST_HAS_PTHREADS)
|
||||
inline void to_timespec(const boost::xtime& xt, timespec& ts)
|
||||
{
|
||||
@@ -55,7 +57,7 @@ inline void to_timespec_duration(const boost::xtime& xt, timespec& ts)
|
||||
boost::xtime cur;
|
||||
int res = 0;
|
||||
res = boost::xtime_get(&cur, boost::TIME_UTC);
|
||||
assert(res == boost::TIME_UTC);
|
||||
BOOST_ASSERT(res == boost::TIME_UTC); (void)res;
|
||||
|
||||
if (boost::xtime_cmp(xt, cur) <= 0)
|
||||
{
|
||||
@@ -86,7 +88,7 @@ inline void to_duration(boost::xtime xt, int& milliseconds)
|
||||
boost::xtime cur;
|
||||
int res = 0;
|
||||
res = boost::xtime_get(&cur, boost::TIME_UTC);
|
||||
assert(res == boost::TIME_UTC);
|
||||
BOOST_ASSERT(res == boost::TIME_UTC); (void)res;
|
||||
|
||||
if (boost::xtime_cmp(xt, cur) <= 0)
|
||||
milliseconds = 0;
|
||||
@@ -108,7 +110,7 @@ inline void to_microduration(boost::xtime xt, int& microseconds)
|
||||
boost::xtime cur;
|
||||
int res = 0;
|
||||
res = boost::xtime_get(&cur, boost::TIME_UTC);
|
||||
assert(res == boost::TIME_UTC);
|
||||
BOOST_ASSERT(res == boost::TIME_UTC); (void)res;
|
||||
|
||||
if (boost::xtime_cmp(xt, cur) <= 0)
|
||||
microseconds = 0;
|
||||
|
||||
@@ -8,13 +8,15 @@
|
||||
|
||||
#if defined(BOOST_HAS_WINTHREADS) && (defined(BOOST_THREAD_BUILD_LIB) || defined(BOOST_THREAD_TEST) || defined(UNDER_CE)) && (!defined(_MSC_VER) || defined(UNDER_CE))
|
||||
|
||||
namespace boost
|
||||
{
|
||||
/*
|
||||
This file is a "null" implementation of tss cleanup; it's
|
||||
purpose is to to eliminate link errors in cases
|
||||
where it is known that tss cleanup is not needed.
|
||||
*/
|
||||
|
||||
extern "C" void tss_cleanup_implemented(void)
|
||||
void tss_cleanup_implemented(void)
|
||||
{
|
||||
/*
|
||||
This function's sole purpose is to cause a link error in cases where
|
||||
@@ -30,5 +32,7 @@
|
||||
longer needed and can be removed.
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //defined(BOOST_HAS_WINTHREADS) && defined(BOOST_THREAD_BUILD_LIB) && !defined(_MSC_VER)
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
|
||||
#include <boost/thread/exceptions.hpp>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
namespace boost {
|
||||
|
||||
thread_exception::thread_exception()
|
||||
: m_sys_err(0)
|
||||
{
|
||||
}
|
||||
|
||||
thread_exception::thread_exception(int sys_err_code)
|
||||
: m_sys_err(sys_err_code)
|
||||
{
|
||||
}
|
||||
|
||||
thread_exception::~thread_exception() throw()
|
||||
{
|
||||
}
|
||||
|
||||
int thread_exception::native_error() const
|
||||
{
|
||||
return m_sys_err;
|
||||
}
|
||||
|
||||
lock_error::lock_error()
|
||||
{
|
||||
}
|
||||
|
||||
lock_error::lock_error(int sys_err_code)
|
||||
: thread_exception(sys_err_code)
|
||||
{
|
||||
}
|
||||
|
||||
lock_error::~lock_error() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char* lock_error::what() const throw()
|
||||
{
|
||||
return "boost::lock_error";
|
||||
}
|
||||
|
||||
thread_resource_error::thread_resource_error()
|
||||
{
|
||||
}
|
||||
|
||||
thread_resource_error::thread_resource_error(int sys_err_code)
|
||||
: thread_exception(sys_err_code)
|
||||
{
|
||||
}
|
||||
|
||||
thread_resource_error::~thread_resource_error() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char* thread_resource_error::what() const throw()
|
||||
{
|
||||
return "boost::thread_resource_error";
|
||||
}
|
||||
|
||||
unsupported_thread_option::unsupported_thread_option()
|
||||
{
|
||||
}
|
||||
|
||||
unsupported_thread_option::unsupported_thread_option(int sys_err_code)
|
||||
: thread_exception(sys_err_code)
|
||||
{
|
||||
}
|
||||
|
||||
unsupported_thread_option::~unsupported_thread_option() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char* unsupported_thread_option::what() const throw()
|
||||
{
|
||||
return "boost::unsupported_thread_option";
|
||||
}
|
||||
|
||||
invalid_thread_argument::invalid_thread_argument()
|
||||
{
|
||||
}
|
||||
|
||||
invalid_thread_argument::invalid_thread_argument(int sys_err_code)
|
||||
: thread_exception(sys_err_code)
|
||||
{
|
||||
}
|
||||
|
||||
invalid_thread_argument::~invalid_thread_argument() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char* invalid_thread_argument::what() const throw()
|
||||
{
|
||||
return "boost::invalid_thread_argument";
|
||||
}
|
||||
|
||||
thread_permission_error::thread_permission_error()
|
||||
{
|
||||
}
|
||||
|
||||
thread_permission_error::thread_permission_error(int sys_err_code)
|
||||
: thread_exception(sys_err_code)
|
||||
{
|
||||
}
|
||||
|
||||
thread_permission_error::~thread_permission_error() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char* thread_permission_error::what() const throw()
|
||||
{
|
||||
return "boost::thread_permission_error";
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <algorithm>
|
||||
#include <windows.h>
|
||||
#ifndef UNDER_CE
|
||||
#include <process.h>
|
||||
#endif
|
||||
@@ -17,35 +16,44 @@
|
||||
#include <boost/thread/once.hpp>
|
||||
#include <boost/thread/tss.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/thread/detail/tss_hooks.hpp>
|
||||
#include <boost/date_time/posix_time/conversion.hpp>
|
||||
#include <windows.h>
|
||||
#include <memory>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
boost::once_flag current_thread_tls_init_flag=BOOST_ONCE_INIT;
|
||||
DWORD current_thread_tls_key=0;
|
||||
#if defined(UNDER_CE)
|
||||
// Windows CE does not define the TLS_OUT_OF_INDEXES constant.
|
||||
DWORD tls_out_of_index=0xFFFFFFFF;
|
||||
#else
|
||||
DWORD tls_out_of_index=TLS_OUT_OF_INDEXES;
|
||||
#endif
|
||||
DWORD current_thread_tls_key=tls_out_of_index;
|
||||
|
||||
void create_current_thread_tls_key()
|
||||
{
|
||||
tss_cleanup_implemented(); // if anyone uses TSS, we need the cleanup linked in
|
||||
current_thread_tls_key=TlsAlloc();
|
||||
BOOST_ASSERT(current_thread_tls_key!=TLS_OUT_OF_INDEXES);
|
||||
BOOST_ASSERT(current_thread_tls_key!=tls_out_of_index);
|
||||
}
|
||||
|
||||
void cleanup_tls_key()
|
||||
{
|
||||
if(current_thread_tls_key)
|
||||
if(current_thread_tls_key!=tls_out_of_index)
|
||||
{
|
||||
TlsFree(current_thread_tls_key);
|
||||
current_thread_tls_key=0;
|
||||
current_thread_tls_key=tls_out_of_index;
|
||||
}
|
||||
}
|
||||
|
||||
detail::thread_data_base* get_current_thread_data()
|
||||
{
|
||||
if(!current_thread_tls_key)
|
||||
if(current_thread_tls_key==tls_out_of_index)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -55,10 +63,13 @@ namespace boost
|
||||
void set_current_thread_data(detail::thread_data_base* new_data)
|
||||
{
|
||||
boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key);
|
||||
BOOST_VERIFY(TlsSetValue(current_thread_tls_key,new_data));
|
||||
if(current_thread_tls_key!=tls_out_of_index)
|
||||
BOOST_VERIFY(TlsSetValue(current_thread_tls_key,new_data));
|
||||
else
|
||||
boost::throw_exception(thread_resource_error());
|
||||
}
|
||||
|
||||
#ifdef BOOST_NO_THREADEX
|
||||
#ifndef BOOST_HAS_THREADEX
|
||||
// Windows CE doesn't define _beginthreadex
|
||||
|
||||
struct ThreadProxyData
|
||||
@@ -71,22 +82,25 @@ namespace boost
|
||||
|
||||
DWORD WINAPI ThreadProxy(LPVOID args)
|
||||
{
|
||||
ThreadProxyData* data=reinterpret_cast<ThreadProxyData*>(args);
|
||||
std::auto_ptr<ThreadProxyData> data(reinterpret_cast<ThreadProxyData*>(args));
|
||||
DWORD ret=data->start_address_(data->arglist_);
|
||||
delete data;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
typedef void* uintptr_t;
|
||||
|
||||
inline uintptr_t const _beginthreadex(void* security, unsigned stack_size, unsigned (__stdcall* start_address)(void*),
|
||||
void* arglist, unsigned initflag, unsigned* thrdaddr)
|
||||
{
|
||||
DWORD threadID;
|
||||
ThreadProxyData* data = new ThreadProxyData(start_address,arglist);
|
||||
HANDLE hthread=CreateThread(static_cast<LPSECURITY_ATTRIBUTES>(security),stack_size,ThreadProxy,
|
||||
new ThreadProxyData(start_address,arglist),initflag,&threadID);
|
||||
if (hthread!=0)
|
||||
*thrdaddr=threadID;
|
||||
data,initflag,&threadID);
|
||||
if (hthread==0) {
|
||||
delete data;
|
||||
return 0;
|
||||
}
|
||||
*thrdaddr=threadID;
|
||||
return reinterpret_cast<uintptr_t const>(hthread);
|
||||
}
|
||||
|
||||
@@ -153,11 +167,11 @@ namespace boost
|
||||
boost::detail::heap_delete(current_node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
set_current_thread_data(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unsigned __stdcall thread_start_function(void* param)
|
||||
{
|
||||
detail::thread_data_base* const thread_info(reinterpret_cast<detail::thread_data_base*>(param));
|
||||
@@ -169,16 +183,18 @@ namespace boost
|
||||
catch(thread_interrupted const&)
|
||||
{
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
std::terminate();
|
||||
}
|
||||
// Removed as it stops the debugger identifying the cause of the exception
|
||||
// Unhandled exceptions still cause the application to terminate
|
||||
// catch(...)
|
||||
// {
|
||||
// std::terminate();
|
||||
// }
|
||||
run_thread_exit_callbacks();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
thread::thread()
|
||||
thread::thread() BOOST_NOEXCEPT
|
||||
{}
|
||||
|
||||
void thread::start_thread()
|
||||
@@ -186,13 +202,26 @@ namespace boost
|
||||
uintptr_t const new_thread=_beginthreadex(0,0,&thread_start_function,thread_info.get(),CREATE_SUSPENDED,&thread_info->id);
|
||||
if(!new_thread)
|
||||
{
|
||||
throw thread_resource_error();
|
||||
boost::throw_exception(thread_resource_error());
|
||||
}
|
||||
intrusive_ptr_add_ref(thread_info.get());
|
||||
thread_info->thread_handle=(detail::win32::handle)(new_thread);
|
||||
ResumeThread(thread_info->thread_handle);
|
||||
}
|
||||
|
||||
void thread::start_thread(const attributes& attr)
|
||||
{
|
||||
//uintptr_t const new_thread=_beginthreadex(attr.get_security(),attr.get_stack_size(),&thread_start_function,thread_info.get(),CREATE_SUSPENDED,&thread_info->id);
|
||||
uintptr_t const new_thread=_beginthreadex(0,attr.get_stack_size(),&thread_start_function,thread_info.get(),CREATE_SUSPENDED,&thread_info->id);
|
||||
if(!new_thread)
|
||||
{
|
||||
boost::throw_exception(thread_resource_error());
|
||||
}
|
||||
intrusive_ptr_add_ref(thread_info.get());
|
||||
thread_info->thread_handle=(detail::win32::handle)(new_thread);
|
||||
ResumeThread(thread_info->thread_handle);
|
||||
}
|
||||
|
||||
thread::thread(detail::thread_data_ptr data):
|
||||
thread_info(data)
|
||||
{}
|
||||
@@ -207,7 +236,7 @@ namespace boost
|
||||
++count;
|
||||
interruption_enabled=false;
|
||||
}
|
||||
|
||||
|
||||
void run()
|
||||
{}
|
||||
private:
|
||||
@@ -218,7 +247,15 @@ namespace boost
|
||||
void make_external_thread_data()
|
||||
{
|
||||
externally_launched_thread* me=detail::heap_new<externally_launched_thread>();
|
||||
set_current_thread_data(me);
|
||||
try
|
||||
{
|
||||
set_current_thread_data(me);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
detail::heap_delete(me);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
detail::thread_data_base* get_or_make_current_thread_data()
|
||||
@@ -231,27 +268,31 @@ namespace boost
|
||||
}
|
||||
return current_thread_data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
thread::~thread()
|
||||
{
|
||||
detach();
|
||||
}
|
||||
|
||||
thread::id thread::get_id() const
|
||||
|
||||
thread::id thread::get_id() const BOOST_NOEXCEPT
|
||||
{
|
||||
return thread::id(get_thread_info());
|
||||
return thread::id((get_thread_info)());
|
||||
}
|
||||
|
||||
bool thread::joinable() const
|
||||
bool thread::joinable() const BOOST_NOEXCEPT
|
||||
{
|
||||
return get_thread_info();
|
||||
return (get_thread_info)();
|
||||
}
|
||||
|
||||
void thread::join()
|
||||
{
|
||||
detail::thread_data_ptr local_thread_info=get_thread_info();
|
||||
if (this_thread::get_id() == get_id())
|
||||
{
|
||||
boost::throw_exception(thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself"));
|
||||
}
|
||||
detail::thread_data_ptr local_thread_info=(get_thread_info)();
|
||||
if(local_thread_info)
|
||||
{
|
||||
this_thread::interruptible_wait(local_thread_info->thread_handle,detail::timeout::sentinel());
|
||||
@@ -261,7 +302,11 @@ namespace boost
|
||||
|
||||
bool thread::timed_join(boost::system_time const& wait_until)
|
||||
{
|
||||
detail::thread_data_ptr local_thread_info=get_thread_info();
|
||||
if (this_thread::get_id() == get_id())
|
||||
{
|
||||
boost::throw_exception(thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself"));
|
||||
}
|
||||
detail::thread_data_ptr local_thread_info=(get_thread_info)();
|
||||
if(local_thread_info)
|
||||
{
|
||||
if(!this_thread::interruptible_wait(local_thread_info->thread_handle,get_milliseconds_until(wait_until)))
|
||||
@@ -272,7 +317,30 @@ namespace boost
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
|
||||
bool thread::try_join_until(const chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp)
|
||||
{
|
||||
if (this_thread::get_id() == get_id())
|
||||
{
|
||||
boost::throw_exception(thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself"));
|
||||
}
|
||||
detail::thread_data_ptr local_thread_info=(get_thread_info)();
|
||||
if(local_thread_info)
|
||||
{
|
||||
chrono::milliseconds rel_time= chrono::ceil<chrono::milliseconds>(tp-chrono::system_clock::now());
|
||||
if(!this_thread::interruptible_wait(local_thread_info->thread_handle,rel_time.count()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
release_handle();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void thread::detach()
|
||||
{
|
||||
release_handle();
|
||||
@@ -280,41 +348,39 @@ namespace boost
|
||||
|
||||
void thread::release_handle()
|
||||
{
|
||||
lock_guard<mutex> l1(thread_info_mutex);
|
||||
thread_info=0;
|
||||
}
|
||||
|
||||
|
||||
void thread::interrupt()
|
||||
{
|
||||
detail::thread_data_ptr local_thread_info=get_thread_info();
|
||||
detail::thread_data_ptr local_thread_info=(get_thread_info)();
|
||||
if(local_thread_info)
|
||||
{
|
||||
local_thread_info->interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool thread::interruption_requested() const
|
||||
{
|
||||
detail::thread_data_ptr local_thread_info=get_thread_info();
|
||||
detail::thread_data_ptr local_thread_info=(get_thread_info)();
|
||||
return local_thread_info.get() && (detail::win32::WaitForSingleObject(local_thread_info->interruption_handle,0)==0);
|
||||
}
|
||||
|
||||
unsigned thread::hardware_concurrency()
|
||||
|
||||
unsigned thread::hardware_concurrency() BOOST_NOEXCEPT
|
||||
{
|
||||
SYSTEM_INFO info={0};
|
||||
SYSTEM_INFO info={{0}};
|
||||
GetSystemInfo(&info);
|
||||
return info.dwNumberOfProcessors;
|
||||
}
|
||||
|
||||
|
||||
thread::native_handle_type thread::native_handle()
|
||||
{
|
||||
detail::thread_data_ptr local_thread_info=get_thread_info();
|
||||
detail::thread_data_ptr local_thread_info=(get_thread_info)();
|
||||
return local_thread_info?(detail::win32::handle)local_thread_info->thread_handle:detail::win32::invalid_handle_value;
|
||||
}
|
||||
|
||||
detail::thread_data_ptr thread::get_thread_info() const
|
||||
detail::thread_data_ptr thread::get_thread_info BOOST_PREVENT_MACRO_SUBSTITUTION () const
|
||||
{
|
||||
boost::mutex::scoped_lock l(thread_info_mutex);
|
||||
return thread_info;
|
||||
}
|
||||
|
||||
@@ -324,7 +390,7 @@ namespace boost
|
||||
{
|
||||
LARGE_INTEGER get_due_time(detail::timeout const& target_time)
|
||||
{
|
||||
LARGE_INTEGER due_time={0};
|
||||
LARGE_INTEGER due_time={{0}};
|
||||
if(target_time.relative)
|
||||
{
|
||||
unsigned long const elapsed_milliseconds=GetTickCount()-target_time.start;
|
||||
@@ -353,13 +419,29 @@ namespace boost
|
||||
else
|
||||
{
|
||||
long const hundred_nanoseconds_in_one_second=10000000;
|
||||
due_time.QuadPart+=target_time.abs_time.time_of_day().fractional_seconds()*(hundred_nanoseconds_in_one_second/target_time.abs_time.time_of_day().ticks_per_second());
|
||||
posix_time::time_duration::tick_type const ticks_per_second=
|
||||
target_time.abs_time.time_of_day().ticks_per_second();
|
||||
if(ticks_per_second>hundred_nanoseconds_in_one_second)
|
||||
{
|
||||
posix_time::time_duration::tick_type const
|
||||
ticks_per_hundred_nanoseconds=
|
||||
ticks_per_second/hundred_nanoseconds_in_one_second;
|
||||
due_time.QuadPart+=
|
||||
target_time.abs_time.time_of_day().fractional_seconds()/
|
||||
ticks_per_hundred_nanoseconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
due_time.QuadPart+=
|
||||
target_time.abs_time.time_of_day().fractional_seconds()*
|
||||
(hundred_nanoseconds_in_one_second/ticks_per_second);
|
||||
}
|
||||
}
|
||||
}
|
||||
return due_time;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool interruptible_wait(detail::win32::handle handle_to_wait_for,detail::timeout target_time)
|
||||
{
|
||||
@@ -380,10 +462,10 @@ namespace boost
|
||||
}
|
||||
|
||||
detail::win32::handle_manager timer_handle;
|
||||
|
||||
|
||||
#ifndef UNDER_CE
|
||||
unsigned const min_timer_wait_period=20;
|
||||
|
||||
|
||||
if(!target_time.is_sentinel())
|
||||
{
|
||||
detail::timeout::remaining_time const time_left=target_time.remaining_milliseconds();
|
||||
@@ -394,7 +476,7 @@ namespace boost
|
||||
if(timer_handle!=0)
|
||||
{
|
||||
LARGE_INTEGER due_time=get_due_time(target_time);
|
||||
|
||||
|
||||
bool const set_time_succeeded=SetWaitableTimer(timer_handle,&due_time,0,0,0,false)!=0;
|
||||
if(set_time_succeeded)
|
||||
{
|
||||
@@ -410,17 +492,17 @@ namespace boost
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool const using_timer=timeout_index!=~0u;
|
||||
detail::timeout::remaining_time time_left(0);
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
if(!using_timer)
|
||||
{
|
||||
time_left=target_time.remaining_milliseconds();
|
||||
}
|
||||
|
||||
|
||||
if(handle_count)
|
||||
{
|
||||
unsigned long const notified_index=detail::win32::WaitForMultipleObjects(handle_count,handles,false,using_timer?INFINITE:time_left.milliseconds);
|
||||
@@ -454,7 +536,7 @@ namespace boost
|
||||
return false;
|
||||
}
|
||||
|
||||
thread::id get_id()
|
||||
thread::id get_id() BOOST_NOEXCEPT
|
||||
{
|
||||
return thread::id(get_or_make_current_thread_data());
|
||||
}
|
||||
@@ -467,22 +549,22 @@ namespace boost
|
||||
throw thread_interrupted();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool interruption_enabled()
|
||||
{
|
||||
return get_current_thread_data() && get_current_thread_data()->interruption_enabled;
|
||||
}
|
||||
|
||||
|
||||
bool interruption_requested()
|
||||
{
|
||||
return get_current_thread_data() && (detail::win32::WaitForSingleObject(get_current_thread_data()->interruption_handle,0)==0);
|
||||
}
|
||||
|
||||
void yield()
|
||||
void yield() BOOST_NOEXCEPT
|
||||
{
|
||||
detail::win32::Sleep(0);
|
||||
}
|
||||
|
||||
|
||||
disable_interruption::disable_interruption():
|
||||
interruption_was_enabled(interruption_enabled())
|
||||
{
|
||||
@@ -491,7 +573,7 @@ namespace boost
|
||||
get_current_thread_data()->interruption_enabled=false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
disable_interruption::~disable_interruption()
|
||||
{
|
||||
if(get_current_thread_data())
|
||||
@@ -507,7 +589,7 @@ namespace boost
|
||||
get_current_thread_data()->interruption_enabled=true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
restore_interruption::~restore_interruption()
|
||||
{
|
||||
if(get_current_thread_data())
|
||||
@@ -523,8 +605,8 @@ namespace boost
|
||||
{
|
||||
detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data());
|
||||
thread_exit_callback_node* const new_node=
|
||||
heap_new<thread_exit_callback_node>(func,
|
||||
current_thread_data->thread_exit_callbacks);
|
||||
heap_new<thread_exit_callback_node>(
|
||||
func,current_thread_data->thread_exit_callbacks);
|
||||
current_thread_data->thread_exit_callbacks=new_node;
|
||||
}
|
||||
|
||||
@@ -554,42 +636,43 @@ namespace boost
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void set_tss_data(void const* key,boost::shared_ptr<tss_cleanup_function> func,void* tss_data,bool cleanup_existing)
|
||||
{
|
||||
if(tss_data_node* const current_node=find_tss_data(key))
|
||||
{
|
||||
if(cleanup_existing && current_node->func.get())
|
||||
if(cleanup_existing && current_node->func.get() && current_node->value)
|
||||
{
|
||||
(*current_node->func)(current_node->value);
|
||||
}
|
||||
current_node->func=func;
|
||||
current_node->value=tss_data;
|
||||
}
|
||||
else
|
||||
else if(func && tss_data)
|
||||
{
|
||||
detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data());
|
||||
tss_data_node* const new_node=heap_new<tss_data_node>(key,func,tss_data,current_thread_data->tss_data);
|
||||
tss_data_node* const new_node=
|
||||
heap_new<tss_data_node>(key,func,tss_data,current_thread_data->tss_data);
|
||||
current_thread_data->tss_data=new_node;
|
||||
}
|
||||
}
|
||||
}
|
||||
BOOST_THREAD_DECL void __cdecl on_process_enter()
|
||||
{}
|
||||
|
||||
BOOST_THREAD_DECL void __cdecl on_thread_enter()
|
||||
{}
|
||||
|
||||
BOOST_THREAD_DECL void __cdecl on_process_exit()
|
||||
{
|
||||
boost::cleanup_tls_key();
|
||||
}
|
||||
|
||||
BOOST_THREAD_DECL void __cdecl on_thread_exit()
|
||||
{
|
||||
boost::run_thread_exit_callbacks();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_process_enter()
|
||||
{}
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_thread_enter()
|
||||
{}
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_process_exit()
|
||||
{
|
||||
boost::cleanup_tls_key();
|
||||
}
|
||||
|
||||
extern "C" BOOST_THREAD_DECL void on_thread_exit()
|
||||
{
|
||||
boost::run_thread_exit_callbacks();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,27 +24,27 @@
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
on_process_enter();
|
||||
on_thread_enter();
|
||||
boost::on_process_enter();
|
||||
boost::on_thread_enter();
|
||||
break;
|
||||
}
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
{
|
||||
on_thread_enter();
|
||||
boost::on_thread_enter();
|
||||
break;
|
||||
}
|
||||
|
||||
case DLL_THREAD_DETACH:
|
||||
{
|
||||
on_thread_exit();
|
||||
boost::on_thread_exit();
|
||||
break;
|
||||
}
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
{
|
||||
on_thread_exit();
|
||||
on_process_exit();
|
||||
boost::on_thread_exit();
|
||||
boost::on_process_exit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,9 @@
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
extern "C" void tss_cleanup_implemented(void)
|
||||
namespace boost
|
||||
{
|
||||
void tss_cleanup_implemented()
|
||||
{
|
||||
/*
|
||||
This function's sole purpose is to cause a link error in cases where
|
||||
@@ -68,5 +70,7 @@
|
||||
longer needed and can be removed.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //defined(BOOST_HAS_WINTHREADS) && defined(BOOST_THREAD_BUILD_DLL)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#if defined(BOOST_HAS_WINTHREADS) && defined(BOOST_THREAD_BUILD_LIB)
|
||||
|
||||
#if defined(__MINGW32__) && !defined(_WIN64)
|
||||
#if (defined(__MINGW32__) && !defined(_WIN64)) || defined(__MINGW64__)
|
||||
|
||||
#include <boost/thread/detail/tss_hooks.hpp>
|
||||
|
||||
@@ -19,7 +19,10 @@
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
extern "C" void tss_cleanup_implemented(void) {}
|
||||
namespace boost
|
||||
{
|
||||
void tss_cleanup_implemented() {}
|
||||
}
|
||||
|
||||
namespace {
|
||||
void NTAPI on_tls_callback(void* h, DWORD dwReason, PVOID pv)
|
||||
@@ -28,33 +31,25 @@ namespace {
|
||||
{
|
||||
case DLL_THREAD_DETACH:
|
||||
{
|
||||
on_thread_exit();
|
||||
boost::on_thread_exit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void on_after_ctors(void)
|
||||
{
|
||||
on_process_enter();
|
||||
}
|
||||
|
||||
void on_before_dtors(void)
|
||||
{
|
||||
on_thread_exit();
|
||||
}
|
||||
|
||||
void on_after_dtors(void)
|
||||
{
|
||||
on_process_exit();
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__MINGW64__) || (__MINGW32_MAJOR_VERSION >3) || \
|
||||
((__MINGW32_MAJOR_VERSION==3) && (__MINGW32_MINOR_VERSION>=18))
|
||||
extern "C"
|
||||
{
|
||||
PIMAGE_TLS_CALLBACK __crt_xl_tls_callback__ __attribute__ ((section(".CRT$XLB"))) = on_tls_callback;
|
||||
}
|
||||
#else
|
||||
extern "C" {
|
||||
|
||||
void (* after_ctors )(void) __attribute__((section(".ctors"))) = on_after_ctors;
|
||||
void (* before_dtors)(void) __attribute__((section(".dtors"))) = on_before_dtors;
|
||||
void (* after_dtors )(void) __attribute__((section(".dtors.zzz"))) = on_after_dtors;
|
||||
void (* after_ctors )() __attribute__((section(".ctors"))) = boost::on_process_enter;
|
||||
void (* before_dtors)() __attribute__((section(".dtors"))) = boost::on_thread_exit;
|
||||
void (* after_dtors )() __attribute__((section(".dtors.zzz"))) = boost::on_process_exit;
|
||||
|
||||
ULONG __tls_index__ = 0;
|
||||
char __tls_end__ __attribute__((section(".tls$zzz"))) = 0;
|
||||
@@ -62,10 +57,8 @@ extern "C" {
|
||||
|
||||
|
||||
PIMAGE_TLS_CALLBACK __crt_xl_start__ __attribute__ ((section(".CRT$XLA"))) = 0;
|
||||
PIMAGE_TLS_CALLBACK __crt_xl_tls_callback__ __attribute__ ((section(".CRT$XLB"))) = on_tls_callback;
|
||||
PIMAGE_TLS_CALLBACK __crt_xl_end__ __attribute__ ((section(".CRT$XLZ"))) = 0;
|
||||
}
|
||||
|
||||
extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata$T"))) =
|
||||
{
|
||||
(DWORD) &__tls_start__,
|
||||
@@ -75,6 +68,7 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata
|
||||
(DWORD) 0,
|
||||
(DWORD) 0
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#elif defined(_MSC_VER) && !defined(UNDER_CE)
|
||||
@@ -89,13 +83,13 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata
|
||||
//Definitions required by implementation
|
||||
|
||||
#if (_MSC_VER < 1300) // 1300 == VC++ 7.0
|
||||
typedef void (__cdecl *_PVFV)(void);
|
||||
typedef void (__cdecl *_PVFV)();
|
||||
#define INIRETSUCCESS
|
||||
#define PVAPI void
|
||||
#define PVAPI void __cdecl
|
||||
#else
|
||||
typedef int (__cdecl *_PVFV)(void);
|
||||
typedef int (__cdecl *_PVFV)();
|
||||
#define INIRETSUCCESS 0
|
||||
#define PVAPI int
|
||||
#define PVAPI int __cdecl
|
||||
#endif
|
||||
|
||||
typedef void (NTAPI* _TLSCB)(HINSTANCE, DWORD, PVOID);
|
||||
@@ -112,9 +106,9 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata
|
||||
{
|
||||
//Forward declarations
|
||||
|
||||
static PVAPI on_tls_prepare(void);
|
||||
static PVAPI on_process_init(void);
|
||||
static PVAPI on_process_term(void);
|
||||
static PVAPI on_tls_prepare();
|
||||
static PVAPI on_process_init();
|
||||
static PVAPI on_process_term();
|
||||
static void NTAPI on_tls_callback(HINSTANCE, DWORD, PVOID);
|
||||
|
||||
//The .CRT$Xxx information is taken from Codeguru:
|
||||
@@ -169,7 +163,7 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata
|
||||
#pragma warning(disable:4189)
|
||||
#endif
|
||||
|
||||
PVAPI on_tls_prepare(void)
|
||||
PVAPI on_tls_prepare()
|
||||
{
|
||||
//The following line has an important side effect:
|
||||
//if the TLS directory is not already there, it will
|
||||
@@ -210,7 +204,7 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
PVAPI on_process_init(void)
|
||||
PVAPI on_process_init()
|
||||
{
|
||||
//Schedule on_thread_exit() to be called for the main
|
||||
//thread before destructors of global objects have been
|
||||
@@ -221,18 +215,18 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata
|
||||
//for destructors of global objects, so that
|
||||
//shouldn't be a problem.
|
||||
|
||||
atexit(on_thread_exit);
|
||||
atexit(boost::on_thread_exit);
|
||||
|
||||
//Call Boost process entry callback here
|
||||
|
||||
on_process_enter();
|
||||
boost::on_process_enter();
|
||||
|
||||
return INIRETSUCCESS;
|
||||
}
|
||||
|
||||
PVAPI on_process_term(void)
|
||||
PVAPI on_process_term()
|
||||
{
|
||||
on_process_exit();
|
||||
boost::on_process_exit();
|
||||
return INIRETSUCCESS;
|
||||
}
|
||||
|
||||
@@ -241,7 +235,7 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata
|
||||
switch (dwReason)
|
||||
{
|
||||
case DLL_THREAD_DETACH:
|
||||
on_thread_exit();
|
||||
boost::on_thread_exit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -251,10 +245,10 @@ extern "C" const IMAGE_TLS_DIRECTORY32 _tls_used __attribute__ ((section(".rdata
|
||||
switch (dwReason)
|
||||
{
|
||||
case DLL_THREAD_DETACH:
|
||||
on_thread_exit();
|
||||
boost::on_thread_exit();
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
on_process_exit();
|
||||
boost::on_process_exit();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
@@ -265,8 +259,9 @@ extern "C"
|
||||
{
|
||||
extern BOOL (WINAPI * const _pRawDllMain)(HANDLE, DWORD, LPVOID)=&dll_callback;
|
||||
}
|
||||
|
||||
extern "C" void tss_cleanup_implemented(void)
|
||||
namespace boost
|
||||
{
|
||||
void tss_cleanup_implemented()
|
||||
{
|
||||
/*
|
||||
This function's sole purpose is to cause a link error in cases where
|
||||
@@ -282,6 +277,8 @@ extern "C"
|
||||
longer needed and can be removed.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#endif //defined(_MSC_VER) && !defined(UNDER_CE)
|
||||
|
||||
#endif //defined(BOOST_HAS_WINTHREADS) && defined(BOOST_THREAD_BUILD_LIB)
|
||||
|
||||
314
test/Jamfile.v2
314
test/Jamfile.v2
@@ -1,6 +1,6 @@
|
||||
# (C) Copyright William E. Kempf 2001.
|
||||
# (C) Copyright 2007 Anthony Williams.
|
||||
# Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
# (C) Copyright William E. Kempf 2001.
|
||||
# (C) Copyright 2007 Anthony Williams.
|
||||
# Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
#
|
||||
# Boost.Threads test Jamfile
|
||||
@@ -25,21 +25,46 @@ project
|
||||
|
||||
rule thread-run ( sources )
|
||||
{
|
||||
return
|
||||
return
|
||||
[ run $(sources) ../build//boost_thread ]
|
||||
[ run $(sources) ../src/tss_null.cpp ../build//boost_thread/<link>static
|
||||
[ run $(sources) ../src/tss_null.cpp ../build//boost_thread/<link>static
|
||||
: : : : $(sources[1]:B)_lib ]
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
rule thread-run2 ( sources : name )
|
||||
{
|
||||
return
|
||||
[ run $(sources) ../build//boost_thread : : :
|
||||
: $(name) ]
|
||||
[ run $(sources) ../src/tss_null.cpp ../build//boost_thread/<link>static
|
||||
: : :
|
||||
: $(name)_lib ]
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
rule thread-compile-fail-V2 ( sources : reqs * : name )
|
||||
{
|
||||
return
|
||||
[ compile-fail $(sources)
|
||||
: $(reqs)
|
||||
: $(name) ]
|
||||
;
|
||||
}
|
||||
|
||||
{
|
||||
test-suite "threads"
|
||||
: [ thread-run test_thread.cpp ]
|
||||
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_thread_return_local.cpp ]
|
||||
[ thread-run test_thread_move_return.cpp ]
|
||||
[ thread-run test_thread_launching.cpp ]
|
||||
[ thread-run test_thread_mf.cpp ]
|
||||
[ thread-run test_thread_exit.cpp ]
|
||||
[ thread-run test_move_function.cpp ]
|
||||
[ thread-run test_mutex.cpp ]
|
||||
[ thread-run test_condition_notify_one.cpp ]
|
||||
@@ -53,9 +78,282 @@ rule thread-run ( sources )
|
||||
[ thread-run test_shared_mutex.cpp ]
|
||||
[ thread-run test_shared_mutex_part_2.cpp ]
|
||||
[ thread-run test_shared_mutex_timed_locks.cpp ]
|
||||
[ thread-run test_shared_mutex_timed_locks_chrono.cpp ]
|
||||
#uncomment the following once these works on windows
|
||||
#[ thread-run test_v2_shared_mutex.cpp ]
|
||||
#[ thread-run test_v2_shared_mutex_part_2.cpp ]
|
||||
#[ thread-run test_v2_shared_mutex_timed_locks.cpp ]
|
||||
[ thread-run test_lock_concept.cpp ]
|
||||
[ thread-run test_generic_locks.cpp ]
|
||||
[ thread-run test_futures.cpp ]
|
||||
[ compile-fail no_implicit_move_from_lvalue_thread.cpp ]
|
||||
[ compile-fail no_implicit_assign_from_lvalue_thread.cpp ]
|
||||
;
|
||||
|
||||
|
||||
#explicit tickets ;
|
||||
test-suite tickets
|
||||
:
|
||||
[ thread-run test_2309.cpp ]
|
||||
[ thread-run test_2501.cpp ]
|
||||
[ thread-run test_2741.cpp ]
|
||||
[ thread-run test_4521.cpp ]
|
||||
[ thread-run test_4648.cpp ]
|
||||
[ thread-run test_4882.cpp ]
|
||||
[ thread-run test_5542_1.cpp ]
|
||||
[ thread-run test_5542_2.cpp ]
|
||||
[ thread-run test_5542_3.cpp ]
|
||||
[ thread-run test_5891.cpp ]
|
||||
[ thread-run test_6130.cpp ]
|
||||
[ thread-run test_6170.cpp ]
|
||||
[ thread-run test_6174.cpp ]
|
||||
;
|
||||
|
||||
|
||||
explicit oth_tickets ;
|
||||
test-suite oth_tickets
|
||||
:
|
||||
[ thread-run test_5351.cpp ]
|
||||
[ thread-run test_5502.cpp ]
|
||||
;
|
||||
|
||||
|
||||
|
||||
#explicit conditions ;
|
||||
test-suite conditions
|
||||
:
|
||||
[ thread-compile-fail-V2 ./sync/conditions/condition_variable/assign_fail.cpp : : condition_variable__assign_f ]
|
||||
[ thread-compile-fail-V2 ./sync/conditions/condition_variable/copy_fail.cpp : : condition_variable__copy_f ]
|
||||
[ thread-run2 ./sync/conditions/condition_variable/default_pass.cpp : condition_variable__default_p ]
|
||||
[ thread-run2 ./sync/conditions/condition_variable/dtor_pass.cpp : condition_variable__dtor_p ]
|
||||
[ thread-run2 ./sync/conditions/condition_variable/native_handle_pass.cpp : condition_variable__native_handle_p ]
|
||||
[ thread-run2 ./sync/conditions/condition_variable/wait_for_pass.cpp : condition_variable__wait_for_p ]
|
||||
[ thread-run2 ./sync/conditions/condition_variable/wait_for_pred_pass.cpp : condition_variable__wait_for_pred_p ]
|
||||
[ thread-run2 ./sync/conditions/condition_variable/wait_until_pass.cpp : condition_variable__wait_until_p ]
|
||||
[ thread-run2 ./sync/conditions/condition_variable/wait_until_pred_pass.cpp : condition_variable__wait_until_pred_p ]
|
||||
|
||||
[ thread-compile-fail-V2 ./sync/conditions/condition_variable_any/assign_fail.cpp : : condition_variable_any__assign_f ]
|
||||
[ thread-compile-fail-V2 ./sync/conditions/condition_variable_any/copy_fail.cpp : : condition_variable_any__copy_f ]
|
||||
[ thread-run2 ./sync/conditions/condition_variable_any/default_pass.cpp : condition_variable_any__default_p ]
|
||||
[ thread-run2 ./sync/conditions/condition_variable_any/dtor_pass.cpp : condition_variable_any__dtor_p ]
|
||||
[ thread-run2 ./sync/conditions/condition_variable_any/wait_for_pass.cpp : condition_variable_any__wait_for_p ]
|
||||
[ thread-run2 ./sync/conditions/condition_variable_any/wait_for_pred_pass.cpp : condition_variable_any__wait_for_pred_p ]
|
||||
[ thread-run2 ./sync/conditions/condition_variable_any/wait_until_pass.cpp : condition_variable_any__wait_until_p ]
|
||||
[ thread-run2 ./sync/conditions/condition_variable_any/wait_until_pred_pass.cpp : condition_variable_any__wait_until_pred_p ]
|
||||
[ thread-run2 ./sync/conditions/cv_status/cv_status_pass.cpp : cv_status__cv_status_p ]
|
||||
;
|
||||
|
||||
#explicit futures ;
|
||||
test-suite futures
|
||||
:
|
||||
# [ thread-run2 ./sync/futures/async/async_pass.cpp : async__async_p ]
|
||||
[ thread-compile-fail-V2 ./sync/futures/promise/copy_assign_fail.cpp : : promise__copy_assign_f ]
|
||||
[ thread-run2 ./sync/futures/promise/default_pass.cpp : promise__default_p ]
|
||||
[ thread-run2 ./sync/futures/promise/dtor_pass.cpp : promise__dtor_p ]
|
||||
[ thread-run2 ./sync/futures/promise/get_future_pass.cpp : promise__get_future_p ]
|
||||
[ thread-run2 ./sync/futures/promise/move_ctor_pass.cpp : promise__move_ctor_p ]
|
||||
[ thread-run2 ./sync/futures/promise/move_assign_pass.cpp : promise__move_asign_p ]
|
||||
|
||||
[ thread-run2 ./sync/futures/future/share_pass.cpp : future__share_p ]
|
||||
|
||||
;
|
||||
|
||||
|
||||
#explicit mutual_exclusion ;
|
||||
test-suite mutual_exclusion
|
||||
:
|
||||
#uncomment the following once these works on windows
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/lock_guard/copy_assign_fail.cpp : : lock_guard__cons__copy_assign_f ]
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/lock_guard/copy_ctor_fail.cpp : : lock_guard__cons__copy_ctor_f ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/lock_guard/adopt_lock_pass.cpp : lock_guard__cons__adopt_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/lock_guard/default_pass.cpp : lock_guard__cons__default_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/lock_guard/types_pass.cpp : lock_guard__types_p ]
|
||||
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/unique_lock/cons/copy_assign_fail.cpp : : unique_lock__cons__copy_assign_f ]
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/unique_lock/cons/copy_ctor_fail.cpp : : unique_lock__cons__copy_ctor_f ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/adopt_lock_pass.cpp : unique_lock__cons__adopt_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/default_pass.cpp : unique_lock__cons__default_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/defer_lock_pass.cpp : unique_lock__cons__defer_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/duration_pass.cpp : unique_lock__cons__duration_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/move_assign_pass.cpp : unique_lock__cons__move_assign_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_pass.cpp : unique_lock__cons__move_ctor_p ]
|
||||
|
||||
#uncomment the following once these works on windows
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_pass.cpp : unique_lock__cons__move_ctor_upgrade_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_try_pass.cpp : unique_lock__cons__move_ctor_upgrade_lock_try_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_for_pass.cpp : unique_lock__cons__move_ctor_upgrade_lock_for_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_until_pass.cpp : unique_lock__cons__move_ctor_upgrade_lock_until_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/mutex_pass.cpp : unique_lock__cons__mutex_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/time_point_pass.cpp : unique_lock__cons__time_point_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/try_to_lock_pass.cpp : unique_lock__cons__try_to_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/locking/lock_pass.cpp : unique_lock__lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/locking/try_lock_for_pass.cpp : unique_lock__try_lock_for_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/locking/try_lock_pass.cpp : unique_lock__try_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/locking/try_lock_until_pass.cpp : unique_lock__try_lock_until_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/locking/unlock_pass.cpp : unique_lock__unlock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/mod/member_swap_pass.cpp : unique_lock__member_swap_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/mod/non_member_swap_pass.cpp : unique_lock__non_member_swap_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/mod/release_pass.cpp : unique_lock__release_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/obs/mutex_pass.cpp : unique_lock__mutex_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/obs/op_bool_pass.cpp : unique_lock__op_bool_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/obs/owns_lock_pass.cpp : unique_lock__owns_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/types_pass.cpp : unique_lock__types_p ]
|
||||
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/shared_lock/cons/copy_assign_fail.cpp : : shared_lock__cons__copy_assign_f ]
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/shared_lock/cons/copy_ctor_fail.cpp : : shared_lock__cons__copy_ctor_f ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/cons/adopt_lock_pass.cpp : shared_lock__cons__adopt_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/cons/default_pass.cpp : shared_lock__cons__default_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/cons/defer_lock_pass.cpp : shared_lock__cons__defer_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/cons/duration_pass.cpp : shared_lock__cons__duration_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/cons/move_assign_pass.cpp : shared_lock__cons__move_assign_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_pass.cpp : shared_lock__cons__move_ctor_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_unique_lock_pass.cpp : shared_lock__cons__move_ctor_unique_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/cons/move_ctor_upgrade_lock_pass.cpp : shared_lock__cons__move_ctor_upgrade_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/cons/mutex_pass.cpp : shared_lock__cons__mutex_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/cons/time_point_pass.cpp : shared_lock__cons__time_point_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/cons/try_to_lock_pass.cpp : shared_lock__cons__try_to_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/locking/lock_pass.cpp : shared_lock__lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/locking/try_lock_for_pass.cpp : shared_lock__try_lock_for_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/locking/try_lock_pass.cpp : shared_lock__try_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/locking/try_lock_until_pass.cpp : shared_lock__try_lock_until_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/locking/unlock_pass.cpp : shared_lock__unlock_p ]
|
||||
|
||||
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/mod/member_swap_pass.cpp : shared_lock__member_swap_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/mod/non_member_swap_pass.cpp : shared_lock__non_member_swap_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/mod/release_pass.cpp : shared_lock__release_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/obs/mutex_pass.cpp : shared_lock__mutex_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/obs/op_bool_pass.cpp : shared_lock__op_bool_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/obs/owns_lock_pass.cpp : shared_lock__owns_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/shared_lock/types_pass.cpp : shared_lock__types_p ]
|
||||
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/copy_assign_fail.cpp : : upgrade_lock__cons__copy_assign_f ]
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/copy_ctor_fail.cpp : : upgrade_lock__cons__copy_ctor_f ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/adopt_lock_pass.cpp : upgrade_lock__cons__adopt_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/default_pass.cpp : upgrade_lock__cons__default_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/defer_lock_pass.cpp : upgrade_lock__cons__defer_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp : upgrade_lock__cons__duration_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/move_assign_pass.cpp : upgrade_lock__cons__move_assign_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_pass.cpp : upgrade_lock__cons__move_ctor_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_unique_lock_pass.cpp : upgrade_lock__cons__move_ctor_unique_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/mutex_pass.cpp : upgrade_lock__cons__mutex_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/time_point_pass.cpp : upgrade_lock__cons__time_point_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/try_to_lock_pass.cpp : upgrade_lock__cons__try_to_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/locking/lock_pass.cpp : upgrade_lock__lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_for_pass.cpp : upgrade_lock__try_lock_for_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_pass.cpp : upgrade_lock__try_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/locking/try_lock_until_pass.cpp : upgrade_lock__try_lock_until_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/locking/unlock_pass.cpp : upgrade_lock__unlock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/mod/member_swap_pass.cpp : upgrade_lock__member_swap_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/mod/non_member_swap_pass.cpp : upgrade_lock__non_member_swap_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/mod/release_pass.cpp : upgrade_lock__release_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/obs/mutex_pass.cpp : upgrade_lock__mutex_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/obs/op_bool_pass.cpp : upgrade_lock__op_bool_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/obs/owns_lock_pass.cpp : upgrade_lock__owns_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/types_pass.cpp : upgrade_lock__types_p ]
|
||||
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/mutex/assign_fail.cpp : : mutex__assign_f ]
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/mutex/copy_fail.cpp : : mutex__copy_f ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/mutex/default_pass.cpp : mutex__default_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/mutex/lock_pass.cpp : mutex__lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/mutex/native_handle_pass.cpp : mutex__native_handle_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/mutex/try_lock_pass.cpp : mutex__try_lock_p ]
|
||||
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/recursive_mutex/assign_fail.cpp : : recursive_mutex__assign_f ]
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/recursive_mutex/copy_fail.cpp : : recursive_mutex__copy_f ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/recursive_mutex/default_pass.cpp : recursive_mutex__default_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/recursive_mutex/lock_pass.cpp : recursive_mutex__lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/recursive_mutex/native_handle_pass.cpp : recursive_mutex__native_handle_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/recursive_mutex/try_lock_pass.cpp : recursive_mutex__try_lock_p ]
|
||||
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/recursive_timed_mutex/assign_fail.cpp : : recursive_timed_mutex__assign_f ]
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/recursive_timed_mutex/copy_fail.cpp : : recursive_timed_mutex__copy_f ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/recursive_timed_mutex/default_pass.cpp : recursive_timed_mutex__default_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/recursive_timed_mutex/lock_pass.cpp : recursive_timed_mutex__lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/recursive_timed_mutex/native_handle_pass.cpp : recursive_timed_mutex__native_handle_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/recursive_timed_mutex/try_lock_for_pass.cpp : recursive_timed_mutex__try_lock_for_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/recursive_timed_mutex/try_lock_pass.cpp : recursive_timed_mutex__try_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/recursive_timed_mutex/try_lock_until_pass.cpp : recursive_timed_mutex__try_lock_until_p ]
|
||||
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/timed_mutex/assign_fail.cpp : : timed_mutex__assign_f ]
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/timed_mutex/copy_fail.cpp : : timed_mutex__copy_f ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/timed_mutex/default_pass.cpp : timed_mutex__default_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/timed_mutex/lock_pass.cpp : timed_mutex__lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/timed_mutex/native_handle_pass.cpp : timed_mutex__native_handle_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/timed_mutex/try_lock_for_pass.cpp : timed_mutex__try_lock_for_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/timed_mutex/try_lock_pass.cpp : timed_mutex__try_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/timed_mutex/try_lock_until_pass.cpp : timed_mutex__try_lock_until_p ]
|
||||
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/shared_mutex/assign_fail.cpp : : shared_mutex__assign_f ]
|
||||
[ thread-compile-fail-V2 ./sync/mutual_exclusion/shared_mutex/copy_fail.cpp : : shared_mutex__copy_f ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/shared_mutex/default_pass.cpp : shared_mutex__default_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/shared_mutex/lock_pass.cpp : shared_mutex__lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/shared_mutex/try_lock_for_pass.cpp : shared_mutex__try_lock_for_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/shared_mutex/try_lock_pass.cpp : shared_mutex__try_lock_p ]
|
||||
[ thread-run2 ./sync/mutual_exclusion/shared_mutex/try_lock_until_pass.cpp : shared_mutex__try_lock_until_p ]
|
||||
|
||||
;
|
||||
|
||||
#explicit this_thread ;
|
||||
test-suite this_thread
|
||||
:
|
||||
[ thread-run2 ./threads/this_thread/get_id/get_id_pass.cpp : this_thread__get_id_p ]
|
||||
[ thread-run2 ./threads/this_thread/sleep_for/sleep_for_pass.cpp : this_thread__sleep_for_p ]
|
||||
[ thread-run2 ./threads/this_thread/sleep_until/sleep_until_pass.cpp : this_thread__sleep_until_p ]
|
||||
;
|
||||
|
||||
#explicit thread ;
|
||||
test-suite thread
|
||||
:
|
||||
[ thread-compile-fail-V2 ./threads/thread/assign/copy_fail.cpp : : thread__assign__copy_f ]
|
||||
[ thread-run2 ./threads/thread/assign/move_pass.cpp : thread__assign__move_p ]
|
||||
[ thread-compile-fail-V2 ./threads/thread/constr/copy_fail.cpp : : thread__constr__copy_f ]
|
||||
[ thread-run2 ./threads/thread/constr/default_pass.cpp : thread__constr__default_p ]
|
||||
[ thread-run2 ./threads/thread/constr/F_pass.cpp : thread__constr__F_p ]
|
||||
[ thread-run2 ./threads/thread/constr/Frvalue_pass.cpp : thread__constr__Frvalue_p ]
|
||||
#[ thread-run2 ./threads/thread/constr/FrvalueArgs_pass.cpp : thread__constr__FrvalueArgs_p ]
|
||||
[ thread-run2 ./threads/thread/constr/move_pass.cpp : thread__constr__move_p ]
|
||||
[ thread-run2 ./threads/thread/destr/dtor_pass.cpp : thread__destr__dtor_p ]
|
||||
[ thread-run2 ./threads/thread/id/hash_pass.cpp : thread__id__hash_p ]
|
||||
[ thread-run2 ./threads/thread/members/detach_pass.cpp : thread__detach_p ]
|
||||
[ thread-run2 ./threads/thread/members/get_id_pass.cpp : thread__get_id_p ]
|
||||
[ thread-run2 ./threads/thread/members/join_pass.cpp : thread__join_p ]
|
||||
[ thread-run2 ./threads/thread/members/joinable_pass.cpp : thread__joinable_p ]
|
||||
[ thread-run2 ./threads/thread/members/native_handle_pass.cpp : thread__native_handle_p ]
|
||||
[ thread-run2 ./threads/thread/members/swap_pass.cpp : thread__swap_p ]
|
||||
[ thread-run2 ./threads/thread/non_members/swap_pass.cpp : swap_threads_p ]
|
||||
[ thread-run2 ./threads/thread/static/hardware_concurrency_pass.cpp : thread__hardware_concurrency_p ]
|
||||
;
|
||||
|
||||
explicit examples ;
|
||||
test-suite examples
|
||||
:
|
||||
[ thread-run ../example/monitor.cpp ]
|
||||
#[ thread-run ../example/starvephil.cpp ]
|
||||
#[ thread-run ../example/tennis.cpp ]
|
||||
#[ thread-run ../example/condition.cpp ]
|
||||
[ thread-run ../example/mutex.cpp ]
|
||||
[ thread-run ../example/once.cpp ]
|
||||
[ thread-run ../example/recursive_mutex.cpp ]
|
||||
[ thread-run2 ../example/thread.cpp : ex_thread ]
|
||||
[ thread-run ../example/thread_group.cpp ]
|
||||
[ thread-run ../example/tss.cpp ]
|
||||
[ thread-run ../example/xtime.cpp ]
|
||||
[ thread-run ../example/shared_monitor.cpp ]
|
||||
#[ thread-run ../example/shared_mutex.cpp ]
|
||||
#[ thread-run ../example/v2_shared_monitor.cpp ]
|
||||
#[ thread-run ../example/v2_shared_mutex.cpp ]
|
||||
;
|
||||
|
||||
#explicit shared_upwards ;
|
||||
#test-suite shared_upwards
|
||||
#:
|
||||
# [ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_shared_lock_try_pass.cpp : unique_lock__cons__move_ctor_shared_lock_try_p ]
|
||||
# [ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_shared_lock_for_pass.cpp : unique_lock__cons__move_ctor_shared_lock_for_p ]
|
||||
# [ thread-run2 ./sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_shared_lock_until_pass.cpp : unique_lock__cons__move_ctor_shared_lock_until_p ]
|
||||
#
|
||||
# [ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_try_pass.cpp : upgrade_lock__cons__move_ctor_shared_lock_try_p ]
|
||||
# [ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_for_pass.cpp : upgrade_lock__cons__move_ctor_shared_lock_for_p ]
|
||||
# [ thread-run2 ./sync/mutual_exclusion/locks/upgrade_lock/cons/move_ctor_shared_lock_until_pass.cpp : upgrade_lock__cons__move_ctor_shared_lock_until_p ]
|
||||
#;
|
||||
}
|
||||
|
||||
28
test/sync/conditions/condition_variable/assign_fail.cpp
Normal file
28
test/sync/conditions/condition_variable/assign_fail.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// condition_variable& operator=(const condition_variable&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
|
||||
int fail()
|
||||
{
|
||||
boost::condition_variable cv0;
|
||||
boost::condition_variable cv1;
|
||||
cv1 = cv0;
|
||||
}
|
||||
|
||||
28
test/sync/conditions/condition_variable/copy_fail.cpp
Normal file
28
test/sync/conditions/condition_variable/copy_fail.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// condition_variable(const condition_variable&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int fail()
|
||||
{
|
||||
boost::condition_variable cv0;
|
||||
boost::condition_variable cv1(cv0);
|
||||
}
|
||||
|
||||
28
test/sync/conditions/condition_variable/default_pass.cpp
Normal file
28
test/sync/conditions/condition_variable/default_pass.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// condition_variable(const condition_variable&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::condition_variable cv0;
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
69
test/sync/conditions/condition_variable/dtor_pass.cpp
Normal file
69
test/sync/conditions/condition_variable/dtor_pass.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// condition_variable(const condition_variable&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
boost::condition_variable* cv;
|
||||
boost::mutex m;
|
||||
typedef boost::unique_lock<boost::mutex> Lock;
|
||||
|
||||
bool f_ready = false;
|
||||
bool g_ready = false;
|
||||
|
||||
void f()
|
||||
{
|
||||
Lock lk(m);
|
||||
f_ready = true;
|
||||
cv->notify_one();
|
||||
cv->wait(lk);
|
||||
delete cv;
|
||||
}
|
||||
|
||||
void g()
|
||||
{
|
||||
Lock lk(m);
|
||||
g_ready = true;
|
||||
cv->notify_one();
|
||||
while (!f_ready)
|
||||
{
|
||||
cv->wait(lk);
|
||||
}
|
||||
cv->notify_one();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cv = new boost::condition_variable;
|
||||
boost::thread th2(g);
|
||||
Lock lk(m);
|
||||
while (!g_ready)
|
||||
{
|
||||
cv->wait(lk);
|
||||
}
|
||||
lk.unlock();
|
||||
boost::thread th1(f);
|
||||
th1.join();
|
||||
th2.join();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// condition_variable(const condition_variable&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if defined BOOST_THREAD_DEFINES_CONDITION_VARIABLE_NATIVE_HANDLE
|
||||
//BOOST_STATIC_ASSERT((boost::is_same<boost::condition_variable::native_handle_type, pthread_cond_t*>::value));
|
||||
boost::condition_variable cv;
|
||||
boost::condition_variable::native_handle_type h = cv.native_handle();
|
||||
BOOST_TEST(h != 0);
|
||||
#else
|
||||
#error "Test not applicable: BOOST_THREAD_DEFINES_CONDITION_VARIABLE_NATIVE_HANDLE not defined for this platform as not supported"
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
95
test/sync/conditions/condition_variable/wait_for_pass.cpp
Normal file
95
test/sync/conditions/condition_variable/wait_for_pass.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// condition_variable(const condition_variable&) = delete;
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#if defined BOOST_THREAD_USES_CHRONO
|
||||
|
||||
boost::condition_variable cv;
|
||||
boost::mutex mut;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
|
||||
void f()
|
||||
{
|
||||
typedef boost::chrono::steady_clock Clock;
|
||||
typedef boost::chrono::milliseconds milliseconds;
|
||||
boost::unique_lock<boost::mutex> lk(mut);
|
||||
BOOST_TEST(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
Clock::time_point t0 = Clock::now();
|
||||
int count=0;
|
||||
while (test2 == 0 && cv.wait_for(lk, milliseconds(250)) == boost::cv_status::no_timeout)
|
||||
count++;
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
{
|
||||
BOOST_TEST(t1 - t0 < milliseconds(250));
|
||||
BOOST_TEST(test2 != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// This test is spurious as it depends on the time the thread system switches the threads
|
||||
BOOST_TEST(t1 - t0 - milliseconds(250) < milliseconds(count*250+5+1000));
|
||||
BOOST_TEST(test2 == 0);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mut);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mut);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
lk.unlock();
|
||||
t.join();
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
|
||||
#endif
|
||||
|
||||
109
test/sync/conditions/condition_variable/wait_for_pred_pass.cpp
Normal file
109
test/sync/conditions/condition_variable/wait_for_pred_pass.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// condition_variable(const condition_variable&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#if defined BOOST_THREAD_USES_CHRONO
|
||||
|
||||
class Pred
|
||||
{
|
||||
int& i_;
|
||||
public:
|
||||
explicit Pred(int& i) :
|
||||
i_(i)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator()()
|
||||
{
|
||||
return i_ != 0;
|
||||
}
|
||||
};
|
||||
|
||||
boost::condition_variable cv;
|
||||
boost::mutex mut;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
|
||||
void f()
|
||||
{
|
||||
typedef boost::chrono::system_clock Clock;
|
||||
typedef boost::chrono::milliseconds milliseconds;
|
||||
boost::unique_lock < boost::mutex > lk(mut);
|
||||
BOOST_TEST(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
Clock::time_point t0 = Clock::now();
|
||||
int count=0;
|
||||
bool r = cv.wait_for(lk, milliseconds(250), Pred(test2));
|
||||
count++;
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
{
|
||||
// This test is spurious as it depends on the time the thread system switches the threads
|
||||
BOOST_TEST(t1 - t0 < milliseconds(250+1000));
|
||||
BOOST_TEST(test2 != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_TEST(t1 - t0 - milliseconds(250) < milliseconds(count*250+2));
|
||||
BOOST_TEST(test2 == 0);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::unique_lock < boost::mutex > lk(mut);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
{
|
||||
boost::unique_lock < boost::mutex > lk(mut);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
lk.unlock();
|
||||
t.join();
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else
|
||||
#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
|
||||
#endif
|
||||
108
test/sync/conditions/condition_variable/wait_until_pass.cpp
Normal file
108
test/sync/conditions/condition_variable/wait_until_pass.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// condition_variable(const condition_variable&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#if defined BOOST_THREAD_USES_CHRONO
|
||||
|
||||
struct Clock
|
||||
{
|
||||
typedef boost::chrono::milliseconds duration;
|
||||
typedef duration::rep rep;
|
||||
typedef duration::period period;
|
||||
typedef boost::chrono::time_point<Clock> time_point;
|
||||
static const bool is_steady = true;
|
||||
|
||||
static time_point now()
|
||||
{
|
||||
using namespace boost::chrono;
|
||||
return time_point(duration_cast<duration> (steady_clock::now().time_since_epoch()));
|
||||
}
|
||||
};
|
||||
|
||||
boost::condition_variable cv;
|
||||
boost::mutex mut;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
|
||||
void f()
|
||||
{
|
||||
boost::unique_lock < boost::mutex > lk(mut);
|
||||
BOOST_TEST(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
Clock::time_point t0 = Clock::now();
|
||||
Clock::time_point t = t0 + Clock::duration(250);
|
||||
int count=0;
|
||||
while (test2 == 0 && cv.wait_until(lk, t) == boost::cv_status::no_timeout)
|
||||
count++;
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
{
|
||||
BOOST_TEST(t1 - t0 < Clock::duration(250));
|
||||
BOOST_TEST(test2 != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// This test is spurious as it depends on the time the thread system switches the threads
|
||||
BOOST_TEST(t1 - t0 - Clock::duration(250) < Clock::duration(count*250+5+1000));
|
||||
BOOST_TEST(test2 == 0);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::unique_lock < boost::mutex > lk(mut);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
{
|
||||
boost::unique_lock < boost::mutex > lk(mut);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
lk.unlock();
|
||||
t.join();
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else
|
||||
#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
|
||||
#endif
|
||||
122
test/sync/conditions/condition_variable/wait_until_pred_pass.cpp
Normal file
122
test/sync/conditions/condition_variable/wait_until_pred_pass.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable>
|
||||
|
||||
// class condition_variable;
|
||||
|
||||
// condition_variable(const condition_variable&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#if defined BOOST_THREAD_USES_CHRONO
|
||||
|
||||
struct Clock
|
||||
{
|
||||
typedef boost::chrono::milliseconds duration;
|
||||
typedef duration::rep rep;
|
||||
typedef duration::period period;
|
||||
typedef boost::chrono::time_point<Clock> time_point;
|
||||
static const bool is_steady = true;
|
||||
|
||||
static time_point now()
|
||||
{
|
||||
using namespace boost::chrono;
|
||||
return time_point(duration_cast<duration> (steady_clock::now().time_since_epoch()));
|
||||
}
|
||||
};
|
||||
|
||||
class Pred
|
||||
{
|
||||
int& i_;
|
||||
public:
|
||||
explicit Pred(int& i) :
|
||||
i_(i)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator()()
|
||||
{
|
||||
return i_ != 0;
|
||||
}
|
||||
};
|
||||
|
||||
boost::condition_variable cv;
|
||||
boost::mutex mut;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
|
||||
void f()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mut);
|
||||
BOOST_TEST(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
Clock::time_point t0 = Clock::now();
|
||||
Clock::time_point t = t0 + Clock::duration(250);
|
||||
bool r = cv.wait_until(lk, t, Pred(test2));
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
{
|
||||
BOOST_TEST(t1 - t0 < Clock::duration(250));
|
||||
BOOST_TEST(test2 != 0);
|
||||
BOOST_TEST(r);
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_TEST(t1 - t0 - Clock::duration(250) < Clock::duration(250+2));
|
||||
BOOST_TEST(test2 == 0);
|
||||
BOOST_TEST(!r);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mut);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mut);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
lk.unlock();
|
||||
t.join();
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else
|
||||
#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
|
||||
#endif
|
||||
28
test/sync/conditions/condition_variable_any/assign_fail.cpp
Normal file
28
test/sync/conditions/condition_variable_any/assign_fail.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable_any>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// condition_variable_any& operator=(const condition_variable_any&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
|
||||
int fail()
|
||||
{
|
||||
boost::condition_variable_any cv0;
|
||||
boost::condition_variable_any cv1;
|
||||
cv1 = cv0;
|
||||
}
|
||||
|
||||
28
test/sync/conditions/condition_variable_any/copy_fail.cpp
Normal file
28
test/sync/conditions/condition_variable_any/copy_fail.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable_any>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// condition_variable_any(const condition_variable_any&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int fail()
|
||||
{
|
||||
boost::condition_variable_any cv0;
|
||||
boost::condition_variable_any cv1(cv0);
|
||||
}
|
||||
|
||||
28
test/sync/conditions/condition_variable_any/default_pass.cpp
Normal file
28
test/sync/conditions/condition_variable_any/default_pass.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable_any>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// condition_variable_any(const condition_variable_any&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::condition_variable_any cv0;
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
69
test/sync/conditions/condition_variable_any/dtor_pass.cpp
Normal file
69
test/sync/conditions/condition_variable_any/dtor_pass.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable_any>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// condition_variable_any(const condition_variable_any&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
boost::condition_variable_any* cv;
|
||||
boost::timed_mutex m;
|
||||
typedef boost::unique_lock<boost::timed_mutex> Lock;
|
||||
|
||||
bool f_ready = false;
|
||||
bool g_ready = false;
|
||||
|
||||
void f()
|
||||
{
|
||||
Lock lk(m);
|
||||
f_ready = true;
|
||||
cv->notify_one();
|
||||
cv->wait(lk);
|
||||
delete cv;
|
||||
}
|
||||
|
||||
void g()
|
||||
{
|
||||
Lock lk(m);
|
||||
g_ready = true;
|
||||
cv->notify_one();
|
||||
while (!f_ready)
|
||||
{
|
||||
cv->wait(lk);
|
||||
}
|
||||
cv->notify_one();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cv = new boost::condition_variable_any;
|
||||
boost::thread th2(g);
|
||||
Lock lk(m);
|
||||
while (!g_ready)
|
||||
{
|
||||
cv->wait(lk);
|
||||
}
|
||||
lk.unlock();
|
||||
boost::thread th1(f);
|
||||
th1.join();
|
||||
th2.join();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable_any>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// condition_variable_any(const condition_variable_any&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#if defined BOOST_THREAD_USES_CHRONO
|
||||
|
||||
boost::condition_variable_any cv;
|
||||
|
||||
typedef boost::timed_mutex L0;
|
||||
typedef boost::unique_lock<L0> L1;
|
||||
|
||||
L0 m0;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
|
||||
void f()
|
||||
{
|
||||
typedef boost::chrono::system_clock Clock;
|
||||
typedef boost::chrono::milliseconds milliseconds;
|
||||
L1 lk(m0);
|
||||
BOOST_TEST(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
int count=0;
|
||||
Clock::time_point t0 = Clock::now();
|
||||
while (test2 == 0 &&
|
||||
cv.wait_for(lk, milliseconds(250)) == boost::cv_status::no_timeout)
|
||||
count++;
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
{
|
||||
BOOST_TEST(t1 - t0 < milliseconds(250));
|
||||
BOOST_TEST(test2 != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// This test is spurious as it depends on the time the thread system switches the threads
|
||||
BOOST_TEST(t1 - t0 - milliseconds(250) < milliseconds(count*250+5+1000));
|
||||
BOOST_TEST(test2 == 0);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
L1 lk(m0);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
{
|
||||
L1 lk(m0);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
lk.unlock();
|
||||
t.join();
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else
|
||||
#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
|
||||
#endif
|
||||
@@ -0,0 +1,110 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable_any>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// condition_variable_any(const condition_variable_any&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#if defined BOOST_THREAD_USES_CHRONO
|
||||
|
||||
class Pred
|
||||
{
|
||||
int& i_;
|
||||
public:
|
||||
explicit Pred(int& i) :
|
||||
i_(i)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator()()
|
||||
{
|
||||
return i_ != 0;
|
||||
}
|
||||
};
|
||||
|
||||
boost::condition_variable_any cv;
|
||||
|
||||
typedef boost::timed_mutex L0;
|
||||
typedef boost::unique_lock<L0> L1;
|
||||
|
||||
L0 m0;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
|
||||
void f()
|
||||
{
|
||||
typedef boost::chrono::system_clock Clock;
|
||||
typedef boost::chrono::milliseconds milliseconds;
|
||||
L1 lk(m0);
|
||||
BOOST_TEST(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
Clock::time_point t0 = Clock::now();
|
||||
bool r = cv.wait_for(lk, milliseconds(250), Pred(test2));
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
{
|
||||
BOOST_TEST(t1 - t0 < milliseconds(250));
|
||||
BOOST_TEST(test2 != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_TEST(t1 - t0 - milliseconds(250) < milliseconds(250+5));
|
||||
BOOST_TEST(test2 == 0);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
L1 lk(m0);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
{
|
||||
L1 lk(m0);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
lk.unlock();
|
||||
t.join();
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else
|
||||
#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
|
||||
#endif
|
||||
112
test/sync/conditions/condition_variable_any/wait_until_pass.cpp
Normal file
112
test/sync/conditions/condition_variable_any/wait_until_pass.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable_any>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// condition_variable_any(const condition_variable_any&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#if defined BOOST_THREAD_USES_CHRONO
|
||||
|
||||
struct Clock
|
||||
{
|
||||
typedef boost::chrono::milliseconds duration;
|
||||
typedef duration::rep rep;
|
||||
typedef duration::period period;
|
||||
typedef boost::chrono::time_point<Clock> time_point;
|
||||
static const bool is_steady = true;
|
||||
|
||||
static time_point now()
|
||||
{
|
||||
using namespace boost::chrono;
|
||||
return time_point(duration_cast<duration> (steady_clock::now().time_since_epoch()));
|
||||
}
|
||||
};
|
||||
|
||||
boost::condition_variable_any cv;
|
||||
|
||||
typedef boost::timed_mutex L0;
|
||||
typedef boost::unique_lock<L0> L1;
|
||||
|
||||
L0 m0;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
|
||||
void f()
|
||||
{
|
||||
L1 lk(m0);
|
||||
BOOST_TEST(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
Clock::time_point t0 = Clock::now();
|
||||
Clock::time_point t = t0 + Clock::duration(250);
|
||||
int count=0;
|
||||
while (test2 == 0 && cv.wait_until(lk, t) == boost::cv_status::no_timeout)
|
||||
count++;
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
{
|
||||
BOOST_TEST(t1 - t0 < Clock::duration(250));
|
||||
BOOST_TEST(test2 != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// This test is spurious as it depends on the time the thread system switches the threads
|
||||
BOOST_TEST(t1 - t0 - Clock::duration(250) < Clock::duration(250*count+5+1000));
|
||||
BOOST_TEST(test2 == 0);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
L1 lk(m0);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
{
|
||||
L1 lk(m0);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
lk.unlock();
|
||||
t.join();
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else
|
||||
#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
|
||||
#endif
|
||||
@@ -0,0 +1,126 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/condition_variable_any>
|
||||
|
||||
// class condition_variable_any;
|
||||
|
||||
// condition_variable_any(const condition_variable_any&) = delete;
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#if defined BOOST_THREAD_USES_CHRONO
|
||||
|
||||
struct Clock
|
||||
{
|
||||
typedef boost::chrono::milliseconds duration;
|
||||
typedef duration::rep rep;
|
||||
typedef duration::period period;
|
||||
typedef boost::chrono::time_point<Clock> time_point;
|
||||
static const bool is_steady = true;
|
||||
|
||||
static time_point now()
|
||||
{
|
||||
using namespace boost::chrono;
|
||||
return time_point(duration_cast<duration> (steady_clock::now().time_since_epoch()));
|
||||
}
|
||||
};
|
||||
|
||||
class Pred
|
||||
{
|
||||
int& i_;
|
||||
public:
|
||||
explicit Pred(int& i) :
|
||||
i_(i)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator()()
|
||||
{
|
||||
return i_ != 0;
|
||||
}
|
||||
};
|
||||
|
||||
boost::condition_variable_any cv;
|
||||
|
||||
typedef boost::timed_mutex L0;
|
||||
typedef boost::unique_lock<L0> L1;
|
||||
|
||||
L0 m0;
|
||||
|
||||
int test1 = 0;
|
||||
int test2 = 0;
|
||||
|
||||
int runs = 0;
|
||||
|
||||
void f()
|
||||
{
|
||||
L1 lk(m0);
|
||||
BOOST_TEST(test2 == 0);
|
||||
test1 = 1;
|
||||
cv.notify_one();
|
||||
Clock::time_point t0 = Clock::now();
|
||||
Clock::time_point t = t0 + Clock::duration(250);
|
||||
bool r = cv.wait_until(lk, t, Pred(test2));
|
||||
Clock::time_point t1 = Clock::now();
|
||||
if (runs == 0)
|
||||
{
|
||||
BOOST_TEST(t1 - t0 < Clock::duration(250));
|
||||
BOOST_TEST(test2 != 0);
|
||||
BOOST_TEST(r);
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_TEST(t1 - t0 - Clock::duration(250) < Clock::duration(250+2));
|
||||
BOOST_TEST(test2 == 0);
|
||||
BOOST_TEST(!r);
|
||||
}
|
||||
++runs;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
L1 lk(m0);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
test2 = 1;
|
||||
lk.unlock();
|
||||
cv.notify_one();
|
||||
t.join();
|
||||
}
|
||||
test1 = 0;
|
||||
test2 = 0;
|
||||
{
|
||||
L1 lk(m0);
|
||||
boost::thread t(f);
|
||||
BOOST_TEST(test1 == 0);
|
||||
while (test1 == 0)
|
||||
cv.wait(lk);
|
||||
BOOST_TEST(test1 != 0);
|
||||
lk.unlock();
|
||||
t.join();
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else
|
||||
#error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"
|
||||
#endif
|
||||
60
test/sync/conditions/cv_status/cv_status_pass.cpp
Normal file
60
test/sync/conditions/cv_status/cv_status_pass.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/thread.hpp>
|
||||
|
||||
// class thread
|
||||
|
||||
// static unsigned hardware_concurrency();
|
||||
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
BOOST_TEST(boost::cv_status::no_timeout != boost::cv_status::timeout);
|
||||
}
|
||||
{
|
||||
boost::cv_status st = boost::cv_status::no_timeout;
|
||||
BOOST_TEST(st == boost::cv_status::no_timeout);
|
||||
BOOST_TEST(boost::cv_status::no_timeout==st);
|
||||
BOOST_TEST(st != boost::cv_status::timeout);
|
||||
BOOST_TEST(boost::cv_status::timeout!=st);
|
||||
}
|
||||
{
|
||||
boost::cv_status st = boost::cv_status::timeout;
|
||||
BOOST_TEST(st == boost::cv_status::timeout);
|
||||
BOOST_TEST(boost::cv_status::timeout==st);
|
||||
BOOST_TEST(st != boost::cv_status::no_timeout);
|
||||
BOOST_TEST(boost::cv_status::no_timeout!=st);
|
||||
}
|
||||
{
|
||||
boost::cv_status st;
|
||||
st = boost::cv_status::no_timeout;
|
||||
BOOST_TEST(st == boost::cv_status::no_timeout);
|
||||
BOOST_TEST(boost::cv_status::no_timeout==st);
|
||||
BOOST_TEST(st != boost::cv_status::timeout);
|
||||
BOOST_TEST(boost::cv_status::timeout!=st);
|
||||
}
|
||||
{
|
||||
boost::cv_status st;
|
||||
st = boost::cv_status::timeout;
|
||||
BOOST_TEST(st == boost::cv_status::timeout);
|
||||
BOOST_TEST(boost::cv_status::timeout==st);
|
||||
BOOST_TEST(st != boost::cv_status::no_timeout);
|
||||
BOOST_TEST(boost::cv_status::no_timeout!=st);
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
184
test/sync/futures/async/async_pass.cpp
Normal file
184
test/sync/futures/async/async_pass.cpp
Normal file
@@ -0,0 +1,184 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/future.hpp>
|
||||
|
||||
// template <class F, class... Args>
|
||||
// future<typename result_of<F(Args...)>::type>
|
||||
// async(F&& f, Args&&... args);
|
||||
|
||||
// template <class F, class... Args>
|
||||
// future<typename result_of<F(Args...)>::type>
|
||||
// async(launch policy, F&& f, Args&&... args);
|
||||
|
||||
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <memory>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
typedef boost::chrono::high_resolution_clock Clock;
|
||||
typedef boost::chrono::milliseconds ms;
|
||||
|
||||
int f0()
|
||||
{
|
||||
boost::this_thread::sleep_for(ms(200));
|
||||
return 3;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
int& f1()
|
||||
{
|
||||
boost::this_thread::sleep_for(ms(200));
|
||||
return i;
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
boost::this_thread::sleep_for(ms(200));
|
||||
}
|
||||
|
||||
boost::unique_ptr<int> f3(int i)
|
||||
{
|
||||
boost::this_thread::sleep_for(ms(200));
|
||||
return boost::unique_ptr<int>(new int(i));
|
||||
}
|
||||
|
||||
boost::unique_ptr<int> f4(boost::unique_ptr<int>&& p)
|
||||
{
|
||||
boost::this_thread::sleep_for(ms(200));
|
||||
return boost::move(p);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::future<int> f = boost::async(f0);
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
BOOST_TEST(f.get() == 3);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 < ms(100));
|
||||
}
|
||||
{
|
||||
boost::future<int> f = boost::async(boost::launch::async, f0);
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
BOOST_TEST(f.get() == 3);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 < ms(100));
|
||||
}
|
||||
{
|
||||
boost::future<int> f = boost::async(boost::launch::any, f0);
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
BOOST_TEST(f.get() == 3);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 < ms(100));
|
||||
}
|
||||
{
|
||||
boost::future<int> f = boost::async(boost::launch::deferred, f0);
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
BOOST_TEST(f.get() == 3);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 > ms(100));
|
||||
}
|
||||
|
||||
{
|
||||
boost::future<int&> f = boost::async(f1);
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
BOOST_TEST(&f.get() == &i);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 < ms(100));
|
||||
}
|
||||
{
|
||||
boost::future<int&> f = boost::async(boost::launch::async, f1);
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
BOOST_TEST(&f.get() == &i);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 < ms(100));
|
||||
}
|
||||
{
|
||||
boost::future<int&> f = boost::async(boost::launch::any, f1);
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
BOOST_TEST(&f.get() == &i);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 < ms(100));
|
||||
}
|
||||
{
|
||||
boost::future<int&> f = boost::async(boost::launch::deferred, f1);
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
BOOST_TEST(&f.get() == &i);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 > ms(100));
|
||||
}
|
||||
|
||||
{
|
||||
boost::future<void> f = boost::async(f2);
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
f.get();
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 < ms(100));
|
||||
}
|
||||
{
|
||||
boost::future<void> f = boost::async(boost::launch::async, f2);
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
f.get();
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 < ms(100));
|
||||
}
|
||||
{
|
||||
boost::future<void> f = boost::async(boost::launch::any, f2);
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
f.get();
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 < ms(100));
|
||||
}
|
||||
{
|
||||
boost::future<void> f = boost::async(boost::launch::deferred, f2);
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
f.get();
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 > ms(100));
|
||||
}
|
||||
|
||||
{
|
||||
boost::future<boost::unique_ptr<int>> f = boost::async(f3, 3);
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
BOOST_TEST(*f.get() == 3);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 < ms(100));
|
||||
}
|
||||
|
||||
{
|
||||
boost::future<boost::unique_ptr<int>> f = boost::async(f4, boost::unique_ptr<int>(new int(3)));
|
||||
boost::this_thread::sleep_for(ms(300));
|
||||
Clock::time_point t0 = Clock::now();
|
||||
BOOST_TEST(*f.get() == 3);
|
||||
Clock::time_point t1 = Clock::now();
|
||||
BOOST_TEST(t1 - t0 < ms(100));
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
84
test/sync/futures/future/share_pass.cpp
Normal file
84
test/sync/futures/future/share_pass.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/future.hpp>
|
||||
|
||||
// class future<R>
|
||||
|
||||
// shared_future<R> share() &&;
|
||||
|
||||
#define BOOST_THREAD_VERSION 2
|
||||
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
{
|
||||
typedef int T;
|
||||
boost::promise<T> p;
|
||||
boost::future<T> f0 = p.get_future();
|
||||
boost::shared_future<T> sf = f0.share();
|
||||
boost::shared_future<T> f = sf;
|
||||
BOOST_TEST(!f0.valid());
|
||||
BOOST_TEST(f.valid());
|
||||
}
|
||||
{
|
||||
typedef int T;
|
||||
boost::future<T> f0;
|
||||
boost::shared_future<T> sf = f0.share();
|
||||
boost::shared_future<T> f = sf;
|
||||
BOOST_TEST(!f0.valid());
|
||||
BOOST_TEST(!f.valid());
|
||||
}
|
||||
{
|
||||
typedef int& T;
|
||||
boost::promise<T> p;
|
||||
boost::future<T> f0 = p.get_future();
|
||||
boost::shared_future<T> sf = f0.share();
|
||||
boost::shared_future<T> f = sf;
|
||||
BOOST_TEST(!f0.valid());
|
||||
BOOST_TEST(f.valid());
|
||||
}
|
||||
{
|
||||
typedef int& T;
|
||||
boost::future<T> f0;
|
||||
boost::shared_future<T> sf = f0.share();
|
||||
boost::shared_future<T> f = sf;
|
||||
BOOST_TEST(!f0.valid());
|
||||
BOOST_TEST(!f.valid());
|
||||
}
|
||||
{
|
||||
typedef void T;
|
||||
boost::promise<T> p;
|
||||
boost::future<T> f0 = p.get_future();
|
||||
boost::shared_future<T> sf = f0.share();
|
||||
boost::shared_future<T> f = sf;
|
||||
BOOST_TEST(!f0.valid());
|
||||
BOOST_TEST(f.valid());
|
||||
}
|
||||
{
|
||||
typedef void T;
|
||||
boost::future<T> f0;
|
||||
boost::shared_future<T> sf = f0.share();
|
||||
boost::shared_future<T> f = sf;
|
||||
BOOST_TEST(!f0.valid());
|
||||
BOOST_TEST(!f.valid());
|
||||
}
|
||||
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
100
test/sync/futures/promise/copy_assign_fail.cpp
Executable file
100
test/sync/futures/promise/copy_assign_fail.cpp
Executable file
@@ -0,0 +1,100 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/future.hpp>
|
||||
// class promise<R>
|
||||
// promise& operator=(const promise& rhs) = delete;
|
||||
|
||||
#define BOOST_THREAD_VERSION 2
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
//BOOST_TEST(test_alloc_base::count == 0);
|
||||
{
|
||||
//boost::promise<int> p0(boost::allocator_arg, test_allocator<int>());
|
||||
//boost::promise<int> p(boost::allocator_arg, test_allocator<int>());
|
||||
boost::promise<int> p0;
|
||||
boost::promise<int> p;
|
||||
//BOOST_TEST(test_alloc_base::count == 2);
|
||||
p = p0;
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
boost::future<int> f = p.get_future();
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
BOOST_TEST(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch (const boost::future_error& e)
|
||||
{
|
||||
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
|
||||
}
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
}
|
||||
//BOOST_TEST(test_alloc_base::count == 0);
|
||||
// {
|
||||
// //boost::promise<int&> p0(boost::allocator_arg, test_allocator<int>());
|
||||
// //boost::promise<int&> p(boost::allocator_arg, test_allocator<int>());
|
||||
// boost::promise<int&> p0;
|
||||
// boost::promise<int&> p;
|
||||
// //BOOST_TEST(test_alloc_base::count == 2);
|
||||
// p = p0;
|
||||
// //BOOST_TEST(test_alloc_base::count == 1);
|
||||
// boost::future<int&> f = p.get_future();
|
||||
// //BOOST_TEST(test_alloc_base::count == 1);
|
||||
// BOOST_TEST(f.valid());
|
||||
// try
|
||||
// {
|
||||
// f = p0.get_future();
|
||||
// BOOST_TEST(false);
|
||||
// }
|
||||
// catch (const boost::future_error& e)
|
||||
// {
|
||||
// BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
|
||||
// }
|
||||
// //BOOST_TEST(test_alloc_base::count == 1);
|
||||
// }
|
||||
// //BOOST_TEST(test_alloc_base::count == 0);
|
||||
// {
|
||||
// //boost::promise<void> p0(boost::allocator_arg, test_allocator<void>());
|
||||
// //boost::promise<void> p(boost::allocator_arg, test_allocator<void>());
|
||||
// boost::promise<void> p0;
|
||||
// boost::promise<void> p;
|
||||
// //BOOST_TEST(test_alloc_base::count == 2);
|
||||
// p = p0;
|
||||
// //BOOST_TEST(test_alloc_base::count == 1);
|
||||
// boost::future<void> f = p.get_future();
|
||||
// //BOOST_TEST(test_alloc_base::count == 1);
|
||||
// BOOST_TEST(f.valid());
|
||||
// try
|
||||
// {
|
||||
// f = p0.get_future();
|
||||
// BOOST_TEST(false);
|
||||
// }
|
||||
// catch (const boost::future_error& e)
|
||||
// {
|
||||
// BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
|
||||
// }
|
||||
// //BOOST_TEST(test_alloc_base::count == 1);
|
||||
// }
|
||||
//BOOST_TEST(test_alloc_base::count == 0);
|
||||
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
52
test/sync/futures/promise/default_pass.cpp
Executable file
52
test/sync/futures/promise/default_pass.cpp
Executable file
@@ -0,0 +1,52 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/future.hpp>
|
||||
|
||||
// class promise<R>
|
||||
|
||||
// promise();
|
||||
|
||||
#define BOOST_THREAD_VERSION 2
|
||||
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << __LINE__ << std::endl;
|
||||
|
||||
{
|
||||
boost::promise<int> p;
|
||||
boost::future<int> f = p.get_future();
|
||||
BOOST_TEST(f.valid());
|
||||
}
|
||||
std::cout << __LINE__ << std::endl;
|
||||
{
|
||||
boost::promise<int&> p;
|
||||
boost::future<int&> f = p.get_future();
|
||||
BOOST_TEST(f.valid());
|
||||
}
|
||||
std::cout << __LINE__ << std::endl;
|
||||
{
|
||||
boost::promise<void> p;
|
||||
std::cout << __LINE__ << std::endl;
|
||||
boost::future<void> f = p.get_future();
|
||||
std::cout << __LINE__ << std::endl;
|
||||
BOOST_TEST(f.valid());
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
122
test/sync/futures/promise/dtor_pass.cpp
Executable file
122
test/sync/futures/promise/dtor_pass.cpp
Executable file
@@ -0,0 +1,122 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/future.hpp>
|
||||
|
||||
// class promise<R>
|
||||
|
||||
// ~promise();
|
||||
|
||||
#define BOOST_THREAD_VERSION 2
|
||||
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << __LINE__ << std::endl;
|
||||
{
|
||||
typedef int T;
|
||||
boost::future<T> f;
|
||||
{
|
||||
boost::promise<T> p;
|
||||
f = p.get_future();
|
||||
p.set_value(3);
|
||||
}
|
||||
BOOST_TEST(f.get() == 3);
|
||||
}
|
||||
std::cout << __LINE__ << std::endl;
|
||||
{
|
||||
typedef int T;
|
||||
boost::future<T> f;
|
||||
{
|
||||
boost::promise<T> p;
|
||||
f = p.get_future();
|
||||
}
|
||||
try
|
||||
{
|
||||
T i = f.get();
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch (const boost::future_error& e)
|
||||
{
|
||||
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise));
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << __LINE__ << std::endl;
|
||||
{
|
||||
typedef int& T;
|
||||
int i = 4;
|
||||
boost::future<T> f;
|
||||
{
|
||||
boost::promise<T> p;
|
||||
f = p.get_future();
|
||||
p.set_value(i);
|
||||
}
|
||||
BOOST_TEST(&f.get() == &i);
|
||||
}
|
||||
std::cout << __LINE__ << std::endl;
|
||||
{
|
||||
typedef int& T;
|
||||
boost::future<T> f;
|
||||
{
|
||||
boost::promise<T> p;
|
||||
f = p.get_future();
|
||||
}
|
||||
try
|
||||
{
|
||||
T i = f.get();
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch (const boost::future_error& e)
|
||||
{
|
||||
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise));
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << __LINE__ << std::endl;
|
||||
{
|
||||
typedef void T;
|
||||
boost::future<T> f;
|
||||
{
|
||||
boost::promise<T> p;
|
||||
f = p.get_future();
|
||||
p.set_value();
|
||||
}
|
||||
f.get();
|
||||
BOOST_TEST(true);
|
||||
}
|
||||
std::cout << __LINE__ << std::endl;
|
||||
{
|
||||
typedef void T;
|
||||
boost::future<T> f;
|
||||
{
|
||||
boost::promise<T> p;
|
||||
f = p.get_future();
|
||||
}
|
||||
try
|
||||
{
|
||||
f.get();
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch (const boost::future_error& e)
|
||||
{
|
||||
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise));
|
||||
}
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
64
test/sync/futures/promise/get_future_pass.cpp
Executable file
64
test/sync/futures/promise/get_future_pass.cpp
Executable file
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/future.hpp>
|
||||
|
||||
// class promise<R>
|
||||
|
||||
// future<R> get_future();
|
||||
|
||||
#define BOOST_THREAD_VERSION 2
|
||||
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
// {
|
||||
// boost::promise<double> p;
|
||||
// boost::future<double> f = p.get_future();
|
||||
// p.set_value(105.5);
|
||||
// BOOST_TEST(f.get() == 105.5);
|
||||
// }
|
||||
// {
|
||||
// boost::promise<double> p;
|
||||
// boost::future<double> f = p.get_future();
|
||||
// try
|
||||
// {
|
||||
// f = p.get_future();
|
||||
// BOOST_TEST(false);
|
||||
// }
|
||||
// catch (const boost::future_error& e)
|
||||
// {
|
||||
// BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::future_already_retrieved));
|
||||
// }
|
||||
// }
|
||||
{
|
||||
boost::promise<double> p;
|
||||
boost::promise<double> p0 = boost::move(p);
|
||||
try
|
||||
{
|
||||
boost::future<double> f = p.get_future();
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch (const boost::future_error& e)
|
||||
{
|
||||
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
105
test/sync/futures/promise/move_assign_pass.cpp
Executable file
105
test/sync/futures/promise/move_assign_pass.cpp
Executable file
@@ -0,0 +1,105 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <future>
|
||||
|
||||
// class promise<R>
|
||||
|
||||
// promise& operator=(promise&& rhs);
|
||||
|
||||
#define BOOST_THREAD_VERSION 2
|
||||
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
boost::mutex m0;
|
||||
boost::mutex m1;
|
||||
|
||||
int main()
|
||||
{
|
||||
//BOOST_TEST(test_alloc_base::count == 0);
|
||||
{
|
||||
//boost::promise<int> p0(boost::allocator_arg, test_allocator<int>());
|
||||
//boost::promise<int> p(boost::allocator_arg, test_allocator<int>());
|
||||
boost::promise<int> p0;
|
||||
boost::promise<int> p;
|
||||
//BOOST_TEST(test_alloc_base::count == 2);
|
||||
p = boost::move(p0);
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
boost::future<int> f = p.get_future();
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
BOOST_TEST(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch (const boost::future_error& e)
|
||||
{
|
||||
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
|
||||
}
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
}
|
||||
//BOOST_TEST(test_alloc_base::count == 0);
|
||||
{
|
||||
//boost::promise<int&> p0(boost::allocator_arg, test_allocator<int>());
|
||||
//boost::promise<int&> p(boost::allocator_arg, test_allocator<int>());
|
||||
boost::promise<int&> p0;
|
||||
boost::promise<int&> p;
|
||||
//BOOST_TEST(test_alloc_base::count == 2);
|
||||
p = boost::move(p0);
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
boost::future<int&> f = p.get_future();
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
BOOST_TEST(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch (const boost::future_error& e)
|
||||
{
|
||||
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
|
||||
}
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
}
|
||||
//BOOST_TEST(test_alloc_base::count == 0);
|
||||
{
|
||||
//boost::promise<void> p0(boost::allocator_arg, test_allocator<void>());
|
||||
//boost::promise<void> p(boost::allocator_arg, test_allocator<void>());
|
||||
boost::promise<void> p0;
|
||||
boost::promise<void> p;
|
||||
//BOOST_TEST(test_alloc_base::count == 2);
|
||||
p = boost::move(p0);
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
boost::future<void> f = p.get_future();
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
BOOST_TEST(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch (const boost::future_error& e)
|
||||
{
|
||||
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
|
||||
}
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
}
|
||||
//BOOST_TEST(test_alloc_base::count == 0);
|
||||
|
||||
return boost::report_errors();
|
||||
|
||||
}
|
||||
|
||||
104
test/sync/futures/promise/move_ctor_pass.cpp
Executable file
104
test/sync/futures/promise/move_ctor_pass.cpp
Executable file
@@ -0,0 +1,104 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <future>
|
||||
|
||||
// class promise<R>
|
||||
|
||||
// promise(promise&& rhs);
|
||||
|
||||
#define BOOST_THREAD_VERSION 2
|
||||
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
boost::mutex m;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << __LINE__ << std::endl;
|
||||
//BOOST_TEST(test_alloc_base::count == 0);
|
||||
{
|
||||
//boost::promise<int> p0(boost::allocator_arg, test_allocator<int>());
|
||||
//boost::promise<int> p(boost::move(p0));
|
||||
boost::promise<int> p0;
|
||||
boost::promise<int> p(boost::move(p0));
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
std::cout << __LINE__ << std::endl;
|
||||
boost::future<int> f = p.get_future();
|
||||
std::cout << __LINE__ << std::endl;
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
BOOST_TEST(f.valid());
|
||||
std::cout << __LINE__ << std::endl;
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch (const boost::future_error& e)
|
||||
{
|
||||
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
|
||||
}
|
||||
std::cout << __LINE__ << std::endl;
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
}
|
||||
std::cout << __LINE__ << std::endl;
|
||||
//BOOST_TEST(test_alloc_base::count == 0);
|
||||
{
|
||||
//boost::promise<int&> p0(boost::allocator_arg, test_allocator<int>());
|
||||
//boost::promise<int&> p(boost::move(p0));
|
||||
boost::promise<int&> p0;
|
||||
boost::promise<int&> p(boost::move(p0));
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
boost::future<int&> f = p.get_future();
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
BOOST_TEST(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch (const boost::future_error& e)
|
||||
{
|
||||
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
|
||||
}
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
}
|
||||
//BOOST_TEST(test_alloc_base::count == 0);
|
||||
{
|
||||
//boost::promise<void> p0(boost::allocator_arg, test_allocator<void>());
|
||||
//boost::promise<void> p(boost::move(p0));
|
||||
boost::promise<void> p0;
|
||||
boost::promise<void> p(boost::move(p0));
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
boost::future<void> f = p.get_future();
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
BOOST_TEST(f.valid());
|
||||
try
|
||||
{
|
||||
f = p0.get_future();
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch (const boost::future_error& e)
|
||||
{
|
||||
BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
|
||||
}
|
||||
//BOOST_TEST(test_alloc_base::count == 1);
|
||||
}
|
||||
//BOOST_TEST(test_alloc_base::count == 0);
|
||||
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
57
test/sync/mutual_exclusion/locks/lock_guard/adopt_lock_pass.cpp
Executable file
57
test/sync/mutual_exclusion/locks/lock_guard/adopt_lock_pass.cpp
Executable file
@@ -0,0 +1,57 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2012 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/locks.hpp>
|
||||
|
||||
// template <class Mutex> class lock_guard;
|
||||
|
||||
// lock_guard(mutex_type& m, adopt_lock_t);
|
||||
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
typedef boost::chrono::high_resolution_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef boost::chrono::milliseconds ms;
|
||||
typedef boost::chrono::nanoseconds ns;
|
||||
|
||||
boost::mutex m;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
time_point t1;
|
||||
{
|
||||
m.lock();
|
||||
boost::lock_guard<boost::mutex> lg(m, boost::adopt_lock);
|
||||
t1 = Clock::now();
|
||||
}
|
||||
ns d = t1 - t0 - ms(250);
|
||||
BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
m.lock();
|
||||
boost::thread t(f);
|
||||
boost::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
35
test/sync/mutual_exclusion/locks/lock_guard/copy_assign_fail.cpp
Executable file
35
test/sync/mutual_exclusion/locks/lock_guard/copy_assign_fail.cpp
Executable file
@@ -0,0 +1,35 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/locks.hpp>
|
||||
|
||||
// template <class Mutex> class lock_guard;
|
||||
|
||||
// lock_guard& operator=(lock_guard const&) = delete;
|
||||
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
boost::mutex m0;
|
||||
boost::mutex m1;
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::lock_guard<boost::mutex> lk0(m0);
|
||||
boost::lock_guard<boost::mutex> lk1(m1);
|
||||
lk1 = lk0;
|
||||
|
||||
}
|
||||
|
||||
34
test/sync/mutual_exclusion/locks/lock_guard/copy_ctor_fail.cpp
Executable file
34
test/sync/mutual_exclusion/locks/lock_guard/copy_ctor_fail.cpp
Executable file
@@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/locks.hpp>
|
||||
|
||||
// template <class Mutex> class lock_guard;
|
||||
|
||||
// lock_guard(lock_guard const&) = delete;
|
||||
|
||||
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
boost::mutex m0;
|
||||
boost::mutex m1;
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::lock_guard<boost::mutex> lk0(m0);
|
||||
boost::lock_guard<boost::mutex> lk1 = lk0;
|
||||
}
|
||||
|
||||
56
test/sync/mutual_exclusion/locks/lock_guard/default_pass.cpp
Executable file
56
test/sync/mutual_exclusion/locks/lock_guard/default_pass.cpp
Executable file
@@ -0,0 +1,56 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/locks.hpp>
|
||||
|
||||
// template <class Mutex> class lock_guard;
|
||||
|
||||
// lock_guard(lock_guard const&) = delete;
|
||||
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
typedef boost::chrono::high_resolution_clock Clock;
|
||||
typedef Clock::time_point time_point;
|
||||
typedef Clock::duration duration;
|
||||
typedef boost::chrono::milliseconds ms;
|
||||
typedef boost::chrono::nanoseconds ns;
|
||||
|
||||
boost::mutex m;
|
||||
|
||||
void f()
|
||||
{
|
||||
time_point t0 = Clock::now();
|
||||
time_point t1;
|
||||
{
|
||||
boost::lock_guard<boost::mutex> lg(m);
|
||||
t1 = Clock::now();
|
||||
}
|
||||
ns d = t1 - t0 - ms(250);
|
||||
// This test is spurious as it depends on the time the thread system switches the threads
|
||||
BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
m.lock();
|
||||
boost::thread t(f);
|
||||
boost::this_thread::sleep_for(ms(250));
|
||||
m.unlock();
|
||||
t.join();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
39
test/sync/mutual_exclusion/locks/lock_guard/types_pass.cpp
Executable file
39
test/sync/mutual_exclusion/locks/lock_guard/types_pass.cpp
Executable file
@@ -0,0 +1,39 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2012 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/mutex.hpp>
|
||||
|
||||
// <mutex>
|
||||
|
||||
// template <class Mutex>
|
||||
// class lock_guard
|
||||
// {
|
||||
// public:
|
||||
// typedef Mutex mutex_type;
|
||||
// ...
|
||||
// };
|
||||
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_STATIC_ASSERT_MSG((boost::is_same<boost::lock_guard<boost::mutex>::mutex_type,
|
||||
boost::mutex>::value), "");
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
37
test/sync/mutual_exclusion/locks/shared_lock/cons/adopt_lock_pass.cpp
Executable file
37
test/sync/mutual_exclusion/locks/shared_lock/cons/adopt_lock_pass.cpp
Executable file
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/locks.hpp>
|
||||
|
||||
// template <class Mutex> class shared_lock;
|
||||
|
||||
// shared_lock(mutex_type& m, adopt_lock_t);
|
||||
|
||||
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_mutex m;
|
||||
m.lock();
|
||||
boost::shared_lock<boost::shared_mutex> lk(m, boost::adopt_lock);
|
||||
BOOST_TEST(lk.mutex() == &m);
|
||||
BOOST_TEST(lk.owns_lock() == true);
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
39
test/sync/mutual_exclusion/locks/shared_lock/cons/copy_assign_fail.cpp
Executable file
39
test/sync/mutual_exclusion/locks/shared_lock/cons/copy_assign_fail.cpp
Executable file
@@ -0,0 +1,39 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Copyright (C) 2011 Vicente J. Botet Escriba
|
||||
//
|
||||
// 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)
|
||||
|
||||
// <boost/thread/locks.hpp>
|
||||
|
||||
// template <class Mutex> class shared_lock;
|
||||
|
||||
// shared_lock& operator=(shared_lock const&) = delete;
|
||||
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
boost::shared_mutex m0;
|
||||
boost::shared_mutex m1;
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> lk0(m0);
|
||||
boost::shared_lock<boost::shared_mutex> lk1(m1);
|
||||
lk1 = lk0;
|
||||
BOOST_TEST(lk1.mutex() == &m0);
|
||||
BOOST_TEST(lk1.owns_lock() == true);
|
||||
BOOST_TEST(lk0.mutex() == 0);
|
||||
BOOST_TEST(lk0.owns_lock() == false);
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user