mirror of
https://github.com/boostorg/thread.git
synced 2026-02-05 22:22:11 +00:00
Compare commits
451 Commits
boost-1.53
...
svn-branch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd51f97e44 | ||
|
|
04e3d918fb | ||
|
|
0073516f0a | ||
|
|
89de3dcf4f | ||
|
|
47f40f991f | ||
|
|
8b351fe473 | ||
|
|
24f1e620e8 | ||
|
|
ed6459ecd2 | ||
|
|
858816b2d2 | ||
|
|
4bc70444a4 | ||
|
|
fcc027369f | ||
|
|
5c78582794 | ||
|
|
7f479a1dec | ||
|
|
4f2a7b2256 | ||
|
|
5c88e6ce61 | ||
|
|
650e374492 | ||
|
|
6319080ef2 | ||
|
|
3ac48bdd65 | ||
|
|
c3c8ada97d | ||
|
|
fd5dd0c2ed | ||
|
|
4a83aa58ed | ||
|
|
7d96aa625c | ||
|
|
d57a4c6565 | ||
|
|
c67e39f126 | ||
|
|
5a3c301582 | ||
|
|
dc5a8a9c4e | ||
|
|
1e49343ff4 | ||
|
|
93d1855e64 | ||
|
|
a39dd7e8b3 | ||
|
|
7e5cb92bab | ||
|
|
62cf0f86f6 | ||
|
|
c12e07754a | ||
|
|
cbc4266774 | ||
|
|
3a038d33e5 | ||
|
|
51ba4be998 | ||
|
|
2d50af8481 | ||
|
|
e438c98070 | ||
|
|
1e2a76de47 | ||
|
|
34311a60fa | ||
|
|
794d54a65c | ||
|
|
d759dd2dba | ||
|
|
fe46155997 | ||
|
|
cacb5b19a6 | ||
|
|
30803a38b2 | ||
|
|
9fc6fec1eb | ||
|
|
29babb974e | ||
|
|
66578bf57b | ||
|
|
1da5f9563c | ||
|
|
52039f75a3 | ||
|
|
bb6fcc3b5c | ||
|
|
1fc1d8aedb | ||
|
|
042a86c984 | ||
|
|
364f3ea030 | ||
|
|
c87d27a06d | ||
|
|
68d7c69a4b | ||
|
|
6873d85650 | ||
|
|
b59e57e4cc | ||
|
|
d0f9d6216a | ||
|
|
28564064ff | ||
|
|
ff9636b8e0 | ||
|
|
d83d23bee0 | ||
|
|
63f35e9f52 | ||
|
|
5ad38d52e8 | ||
|
|
9d6cd40d8d | ||
|
|
4362cd655e | ||
|
|
0c44630029 | ||
|
|
a01af79331 | ||
|
|
2df6ce78a4 | ||
|
|
3951871d70 | ||
|
|
5a1a9df623 | ||
|
|
a6f67e25e3 | ||
|
|
b69ec54695 | ||
|
|
465aee1b66 | ||
|
|
14d3c59682 | ||
|
|
3f2d8f8865 | ||
|
|
dc8449bd0e | ||
|
|
d3a6277714 | ||
|
|
81d8944b96 | ||
|
|
54faaaf087 | ||
|
|
5a43d5ffe9 | ||
|
|
c628e51e6c | ||
|
|
a66b269198 | ||
|
|
9e07202e21 | ||
|
|
9e2a34ca9d | ||
|
|
4cf80c6685 | ||
|
|
455c31c0e9 | ||
|
|
a8d5fd48c1 | ||
|
|
294a5404c2 | ||
|
|
6d01267030 | ||
|
|
1c48d237a8 | ||
|
|
11ae5c8c44 | ||
|
|
9d10bd035a | ||
|
|
7b48c02d2f | ||
|
|
d8a9331464 | ||
|
|
b60968b045 | ||
|
|
da41bdb632 | ||
|
|
5fcfd0e4e8 | ||
|
|
2d2d1112d6 | ||
|
|
7cf6934515 | ||
|
|
757327ba10 | ||
|
|
a82843d3ab | ||
|
|
5779f6676d | ||
|
|
b359424858 | ||
|
|
a5f7d92960 | ||
|
|
83167d8c15 | ||
|
|
7d2270f8c8 | ||
|
|
f87dbb83b1 | ||
|
|
1a613d03a9 | ||
|
|
d42f4ff169 | ||
|
|
ffbcf96d90 | ||
|
|
f5e246ebb0 | ||
|
|
467a88c4f8 | ||
|
|
f021bad1d5 | ||
|
|
ecd97ec4ea | ||
|
|
c71882816c | ||
|
|
ef5d43fac9 | ||
|
|
fb5404947e | ||
|
|
f24086fe89 | ||
|
|
3e64214e68 | ||
|
|
ed4f0f7b6d | ||
|
|
50c18d6274 | ||
|
|
d5cf734a21 | ||
|
|
43f0c059d3 | ||
|
|
e775ef5c27 | ||
|
|
06b7a41add | ||
|
|
06d2a11127 | ||
|
|
6dd195bbc6 | ||
|
|
8a259612cd | ||
|
|
9fb88b8f47 | ||
|
|
528fcbde56 | ||
|
|
a0397315b2 | ||
|
|
44ec248340 | ||
|
|
7eba48576c | ||
|
|
451027deec | ||
|
|
16b42b6c63 | ||
|
|
a543b918f0 | ||
|
|
619ddf54b9 | ||
|
|
116c947af9 | ||
|
|
a0931c117d | ||
|
|
79e1e88f2e | ||
|
|
af3b5f3227 | ||
|
|
7bebf0a062 | ||
|
|
6dad044ab7 | ||
|
|
19bd0d5eba | ||
|
|
f922fa56e4 | ||
|
|
290faf192d | ||
|
|
054bbad65a | ||
|
|
df7fbe085a | ||
|
|
b03cebff7b | ||
|
|
c9c46e87b5 | ||
|
|
d4e6332eca | ||
|
|
80594adcbb | ||
|
|
4ea14fb9da | ||
|
|
5a22af7639 | ||
|
|
7b157ab5f4 | ||
|
|
a73425eb00 | ||
|
|
b254afc229 | ||
|
|
a1edda3437 | ||
|
|
c784369f76 | ||
|
|
0b7462c4f2 | ||
|
|
23ff6e0120 | ||
|
|
06491889ea | ||
|
|
abf441ee63 | ||
|
|
9615a51123 | ||
|
|
a0bfa7faeb | ||
|
|
44b741e445 | ||
|
|
41d336e7fb | ||
|
|
fc177914e1 | ||
|
|
d0056e0cc8 | ||
|
|
6075cf2df6 | ||
|
|
1eacb8c71d | ||
|
|
7476f71af6 | ||
|
|
d86b5d2c0d | ||
|
|
09f86d603e | ||
|
|
ca3d7dab0b | ||
|
|
7e35a60650 | ||
|
|
2b5bd7275e | ||
|
|
ca37d07184 | ||
|
|
6f2efbcb32 | ||
|
|
1ce6a90f95 | ||
|
|
0a101e15d1 | ||
|
|
d2f7766f8a | ||
|
|
ba7a0935f2 | ||
|
|
7277a94411 | ||
|
|
197bbc1fd3 | ||
|
|
b9e2d7b13d | ||
|
|
579501d98e | ||
|
|
dc352450ca | ||
|
|
21b2bbc8ca | ||
|
|
bd9105a104 | ||
|
|
935d851cdf | ||
|
|
68142e8ff8 | ||
|
|
1dad495280 | ||
|
|
fb2310b48a | ||
|
|
247e9a4f09 | ||
|
|
c1ec1ada0e | ||
|
|
d030dbd61c | ||
|
|
bebd56ee21 | ||
|
|
75586eec0e | ||
|
|
659343d287 | ||
|
|
8e63c72867 | ||
|
|
65416bb8b6 | ||
|
|
71a647b66b | ||
|
|
fc57e9dde0 | ||
|
|
4acfe0975c | ||
|
|
158e8ead50 | ||
|
|
0fc69c4d9e | ||
|
|
e314bf03ce | ||
|
|
6f2decdacf | ||
|
|
4bd3e09a0d | ||
|
|
a16f508b8a | ||
|
|
1642db3441 | ||
|
|
b389079417 | ||
|
|
8f7be637b2 | ||
|
|
94c15aa0cc | ||
|
|
951c8952ff | ||
|
|
59f91a2405 | ||
|
|
f4a3d52654 | ||
|
|
517e177d7a | ||
|
|
e72184e9ee | ||
|
|
73348d69d2 | ||
|
|
15eff9e412 | ||
|
|
dd70cd5b40 | ||
|
|
b290f995d0 | ||
|
|
c1dd0e1e43 | ||
|
|
44a02c1f5f | ||
|
|
a0071b301b | ||
|
|
c77281f724 | ||
|
|
8a0578c93c | ||
|
|
c7dcb1daae | ||
|
|
af330fb61b | ||
|
|
ab64afa2a7 | ||
|
|
85792f9946 | ||
|
|
e0d4e63e48 | ||
|
|
b2bd9f4ca9 | ||
|
|
189356680b | ||
|
|
0e0cd2c950 | ||
|
|
a849a41367 | ||
|
|
4b1c13e5cb | ||
|
|
f3777b9306 | ||
|
|
3e5e12e1ac | ||
|
|
a50176c259 | ||
|
|
94e524a1e6 | ||
|
|
cb3259b23f | ||
|
|
ec811d3c4a | ||
|
|
bf67321336 | ||
|
|
4b71ef9354 | ||
|
|
23bf16a638 | ||
|
|
c3ada352f4 | ||
|
|
610bdc4aca | ||
|
|
6675f4645f | ||
|
|
2895bfe269 | ||
|
|
27e2d632cd | ||
|
|
abdaa7b5b3 | ||
|
|
e0ed1d6d61 | ||
|
|
f8b1287153 | ||
|
|
5ed50d68f2 | ||
|
|
2f0a6c01c2 | ||
|
|
c8edd6c795 | ||
|
|
2b8930a5bf | ||
|
|
7c89563108 | ||
|
|
fcb94bcecf | ||
|
|
593e9e0f2f | ||
|
|
4209dfaa7f | ||
|
|
0fac7be5b9 | ||
|
|
0936913bf6 | ||
|
|
03ebc320f1 | ||
|
|
ea11670593 | ||
|
|
607080857b | ||
|
|
6728fdb3b1 | ||
|
|
580c1b7be4 | ||
|
|
03a43d09a4 | ||
|
|
7f043d7b07 | ||
|
|
77a8c6667f | ||
|
|
418a3f6978 | ||
|
|
6b300d2e4c | ||
|
|
50ae9d93a6 | ||
|
|
168ee37d30 | ||
|
|
81528d64d5 | ||
|
|
e6b8a133a8 | ||
|
|
047ca43b72 | ||
|
|
3c6509184a | ||
|
|
ec1ce4cf98 | ||
|
|
526478338d | ||
|
|
f49e6e8dc3 | ||
|
|
186d58eef7 | ||
|
|
d2bbc1b7c1 | ||
|
|
2a503b5c81 | ||
|
|
a25b918a67 | ||
|
|
821376f552 | ||
|
|
4387de4be8 | ||
|
|
0663b30528 | ||
|
|
37b0eb2c48 | ||
|
|
de0272abcf | ||
|
|
cfc3634108 | ||
|
|
1c62b1599d | ||
|
|
1d2ec17d52 | ||
|
|
0d9e8a0c3c | ||
|
|
9b28bb59c9 | ||
|
|
0fce559711 | ||
|
|
de191d213e | ||
|
|
ae89c307bf | ||
|
|
0dba7ba99b | ||
|
|
1b67c83359 | ||
|
|
d28465b656 | ||
|
|
bb3493bdf0 | ||
|
|
0cd8326f21 | ||
|
|
5c5c818bc5 | ||
|
|
124b99b2a4 | ||
|
|
1cabac151a | ||
|
|
df48b734a2 | ||
|
|
039d744960 | ||
|
|
004e8a4fcf | ||
|
|
d8f8acbe38 | ||
|
|
8a01f9ee09 | ||
|
|
315af061cd | ||
|
|
18491c933d | ||
|
|
d01c0232da | ||
|
|
91e32e3f02 | ||
|
|
88294f4161 | ||
|
|
9cdc23159a | ||
|
|
c95f1d95af | ||
|
|
45c87d392f | ||
|
|
1c0a4999b8 | ||
|
|
30bfc7bcea | ||
|
|
48f8c1c1c8 | ||
|
|
c47ea136b6 | ||
|
|
a3d30b2a89 | ||
|
|
11e15ff0f2 | ||
|
|
fb4b4fb14a | ||
|
|
0ede82e059 | ||
|
|
708b660c0b | ||
|
|
9f27bba490 | ||
|
|
095da2890e | ||
|
|
389d76cbc1 | ||
|
|
493cbc030c | ||
|
|
2f7b936cd6 | ||
|
|
6f3ee1eebf | ||
|
|
32f7b212bd | ||
|
|
4fcdabca90 | ||
|
|
b03de37155 | ||
|
|
73af713503 | ||
|
|
a903532cef | ||
|
|
d6178b3139 | ||
|
|
ec1241a6d8 | ||
|
|
ae819901ab | ||
|
|
3c0294cf3a | ||
|
|
21bc767445 | ||
|
|
47b6368ef7 | ||
|
|
a3098b5dfd | ||
|
|
bd69c9382f | ||
|
|
b47f43df59 | ||
|
|
e9217d02f0 | ||
|
|
6741c8420a | ||
|
|
fe45847841 | ||
|
|
5d13b87dd3 | ||
|
|
e1f5fbdc33 | ||
|
|
b342cf683b | ||
|
|
e94946cc8c | ||
|
|
8604ca1b85 | ||
|
|
9847f57ce7 | ||
|
|
74e2c4cbcb | ||
|
|
7b54159af3 | ||
|
|
16ad9c868e | ||
|
|
26f4ad3db2 | ||
|
|
715928e143 | ||
|
|
40d694e893 | ||
|
|
4d84fb97c9 | ||
|
|
ab7bb7a82d | ||
|
|
171be40a1f | ||
|
|
18d4a8a0f8 | ||
|
|
dedaa7e617 | ||
|
|
6173ae42a9 | ||
|
|
792604127e | ||
|
|
81d0aaf7bc | ||
|
|
26c495e5b3 | ||
|
|
a1f8717170 | ||
|
|
460a38b994 | ||
|
|
dbefae706c | ||
|
|
a33e82af60 | ||
|
|
8f283b3c2b | ||
|
|
b1ae3a98e8 | ||
|
|
fcaaa68f87 | ||
|
|
b7622b7407 | ||
|
|
a56358c8f8 | ||
|
|
dafe4bea1a | ||
|
|
408a6cb70e | ||
|
|
97c0ddbee4 | ||
|
|
330502ea1e | ||
|
|
662118b5c6 | ||
|
|
8bee2291fd | ||
|
|
39c4db3e66 | ||
|
|
749b1034f9 | ||
|
|
735102d4a0 | ||
|
|
5e30d7486e | ||
|
|
71f864bc5c | ||
|
|
b31c1a11d5 | ||
|
|
bf03f733a6 | ||
|
|
ca04d699bc | ||
|
|
530aaaae38 | ||
|
|
36970f3240 | ||
|
|
7c97dc8131 | ||
|
|
a7336c2c5e | ||
|
|
8866935d0b | ||
|
|
4f06c2392b | ||
|
|
677113cfbe | ||
|
|
a01faf1bb8 | ||
|
|
050b43757f | ||
|
|
448c4b21b5 | ||
|
|
84d8dea5ba | ||
|
|
5fa5b680f0 | ||
|
|
5b26427079 | ||
|
|
d426d2ca88 | ||
|
|
2e5bc32b33 | ||
|
|
b0b975e8ef | ||
|
|
1f4df63577 | ||
|
|
cf7c218a65 | ||
|
|
1a1751b45d | ||
|
|
0354c2fcc3 | ||
|
|
1679cd2fff | ||
|
|
32db9f2e71 | ||
|
|
6b98bee683 | ||
|
|
7de77cf13c | ||
|
|
8334f4e68a | ||
|
|
1ac7e7129d | ||
|
|
daec1268f9 | ||
|
|
c47bd34760 | ||
|
|
0d9ebfc820 | ||
|
|
3332d8df66 | ||
|
|
852c173c96 | ||
|
|
bcf30f2dfc | ||
|
|
2ea1aec7fd | ||
|
|
dc5a26c5d3 | ||
|
|
3c8f164371 | ||
|
|
93c14be188 | ||
|
|
b305cc29fc | ||
|
|
c2001fb9d2 | ||
|
|
d3a8321be0 | ||
|
|
8bfd588b4c | ||
|
|
5268fd3749 | ||
|
|
19bbd85d9d | ||
|
|
deca987299 | ||
|
|
1a4eed3b69 | ||
|
|
1214f99227 | ||
|
|
51530e03a5 | ||
|
|
66263dd7b3 | ||
|
|
6b0ce64d5e | ||
|
|
3b080058ed | ||
|
|
00996a2a02 | ||
|
|
c0299f4a1e | ||
|
|
e09105de98 |
@@ -36,6 +36,7 @@ import os ;
|
||||
import feature ;
|
||||
import indirect ;
|
||||
import path ;
|
||||
import configure ;
|
||||
|
||||
project boost/thread
|
||||
: source-location ../src
|
||||
@@ -49,8 +50,8 @@ project boost/thread
|
||||
<toolset>gcc:<cxxflags>-Wno-long-long
|
||||
#<define>BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||||
#<define>BOOST_SYSTEM_NO_DEPRECATED
|
||||
#<define>BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS
|
||||
|
||||
#<define>BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS
|
||||
|
||||
<library>/boost/system//boost_system
|
||||
#-pedantic -ansi -std=gnu++0x -Wextra -fpermissive
|
||||
<warnings>all
|
||||
@@ -59,12 +60,18 @@ project boost/thread
|
||||
<toolset>gcc:<cxxflags>-Wno-long-long
|
||||
#<toolset>gcc:<cxxflags>-ansi
|
||||
#<toolset>gcc:<cxxflags>-fpermissive
|
||||
<toolset>gcc:<cxxflags>-Wno-variadic-macros
|
||||
#<toolset>gcc:<cxxflags>-Wunused-local-typedefs
|
||||
<toolset>gcc:<cxxflags>-Wunused-function
|
||||
|
||||
<toolset>darwin:<cxxflags>-Wextra
|
||||
<toolset>darwin:<cxxflags>-pedantic
|
||||
#<toolset>darwin:<cxxflags>-ansi
|
||||
<toolset>darwin:<cxxflags>-fpermissive
|
||||
<toolset>darwin:<cxxflags>-Wno-long-long
|
||||
<toolset>darwin:<cxxflags>-Wno-variadic-macros
|
||||
#<toolset>darwin:<cxxflags>-Wunused-local-typedefs
|
||||
<toolset>darwin:<cxxflags>-Wunused-function
|
||||
|
||||
#<toolset>pathscale:<cxxflags>-Wextra
|
||||
<toolset>pathscale:<cxxflags>-Wno-long-long
|
||||
@@ -75,6 +82,8 @@ project boost/thread
|
||||
#<toolset>clang:<cxxflags>-ansi
|
||||
#<toolset>clang:<cxxflags>-fpermissive
|
||||
<toolset>clang:<cxxflags>-Wno-long-long
|
||||
<toolset>clang:<cxxflags>-Wunused-function
|
||||
<toolset>clang:<cxxflags>-Wno-variadic-macros
|
||||
|
||||
<toolset>gcc-mingw-4.4.0:<cxxflags>-fdiagnostics-show-option
|
||||
<toolset>gcc-mingw-4.5.0:<cxxflags>-fdiagnostics-show-option
|
||||
@@ -82,6 +91,7 @@ project boost/thread
|
||||
<toolset>gcc-mingw-4.6.3:<cxxflags>-fdiagnostics-show-option
|
||||
<toolset>gcc-mingw-4.7.0:<cxxflags>-fdiagnostics-show-option
|
||||
<toolset>gcc-mingw-4.8.0:<cxxflags>-fdiagnostics-show-option
|
||||
#<toolset>gcc:<cxxflags>-Wno-missing-field-initializers
|
||||
|
||||
<toolset>darwin-4.6.2:<cxxflags>-Wno-delete-non-virtual-dtor
|
||||
<toolset>darwin-4.7.0:<cxxflags>-Wno-delete-non-virtual-dtor
|
||||
@@ -93,7 +103,7 @@ project boost/thread
|
||||
<toolset>clang-3.0:<cxxflags>-Wno-delete-non-virtual-dtor
|
||||
#<toolset>clang-3.0:<cxxflags>-Wno-unused-function
|
||||
#<toolset>clang-3.0:<cxxflags>-Wno-unused-variable
|
||||
|
||||
|
||||
# Note: Some of the remarks from the Intel compiler are disabled
|
||||
# remark #193: zero used for undefined preprocessing identifier "XXX"
|
||||
# remark #304: access control not specified ("public" by default)
|
||||
@@ -104,7 +114,9 @@ project boost/thread
|
||||
<toolset>intel:<cxxflags>-wd193,304,383,444
|
||||
<toolset>intel:<cxxflags>-wd593,981
|
||||
<toolset>intel:<cxxflags>-wd1418
|
||||
<toolset>intel:<cxxflags>-wd2415
|
||||
<toolset>intel:<cxxflags>-wd2415
|
||||
|
||||
<toolset>msvc:<cxxflags>/wd4512
|
||||
|
||||
|
||||
# : default-build <threading>multi
|
||||
@@ -115,7 +127,7 @@ project boost/thread
|
||||
<link>shared:<define>BOOST_THREAD_BUILD_DLL=1
|
||||
#<define>BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||||
#<define>BOOST_SYSTEM_NO_DEPRECATED
|
||||
#<define>BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS
|
||||
#<define>BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS
|
||||
<library>/boost/system//boost_system
|
||||
;
|
||||
|
||||
@@ -129,6 +141,8 @@ local rule default_threadapi ( )
|
||||
feature.feature threadapi : pthread win32 : propagated ;
|
||||
feature.set-default threadapi : [ default_threadapi ] ;
|
||||
|
||||
exe has_atomic_flag_lockfree : ../build/has_atomic_flag_lockfree_test.cpp ;
|
||||
|
||||
rule tag ( name : type ? : property-set )
|
||||
{
|
||||
local result = $(name) ;
|
||||
@@ -225,10 +239,10 @@ rule usage-requirements ( properties * )
|
||||
}
|
||||
}
|
||||
|
||||
if ! <toolset>vacpp in $(properties) || <toolset-vacpp:version>11.1 in $(properties) || <toolset-vacpp:version>12.1.0.1 in $(properties)
|
||||
{
|
||||
#if ! <toolset>vacpp in $(properties) || <toolset-vacpp:version>11.1 in $(properties) || <toolset-vacpp:version>12.1.0.1 in $(properties) || <toolset-vacpp:version>12.1 in $(properties)
|
||||
#{
|
||||
result += <library>/boost/chrono//boost_chrono ;
|
||||
}
|
||||
#}
|
||||
|
||||
return $(result) ;
|
||||
}
|
||||
@@ -252,8 +266,15 @@ rule requirements ( properties * )
|
||||
result = <build>no ;
|
||||
}
|
||||
}
|
||||
result += <define>BOOST_THREAD_DONT_USE_CHRONO ;
|
||||
if ! [ configure.builds has_atomic_flag_lockfree
|
||||
: $(properties) : "lockfree boost::atomic_flag" ] {
|
||||
result += <library>/boost/atomic//boost_atomic ;
|
||||
}
|
||||
} else {
|
||||
result += <define>BOOST_THREAD_USES_CHRONO ;
|
||||
result += <library>/boost/chrono//boost_chrono ;
|
||||
}
|
||||
result += <define>BOOST_THREAD_DONT_USE_CHRONO ;
|
||||
|
||||
return $(result) ;
|
||||
}
|
||||
@@ -263,6 +284,7 @@ alias thread_sources
|
||||
win32/thread.cpp
|
||||
win32/tss_dll.cpp
|
||||
win32/tss_pe.cpp
|
||||
future.cpp
|
||||
: ## requirements ##
|
||||
<threadapi>win32
|
||||
;
|
||||
@@ -271,6 +293,7 @@ alias thread_sources
|
||||
: ## pthread sources ##
|
||||
pthread/thread.cpp
|
||||
pthread/once.cpp
|
||||
future.cpp
|
||||
: ## requirements ##
|
||||
<threadapi>pthread
|
||||
;
|
||||
@@ -278,7 +301,7 @@ alias thread_sources
|
||||
explicit thread_sources ;
|
||||
|
||||
lib boost_thread
|
||||
: thread_sources future.cpp
|
||||
: thread_sources
|
||||
: <conditional>@requirements
|
||||
:
|
||||
: <link>shared:<define>BOOST_THREAD_USE_DLL=1
|
||||
|
||||
13
build/has_atomic_flag_lockfree_test.cpp
Normal file
13
build/has_atomic_flag_lockfree_test.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2013, Petr Machata, Red Hat Inc.
|
||||
//
|
||||
// Use modification and distribution are subject to the boost Software
|
||||
// License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt).
|
||||
|
||||
#include "../../../boost/atomic.hpp"
|
||||
#include "../../../boost/static_assert.hpp"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
BOOST_STATIC_ASSERT(BOOST_ATOMIC_FLAG_LOCK_FREE);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
[/
|
||||
(C) Copyright 2007-8 Anthony Williams.
|
||||
(C) Copyright 2013 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:barriers Barriers]
|
||||
[section:barriers Barriers -- EXTENSION]
|
||||
|
||||
A barrier is a simple concept. Also known as a ['rendezvous], it is a synchronization point between multiple threads. The barrier is
|
||||
configured for a particular number of threads (`n`), and as threads reach the barrier they must wait until all `n` threads have
|
||||
@@ -18,15 +19,22 @@ arrived. Once the `n`-th thread has reached the barrier, all the waiting threads
|
||||
class barrier
|
||||
{
|
||||
public:
|
||||
barrier(barrier const&) = delete;
|
||||
barrier& operator=(barrier const&) = delete;
|
||||
|
||||
barrier(unsigned int count);
|
||||
template <typename F>
|
||||
barrier(unsigned int count, F&&);
|
||||
|
||||
~barrier();
|
||||
|
||||
bool wait();
|
||||
void count_down_and_wait();
|
||||
};
|
||||
|
||||
Instances of __barrier__ are not copyable or movable.
|
||||
|
||||
[heading Constructor]
|
||||
[section Constructor `barrier(unsigned int)`]
|
||||
|
||||
barrier(unsigned int count);
|
||||
|
||||
@@ -38,7 +46,24 @@ Instances of __barrier__ are not copyable or movable.
|
||||
|
||||
]
|
||||
|
||||
[heading Destructor]
|
||||
[endsect]
|
||||
[section Constructor `barrier(unsigned int, F&&)`]
|
||||
|
||||
barrier(unsigned int count, F&& completion);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [The result type of the completion function call `completion()` is `void` or `unsigned int`.]]
|
||||
|
||||
[[Effects:] [Construct a barrier for `count` threads and a completion function `completion`.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error occurs.]]
|
||||
|
||||
]
|
||||
|
||||
|
||||
[endsect]
|
||||
[section Destructor `~barrier()`]
|
||||
|
||||
~barrier();
|
||||
|
||||
@@ -52,21 +77,55 @@ Instances of __barrier__ are not copyable or movable.
|
||||
|
||||
]
|
||||
|
||||
[heading Member function `wait`]
|
||||
[endsect]
|
||||
[section Member Function `wait()`]
|
||||
|
||||
bool wait();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Block until `count` threads have called `wait` on `*this`. When the `count`-th thread calls `wait`, all waiting threads
|
||||
are unblocked, and the barrier is reset. ]]
|
||||
[[Effects:] [Block until `count` threads have called `wait` or `count_down_and_wait` on `*this`. When the `count`-th thread calls `wait`, the barrier is reset and all waiting threads are unblocked.
|
||||
The reset depends on whether the barrier was constructed with a completion function or not. If there is no completion function or if the completion function result is void, the reset consists in restoring the original count. Otherwise the rest consist in assigning the result of the completion function (which must not be 0).]]
|
||||
|
||||
[[Returns:] [`true` for exactly one thread from each batch of waiting threads, `false` otherwise.]]
|
||||
|
||||
[[Throws:] [__thread_resource_error__ if an error occurs.]]
|
||||
[[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.
|
||||
|
||||
]]
|
||||
|
||||
[[Notes:] [`wait()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section Member Function `count_down_and_wait()`]
|
||||
|
||||
void count_down_and_wait();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Block until `count` threads have called `wait` or `count_down_and_wait` on `*this`. When the `count`-th thread calls `wait`, the barrier is reset and all waiting threads are unblocked.
|
||||
The reset depends on whether the barrier was constructed with a completion function or not. If there is no completion function or if the completion function result is void, the reset consists in restoring the original count. Otherwise the rest consist in assigning the result of the completion function (which must not be 0).]]
|
||||
|
||||
[[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.
|
||||
|
||||
]]
|
||||
|
||||
[[Notes:] [`count_down_and_wait()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[/
|
||||
(C) Copyright 2007-11 Anthony Williams.
|
||||
(C) Copyright 2011-12 Vicente J. Botet Escriba.
|
||||
(C) Copyright 2011-13 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).
|
||||
@@ -8,6 +8,76 @@
|
||||
|
||||
[section:changes History]
|
||||
|
||||
[heading Version 4.2.0 - boost 1.55]
|
||||
|
||||
[*New Features:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8519 #8519] Synchro: Update class barrier with a completion function.
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8515 #8515] Async: Add shared_future::then.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8615 #8615] Async: Replace make_future/make_shared_future by make_ready_future.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8627 #8627] Async: Add future<>::unwrap and unwrapping constructor.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8677 #8677] Async: Add future<>::get_or.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8678 #8678] Async: Add future<>::fallback_to.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8955 #8955] Request for more efficient way to get exception_ptr from future.
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8891 #8891] upgrade_to_unique_lock: missing mutex() function.
|
||||
|
||||
[*Fixed Bugs:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8768 #8768] win32 condition_variable::wait_until infinite wait in rare cases.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8817 #8817] Boost Thread Windows CE _createthreadex handling breaks mingw w64.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8943 #8943] Failed to compile code using boost::call_once with Intel C++ Composer XE 2013 on Windows.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8931 #8931] Typos in external_locking reference.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9029 #9029] Misprint in documentation.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9037 #9037] gcc -Wshadow gives warnings in condition_variable{,_fwd}.hpp.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9041 #9041] Boost.Thread DSO's may need to link with Boost.Atomic.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9048 #9048] boost::scoped_thread useless ctor with variadic template arguments.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/9079 #9079] Condition variable will wait forever for some timepoint values (Win).
|
||||
|
||||
[heading Version 4.1.0 - boost 1.54]
|
||||
|
||||
[*New Features:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7285 #7285] C++11 compliance: Allow to pass movable arguments for call_once.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7445 #7445] Async: Add future<>.then
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7449 #7449] Synchro: Add a synchronized value class
|
||||
|
||||
[*Fixed Bugs:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4878 #4878] MinGW 4.5.0 undefined reference to bool interruptible_wait(detail::win32::handle handle_to_wait_for,detail::t imeout target_time).
|
||||
* [@http://svn.boost.org/trac/boost/ticket/4882 #4882] Win32 shared_mutex does not handle timeouts correctly.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5752 #5752] boost::call_once() is unreliable on some platforms
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6652 #6652] Boost.Thread shared_mutex.hpp:50:99: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6843 #6843] [Intel C++] Compile Errors with '#include <atomic>'
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6966 #6966] future boost::future_category inconsistent dll linkage
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7720 #7720] exception lock_error while intensive locking/unlocking of mutex
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7755 #7755] Thread: deadlock with shared_mutex on Windows
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7980 #7980] Build error: msvc-11.0 and BOOST_THREAD_DONT_USE_DATETIME
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7982 #7982] pthread_delay_np() parm compile error on AIX
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8027 #8027] thread library fails to compile with Visual Studio 2003
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8070 #8070] prefer GetTickCount64 over GetTickCount
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8136 #8136] boost::this_thread::sleep_for() sleeps longer than it should in Windows
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8212 #8212] Boost thread compilation error on Solaris 10
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8237 #8237] fix documentation for 'thread_group'
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8239 #8239] barrier::wait() not marked as interruption_point
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8323 #8323] boost::thread::try_join_for/try_join_until may block indefinitely due to a combination of problems in Boost.Thread and Boost.Chrono
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8337 #8337] The internal representation of "std::string(this->code()->message())" escapes, but is destroyed when it exits scope.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8371 #8371] C++11 once_flag enabled when constexpr is not available
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8422 #8422] Assertion in win32::WaitForSingleObject()
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8443 #8443] Header file inclusion order may cause crashes
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8451 #8451] Missing documented function 'boost::scoped_thread::joinable'
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8458 #8458] -DBOOST_THREAD_DONT_USE_CHRONO in thread.obj.rsp but not explicitly set
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8530 #8530] [Coverity] Unused variable thread_handle, uninitialized variable cond_mutex in thread/pthread/thread_data.hpp
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8550 #8550] static linking of Boost.Thread with an MFC-Dll
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8576 #8576] "sur parolle" should be "sur parole".
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8596 #8596] With C++0x enabled, boost::packaged_task stores a reference to function objects, instead of a copy.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8626 #8626] Reintroduce BOOST_VERIFY on pthread_mutex_destroy return type
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8645 #8645] Typo in Strict lock definition
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8671 #8671] promise: set_..._at_thread_exit
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8672 #8672] future<>::then(void()) doesn't works
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8674 #8674] Futures as local named objects can't be returned with implicit move.
|
||||
|
||||
[heading Version 4.0.0 - boost 1.53]
|
||||
|
||||
[/
|
||||
@@ -41,6 +111,7 @@ Provided when BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK is defined (Default
|
||||
See BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK and BOOST_THREAD_DONT_PROVIDE_SIGNATURE_PACKAGED_TASK.
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7282 #7282] C++11 compliance: Add packaged_task::make_ready_at_thread_exit function
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7285 #7285] C++11 compliance: Allow to pass movable arguments for call_once
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7412 #7412] C++11 compliance: Add async from movable callable and movable arguments
|
||||
Provided when BOOST_THREAD_PROVIDES_VARIADIC_THREAD and BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK are defined (Default value from Boost 1.55):
|
||||
@@ -63,11 +134,13 @@ See BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK and BOOST_THREAD_DONT_PROVIDE_
|
||||
|
||||
[*Fixed Bugs:]
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/5752 #5752] boost::call_once() is unreliable on some platforms
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7464 #7464] BOOST_TEST(n_alive == 1); fails due to race condition in a regression test tool.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7657 #7657] Serious performance and memory consumption hit if condition_variable methods condition notify_one or notify_all is used repeatedly.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7665 #7665] this_thread::sleep_for no longer uses steady_clock in thread.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7668 #7668] thread_group::join_all() should check whether its threads are joinable.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7669 #7669] thread_group::join_all() should catch resource_deadlock_would_occur.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7671 #7671] Error including boost/thread.hpp header on iOS.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7672 #7672] lockable_traits.hpp syntax error: "defined" token misspelled.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7798 #7798] boost::future set_wait_callback thread safety issues.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7808 #7808] Incorrect description of effects for this_thread::sleep_for and this_thread::sleep_until.
|
||||
@@ -75,6 +148,8 @@ See BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK and BOOST_THREAD_DONT_PROVIDE_
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7874 #7874] compile warning: thread.hpp:342: warning: type attributes are honored only at type definition.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7875 #7875] BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED should not be enabled by default.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7882 #7882] wrong exception text from condition_variable::wait(unique_lock<mutex>&).
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7890 #7890] thread::do_try_join_until() is missing a return type.
|
||||
|
||||
|
||||
|
||||
[heading Version 3.1.0 - boost 1.52]
|
||||
@@ -344,18 +419,28 @@ been moved to __thread_id__.
|
||||
The following features will be included in next releases.
|
||||
|
||||
# Complete the C++11 missing features, in particular
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7285 #7285] C++11 compliance: Allow to pass movable arguments for call_once.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6227 #6227] C++11 compliance: Use of variadic templates on Generic Locking Algorithms on compilers providing them.
|
||||
|
||||
|
||||
# Add some of the extension proposed in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3428.pdf A Standardized Representation of Asynchronous Operations], in particular
|
||||
|
||||
# Add some minor features, in particular
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7589 #7589] Synchro: Add polymorphic lockables.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7449 #7449] Synchro: Add a synchronized value class.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7445 #7445] Async: Add future<>.then.
|
||||
|
||||
# Add some features based on C++ proposals, in particular
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8274 #8274] Synchro: Add concurrent queue
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8518 #8518] Synchro: Add a latch class.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8273 #8273] Synchro: Add externally locked streams.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8513 #8513] Async: Add a basic thread_pool executor.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8514 #8514] Async: Add a thread_pool executor with work stealing.
|
||||
|
||||
# Add some of the extension proposed in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3428.pdf A Standardized Representation of Asynchronous Operations] or extension to them, in particular
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7446 #7446] Async: Add when_any.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7447 #7447] Async: Add when_all.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/7448 #7448] Async: Add async taking a scheduler parameter.
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8516 #8516] Async: Add future/shared_future::then taking a scheduler as parameter.
|
||||
|
||||
# And some additional extensions related to futures as:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/8517 #8517] Async: Add a variadic shared_future::then.
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
|
||||
[section:cpp11 C++11 standard Thread library]
|
||||
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3376.html C++11 standard]]
|
||||
|
||||
|
||||
[table C++11 standard Conformance
|
||||
[[Section] [Description] [Status] [Comments] [Ticket]]
|
||||
[[30] [Thread support library] [Partial] [-] [-]]
|
||||
[[30] [Thread support library] [Yes] [-] [-]]
|
||||
[[30.1] [General] [-] [-] [-]]
|
||||
[[30.2] [Requirements] [-] [-] [-]]
|
||||
[[30.2.1] [Template parameter names] [-] [-] [-]]
|
||||
@@ -51,18 +53,18 @@
|
||||
[[30.4.2.2.1] [unique_lock constructors, destructor, and assignment] [Yes] [-] [-]]
|
||||
[[30.4.2.2.2] [unique_lock locking] [Yes] [-] [-]]
|
||||
[[30.4.2.2.3] [unique_lock modifiers] [Yes] [-] [-]]
|
||||
[[30.4.2.2.4] [unique_lock observers] [Yes] [] [-]]
|
||||
[[30.4.2.2.4] [unique_lock observers] [Yes] [ - ] [-]]
|
||||
[[30.4.3] [Generic locking algorithms] [Partial] [variadic] [#6227]]
|
||||
[[30.4.4] [Call once] [Partial] [call_once] [#7285]]
|
||||
[[30.4.4] [Call once] [Yes] [-] [-]]
|
||||
[[30.4.4.1] [Struct once_flag] [Yes] [-] [-]]
|
||||
[[30.4.4.2] [Function call_once] [Partial] [interface] [#7285]]
|
||||
[[30.4.4.2] [Function call_once] [Yes] [-] [-]]
|
||||
[[30.5] [Condition variables] [Yes] [-] [-]]
|
||||
[[30.5.1] [Class condition_variable] [Yes] [-] [-]]
|
||||
[[30.5.2] [Class condition_variable_any] [Yes] [-] [-]]
|
||||
[[30.6] [Futures] [Partial] [noexcept] [#7279]]
|
||||
[[30.6] [Futures] [Yes] [-] [-]]
|
||||
[[30.6.1] [Overview] [Partial] [-] [-]]
|
||||
[[30.6.2] [Error handling] [Yes] [-] [-]]
|
||||
[[30.6.3] [Class future_error] [Partial] [noexcept] [#7279]]
|
||||
[[30.6.3] [Class future_error] [-] [-] [-]]
|
||||
[[30.6.4] [Shared state] [-] [-] [-]]
|
||||
[[30.6.5] [Class template promise] [Yes] [-] [-]]
|
||||
[[30.6.6] [Class template future] [Yes] [-] [-]]
|
||||
@@ -86,24 +88,160 @@
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:shared Shared Locking extensions]
|
||||
[section:cxx14 C++14 standard Thread library - accepted changes]
|
||||
|
||||
[table Howard's Shared Locking Proposal Conformance
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3485.html C++14 on-going standard]]
|
||||
|
||||
|
||||
[table [@http://isocpp.org/files/papers/N3659.html N3659 Shared locking in C++ revision 2] Conformance
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[X] [Shared Locking] [Yes] [Needs `BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSION]]
|
||||
[[X.1] [Shared Lockables Concepts] [Yes] [ - ]]
|
||||
[[X.1.1] [SharedLockable concept] [Yes] [ - ]]
|
||||
[[X.1.2] [UpgradeLockable concept] [Yes] [ - ]]
|
||||
[[X.2] [Shared Mutex Types] [Yes] [ - ]]
|
||||
[[X.2.1] [shared_mutex class] [Yes] [ - ]]
|
||||
[[X.2.2] [upgrade_mutex class] [Yes] [ - ]]
|
||||
[[X.3] [Locks] [Yes] [-]]
|
||||
[[X.3.1] [unique_lock class adaptations] [Yes] [-]]
|
||||
[[X.3.2] [shared_lock class] [Yes] [ - ]]
|
||||
[[X.3.3] [upgrade_lock class] [Yes] [-]]
|
||||
[[30.4.1.4] [Shared Lockables Types] [Yes] [ - ]]
|
||||
[[30.4.1.4.1] [shared_mutex class] [Yes] [ - ]]
|
||||
[[30.4.2.3] [Class template shared_lock] [Yes] [-]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:cxx1y C++1y TS Concurrency - On going proposals]
|
||||
|
||||
[section:latch C++ Latches and Barriers]
|
||||
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3600.html N3659 C++ Latches and Barriers]]
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3666.html N3659 C++ Latches and Barriers]]
|
||||
|
||||
[table C++ Latches and Barriers Conformance
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[X.1] [Class latch] [Partial] [ A new class latch has been added. The interface is a super set of the one of the proposal, taking some of the functions of the class barrier.]]
|
||||
[[X.2] [Class barrier] [No] [ Even if Boost.Thread has a class boost:barrier it doesn't provides the same kind of services. There is an experimental completion_latch that could be used instead. ]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:queue C++ Concurrent Queues]
|
||||
|
||||
[note [@ http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3533.html N3533 C++ Concurrent Queues]]
|
||||
|
||||
[table C++ Concurrent Queues Conformance
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[X.1] [Conceptual interface] [Partial] [ The interface provided has some differences respect to this proposal. All the functions having a queue_op_status are not provided. No lock-free concrete classes ]]
|
||||
[[X.1.1] [Basic Operations] [Partial] [ - ]]
|
||||
[[X.1.1.1] [push] [yes] [ - ]]
|
||||
[[X.1.1.2] [value_pop] [no] [ renamed pull with two flavors + a ptr_pull that returns a sharted_ptr<>. ]]
|
||||
[[X.1.2] [Non-waiting operations] [ - ] [ - ]]
|
||||
[[X.1.2.1] [try_push] [Partial] [ return bool instead ]]
|
||||
[[X.1.2.2] [try_pop] [Partial] [ renamed try_pull, returns null ]]
|
||||
[[X.1.3] [Non-blocking operations] [ - ] [ - ]]
|
||||
[[X.1.3.1] [nonblocking_push] [Partial] [ renamed try_push(no_block, ]]
|
||||
[[X.1.3.2] [nonblocking_pop] [Partial] [ renamed try_pop(no_block, ]]
|
||||
[[X.1.4] [Push-front operations] [No] [ - ]]
|
||||
[[X.1.5] [Closed queues] [Partial] [ - ]]
|
||||
[[X.1.5.1] [close] [Yes] [ - ]]
|
||||
[[X.1.5.2] [is_closed] [Yes] [ - ]]
|
||||
[[X.1.5.3] [wait_push] [Partial] [ - ]]
|
||||
[[X.1.5.4] [wait_pop] [Partial] [ - ]]
|
||||
[[X.1.5.5] [wait_push_front] [no] [ - ]]
|
||||
[[X.1.5.6] [wait_pop] [Partial] [ - ]]
|
||||
[[X.1.5.6] [open] [no] [ - ]]
|
||||
[[X.1.6] [Empty and Full Queues] [Yes] [ - ]]
|
||||
[[X.1.6.1] [is_empty] [Yes] [ - ]]
|
||||
[[X.1.6.2] [is_full] [Yes] [ Added capacity ]]
|
||||
[[X.1.7] [Queue Names] [No] [ Not considere a must for the time been. ]]
|
||||
[[X.1.8] [Element Type Requirements] [Yes?] [ - ]]
|
||||
[[X.1.9] [Exception Handling] [Yes?] [ - ]]
|
||||
[[X.1.10] [Queue Ordering] [Yes?] [ - ]]
|
||||
[[X.1.11] [Lock-Free Implementations] [No] [ waiting to stabilize the lock-based interface. Will use Boost.LockFree once it is Move aware. ]]
|
||||
[[X.2] [Concrete queues] [Partial] [ - ]]
|
||||
[[X.2.1] [Locking Buffer Queue] [Partial] [ classes sync_queue and a sync_bounded_queue. ]]
|
||||
[[X.2.1] [Lock-Free Buffer Queue] [No] [ - ]]
|
||||
[[X.3] [Additional Conceptual Tools] [No] [ - ]]
|
||||
[[X.3.1] [Fronts and Backs] [No] [ - ]]
|
||||
[[X.3.2] [Streaming Iterators] [No] [ - ]]
|
||||
[[X.3.3] [Storage Iterators] [No] [ - ]]
|
||||
[[X.3.4] [Binary Interfaces] [No] [ - ]]
|
||||
[[X.3.4] [Managed Indirection] [No] [ - ]]
|
||||
]
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:executors Asynchronous Executors]
|
||||
|
||||
While Boost.Thread implementation of executors would not use dynamic polymorphism, it is worth comparing with the current trend on the standard.
|
||||
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3378.pdf N3378 A preliminary proposal for work executors]]
|
||||
|
||||
|
||||
[table Asynchronous Executors
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[30.X.1] [Class executor] [No] [ - ]]
|
||||
[[30.X.1.1] [add] [No] [ renamed with a function template submit ]]
|
||||
[[30.X.1.1] [num_of_pendin_closures] [??] [ ]]
|
||||
[[30.X.2] [Class sceduled_executor] [No] [ - ]]
|
||||
[[30.X.2.1] [add_at] [No] [ renamed with a function template submit_at ]]
|
||||
[[30.X.2.2] [add_after] [No] [ renamed with a function template submit_after ]]
|
||||
[[30.X.3] [Executor utilities functions] [No] [ - ]]
|
||||
[[30.X.3.1] [default_executor] [No] [ - ]]
|
||||
[[30.X.3.2] [set_default_executor] [No] [ - ]]
|
||||
[[30.X.3.3] [singleton_inline_executor] [No] [ - ]]
|
||||
[[30.X.4] [Concrete executor classes] [No] [ - ]]
|
||||
[[30.X.4.1] [loop_executor] [No] [ - ]]
|
||||
[[30.X.4.1] [serial_executor] [No] [ - ]]
|
||||
[[30.X.4.1] [thread_pool] [No] [ #8513 ]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:async A Standardized Representation of Asynchronous Operations]
|
||||
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3558.pdf N3558 A Standardized Representation of Asynchronous Operations]]
|
||||
[note These functions are based on the [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3634.pdf [*N3634 - Improvements to std::future<T> and related APIs]] C++1y proposal by N. Gustafsson, A. Laksberg, H. Sutter, S. Mithani.]
|
||||
|
||||
[table Improvements to std::future<T> and related APIs]
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[30.6.6] [Class template future] [Partial] [ - ]]
|
||||
[[30.6.6.1] [then] [Partial] [ executor interface missing #8516 ]]
|
||||
[[30.6.6.2] [unwrap] [Yes] [ - ]]
|
||||
[[30.6.6.3] [ready] [Partial] [ is_ready ]]
|
||||
[[30.6.7] [Class template shared_future] [Partial] [ - ]]
|
||||
[[30.6.7.1] [then] [Yes] [ executor interface missing #8516 ]]
|
||||
[[30.6.7.2] [unwrap] [No] [ #XXXX ]]
|
||||
[[30.6.7.3] [ready] [Partial] [ is_ready ]]
|
||||
[[30.6.X] [Function template when_any] [No] [ #7446 ]]
|
||||
[[30.6.X] [Function template when_all] [No] [ #7447 ]]
|
||||
[[30.6.X] [Function template make_ready_future] [Yes] [ - ]]
|
||||
[[30.6.8] [Function template async ] [No] [ executor interface missing #7448 ]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:stream_mutex C++ Stream Mutexes - C++ Stream Guards]
|
||||
|
||||
While Boost.Thread implementation of stream mutexes differ in the approach, it is worth comparing with the current trend on the standard.
|
||||
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3535.html N3535 - C++ Stream Mutexes]. This has been replaced already by N3678 - C++ Stream Guards.]
|
||||
|
||||
[table C++ C++ Stream MutexesConformance
|
||||
[[Section] [Description] [Status] [Comments]]
|
||||
[[X.1] [Class template stream_mutex] [Partial] [ externally_locked_stream<> ]]
|
||||
[[X.2.1] [constructor] [Partial] [ externally_locked_stream needs a mutex in addition as argumement. ]]
|
||||
[[X.2.2] [lock] [yes] [ - ]]
|
||||
[[X.2.3] [unlock] [yes] [ - ]]
|
||||
[[X.2.4] [try_lock] [yes] [ - ]]
|
||||
[[X.2.5] [hold] [Yes] [ - ]]
|
||||
[[X.2.6] [bypass] [Yes] [ - ]]
|
||||
[[X.2] [Class template stream_guard] [Yes] [ - ]]
|
||||
[[X.2.1] [stream_guard] [Yes] [ - ]]
|
||||
[[X.2.2] [~stream_guard] [Yes] [ - ]]
|
||||
[[X.2.3] [bypass] [Yes] [ - ]]
|
||||
[[X.3] [Stream Operators] [Yes] [.]]
|
||||
[[X.4] [Predefined Objects] [No] [.]]
|
||||
]
|
||||
|
||||
[note [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3678.html N3678 - C++ Stream Guards]]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
[table Default Values for Configurable Features
|
||||
[[Feature] [Anti-Feature] [V2] [V3] [V4] ]
|
||||
[[USES_CHRONO] [DONT_USE_CHRONO] [YES] [YES] [YES] ]
|
||||
[[USES_CHRONO] [DONT_USE_CHRONO] [YES/NO] [YES/NO] [YES/NO] ]
|
||||
[[PROVIDES_INTERRUPTIONS] [DONT_PROVIDE_INTERRUPTIONS] [YES] [YES] [YES] ]
|
||||
[[THROW_IF_PRECONDITION_NOT_SATISFIED] [-] [NO] [NO] [NO] ]
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
[[PROVIDES_ONCE_CXX11] [DONT_PROVIDE_ONCE_CXX11] [NO] [YES] [YES] ]
|
||||
[[USES_MOVE] [DONT_USE_MOVE] [NO] [YES] [YES] ]
|
||||
|
||||
[[USES_DATETIME] [DONT_USE_DATETIME] [YES] [YES] [NO] ]
|
||||
[[USES_DATETIME] [DONT_USE_DATETIME] [YES/NO] [YES/NO] [YES/NO] ]
|
||||
[[PROVIDES_THREAD_EQ] [DONT_PROVIDE_THREAD_EQ] [YES] [YES] [NO] ]
|
||||
[[PROVIDES_CONDITION] [DONT_PROVIDE_CONDITION] [YES] [YES] [NO] ]
|
||||
[[PROVIDES_NESTED_LOCKS] [DONT_PROVIDE_NESTED_LOCKS] [YES] [YES] [NO] ]
|
||||
@@ -47,6 +47,8 @@
|
||||
|
||||
Boost.Thread uses by default Boost.Chrono for the time related functions and define `BOOST_THREAD_USES_CHRONO` if `BOOST_THREAD_DONT_USE_CHRONO` is not defined. The user should define `BOOST_THREAD_DONT_USE_CHRONO` for compilers that don't work well with Boost.Chrono.
|
||||
|
||||
[warning When defined BOOST_THREAD_PLATFORM_WIN32 BOOST_THREAD_USES_CHRONO is defined independently of user settings.]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
@@ -69,25 +71,35 @@ The Boost.DateTime time related functions introduced in Boost 1.35.0, using the
|
||||
* __timed_lock_ref__
|
||||
|
||||
|
||||
When `BOOST_THREAD_VERSION<=3` define `BOOST_THREAD_DONT_USE_DATETIME ` if you don't want to use Boost.DateTime related interfaces.
|
||||
When `BOOST_THREAD_VERSION>3` define `BOOST_THREAD_USES_DATETIME ` if you want to use Boost.DateTime related interfaces.
|
||||
When `BOOST_THREAD_VERSION<=3` && defined BOOST_THREAD_PLATFORM_PTHREAD define `BOOST_THREAD_DONT_USE_DATETIME` if you don't want to use Boost.DateTime related interfaces.
|
||||
When `BOOST_THREAD_VERSION>3` && defined BOOST_THREAD_PLATFORM_PTHREAD define `BOOST_THREAD_USES_DATETIME` if you want to use Boost.DateTime related interfaces.
|
||||
|
||||
[warning When defined BOOST_THREAD_PLATFORM_WIN32 BOOST_THREAD_USES_DATETIME is defined independently of user settings.]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move Boost.Atomic]
|
||||
|
||||
[section:thread_eq `boost::thread::oprator==` deprecated]
|
||||
Boost.Thread uses by default an Boost.Atomic in POSIX platforms to implement call_once..
|
||||
|
||||
The following nested typedefs are deprecated:
|
||||
Define `BOOST_THREAD_USES_ATOMIC ` if you want to use Boost.Atomic.
|
||||
Define `BOOST_THREAD_DONT_USE_ATOMIC ` if you don't want to use Boost.Atomic or if it is not supported in your platform.
|
||||
|
||||
* `boost::thread::oprator==`
|
||||
* `boost::thread::oprator!=`
|
||||
[endsect]
|
||||
|
||||
[section:thread_eq `boost::thread::operator==` deprecated]
|
||||
|
||||
The following operators are deprecated:
|
||||
|
||||
* `boost::thread::operator==`
|
||||
* `boost::thread::operator!=`
|
||||
|
||||
When `BOOST_THREAD_PROVIDES_THREAD_EQ` is defined Boost.Thread provides these deprecated feature.
|
||||
|
||||
Use instead
|
||||
|
||||
* `boost::thread::id::oprator==`
|
||||
* `boost::thread::id::oprator!=`
|
||||
* `boost::thread::id::operator==`
|
||||
* `boost::thread::id::operator!=`
|
||||
|
||||
[warning This is a breaking change respect to version 1.x.]
|
||||
|
||||
@@ -343,7 +355,7 @@ The user can request the version 3 by defining `BOOST_THREAD_VERSION` to 3. In t
|
||||
|
||||
* Breaking change `BOOST_THREAD_DONT_PROVIDE_PROMISE_LAZY`
|
||||
|
||||
The default value for `BOOST_THREAD_VERSION` will be changed to 3 since Boost 1.54.
|
||||
[/The default value for `BOOST_THREAD_VERSION` will be changed to 3 since Boost 1.54.]
|
||||
|
||||
The user can request the version 4 by defining `BOOST_THREAD_VERSION` to 4. In this case the following breaking or extending macros are defined if the opposite is not requested:
|
||||
|
||||
@@ -354,7 +366,7 @@ The user can request the version 4 by defining `BOOST_THREAD_VERSION` to 4. In t
|
||||
* Breaking change `BOOST_THREAD_DONT_USE_DATETIME`
|
||||
|
||||
|
||||
The default value for `BOOST_THREAD_VERSION` will be changed to 4 since Boost 1.56.
|
||||
[/The default value for `BOOST_THREAD_VERSION` will be changed to 4 since Boost 1.58.]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
@@ -182,10 +182,12 @@ For now, let's make a couple of enhancements to the `lock_guard` class template
|
||||
We'll call the enhanced version `strict_lock`. Essentially, a `strict_lock`'s role is only to live on the stack as an automatic variable.
|
||||
`strict_lock` must adhere to a non-copy and non-alias policy.
|
||||
`strict_lock` disables copying by making the copy constructor and the assignment operator private.
|
||||
While we're at it, let's disable operator new and operator delete;
|
||||
While we're at it, let's disable operator new and operator delete.
|
||||
|
||||
[/
|
||||
`strict_lock` are not intended to be allocated on the heap.
|
||||
`strict_lock` avoids aliasing by using a slightly less orthodox and less well-known technique: disable address taking.
|
||||
|
||||
]
|
||||
|
||||
template <typename Lockable>
|
||||
class strict_lock {
|
||||
@@ -215,7 +217,7 @@ Silence can be sometimes louder than words-what's forbidden to do with a `strict
|
||||
* You can create a `strict_lock<T>` only starting from a valid T object. Notice that there is no other way you can create a `strict_lock<T>`.
|
||||
|
||||
BankAccount myAccount("John Doe", "123-45-6789");
|
||||
strict_locerk<BankAccount> myLock(myAccount); // ok
|
||||
strict_lock<BankAccount> myLock(myAccount); // ok
|
||||
|
||||
* You cannot copy `strict_lock`s to one another. In particular, you cannot pass `strict_lock`s by value to functions or have them returned by functions:
|
||||
|
||||
@@ -229,6 +231,7 @@ Silence can be sometimes louder than words-what's forbidden to do with a `strict
|
||||
// ok, Bar takes a reference to strict_lock<BankAccount>
|
||||
extern void Bar(strict_lock<BankAccount>&);
|
||||
|
||||
[/
|
||||
* You cannot allocate a `strict_lock` on the heap. However, you still can put `strict_lock`s on the heap if they're members of a class.
|
||||
|
||||
strict_lock<BankAccount>* pL =
|
||||
@@ -250,8 +253,9 @@ Silence can be sometimes louder than words-what's forbidden to do with a `strict
|
||||
strict_lock<BankAccount>& rAlias = myLock; // ok
|
||||
|
||||
Fortunately, references don't engender as bad aliasing as pointers because they're much less versatile (references cannot be copied or reseated).
|
||||
|
||||
* You can even make `strict_lock` final; that is, impossible to derive from. This task is left in the form of an exercise to the reader.
|
||||
]
|
||||
[/* You can even make `strict_lock` final; that is, impossible to derive from. This task is left in the form of an exercise to the reader.
|
||||
]
|
||||
|
||||
All these rules were put in place with one purpose-enforcing that owning a `strict_lock<T>` is a reasonably strong guarantee that
|
||||
|
||||
@@ -398,8 +402,8 @@ The solution is to use a little bridge template `externally_locked` that control
|
||||
|
||||
T& get(strict_lock<Lockable>& lock) {
|
||||
|
||||
#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME // define BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME if you don't want to check locker check the same lockable
|
||||
if (!lock.is_locking(&lockable_)) throw lock_error(); run time check throw if not locks the same
|
||||
#ifdef BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||||
if (!lock.owns_lock(&lockable_)) throw lock_error(); run time check throw if not locks the same
|
||||
#endif
|
||||
return obj_;
|
||||
}
|
||||
@@ -464,7 +468,7 @@ Now imagine that the AccountManager function needs to take a `unique_lock` in or
|
||||
We need a way to transfer the ownership from the `unique_lock` to a `strict_lock` the time we are working with `savingsAcct_` and then restore the ownership on `unique_lock`.
|
||||
|
||||
void AccountManager::AMoreComplicatedChecking2Savings(int amount) {
|
||||
unique_lock<AccountManager> guard(*this, defer_lock);
|
||||
unique_lock<AccountManager> guard1(*this, defer_lock);
|
||||
if (some_condition()) {
|
||||
guard1.lock();
|
||||
}
|
||||
@@ -478,7 +482,7 @@ We need a way to transfer the ownership from the `unique_lock` to a `strict_lock
|
||||
|
||||
In order to make this code compilable we need to store either a Lockable or a `unique_lock<Lockable>` reference depending on the constructor. Store which kind of reference we have stored,and in the destructor call either to the Lockable `unlock` or restore the ownership.
|
||||
|
||||
This seams too complicated to me. Another possibility is to define a nested strict lock class. The drawback is that instead of having only one strict lock we have two and we need either to duplicate every function taking a `strict\_lock` or make these function templates functions. The problem with template functions is that we don't profit anymore of the C++ type system. We must add some static metafunction that check that the Locker parameter is a strict lock. The problem is that we can not really check this or can we?. The `is_strict_lock` metafunction must be specialized by the strict lock developer. We need to belive it "sur parolle". The advantage is that now we can manage with more than two strict locks without changing our code. Ths is really nice.
|
||||
This seams too complicated to me. Another possibility is to define a nested strict lock class. The drawback is that instead of having only one strict lock we have two and we need either to duplicate every function taking a `strict_lock` or make these function templates functions. The problem with template functions is that we don't profit anymore of the C++ type system. We must add some static metafunction that check that the Locker parameter is a strict lock. The problem is that we can not really check this or can we?. The `is_strict_lock` metafunction must be specialized by the strict lock developer. We need to belive it "sur parole". The advantage is that now we can manage with more than two strict locks without changing our code. This is really nice.
|
||||
|
||||
Now we need to state that both classes are `strict_lock`s.
|
||||
|
||||
@@ -508,7 +512,7 @@ First `nested_strict_lock` class will store on a temporary lock the `Locker`, an
|
||||
: lock_(lock) // Store reference to locker
|
||||
, tmp_lock_(lock.move()) // Move ownership to temporaty locker
|
||||
{
|
||||
#ifndef BOOST_THREAD_STRCIT_LOCKER_DONT_CHECK_OWNERSHIP // Define BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_OWNERSHIP if you don't want to check locker ownership
|
||||
#ifdef BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||||
if (tmp_lock_.mutex()==0) {
|
||||
lock_=tmp_lock_.move(); // Rollback for coherency purposes
|
||||
throw lock_error();
|
||||
@@ -519,24 +523,29 @@ First `nested_strict_lock` class will store on a temporary lock the `Locker`, an
|
||||
~nested_strict_lock() {
|
||||
lock_=tmp_lock_.move(); // Move ownership to nesting locker
|
||||
}
|
||||
typedef bool (nested_strict_lock::*bool_type)() const;
|
||||
operator bool_type() const { return &nested_strict_lock::owns_lock; }
|
||||
bool operator!() const { return false; }
|
||||
bool owns_lock() const { return true; }
|
||||
const lockable_type* mutex() const { return tmp_lock_.mutex(); }
|
||||
bool is_locking(lockable_type* l) const { return l==mutex(); }
|
||||
lockable_type* mutex() const { return tmp_lock_.mutex(); }
|
||||
bool owns_lock(lockable_type* l) const { return l==mutex(); }
|
||||
|
||||
BOOST_ADRESS_OF_DELETE(nested_strict_lock)
|
||||
BOOST_HEAP_ALLOCATEION_DELETE(nested_strict_lock)
|
||||
BOOST_DEFAULT_CONSTRUCTOR_DELETE(nested_strict_lock) 8
|
||||
BOOST_COPY_CONSTRUCTOR_DELETE(nested_strict_lock) 9
|
||||
BOOST_COPY_ASSIGNEMENT_DELETE(nested_strict_lock) 10
|
||||
|
||||
private:
|
||||
Locker& lock_;
|
||||
Locker tmp_lock_;
|
||||
};
|
||||
|
||||
[/
|
||||
typedef bool (nested_strict_lock::*bool_type)() const;
|
||||
operator bool_type() const { return &nested_strict_lock::owns_lock; }
|
||||
bool operator!() const { return false; }
|
||||
|
||||
BOOST_ADRESS_OF_DELETE(nested_strict_lock)
|
||||
BOOST_HEAP_ALLOCATEION_DELETE(nested_strict_lock)
|
||||
BOOST_DEFAULT_CONSTRUCTOR_DELETE(nested_strict_lock)
|
||||
BOOST_COPY_CONSTRUCTOR_DELETE(nested_strict_lock)
|
||||
BOOST_COPY_ASSIGNEMENT_DELETE(nested_strict_lock)
|
||||
|
||||
]
|
||||
|
||||
The `externally_locked` get function is now a template function taking a Locker as parameters instead of a `strict_lock`.
|
||||
We can add test in debug mode that ensure that the Lockable object is locked.
|
||||
|
||||
@@ -548,14 +557,14 @@ We can add test in debug mode that ensure that the Lockable object is locked.
|
||||
T& get(Locker& lock) {
|
||||
BOOST_CONCEPT_ASSERT((StrictLockerConcept<Locker>));
|
||||
|
||||
BOOST_STATIC_ASSERT((is_strict_lock<Locker>::value)); // locker is a strict locker "sur parolle"
|
||||
BOOST_STATIC_ASSERT((is_strict_lock<Locker>::value)); // locker is a strict locker "sur parole"
|
||||
BOOST_STATIC_ASSERT((is_same<Lockable,
|
||||
typename lockable_type<Locker>::type>::value)); // that locks the same type
|
||||
#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_OWNERSHIP // define BOOST_THREAD_EXTERNALLY_LOCKED_NO_CHECK_OWNERSHIP if you don't want to check locker ownership
|
||||
if (! lock ) throw lock_error(); // run time check throw if no locked
|
||||
#endif
|
||||
#ifndef BOOST_THREAD_EXTERNALLY_LOCKED_DONT_CHECK_SAME
|
||||
if (!lock.is_locking(&lockable_)) throw lock_error();
|
||||
#ifdef BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||||
if (!lock.owns_lock(&lockable_)) throw lock_error();
|
||||
#endif
|
||||
return obj_;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -293,7 +293,7 @@ that is to allow multiple concurrent get operations.
|
||||
|
||||
[heading Multiple get]
|
||||
|
||||
The second `get()` call in the following example future
|
||||
The second `get()` call in the following example is undefined.
|
||||
|
||||
void bad_second_use( type arg ) {
|
||||
|
||||
@@ -369,17 +369,17 @@ and a `shared_future` that can be shared between several threads, but there were
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:make_future Making immediate futures easier]
|
||||
[section:make_ready_future Making immediate futures easier]
|
||||
|
||||
Some functions may know the value at the point of construction. In these cases the value is immediately available,
|
||||
but needs to be returned as a future or shared_future. By using make_future (make_shared_future) a future (shared_future)
|
||||
but needs to be returned as a future or shared_future. By using make_ready_future a future
|
||||
can be created which holds a pre-computed result in its shared state.
|
||||
|
||||
Without these features it is non-trivial to create a future directly from a value.
|
||||
First a promise must be created, then the promise is set, and lastly the future is retrieved from the promise.
|
||||
This can now be done with one operation.
|
||||
|
||||
[heading make_future / make_shared_future]
|
||||
[heading make_ready_future]
|
||||
|
||||
This function creates a future for a given value. If no value is given then a future<void> is returned.
|
||||
This function is primarily useful in cases where sometimes, the return value is immediately available, but sometimes
|
||||
@@ -389,16 +389,14 @@ the function must return an eventual value represented as a future.
|
||||
|
||||
boost::future<int> compute(int x)
|
||||
{
|
||||
if (x == 0) return boost::make_future(0);
|
||||
if (x < 0) return boost::make_future(-1);
|
||||
if (x == 0) return boost::make_ready_future(0);
|
||||
if (x < 0) return boost::make_ready_future<int>(std::logic_error("Error"));
|
||||
boost::future<int> f1 = boost::async([]() { return x+1; });
|
||||
return f1;
|
||||
}
|
||||
|
||||
There are two variations of this function. The first takes a value of any type, and returns a future of that type.
|
||||
The input value is passed to the shared state of the returned future. The second version takes no input and returns a future<void>.
|
||||
make_shared_future has the same functionality as make_future, except has a return type of shared_future.
|
||||
|
||||
The input value is passed to the shared state of the returned future. The second version takes no input and returns a future<void>.
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -406,16 +404,16 @@ make_shared_future has the same functionality as make_future, except has a retur
|
||||
|
||||
In asynchronous programming, it is very common for one asynchronous operation, on completion, to invoke a second
|
||||
operation and pass data to it. The current C++ standard does not allow one to register a continuation to a future.
|
||||
With .then, instead of waiting for the result, a continuation is "attached" to the asynchronous operation, which is
|
||||
invoked when the result is ready. Continuations registered using the .then function will help to avoid blocking waits
|
||||
With `.then`, instead of waiting for the result, a continuation is "attached" to the asynchronous operation, which is
|
||||
invoked when the result is ready. Continuations registered using the `.then` function will help to avoid blocking waits
|
||||
or wasting threads on polling, greatly improving the responsiveness and scalability of an application.
|
||||
|
||||
future.then provides the ability to sequentially compose two futures by declaring one to be the continuation of another.
|
||||
With .then the antecedent future is ready (has a value or exception stored in the shared state) before the continuation
|
||||
`future.then()` provides the ability to sequentially compose two futures by declaring one to be the continuation of another.
|
||||
With `.then()` the antecedent future is ready (has a value or exception stored in the shared state) before the continuation
|
||||
starts as instructed by the lambda function.
|
||||
|
||||
In the example below the future<int> f2 is registered to be a continuation of future<int> f1 using the .then member
|
||||
function. This operation takes a lambda function which describes how f2 should proceed after f1 is ready.
|
||||
In the example below the `future<int>` `f2` is registered to be a continuation of `future<int>` `f1` using the `.then()` member
|
||||
function. This operation takes a lambda function which describes how `f2` should proceed after `f1` is ready.
|
||||
|
||||
|
||||
#include <boost/thread/future.hpp>
|
||||
@@ -428,7 +426,7 @@ function. This operation takes a lambda function which describes how f2 should p
|
||||
|
||||
One key feature of this function is the ability to chain multiple asynchronous operations. In asynchronous programming,
|
||||
it's common to define a sequence of operations, in which each continuation executes only when the previous one completes.
|
||||
In some cases, the antecedent future produces a value that the continuation accepts as input. By using future.then,
|
||||
In some cases, the antecedent future produces a value that the continuation accepts as input. By using `future.then()`,
|
||||
creating a chain of continuations becomes straightforward and intuitive:
|
||||
|
||||
myFuture.then(...).then(...).then(...).
|
||||
@@ -441,21 +439,20 @@ Some points to note are:
|
||||
|
||||
Input Parameters:
|
||||
|
||||
* Lambda function2: One option which was considered was to follow JavaScript's approach and take two functions, one for
|
||||
success and one for error handling. However this option is not viable in C++ as there is no single base type for
|
||||
exceptions as there is in JavaScript. The lambda function takes a future as its input which carries the exception
|
||||
* Lambda function: One option which can be considered is to take two functions, one for
|
||||
success and one for error handling. However this option has not been retained for the moment.
|
||||
The lambda function takes a future as its input which carries the exception
|
||||
through. This makes propagating exceptions straightforward. This approach also simplifies the chaining of continuations.
|
||||
* Scheduler: Providing an overload to .then, to take a scheduler reference places great flexibility over the execution
|
||||
* Scheduler: Providing an overload to `.then`, to take a scheduler reference places great flexibility over the execution
|
||||
of the future in the programmer's hand. As described above, often taking a launch policy is not sufficient for powerful
|
||||
asynchronous operations. The lifetime of the scheduler must outlive the continuation.
|
||||
* Launch policy: if the additional flexibility that the scheduler provides is not required.
|
||||
|
||||
|
||||
Return values: The decision to return a future was based primarily on the ability to chain multiple continuations using
|
||||
.then. This benefit of composability gives the programmer incredible control and flexibility over their code. Returning
|
||||
a future object rather than a shared_future is also a much cheaper operation thereby improving performance. A
|
||||
shared_future object is not necessary to take advantage of the chaining feature. It is also easy to go from a future
|
||||
to a shared_future when needed using future::share().
|
||||
`.then()`. This benefit of composability gives the programmer incredible control and flexibility over their code. Returning
|
||||
a `future` object rather than a `shared_future` is also a much cheaper operation thereby improving performance. A
|
||||
`shared_future` object is not necessary to take advantage of the chaining feature. It is also easy to go from a `future`
|
||||
to a `shared_future` when needed using future::share().
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -55,6 +55,9 @@ The following example includes a bank account of a person (Joe) and two componen
|
||||
|
||||
From time to time, the `bankAgent` will deposit $500 in `JoesAccount`. Joe will similarly withdraw $100 from his account. These sentences describe that the bankAgent and Joe are executed concurrently.
|
||||
|
||||
[endsect]
|
||||
[section Internal locking]
|
||||
|
||||
The above example works well as long as the bankAgent and Joe doesn't access JoesAccount at the same time. There is, however, no guarantee that this will not happen. We may use a mutex to guarantee exclusive access to each bank.
|
||||
|
||||
class BankAccount {
|
||||
@@ -75,7 +78,7 @@ The above example works well as long as the bankAgent and Joe doesn't access Joe
|
||||
mtx_.lock();
|
||||
int b = balance_;
|
||||
mtx_.unlock();
|
||||
return balance_;
|
||||
return b;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -105,6 +108,9 @@ With the RAII idiom we can simplify a lot this using the scoped locks. In the co
|
||||
|
||||
The object-level locking idiom doesn't cover the entire richness of a threading model. For example, the model above is quite deadlock-prone when you try to coordinate multi-object transactions. Nonetheless, object-level locking is useful in many cases, and in combination with other mechanisms can provide a satisfactory solution to many threaded access problems in object-oriented programs.
|
||||
|
||||
[endsect]
|
||||
[section Internal and external locking]
|
||||
|
||||
The BankAccount class above uses internal locking. Basically, a class that uses internal locking guarantees that any concurrent calls to its public member functions don't corrupt an instance of that class. This is typically ensured by having each public member function acquire a lock on the object upon entry. This way, for any given object of that class, there can be only one member function call active at any moment, so the operations are nicely serialized.
|
||||
|
||||
This approach is reasonably easy to implement and has an attractive simplicity. Unfortunately, "simple" might sometimes morph into "simplistic."
|
||||
@@ -203,6 +209,24 @@ As `boost::mutex` is not recursive, we need to use its recursive version `boost:
|
||||
// ...
|
||||
};
|
||||
|
||||
The caller-ensured locking approach is more flexible and the most efficient, but very dangerous. In an implementation using caller-ensured locking, BankAccount still holds a mutex, but its member functions don't manipulate it at all. Deposit and Withdraw are not thread-safe anymore. Instead, the client code is responsible for locking BankAccount properly.
|
||||
|
||||
class BankAccount
|
||||
: public basic_lockable_adapter<boost:mutex> {
|
||||
int balance_;
|
||||
public:
|
||||
void Deposit(int amount) {
|
||||
balance_ += amount;
|
||||
}
|
||||
void Withdraw(int amount) {
|
||||
balance_ -= amount;
|
||||
}
|
||||
};
|
||||
|
||||
Obviously, the caller-ensured locking approach has a safety problem. BankAccount's implementation code is finite, and easy to reach and maintain, but there's an unbounded amount of client code that manipulates BankAccount objects. In designing applications, it's important to differentiate between requirements imposed on bounded code and unbounded code. If your class makes undue requirements on unbounded code, that's usually a sign that encapsulation is out the window.
|
||||
|
||||
To conclude, if in designing a multi-threaded class you settle on internal locking, you expose yourself to inefficiency or deadlocks. On the other hand, if you rely on caller-provided locking, you make your class error-prone and difficult to use. Finally, external locking completely avoids the issue by leaving it all to the client code.
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -440,11 +464,6 @@ Monitors and conditions are useful for describing simple cases of shared objects
|
||||
[endsect] [/Monitors]
|
||||
]
|
||||
|
||||
[section Synchronized variables]
|
||||
[/include synchronized_value.qbk]
|
||||
[endsect] [/Synchronized variables]
|
||||
|
||||
|
||||
[endsect] [/Internal Locking]
|
||||
|
||||
|
||||
|
||||
419
doc/latch.qbk
Normal file
419
doc/latch.qbk
Normal file
@@ -0,0 +1,419 @@
|
||||
[/
|
||||
(C) Copyright 2013 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:latches Latches -- EXPERIMENTAL]
|
||||
|
||||
[////////////////////]
|
||||
[section Introdcution]
|
||||
|
||||
Latches are a thread co-ordination mechanism that allow one or more threads to block until one or more threads have reached a point.
|
||||
|
||||
[/
|
||||
An individual latch is a reusable object; once the operation has been completed, the threads can re-use the same barrier. It is thus useful for managing repeated tasks handled by multiple threads.
|
||||
|
||||
A completion latch is like a latch that allows to associate a completion function which will be called once the internal counter reaches the value 0 and all the consumer threads have taken care of the notification.
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[////////////////]
|
||||
[section Examples]
|
||||
|
||||
Sample use cases for the latch include:
|
||||
|
||||
* Setting multiple threads to perform a task, and then waiting until all threads have reached a common point.
|
||||
* Creating multiple threads, which wait for a signal before advancing beyond a common point.
|
||||
|
||||
An example of the first use case would be as follows:
|
||||
|
||||
void DoWork(thread_pool* pool) {
|
||||
latch completion_latch(NTASKS);
|
||||
for (int i = 0; i < NTASKS; ++i) {
|
||||
pool->submit([&] {
|
||||
// perform work
|
||||
...
|
||||
completion_latch.count_down();
|
||||
}));
|
||||
}
|
||||
// Block until work is done
|
||||
completion_latch.wait();
|
||||
}
|
||||
|
||||
An example of the second use case is shown below. We need to load data and then process it using a number of threads. Loading the data is I/O bound, whereas starting threads and creating data structures is CPU bound. By running these in parallel, throughput can be increased.
|
||||
|
||||
void DoWork() {
|
||||
latch start_latch(1);
|
||||
vector<thread*> workers;
|
||||
for (int i = 0; i < NTHREADS; ++i) {
|
||||
workers.push_back(new thread([&] {
|
||||
// Initialize data structures. This is CPU bound.
|
||||
...
|
||||
start_latch.wait();
|
||||
// perform work
|
||||
...
|
||||
}));
|
||||
}
|
||||
// Load input data. This is I/O bound.
|
||||
...
|
||||
// Threads can now start processing
|
||||
start_latch.count_down();
|
||||
}
|
||||
|
||||
[/
|
||||
The completion latches can be used to co-ordinate also a set of threads carrying out a repeated task. The number of threads can be adjusted dynamically to respond to changing requirements.
|
||||
|
||||
In the example below, a number of threads are performing a multi-stage task. Some tasks may require fewer steps than others, meaning that some threads may finish before others. We reduce the number of threads waiting on the latch when this happens.
|
||||
|
||||
void DoWork() {
|
||||
Tasks& tasks;
|
||||
size_t initial_threads;
|
||||
atomic<size_t> current_threads(initial_threads)
|
||||
vector<thread*> workers;
|
||||
|
||||
// Create a barrier, and set a lambda that will be invoked every time the
|
||||
// barrier counts down. If one or more active threads have completed,
|
||||
// reduce the number of threads.
|
||||
completion_latch task_barrier(n_threads);
|
||||
task_barrier.then([&] {
|
||||
task_barrier.reset(current_threads);
|
||||
});
|
||||
|
||||
for (int i = 0; i < n_threads; ++i) {
|
||||
workers.push_back(new thread([&] {
|
||||
bool active = true;
|
||||
while(active) {
|
||||
Task task = tasks.get();
|
||||
// perform task
|
||||
...
|
||||
if (finished(task)) {
|
||||
current_threads--;
|
||||
active = false;
|
||||
}
|
||||
task_barrier.count_down_and_wait();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Read each stage of the task until all stages are complete.
|
||||
while (!finished()) {
|
||||
GetNextStage(tasks);
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////]
|
||||
[section:latch Class `latch`]
|
||||
|
||||
#include <boost/thread/latch.hpp>
|
||||
|
||||
class latch
|
||||
{
|
||||
public:
|
||||
latch(latch const&) = delete;
|
||||
latch& operator=(latch const&) = delete;
|
||||
|
||||
latch(std::size_t count);
|
||||
~latch();
|
||||
|
||||
void wait();
|
||||
bool try_wait();
|
||||
template <class Rep, class Period>
|
||||
cv_status wait_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class lock_type, class Clock, class Duration>
|
||||
cv_status wait_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
void count_down();
|
||||
void count_down_and_wait();
|
||||
|
||||
};
|
||||
|
||||
|
||||
[/
|
||||
void reset(std::size_t count);
|
||||
]
|
||||
|
||||
A latch maintains an internal counter that is initialized when the latch is created. One or more threads may block waiting until the counter is decremented to 0.
|
||||
|
||||
Instances of __latch__ are not copyable or movable.
|
||||
|
||||
[///////////////////]
|
||||
[section Constructor `latch(std::size_t)`]
|
||||
|
||||
latch(std::size_t count);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Construct a latch with is initial value for the internal counter.]]
|
||||
|
||||
[[Note:] [The counter could be zero.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[//////////////////]
|
||||
[section Destructor `~latch()`]
|
||||
|
||||
~latch();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [No threads are waiting or invoking count_down on `*this`.]]
|
||||
|
||||
[[Effects:] [Destroys `*this` latch.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[/////////////////////////////////////]
|
||||
[section:wait Member Function `wait()`]
|
||||
|
||||
void wait();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Block the calling thread until the internal count reaches the value zero. Then all waiting threads
|
||||
are unblocked. ]]
|
||||
|
||||
[[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.
|
||||
]]
|
||||
|
||||
[[Notes:] [`wait()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[/////////////////////////////////////////////]
|
||||
[section:try_wait Member Function `try_wait()`]
|
||||
|
||||
bool try_wait();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [Returns true if the internal count is 0, and false otherwise. Does not block the calling thread. ]]
|
||||
|
||||
[[Throws:] [
|
||||
- __thread_resource_error__ if an error occurs.
|
||||
]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[//////////////////////////////////////////////]
|
||||
[section:wait_for Member Function `wait_for() `]
|
||||
|
||||
template <class Rep, class Period>
|
||||
cv_status wait_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Block the calling thread until the internal count reaches the value zero or the duration has been elapsed. If no timeout, all waiting threads are unblocked. ]]
|
||||
[[Returns:] [cv_status::no_timeout if the internal count is 0, and cv_status::timeout if duration has been elapsed. ]]
|
||||
|
||||
[[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.
|
||||
]]
|
||||
|
||||
[[Notes:] [`wait_for()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[/////////////////////////////////////////////////]
|
||||
[section:wait_until Member Function `wait_until()`]
|
||||
|
||||
template <class lock_type, class Clock, class Duration>
|
||||
cv_status wait_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Block the calling thread until the internal count reaches the value zero or the time_point has been reached. If no timeout, all waiting threads are unblocked. ]]
|
||||
[[Returns:] [cv_status::no_timeout if the internal count is 0, and cv_status::timeout if time_point has been reached.]]
|
||||
|
||||
[[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.
|
||||
]]
|
||||
|
||||
[[Notes:] [`wait_until()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[/////////////////////////////////////////////////]
|
||||
[section:count_down Member Function `count_down()`]
|
||||
|
||||
void count_down();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [The internal counter is non zero.]]
|
||||
[[Effects:] [Decrements the internal count by 1, and returns. If the count reaches 0, any threads blocked in wait() will be released. ]]
|
||||
|
||||
[[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.
|
||||
]]
|
||||
[[Notes:] [`count_down()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////////////////////////////////////////]
|
||||
[section:count_down_and_wait Member Function `count_down_and_wait()`]
|
||||
|
||||
void count_down_and_wait();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [The internal counter is non zero.]]
|
||||
[[Effects:] [Decrements the internal count by 1. If the resulting count is not 0, blocks the calling thread until the internal count is decremented to 0 by one or more other threads calling count_down() or count_down_and_wait(). ]]
|
||||
|
||||
[[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.
|
||||
]]
|
||||
[[Notes:] [`count_down_and_wait()` is an ['interruption point].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////////////]
|
||||
[
|
||||
[section:reset Member Function `reset()`]
|
||||
|
||||
reset( size_t );
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [This function may only be invoked when there are no other threads currently inside the waiting functions.]]
|
||||
|
||||
[[Returns:] [Resets the latch with a new value for the initial thread count. ]]
|
||||
|
||||
[[Throws:] [
|
||||
- __thread_resource_error__ if an error occurs.
|
||||
]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
]
|
||||
[endsect] [/ latch]
|
||||
|
||||
[/
|
||||
[//////////////////////////////////////////////////]
|
||||
[section:completion_latch Class `completion_latch `]
|
||||
|
||||
#include <boost/thread/completion_latch.hpp>
|
||||
|
||||
class completion_latch
|
||||
{
|
||||
public:
|
||||
typedef 'implementation defined' completion_function;
|
||||
|
||||
completion_latch(completion_latch const&) = delete;
|
||||
completion_latch& operator=(completion_latch const&) = delete;
|
||||
|
||||
completion_latch(std::size_t count);
|
||||
template <typename F>
|
||||
completion_latch(std::size_t count, F&& funct);
|
||||
~completion_latch();
|
||||
|
||||
void wait();
|
||||
bool try_wait();
|
||||
template <class Rep, class Period>
|
||||
cv_status wait_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
template <class lock_type, class Clock, class Duration>
|
||||
cv_status wait_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
void count_down();
|
||||
void count_down_and_wait();
|
||||
void reset(std::size_t count);
|
||||
template <typename F>
|
||||
completion_function then(F&& funct);
|
||||
};
|
||||
|
||||
|
||||
A completion latch is like a latch that allows to associate a completion function which will be called once the internal counter reaches the value 0 and all the consumer threads have taken care of the notification.
|
||||
|
||||
Instances of completion_latch are not copyable or movable.
|
||||
|
||||
Only the additional functions are documented.
|
||||
|
||||
[/////////////////////]
|
||||
[section:c Constructor]
|
||||
|
||||
completion_latch(std::size_t count);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Construct a completion_latch with is initial value for the internal counter and a noop completion function.]]
|
||||
|
||||
[[Note:] [The counter could be zero and rest later.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////////////////////]
|
||||
[section:cf Constructor with completion function]
|
||||
|
||||
template <typename F>
|
||||
completion_latch(std::size_t count, F&& funct);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Construct a completion_latch with is initial value for the internal counter and the completion function `funct`.]]
|
||||
|
||||
[[Note:] [The counter could be zero and reset later.]]
|
||||
|
||||
[[Throws:] [
|
||||
|
||||
- Any exception thrown by the copy/move construction of funct.
|
||||
|
||||
]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////////]
|
||||
[section:then Member Function `then`]
|
||||
|
||||
template <typename F>
|
||||
completion_function then(F&& funct);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [This function may only be invoked when there are no other threads currently inside the waiting functions. It may also be invoked from within the registered completion function. ]]
|
||||
|
||||
[[Effects:] [Associates the parameter `funct` as completion function of the latch. The next time the internal count reaches 0, this function will be invoked.]]
|
||||
[[Returns:] [The old completion function.]]
|
||||
|
||||
[[Throws:] [
|
||||
- __thread_resource_error__ if an error occurs.
|
||||
|
||||
- Any exception thrown by the copy/move construction of completion functions.
|
||||
]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect] [/ completion_latch]
|
||||
]
|
||||
|
||||
[endsect] [/ Latches]
|
||||
117
doc/lockable_adapter.qbk
Normal file
117
doc/lockable_adapter.qbk
Normal file
@@ -0,0 +1,117 @@
|
||||
[/
|
||||
(C) Copyright 2008-2013 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:lockable_adapter_hpp Header `<boost/thread/lockable_adapter.hpp>`]
|
||||
[/==========================================================================================]
|
||||
|
||||
namespace boost {
|
||||
template <typename Lockable> class basic_lockable_adapter;
|
||||
template <typename Lockable> class lockable_adapter;
|
||||
template <typename TimedLock> class timed_lockable_adapter;
|
||||
template <typename SharableLock> class shared_lockable_adapter;
|
||||
template <typename UpgradableLock> class upgrade_lockable_adapter;
|
||||
}
|
||||
|
||||
[section Template Class `basic_lockable_adapter<>`]
|
||||
|
||||
template <typename Lockable>
|
||||
class basic_lockable_adapter {
|
||||
public:
|
||||
basic_lockable_adapter(basic_lockable_adapter const&) = delete
|
||||
basic_lockable_adapter& opearator=(basic_lockable_adapter const&) = delete
|
||||
|
||||
typedef Lockable mutex_type;
|
||||
|
||||
basic_lockable_adapter() {}
|
||||
void lock();
|
||||
void unlock();
|
||||
bool try_lock();
|
||||
};
|
||||
|
||||
[endsect]
|
||||
[section Template Class `lockable_adapter<>`]
|
||||
|
||||
template <typename Lockable>
|
||||
class lockable_adapter : : public basic_lockable_adapter<Lockable> {
|
||||
public:
|
||||
lockable_adapter() {}
|
||||
|
||||
bool try_lock();
|
||||
};
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Template Class `timed_lockable_adapter<>`]
|
||||
|
||||
template <typename TimedLock>
|
||||
class timed_lockable_adapter : public lockable_adapter<TimedLock> {
|
||||
public:
|
||||
timed_lockable_adapter() {}
|
||||
|
||||
bool try_lock_until(system_time const & abs_time);
|
||||
template<typename TimeDuration>
|
||||
bool try_lock_for(TimeDuration const & relative_time);
|
||||
|
||||
void lock_until(system_time const & abs_time);
|
||||
template<typename TimeDuration>
|
||||
void lock_for(TimeDuration const & relative_time);
|
||||
};
|
||||
|
||||
[endsect]
|
||||
[section Template Class `shared_lockable_adapter<>`]
|
||||
|
||||
template <typename SharableLock>
|
||||
class shared_lockable_adapter : public timed_lockable_adapter<SharableLock> {
|
||||
public:
|
||||
shared_lockable_adapter() {}
|
||||
void lock_shared();
|
||||
bool try_lock_shared();
|
||||
void unlock_shared();
|
||||
|
||||
bool try_lock_shared_until(system_time const& t);
|
||||
template<typename TimeDuration>
|
||||
bool try_lock_shared_for(TimeDuration const& t);
|
||||
|
||||
template<typename TimeDuration>
|
||||
void lock_shared_for(TimeDuration const& t);
|
||||
void lock_shared_until(system_time const& t);
|
||||
};
|
||||
|
||||
|
||||
[endsect]
|
||||
[section Template Class `upgrade_lockable_adapter<>`]
|
||||
|
||||
template <typename UpgradableLock>
|
||||
class upgrade_lockable_adapter : public shared_lockable_adapter<UpgradableLock>{
|
||||
public:
|
||||
upgrade_lockable_adapter();
|
||||
|
||||
void lock_upgrade();
|
||||
bool try_lock_upgrade();
|
||||
void unlock_upgrade();
|
||||
|
||||
void unlock_upgrade_and_lock();
|
||||
void unlock_and_lock_upgrade();
|
||||
void unlock_and_lock_shared();
|
||||
void unlock_upgrade_and_lock_shared();
|
||||
|
||||
bool try_lock_upgrade_until(system_time const&t);
|
||||
template<typename TimeDuration>
|
||||
bool try_lock_upgrade_for(TimeDuration const&t);
|
||||
void lock_upgrade_until(system_time const&t);
|
||||
template<typename TimeDuration>
|
||||
void lock_upgrade_for(TimeDuration const&t);
|
||||
};
|
||||
|
||||
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ Lock ownership acquired through a call to __lock_ref__ must be released through
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [The calling thread doesn't owns the mutex if the mutex is not recursive.]]
|
||||
|
||||
[[Effects:] [The current thread blocks until ownership can be obtained for the current thread.]]
|
||||
|
||||
[[Synchronization:] [Prior `unlock()` operations on the same object synchronizes with this operation. ]]
|
||||
@@ -97,7 +99,12 @@ Lock ownership acquired through a call to __lock_ref__ must be released through
|
||||
}
|
||||
}
|
||||
|
||||
Some of the algorithms on mutexes use this trait via SFINAE. If BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES is defined you will need to specialize this traits for the models of BasicLockable you could build.
|
||||
|
||||
Some of the algorithms on mutexes use this trait via SFINAE.
|
||||
|
||||
This trait is true_type if the parameter L meets the __Lockable requirements.
|
||||
|
||||
[warning If BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES is defined you will need to specialize this traits for the models of BasicLockable you could build.]
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
@@ -121,6 +128,9 @@ Lock ownership acquired through a call to __try_lock_ref__ must be released thro
|
||||
|
||||
[variablelist
|
||||
|
||||
|
||||
[[Requires:] [The calling thread doesn't owns the mutex if the mutex is not recursive.]]
|
||||
|
||||
[[Effects:] [Attempt to obtain ownership for the current thread without blocking.]]
|
||||
|
||||
[[Synchronization:] [If `try_lock()` returns true, prior `unlock()` operations on the same object synchronize with this operation.]]
|
||||
@@ -152,7 +162,11 @@ failure, even in the absence of spurious failures.]]
|
||||
}
|
||||
}
|
||||
|
||||
Some of the algorithms on mutexes use this trait via SFINAE. If BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES is defined you will need to specialize this traits for the models of Lockable you could build.
|
||||
Some of the algorithms on mutexes use this trait via SFINAE.
|
||||
|
||||
This trait is true_type if the parameter L meets the __Lockable requirements.
|
||||
|
||||
[warning If BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES is defined you will need to specialize this traits for the models of Lockable you could build.]
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
@@ -162,7 +176,7 @@ Some of the algorithms on mutexes use this trait via SFINAE. If BOOST_THREAD_NO_
|
||||
The user could require that the mutex passed to an algorithm is a recursive one. Whether a lockable is recursive or not can not be checked using template meta-programming. This is the motivation for the following trait.
|
||||
|
||||
|
||||
[section:is_recursive_mutex_sur_parolle `is_recursive_mutex_sur_parolle` trait -- EXTENSION]
|
||||
[section:is_recursive_mutex_sur_parole `is_recursive_mutex_sur_parole` trait -- EXTENSION]
|
||||
|
||||
// #include <boost/thread/lockable_traits.hpp>
|
||||
|
||||
@@ -171,20 +185,51 @@ The user could require that the mutex passed to an algorithm is a recursive one.
|
||||
namespace sync
|
||||
{
|
||||
template<typename L>
|
||||
class is_recursive_mutex_sur_parolle: false_type; // EXTENSION
|
||||
class is_recursive_mutex_sur_parole: false_type; // EXTENSION
|
||||
template<>
|
||||
class is_recursive_mutex_sur_parolle<recursive_mutex>: true_type; // EXTENSION
|
||||
class is_recursive_mutex_sur_parole<recursive_mutex>: true_type; // EXTENSION
|
||||
template<>
|
||||
class is_recursive_mutex_sur_parolle<timed_recursive_mutex>: true_type; // EXTENSION
|
||||
class is_recursive_mutex_sur_parole<timed_recursive_mutex>: true_type; // EXTENSION
|
||||
}
|
||||
}
|
||||
|
||||
The trait `is_recursive_mutex_sur_parolle` is `false_type` by default and is specialized for the provide `recursive_mutex` and `timed_recursive_mutex`.
|
||||
The trait `is_recursive_mutex_sur_parole` is `false_type` by default and is specialized for the provide `recursive_mutex` and `timed_recursive_mutex`.
|
||||
|
||||
It should be specialized by the user providing other model of recursive lockable.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:is_recursive_basic_lockable `is_recursive_basic_lockable` trait -- EXTENSION]
|
||||
|
||||
// #include <boost/thread/lockable_traits.hpp>
|
||||
namespace boost
|
||||
{
|
||||
namespace sync
|
||||
{
|
||||
template<typename L>
|
||||
class is_recursive_basic_lockable;// EXTENSION
|
||||
}
|
||||
}
|
||||
|
||||
This traits is true_type if is_basic_lockable and is_recursive_mutex_sur_parole.
|
||||
|
||||
[endsect]
|
||||
[section:is_recursive_lockable `is_recursive_lockable` trait -- EXTENSION]
|
||||
|
||||
// #include <boost/thread/lockable_traits.hpp>
|
||||
namespace boost
|
||||
{
|
||||
namespace sync
|
||||
{
|
||||
template<typename L>
|
||||
class is_recursive_lockable;// EXTENSION
|
||||
}
|
||||
}
|
||||
|
||||
This traits is true_type if is_lockable and is_recursive_mutex_sur_parole.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
@@ -220,6 +265,8 @@ Lock ownership acquired through a call to __try_lock_for or __try_lock_until mus
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [The calling thread doesn't owns the mutex if the mutex is not recursive.]]
|
||||
|
||||
[[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__.]]
|
||||
|
||||
@@ -239,6 +286,8 @@ reached. If the specified time has already passed, behaves as __try_lock_ref__.]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [The calling thread doesn't owns the mutex if the mutex is not recursive.]]
|
||||
|
||||
[[Effects:] [As-if `__try_lock_until(chrono::steady_clock::now() + rel_time)`.]]
|
||||
|
||||
[[Synchronization:] [If `try_lock_for()` returns true, prior `unlock()` operations on the same object synchronize with this operation.]]
|
||||
@@ -295,14 +344,14 @@ reached. If the specified time has already passed, behaves as __try_lock_ref__.]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:shared_lockable `SharedLockable` Concept -- EXTENSION]
|
||||
[section:shared_lockable `SharedLockable` Concept -- C++14]
|
||||
|
||||
// #include <boost/thread/lockable_concepts.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template<typename L>
|
||||
class SharedLockable; // EXTENSION
|
||||
class SharedLockable; // C++14
|
||||
}
|
||||
|
||||
|
||||
@@ -1086,7 +1135,7 @@ object passed to the constructor.]]
|
||||
}
|
||||
|
||||
|
||||
A StrictLock is a lock that ensures that the associated mutex is locked during the lifetime if the lock.
|
||||
A StrictLock is a lock that ensures that the associated mutex is locked during the lifetime of the lock.
|
||||
|
||||
A type `L` meets the StrictLock requirements if the following expressions are well-formed and have the specified semantics
|
||||
|
||||
@@ -1107,13 +1156,13 @@ The type L::mutex_type denotes the mutex that is locked by this lock.
|
||||
|
||||
[endsect] [/ mutex_type]
|
||||
|
||||
[section:is_strict_lock_sur_parolle `is_strict_lock_sur_parolle<L>`]
|
||||
[section:is_strict_lock_sur_parole `is_strict_lock_sur_parole<L>`]
|
||||
|
||||
As the semantic "ensures that the associated mutex is locked during the lifetime if the lock. " can not be described by syntactic requirements a `is_strict_lock_sur_parolle` trait must be specialized by the user defining the lock so that the following assertion is true:
|
||||
As the semantic "ensures that the associated mutex is locked during the lifetime of the lock. " can not be described by syntactic requirements a `is_strict_lock_sur_parole` trait must be specialized by the user defining the lock so that the following assertion is true:
|
||||
|
||||
is_strict_lock_sur_parolle<L>::value == true
|
||||
is_strict_lock_sur_parole<L>::value == true
|
||||
|
||||
[endsect] [/ is_strict_lock_sur_parolle]
|
||||
[endsect] [/ is_strict_lock_sur_parole]
|
||||
|
||||
[section:owns_lock `cl.owns_lock(m);`]
|
||||
|
||||
@@ -1134,8 +1183,8 @@ As the semantic "ensures that the associated mutex is locked during the lifetime
|
||||
The following classes are models of `StrictLock`:
|
||||
|
||||
* strict_lock: ensured by construction,
|
||||
* nested_strict_lock: ensured by construction,
|
||||
* __lock_guard__: "sur parolle" as the user could use adopt_lock_t constructor overload without having locked the mutex.
|
||||
* nested_strict_lock: "sur parole" as the user could use adopt_lock_t on unique_lock constructor overload without having locked the mutex,
|
||||
* __lock_guard__: "sur parole" as the user could use adopt_lock_t constructor overload without having locked the mutex.
|
||||
|
||||
[endsect] [/ Models]
|
||||
|
||||
@@ -1156,9 +1205,9 @@ The following classes are models of `StrictLock`:
|
||||
template<typename Mutex>
|
||||
void swap(unique_lock <Mutex>& lhs, unique_lock <Mutex>& rhs);
|
||||
template<typename Lockable>
|
||||
class shared_lock; // EXTENSION
|
||||
class shared_lock; // C++14
|
||||
template<typename Mutex>
|
||||
void swap(shared_lock<Mutex>& lhs,shared_lock<Mutex>& rhs); // EXTENSION
|
||||
void swap(shared_lock<Mutex>& lhs,shared_lock<Mutex>& rhs); // C++14
|
||||
template<typename Lockable>
|
||||
class upgrade_lock; // EXTENSION
|
||||
template<typename Mutex>
|
||||
@@ -1186,13 +1235,13 @@ The following classes are models of `StrictLock`:
|
||||
unique_lock(Lockable& m_,try_to_lock_t);
|
||||
|
||||
#ifdef BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSION
|
||||
unique_lock(shared_lock<mutex_type>&& sl, try_to_lock_t)
|
||||
unique_lock(shared_lock<mutex_type>&& sl, try_to_lock_t); // C++14
|
||||
template <class Clock, class Duration>
|
||||
unique_lock(shared_lock<mutex_type>&& sl,
|
||||
const chrono::time_point<Clock, Duration>& abs_time);
|
||||
const chrono::time_point<Clock, Duration>& abs_time); // C++14
|
||||
template <class Rep, class Period>
|
||||
unique_lock(shared_lock<mutex_type>&& sl,
|
||||
const chrono::duration<Rep, Period>& rel_time)
|
||||
const chrono::duration<Rep, Period>& rel_time); // C++14
|
||||
#endif
|
||||
|
||||
template <class Clock, class Duration>
|
||||
@@ -1204,7 +1253,7 @@ The following classes are models of `StrictLock`:
|
||||
unique_lock(unique_lock const&) = delete;
|
||||
unique_lock& operator=(unique_lock const&) = delete;
|
||||
unique_lock(unique_lock<Lockable>&& other) noexcept;
|
||||
explicit unique_lock(upgrade_lock<Lockable>&& other) noexcept;
|
||||
explicit unique_lock(upgrade_lock<Lockable>&& other) noexcept; // EXTENSION
|
||||
|
||||
unique_lock& operator=(unique_lock<Lockable>&& other) noexcept;
|
||||
|
||||
@@ -1224,7 +1273,7 @@ The following classes are models of `StrictLock`:
|
||||
explicit operator bool() const noexcept;
|
||||
bool owns_lock() const noexcept;
|
||||
|
||||
Lockable* mutex() const noexcept;
|
||||
mutex_type* mutex() const noexcept;
|
||||
|
||||
#if defined BOOST_THREAD_USE_DATE_TIME || defined BOOST_THREAD_DONT_USE_CHRONO
|
||||
unique_lock(Lockable& m_,system_time const& target_time);
|
||||
@@ -1486,7 +1535,7 @@ object associated with `*this`.]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:mutex `Lockable* mutex() const`]
|
||||
[section:mutex `Lockable* mutex() const noexcept`]
|
||||
|
||||
[variablelist
|
||||
|
||||
@@ -1534,7 +1583,7 @@ __owns_lock_ref__ returns `false`.]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:shared_lock Class template `shared_lock` - EXTENSION]
|
||||
[section:shared_lock Class template `shared_lock` - C++14]
|
||||
|
||||
// #include <boost/thread/locks.hpp>
|
||||
// #include <boost/thread/lock_types.hpp>
|
||||
@@ -1572,7 +1621,7 @@ __owns_lock_ref__ returns `false`.]]
|
||||
void unlock();
|
||||
|
||||
// Conversion from upgrade locking
|
||||
explicit shared_lock(upgrade_lock<Lockable> && other);
|
||||
explicit shared_lock(upgrade_lock<Lockable> && other); // EXTENSION
|
||||
|
||||
// Conversion from exclusive locking
|
||||
explicit shared_lock(unique_lock<Lockable> && other);
|
||||
@@ -1858,7 +1907,7 @@ state (including the destructor) must be called by the same thread that acquired
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:upgrade_to_unique_lock Class template `upgrade_to_unique_lock`]
|
||||
[section:upgrade_to_unique_lock Class template `upgrade_to_unique_lock` -- EXTENSION]
|
||||
|
||||
// #include <boost/thread/locks.hpp>
|
||||
// #include <boost/thread/lock_types.hpp>
|
||||
@@ -1881,6 +1930,8 @@ state (including the destructor) must be called by the same thread that acquired
|
||||
|
||||
explicit operator bool() const;
|
||||
bool owns_lock() const;
|
||||
mutex_type* mutex() const;
|
||||
|
||||
};
|
||||
|
||||
__upgrade_to_unique_lock__ allows for a temporary upgrade of an __upgrade_lock__ to exclusive ownership. When constructed with a
|
||||
@@ -1890,7 +1941,7 @@ __lockable_concept_type__ is downgraded back to ['upgrade ownership].
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:scoped_try_lock Mutex-specific class `scoped_try_lock`]
|
||||
[section:scoped_try_lock Mutex-specific class `scoped_try_lock` -- DEPRECATED]
|
||||
|
||||
class MutexType::scoped_try_lock
|
||||
{
|
||||
@@ -1977,9 +2028,9 @@ __reverse_mutex reverse the operations of a __BasicLockable, that unlocks the lo
|
||||
template <typename Lock>
|
||||
class nested_strict_lock;
|
||||
template <typename Lockable>
|
||||
struct is_strict_lock_sur_parolle<strict_lock<Lockable> >;
|
||||
struct is_strict_lock_sur_parole<strict_lock<Lockable> >;
|
||||
template <typename Lock>
|
||||
struct is_strict_lock_sur_parolle<nested_strict_lock<Lock> >;
|
||||
struct is_strict_lock_sur_parole<nested_strict_lock<Lock> >;
|
||||
|
||||
#if ! defined BOOST_THREAD_NO_MAKE_STRICT_LOCK
|
||||
template <typename Lockable>
|
||||
@@ -2002,6 +2053,8 @@ __reverse_mutex reverse the operations of a __BasicLockable, that unlocks the lo
|
||||
{
|
||||
public:
|
||||
typedef BasicLockable mutex_type;
|
||||
strict_lock(strict_lock const& m_) = delete;
|
||||
strict_lock& operator=(strict_lock const& m_) = delete;
|
||||
explicit strict_lock(mutex_type& m_);
|
||||
~strict_lock();
|
||||
|
||||
@@ -2052,6 +2105,8 @@ object passed to the constructor.]]
|
||||
{
|
||||
public:
|
||||
typedef BasicLockable mutex_type;
|
||||
nested_strict_lock(nested_strict_lock const& m_) = delete;
|
||||
nested_strict_lock& operator=(nested_strict_lock const& m_) = delete;
|
||||
explicit nested_strict_lock(Lock& lk),
|
||||
~nested_strict_lock() noexcept;
|
||||
|
||||
@@ -2154,15 +2209,247 @@ If the lock doesn't owns the mutex lock it.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:lock_ptrs Locking pointers]
|
||||
|
||||
// #include <boost/thread/synchroniezd_value.hpp>
|
||||
// #include <boost/thread/strict_lock_ptr.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template<typename T, typename Lockable = mutex>
|
||||
class strict_lock_ptr;
|
||||
template<typename T, typename Lockable = mutex>
|
||||
class const_strict_lock_ptr;
|
||||
}
|
||||
|
||||
|
||||
[/
|
||||
template<typename T, typename Lockable = mutex>
|
||||
class unique_lock_ptr;
|
||||
template<typename T, typename Lockable = mutex>
|
||||
class const_unique_lock_ptr;
|
||||
|
||||
]
|
||||
|
||||
[section:const_strict_lock_ptr Class template `const_strict_lock_ptr `]
|
||||
|
||||
// #include <boost/thread/synchroniezd_value.hpp>
|
||||
// #include <boost/thread/strict_lock_ptr.hpp>
|
||||
|
||||
|
||||
template <typename T, typename Lockable = mutex>
|
||||
class const_strict_lock_ptr
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef Lockable mutex_type;
|
||||
|
||||
const_strict_lock_ptr(const_strict_lock_ptr const& m_) = delete;
|
||||
const_strict_lock_ptr& operator=(const_strict_lock_ptr const& m_) = delete;
|
||||
|
||||
const_strict_lock_ptr(T const& val, Lockable & mtx);
|
||||
const_strict_lock_ptr(T const& val, Lockable & mtx, adopt_lock_t tag);
|
||||
|
||||
~const_strict_lock_ptr();
|
||||
|
||||
const T* operator->() const;
|
||||
const T& operator*() const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
[section:constructor `const_strict_lock_ptr(T const&,Lockable&)`]
|
||||
|
||||
|
||||
const_strict_lock_ptr(T const& val, Lockable & m);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Invokes [lock_ref_link `m.lock()`], stores a reference to it and to the value type `val`.]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the call to [lock_ref_link `m.lock()`].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:constructor_adopt `const_strict_lock_ptr(T const&,Lockable&,adopt_lock_t)`]
|
||||
|
||||
const_strict_lock_ptr(T const& val, Lockable & m, adopt_lock_t tag);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Stores a reference to it and to the value type `val`.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:destructor `~const_strict_lock_ptr()`]
|
||||
|
||||
~const_strict_lock_ptr();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Invokes [unlock_ref_link `m.unlock()`] on the __lockable_concept_type__
|
||||
object passed to the constructor.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:indir `operator->() const`]
|
||||
|
||||
const T* operator->() const;
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [return a constant pointer to the protected value.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:deref `operator*() const`]
|
||||
|
||||
const T& operator*() const;
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [return a constant reference to the protected value.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect] [/ const_strict_lock_ptr ]
|
||||
|
||||
[section:strict_lock_ptr Class template `strict_lock_ptr`]
|
||||
|
||||
// #include <boost/thread/synchroniezd_value.hpp>
|
||||
// #include <boost/thread/strict_lock_ptr.hpp>
|
||||
|
||||
template <typename T, typename Lockable = mutex>
|
||||
class strict_lock_ptr : public const_strict_lock_ptr<T,Lockable>
|
||||
{
|
||||
public:
|
||||
strict_lock_ptr(strict_lock_ptr const& m_) = delete;
|
||||
strict_lock_ptr& operator=(strict_lock_ptr const& m_) = delete;
|
||||
|
||||
strict_lock_ptr(T & val, Lockable & mtx);
|
||||
strict_lock_ptr(T & val, Lockable & mtx, adopt_lock_t tag);
|
||||
~strict_lock_ptr();
|
||||
|
||||
T* operator->();
|
||||
T& operator*();
|
||||
|
||||
};
|
||||
|
||||
|
||||
[section:constructor `strict_lock_ptr(T const&,Lockable&)`]
|
||||
|
||||
|
||||
strict_lock_ptr(T const& val, Lockable & m);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Invokes [lock_ref_link `m.lock()`], stores a reference to it and to the value type `val`.]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the call to [lock_ref_link `m.lock()`].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:constructor_adopt `strict_lock_ptr(T const&,Lockable&,adopt_lock_t)`]
|
||||
|
||||
strict_lock_ptr(T const& val, Lockable & m, adopt_lock_t tag);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Stores a reference to it and to the value type `val`.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:destructor `~strict_lock_ptr()`]
|
||||
|
||||
~ strict_lock_ptr();
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Invokes [unlock_ref_link `m.unlock()`] on the __lockable_concept_type__
|
||||
object passed to the constructor.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:indir `operator->()`]
|
||||
|
||||
T* operator->();
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [return a pointer to the protected value.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:deref `operator*()`]
|
||||
|
||||
T& operator*();
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [return a reference to the protected value.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect] [/ strict_lock_ptr ]
|
||||
|
||||
[endsect] [/ lock_ptrs ]
|
||||
|
||||
|
||||
[section Externally Locked]
|
||||
|
||||
// #include <boost/thread/externally_locked.hpp>
|
||||
template <class T, typename MutexType = boost::mutex>
|
||||
class externally_locked;
|
||||
template <class T, typename MutexType>
|
||||
class externally_locked<T&, MutexType>;
|
||||
|
||||
template <typename T, typename MutexType>
|
||||
void swap(externally_locked<T, MutexType> & lhs, externally_locked<T, MutexType> & rhs);
|
||||
|
||||
[section Template Class `externally_locked`]
|
||||
[section:externally_locked Template Class `externally_locked`]
|
||||
|
||||
// #include <boost/thread/externally_locked.hpp>
|
||||
|
||||
@@ -2178,8 +2465,11 @@ If the lock doesn't owns the mutex lock it.
|
||||
externally_locked(mutex_type& mtx, const T& obj);
|
||||
externally_locked(mutex_type& mtx,T&& obj);
|
||||
explicit externally_locked(mutex_type& mtx);
|
||||
externally_locked(externally_locked const& rhs);
|
||||
externally_locked(externally_locked&& rhs);
|
||||
|
||||
externally_locked& operator=(externally_locked const& rhs);
|
||||
externally_locked& operator=(externally_locked&& rhs);
|
||||
|
||||
// observers
|
||||
T& get(strict_lock<mutex_type>& lk);
|
||||
const T& get(strict_lock<mutex_type>& lk) const;
|
||||
@@ -2194,7 +2484,7 @@ If the lock doesn't owns the mutex lock it.
|
||||
template <class Lock>
|
||||
T const& get(Lock& lk) const;
|
||||
|
||||
mutex_type* mutex();
|
||||
mutex_type* mutex() const noexcept;
|
||||
|
||||
// modifiers
|
||||
void lock();
|
||||
@@ -2258,7 +2548,7 @@ Only the specificities respect to __Lockable are described here.
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////]
|
||||
[section:constructor4 `externally_locked(externally_locked&)`]
|
||||
[section:constructor4 `externally_locked(externally_locked&&)`]
|
||||
|
||||
externally_locked(externally_locked&& rhs);
|
||||
|
||||
@@ -2266,13 +2556,62 @@ Only the specificities respect to __Lockable are described here.
|
||||
|
||||
[[Requires:] [T is a model of Movable.]]
|
||||
|
||||
[[Effects:] [Moves an externally locked object by moving the the cloaked type and copying the mutex reference ]]
|
||||
[[Effects:] [Move constructs an externally locked object by moving the cloaked type and copying the mutex reference ]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the call to `T(T&&)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////]
|
||||
[section:constructor5 `externally_locked(externally_locked&)`]
|
||||
|
||||
externally_locked(externally_locked& rhs);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [T is a model of Copyable.]]
|
||||
|
||||
[[Effects:] [Copy constructs an externally locked object by copying the cloaked type and copying the mutex reference ]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the call to `T(T&)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////]
|
||||
[section:assign4 `externally_locked(externally_locked&&)`]
|
||||
|
||||
externally_locked& operator=(externally_locked&& rhs);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [T is a model of Movable.]]
|
||||
|
||||
[[Effects:] [Move assigns an externally locked object by moving the cloaked type and copying the mutex reference ]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the call to `T::operator=(T&&)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////]
|
||||
[section:assign5 `externally_locked(externally_locked&)`]
|
||||
|
||||
externally_locked& operator=(externally_locked const& rhs);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [T is a model of Copyable.]]
|
||||
|
||||
[[Effects:] [Copy assigns an externally locked object by copying the cloaked type and copying the mutex reference ]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the call to `T::operator=(T&)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[///////////////////////////////]
|
||||
[section:get1 `get(strict_lock<mutex_type>&)`]
|
||||
|
||||
@@ -2331,8 +2670,172 @@ Only the specificities respect to __Lockable are described here.
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
[section:externally_locked_ref Template Class `externally_locked<T&>`]
|
||||
|
||||
// #include <boost/thread/externally_locked.hpp>
|
||||
|
||||
template <class T, typename MutexType>
|
||||
class externally_locked<T&, MutexType>
|
||||
{
|
||||
//BOOST_CONCEPT_ASSERT(( CopyConstructible<T> ));
|
||||
BOOST_CONCEPT_ASSERT(( BasicLockable<MutexType> ));
|
||||
|
||||
public:
|
||||
typedef MutexType mutex_type;
|
||||
|
||||
externally_locked(mutex_type& mtx, T& obj);
|
||||
explicit externally_locked(mutex_type& mtx);
|
||||
externally_locked(externally_locked const& rhs) noexcept;
|
||||
externally_locked(externally_locked&& rhs) noexcept;
|
||||
externally_locked& operator=(externally_locked const& rhs) noexcept;
|
||||
externally_locked& operator=(externally_locked&& rhs) noexcept;
|
||||
|
||||
// observers
|
||||
T& get(strict_lock<mutex_type>& lk);
|
||||
const T& get(strict_lock<mutex_type>& lk) const;
|
||||
|
||||
template <class Lock>
|
||||
T& get(nested_strict_lock<Lock>& lk);
|
||||
template <class Lock>
|
||||
const T& get(nested_strict_lock<Lock>& lk) const;
|
||||
|
||||
template <class Lock>
|
||||
T& get(Lock& lk);
|
||||
template <class Lock>
|
||||
T const& get(Lock& lk) const;
|
||||
|
||||
mutex_type* mutex() const noexcept;
|
||||
|
||||
// modifiers
|
||||
void lock();
|
||||
void unlock();
|
||||
bool try_lock();
|
||||
void swap(externally_locked&) noexcept;
|
||||
};
|
||||
|
||||
`externally_locked` is a model of __Lockable, it cloaks an object of type `T`, and actually provides full
|
||||
access to that object through the get and set member functions, provided you
|
||||
pass a reference to a strict lock object.
|
||||
|
||||
Only the specificities respect to __Lockable are described here.
|
||||
|
||||
[///////////////////////////////]
|
||||
[section:swap `swap(externally_locked, externally_locked&)`]
|
||||
[section:constructor1 `externally_locked<T&>(mutex_type&, T&)`]
|
||||
|
||||
externally_locked<T&>(mutex_type& mtx, T& obj) noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
|
||||
[[Effects:] [Constructs an externally locked object copying the cloaked reference.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////]
|
||||
[section:constructor4 `externally_locked<T&>(externally_locked&&)`]
|
||||
|
||||
externally_locked(externally_locked&& rhs) noexcept;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Moves an externally locked object by moving the cloaked type and copying the mutex reference ]]
|
||||
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////]
|
||||
[section:assign4 `externally_locked(externally_locked&&)`]
|
||||
|
||||
externally_locked& operator=(externally_locked&& rhs);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Move assigns an externally locked object by copying the cloaked reference and copying the mutex reference ]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////]
|
||||
[section:assign5 `externally_locked(externally_locked&)`]
|
||||
|
||||
externally_locked& operator=(externally_locked const& rhs);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [T is a model of Copyable.]]
|
||||
|
||||
[[Effects:] [Copy assigns an externally locked object by copying the cloaked reference and copying the mutex reference ]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the call to `T::operator=(T&)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[///////////////////////////////]
|
||||
[section:get1 `get(strict_lock<mutex_type>&)`]
|
||||
|
||||
T& get(strict_lock<mutex_type>& lk);
|
||||
const T& get(strict_lock<mutex_type>& lk) const;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [The `lk` parameter must be locking the associated mutex.]]
|
||||
|
||||
[[Returns:] [A reference to the cloaked object ]]
|
||||
|
||||
[[Throws:] [__lock_error__ if `BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED` is defined and the run-time preconditions are not satisfied .]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[///////////////////////////////]
|
||||
[section:get2 `get(strict_lock<nested_strict_lock<Lock>>&)`]
|
||||
|
||||
template <class Lock>
|
||||
T& get(nested_strict_lock<Lock>& lk);
|
||||
template <class Lock>
|
||||
const T& get(nested_strict_lock<Lock>& lk) const;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`is_same<mutex_type, typename Lock::mutex_type>` and the `lk` parameter must be locking the associated mutex.]]
|
||||
|
||||
[[Returns:] [A reference to the cloaked object ]]
|
||||
|
||||
[[Throws:] [__lock_error__ if `BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED` is defined and the run-time preconditions are not satisfied .]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[///////////////////////////////]
|
||||
[section:get3 `get(strict_lock<nested_strict_lock<Lock>>&)`]
|
||||
|
||||
template <class Lock>
|
||||
T& get(Lock& lk);
|
||||
template <class Lock>
|
||||
T const& get(Lock& lk) const;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`Lock` is a model of __StrictLock, `is_same<mutex_type, typename Lock::mutex_type>` and the `lk` parameter must be locking the associated mutex.]]
|
||||
|
||||
[[Returns:] [A reference to the cloaked object ]]
|
||||
|
||||
[[Throws:] [__lock_error__ if `BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED` is defined and the run-time preconditions are not satisfied .]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[///////////////////////////////]
|
||||
[section:swap `swap(externally_locked&, externally_locked&)`]
|
||||
|
||||
template <typename T, typename MutexType>
|
||||
void swap(externally_locked<T, MutexType> & lhs, externally_locked<T, MutexType> & rhs)
|
||||
|
||||
@@ -239,3 +239,6 @@ implementation. If no such instance exists, `native_handle()` and `native_handle
|
||||
[include shared_mutex_ref.qbk]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
|
||||
28
doc/once.qbk
28
doc/once.qbk
@@ -12,8 +12,8 @@
|
||||
namespace boost
|
||||
{
|
||||
struct once_flag;
|
||||
template<typename Callable>
|
||||
void call_once(once_flag& flag,Callable func);
|
||||
template<typename Function, class ...ArgTypes>
|
||||
inline void call_once(once_flag& flag, Function&& f, ArgTypes&&... args);
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0
|
||||
void call_once(void (*func)(),once_flag& flag);
|
||||
@@ -21,6 +21,11 @@
|
||||
|
||||
}
|
||||
|
||||
[warning the variadic prototype is provided only on C++11 compilers supporting variadic templates, otherwise the interface is limited up to 3 parameters.]
|
||||
|
||||
[warning the move semantics is ensured only on C++11 compilers supporting SFINAE expression, decltype N3276 and auto. Waiting for a boost::bind that is move aware.]
|
||||
|
||||
|
||||
`boost::call_once` provides a mechanism for ensuring that an initialization routine is run exactly once without data races or deadlocks.
|
||||
|
||||
[section:once_flag Typedef `once_flag`]
|
||||
@@ -45,24 +50,22 @@ Objects of type `boost::once_flag` shall be initialized with `BOOST_ONCE_INIT` i
|
||||
|
||||
[section:call_once Non-member function `call_once`]
|
||||
|
||||
template<typename Callable>
|
||||
void call_once(once_flag& flag,Callable func);
|
||||
template<typename Function, class ...ArgTypes>
|
||||
inline void call_once(once_flag& flag, Function&& f, ArgTypes&&... args);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`Callable` is `CopyConstructible`. Copying `func` shall have no side effects, and the effect of calling the copy shall
|
||||
be equivalent to calling the original. ]]
|
||||
[[Requires:] [`Function` and each or the `ArgTypes` are `MoveConstructible` and `invoke(decay_copy(boost::forward<Function>(f)), decay_copy(boost::forward<ArgTypes>(args))...)` shall be well formed. ]]
|
||||
|
||||
[[Effects:] [Calls to `call_once` on the same `once_flag` object are serialized. If there has been no prior effective `call_once` on
|
||||
the same `once_flag` object, the argument `func` (or a copy thereof) is called as-if by invoking `func()`, and the invocation of
|
||||
`call_once` is effective if and only if `func()` returns without exception. If an exception is thrown, the exception is
|
||||
propagated to the caller. If there has been a prior effective `call_once` on the same `once_flag` object, the `call_once` returns
|
||||
the same `once_flag` object, the argument `func` is called as-if by invoking `invoke(decay_copy(boost::forward<Function>(f)), decay_copy(boost::forward<ArgTypes>(args))...)`, and the invocation of
|
||||
`call_once` is effective if and only if `invoke(decay_copy(boost::forward<Function>(f)), decay_copy(boost::forward<ArgTypes>(args))...)` returns without exception. If an exception is thrown, the exception is propagated to the caller. If there has been a prior effective `call_once` on the same `once_flag` object, the `call_once` returns
|
||||
without invoking `func`. ]]
|
||||
|
||||
[[Synchronization:] [The completion of an effective `call_once` invocation on a `once_flag` object, synchronizes with
|
||||
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`.]]
|
||||
[[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
|
||||
@@ -73,11 +76,14 @@ 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.]]
|
||||
|
||||
|
||||
[[Note:] [On some compilers this function has some restrictions, e.g. if variadic templates are not supported the number of arguments is limited to 3; .]]
|
||||
|
||||
]
|
||||
|
||||
void call_once(void (*func)(),once_flag& flag);
|
||||
|
||||
This second overload is provided for backwards compatibility. The effects of `call_once(func,flag)` shall be the same as those of
|
||||
This second overload is provided for backwards compatibility and is deprecated. The effects of `call_once(func,flag)` shall be the same as those of
|
||||
`call_once(flag,func)`.
|
||||
|
||||
[endsect]
|
||||
|
||||
@@ -105,6 +105,8 @@ The difference between strict_scoped_thread and scoped_thread is that the strict
|
||||
strict_scoped_thread& operator=(strict_scoped_thread const&) = delete;
|
||||
|
||||
explicit strict_scoped_thread(thread&& t) noexcept;
|
||||
template <typename F&&, typename ...Args>
|
||||
explicit strict_scoped_thread(F&&, Args&&...);
|
||||
|
||||
~strict_scoped_thread();
|
||||
|
||||
@@ -125,7 +127,7 @@ This wrapper can be used to join the thread before destroying it seems a natural
|
||||
|
||||
boost::strict_scoped_thread<> t((boost::thread(F)));
|
||||
|
||||
[section:default_constructor Default Constructor]
|
||||
[section:default_constructor Constructor from a __thread]
|
||||
|
||||
explicit strict_scoped_thread(thread&& t) noexcept;
|
||||
|
||||
@@ -139,6 +141,24 @@ This wrapper can be used to join the thread before destroying it seems a natural
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:call_constructor Move Constructor from a Callable]
|
||||
|
||||
template <typename F&&, typename ...Args>
|
||||
explicit strict_scoped_thread(F&&, Args&&...);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Construct a internal thread in place.]]
|
||||
|
||||
[[Postconditions:] [`*this.t_` refers to the newly created thread of execution and `this->get_id()!=thread::id()`.]]
|
||||
|
||||
[[Throws:] [Any exception the thread construction can throw.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:destructor Destructor]
|
||||
|
||||
~strict_scoped_thread();
|
||||
@@ -149,7 +169,6 @@ This wrapper can be used to join the thread before destroying it seems a natural
|
||||
|
||||
[[Throws:] [Nothing: The `CallableThread()(t_)` should not throw when joining the thread as the scoped variable is on a scope outside the thread function.]]
|
||||
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
@@ -160,6 +179,7 @@ This wrapper can be used to join the thread before destroying it seems a natural
|
||||
|
||||
#include <boost/thread/scoped_thread.hpp>
|
||||
|
||||
template <class CallableThread>
|
||||
class scoped_thread
|
||||
{
|
||||
thread t_; // for exposition purposes only
|
||||
@@ -169,6 +189,8 @@ This wrapper can be used to join the thread before destroying it seems a natural
|
||||
scoped_thread& operator=(const scoped_thread&) = delete;
|
||||
|
||||
explicit scoped_thread(thread&& th) noexcept;
|
||||
template <typename F&&, typename ...Args>
|
||||
explicit scoped_thread(F&&, Args&&...);
|
||||
|
||||
~scoped_thread();
|
||||
|
||||
@@ -194,6 +216,7 @@ This wrapper can be used to join the thread before destroying it seems a natural
|
||||
void detach();
|
||||
|
||||
static unsigned hardware_concurrency() noexcept;
|
||||
static unsigned physical_concurrency() noexcept;
|
||||
|
||||
typedef thread::native_handle_type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
@@ -298,6 +321,23 @@ any) to `*this`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:call_constructor Move Constructor from a Callable]
|
||||
|
||||
template <typename F&&, typename ...Args>
|
||||
explicit scoped_thread(F&&, Args&&...);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Construct a internal thread in place.]]
|
||||
|
||||
[[Postconditions:] [`*this.t_` refers to the newly created thread of execution and `this->get_id()!=thread::id()`.]]
|
||||
|
||||
[[Throws:] [Any exception the thread construction can throw.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:destructor Destructor]
|
||||
|
||||
@@ -419,6 +459,20 @@ any) to `*this`.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:physical_concurrency Static member function `physical_concurrency()`]
|
||||
|
||||
unsigned physical_concurrency() noexecpt;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Equivalent to return `thread::physical_concurrency()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:nativehandle Member function `native_handle()`]
|
||||
|
||||
typedef thread::native_handle_type native_handle_type;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:shared_mutex Class `shared_mutex` -- EXTENSION]
|
||||
[section:shared_mutex Class `shared_mutex` -- C++14]
|
||||
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
|
||||
@@ -36,18 +36,18 @@
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0
|
||||
// use upgrade_mutex instead.
|
||||
void lock_upgrade();
|
||||
void unlock_upgrade();
|
||||
void lock_upgrade(); // EXTENSION
|
||||
void unlock_upgrade(); // EXTENSION
|
||||
|
||||
void unlock_upgrade_and_lock();
|
||||
void unlock_and_lock_upgrade();
|
||||
void unlock_and_lock_shared();
|
||||
void unlock_upgrade_and_lock_shared();
|
||||
void unlock_upgrade_and_lock(); // EXTENSION
|
||||
void unlock_and_lock_upgrade(); // EXTENSION
|
||||
void unlock_and_lock_shared(); // EXTENSION
|
||||
void unlock_upgrade_and_lock_shared(); // EXTENSION
|
||||
#endif
|
||||
|
||||
#if defined BOOST_THREAD_USES_DATETIME
|
||||
bool timed_lock_shared(system_time const& timeout);
|
||||
bool timed_lock(system_time const& timeout);
|
||||
bool timed_lock_shared(system_time const& timeout); // DEPRECATED
|
||||
bool timed_lock(system_time const& timeout); // DEPRECATED
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
554
doc/sync_queues_ref.qbk
Normal file
554
doc/sync_queues_ref.qbk
Normal file
@@ -0,0 +1,554 @@
|
||||
[/
|
||||
/ Copyright (c) 2013 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:synchronized_queues Synchronized Queues -- EXPERIMENTAL]
|
||||
|
||||
[warning These features are experimental and subject to change in future versions. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
|
||||
|
||||
[note These features are based on the [@http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3533.html [*N3533 - C++ Concurrent Queues]] C++1y proposal from Lawrence Crowl and Chris Mysen and [@http://www.manning.com/williams/ [*C++ Concurrency in Action]] from Anthony Williams.]
|
||||
|
||||
|
||||
[section:tutorial Tutorial]
|
||||
|
||||
Concurrent queues are a well know mechanism for communicating data between different threads.
|
||||
|
||||
Concurrent queues have inherently copy/move semantics for the data handling operation. Reference-returning interfaces are forbidden as multiple access to these references can not be thread-safe.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:ref Reference]
|
||||
|
||||
[section:sync_queue_req Synchronized Queue Model]
|
||||
|
||||
[section:bounded_unbounded Bounded-Unbounded Queues]
|
||||
|
||||
One of the major features of a concurrent queue is whether it has a bounded-unbounded capacity.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:locking Locking/Lock-free Queues]
|
||||
|
||||
Locking queues can by nature block waiting for the queue to be non-empty or non-full.
|
||||
|
||||
Lock-free queues will have some trouble waiting for the queue to be non-empty or non-full queues. These queues can not define operations such as push (and pull for bounded queues). That is, it could have blocking operations (presumably emulated with busy wait) but not waiting operations.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:closed Closed Queue]
|
||||
|
||||
Threads using a queue for communication need some mechanism to signal when the queue is no longer needed. The usual approach is add an additional out-of-band signal. However, this approach suffers from the flaw that threads waiting on either full or empty queues need to be woken up when the queue is no longer needed. Rather than require an out-of-band signal, we chose to directly support such a signal in the queue itself, which considerably simplifies coding.
|
||||
|
||||
To achieve this signal, a thread may close a queue. Once closed, no new elements may be pushed onto the queue. Push operations on a closed queue will either return queue_op_status::closed (when they have a queue_op_status return type), set the closed parameter if it has one or throw sync_queue::closed (when they do not). Elements already on the queue may be pulled off. When a queue is empty and closed, pull operations will either return queue_op_status::closed (when they have a status return), set the closed parameter if it has one or throw sync_queue::closed (when they do not).
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:exception Concurrent Queues Throw specification]
|
||||
[section:locking Locking]
|
||||
|
||||
All the functions are defined as if we had in addition to its specific Throw specification the following:
|
||||
|
||||
[variablelist
|
||||
[[Throws:] [Any exception thrown by the internal locking.]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:bad_alloc Allocation]
|
||||
|
||||
All the functions that allocate a resource are defined as if we had in addition to its specific Throw specification the following:
|
||||
|
||||
[variablelist
|
||||
[[Throws:] [Any exception due to allocation errors.]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section:BasicConcurrentQueue Basic Concurrent Queue Operations]
|
||||
|
||||
The essential solution to the problem of concurrent queuing is to shift to value-based operations, rather than reference-based operations.
|
||||
|
||||
The BasicConcurrentQueue concept models the basic operations of a concurrent queue.
|
||||
|
||||
A type `Q` meets the BasicConcurrentQueue requirements if the following expressions are well-formed and have the specified semantics
|
||||
|
||||
* Q::value_type
|
||||
* Q::size_type
|
||||
* `q.push(e);`
|
||||
* `q.push(rve);`
|
||||
* `q.pull(lre);`
|
||||
* `lre = q.pull();`
|
||||
* `spe = q.ptr_pull();`
|
||||
* `b = q.empty();`
|
||||
* `u = q.size();`
|
||||
|
||||
where
|
||||
|
||||
* `q` denotes a value of type `Q`,
|
||||
* `e` denotes a value of type Q::value_type,
|
||||
* `u` denotes a value of type Q::size_type,
|
||||
* `lve` denotes a lvalue referece of type Q::value_type,
|
||||
* `rve` denotes a rvalue referece of type Q::value_type:
|
||||
* `spe` denotes a shared_ptr<Q::value_type>
|
||||
|
||||
|
||||
[section:push `q.push(e);`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Waits until the queue is not full (for bounded queues) and then push `e` to the queue copying it (this could need an allocation for unbounded queues).]]
|
||||
|
||||
[[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
|
||||
|
||||
[[Postcondition:] [`! q.empty()`.]]
|
||||
|
||||
[[Return type:] [`void`.]]
|
||||
|
||||
[[Throws:] [If the queue was closed, throws sync_queue_is_closed. Any exception thrown by the copy of `e`.]]
|
||||
|
||||
[[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:push_m `q.push(rve);`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Waits until the queue is not full (for bounded queues) and then push `e` to the queue moving it (this could need an allocation for unbounded queues).]]
|
||||
|
||||
[[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
|
||||
|
||||
[[Postcondition:] [`! q.empty()`.]]
|
||||
|
||||
[[Return type:] [`void`.]]
|
||||
|
||||
[[Throws:] [If the queue is closed, throws sync_queue_is_closed. Any exception thrown by the copy of `e`.]]
|
||||
|
||||
[[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:pull_lv `q.pull(lve)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Waits until the queue is not empty and then pull the element from the queue `q` and moves the pulled element into `lve` (this could need an allocation for unbounded queues).]]
|
||||
|
||||
[[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
|
||||
|
||||
[[Postcondition:] [`! q.full()`.]]
|
||||
|
||||
[[Return type:] [`void`.]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the move of `e`.]]
|
||||
|
||||
[[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:pull `e = q.pull()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [Q::value_type is no throw copy movable. This is needed to ensure the exception safety.]]
|
||||
|
||||
[[Effects:] [Waits until the queue is not empty and not closed. If the queue is empty and closed throws sync_queue_is_closed. Otherwise pull the element from the queue `q` and moves the pulled element.]]
|
||||
|
||||
[[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
|
||||
|
||||
[[Postcondition:] [`! q.full()`.]]
|
||||
|
||||
[[Return type:] [`Q::value_type`.]]
|
||||
|
||||
[[Return:] [The pulled element.]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the copy of `e`.]]
|
||||
|
||||
[[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:ptr_pull `spe = q.ptr_pull()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[/[Requires:] [Q::value_type is no throw copy movable. This is needed to ensure the exception safety. ]]
|
||||
|
||||
[[Effects:] [Waits until the queue is not empty and not closed. If the queue is empty and closed throws sync_queue_is_closed. Otherwise pull the element from the queue `q` and moves the pulled element into a shared_ptr.]]
|
||||
|
||||
[[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
|
||||
|
||||
[[Postcondition:] [`! q.full()`.]]
|
||||
|
||||
[[Return type:] [`Q::value_type`.]]
|
||||
|
||||
[[Return:] [A shared_ptr containing the pulled element.]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the move of `e`. Any exception throw when allocation resources are missing. ]]
|
||||
|
||||
[[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:non_waaiting Non-waiting Concurrent Queue Operations]
|
||||
|
||||
The ConcurrentQueue concept models a queue with .
|
||||
|
||||
|
||||
A type `Q` meets the ConcurrentQueue requirements if the following expressions are well-formed and have the specified semantics
|
||||
|
||||
* `b = q.try_push(e);`
|
||||
* `b = q.try_push(rve);`
|
||||
* `b = q.try_pull(lre);`
|
||||
|
||||
where
|
||||
|
||||
* `q` denotes a value of type `Q`,
|
||||
* `e` denotes a value of type Q::value_type,
|
||||
* `u` denotes a value of type Q::size_type,
|
||||
* `lve` denotes a lvalue referece of type Q::value_type,
|
||||
* `rve` denotes a rvalue referece of type Q::value_type:
|
||||
* `spe` denotes a shared_ptr<Q::value_type>
|
||||
|
||||
|
||||
[section:try_push `q.try_push(e);`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If the queue `q` is not full, push the `e` to the queue copying it.]]
|
||||
|
||||
[[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation when the operation succeeds. ]]
|
||||
|
||||
[[Return type:] [`bool`.]]
|
||||
|
||||
[[Return:] [If the queue `q` is full return `false`, otherwise return `true`;]]
|
||||
|
||||
[[Postcondition:] [If the call returns `true`, `! q.empty()`.]]
|
||||
|
||||
[[Throws:] [If the queue is closed, throws sync_queue_is_closed. Any exception thrown by the copy of `e`.]]
|
||||
|
||||
[[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:try_push_m `q.try_push(rve());`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [If the queue `q` is not full, push the `e` onto the queue moving it.]]
|
||||
|
||||
[[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
|
||||
|
||||
[[Return type:] [`bool`.]]
|
||||
|
||||
[[Return:] [If the queue `q` is full return `false`, otherwise return `true`;]]
|
||||
|
||||
[[Postcondition:] [If the call returns `true`, `! q.empty()`.]]
|
||||
|
||||
[[Throws:] [If the queue is closed, throws sync_queue_is_closed. Any exception thrown by the copy of `e`.]]
|
||||
|
||||
[[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:pull_lv `b = q.try_pull(lve)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Waits until the queue is not empty and then pull the element from the queue `q` and moves the pulled element into `lve` (this could need an allocation for unbounded queues).]]
|
||||
|
||||
[[Synchronization:] [Prior pull-like operations on the same object synchronizes with this operation.]]
|
||||
|
||||
[[Postcondition:] [`! q.full()`.]]
|
||||
|
||||
[[Return type:] [`bool`.]]
|
||||
|
||||
[[Return:] [If the queue `q` is full return `false`, otherwise return `true`;]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the move of `e`.]]
|
||||
|
||||
[[Exception safety:] [If an exception is thrown then the queue state is unmodified.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section:non_blocking Non-blocking Concurrent Queue Operations]
|
||||
|
||||
For cases when blocking for mutual exclusion is undesirable, we have non-blocking operations. The interface is the same as the try operations but is allowed to also return queue_op_status::busy in case the operation is unable to complete without blocking.
|
||||
|
||||
Non-blocking operations are provided only for BlockingQueues
|
||||
|
||||
* `b = q.try_push(nb, e);`
|
||||
* `b = q.try_push(nb, rve);`
|
||||
* `b = q.try_pull(nb, lre);`
|
||||
|
||||
|
||||
where
|
||||
|
||||
* `q` denotes a value of type `Q`,
|
||||
* `e` denotes a value of type Q::value_type,
|
||||
* `u` denotes a value of type Q::size_type,
|
||||
* `lve` denotes a lvalue referece of type Q::value_type,
|
||||
* `rve` denotes a rvalue referece of type Q::value_type:
|
||||
* `spe` denotes a shared_ptr<Q::value_type>
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:bounded Bounded Concurrent Queue Operations]
|
||||
|
||||
Bounded queues add the following valid expressions
|
||||
|
||||
* `Q q(u);`
|
||||
* `b = q.full();`
|
||||
* `u = q.capacity();`
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:closed_op Closed Concurrent Queue Operations]
|
||||
|
||||
|
||||
* `q.close();`
|
||||
* `b = q.closed();`
|
||||
|
||||
Basic expressions
|
||||
|
||||
* `q.push(e,c);`
|
||||
* `q.push(rve,c);`
|
||||
* `q.pull(lre,c);`
|
||||
* `spe = q.ptr_pull(c);`
|
||||
|
||||
Non-waiting operations
|
||||
|
||||
* `b = q.try_push(e, c);`
|
||||
* `b = q.try_push(rve, c);`
|
||||
* `b = q.try_pull(lre, c);`
|
||||
|
||||
Non-blocking operations are provided by BlockingQueues
|
||||
|
||||
* `b = q.try_push(nb, e, c);`
|
||||
* `b = q.try_push(nb, rve, c);`
|
||||
* `b = q.try_pull(nb, lre, c);`
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:sync_bounded_queue_ref Synchronized Bounded Queue]
|
||||
|
||||
#include <boost/thread/sync_bounded_queue.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
struct sync_queue_is_closed : std::exception {};
|
||||
|
||||
template <typename ValueType>
|
||||
class sync_bounded_queue;
|
||||
|
||||
// Stream-like operators
|
||||
template <typename ValueType>
|
||||
sync_bounded_queue<ValueType>& operator<<(sync_bounded_queue<ValueType>& sbq, ValueType&& elem);
|
||||
template <typename ValueType>
|
||||
sync_bounded_queue<ValueType>& operator<<(sync_bounded_queue<ValueType>& sbq, ValueType const&elem);
|
||||
template <typename ValueType>
|
||||
sync_bounded_queue<ValueType>& operator>>(sync_bounded_queue<ValueType>& sbq, ValueType &elem);
|
||||
}
|
||||
|
||||
[section:sync_queue_is_closed Class `sync_queue_is_closed`]
|
||||
|
||||
#include <boost/thread/sync_bounded_queue.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
struct sync_queue_is_closed : std::exception {};
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:sync_bounded_queue Class template `sync_bounded_queue<>`]
|
||||
|
||||
#include <boost/thread/sync_bounded_queue.hpp>
|
||||
namespace boost
|
||||
{
|
||||
template <typename ValueType>
|
||||
class sync_bounded_queue
|
||||
{
|
||||
public:
|
||||
typedef ValueType value_type;
|
||||
typedef std::size_t size_type;
|
||||
|
||||
sync_bounded_queue(sync_bounded_queue const&) = delete;
|
||||
sync_bounded_queue& operator=(sync_bounded_queue const&) = delete;
|
||||
explicit sync_bounded_queue(size_type max_elems);
|
||||
template <typename Range>
|
||||
sync_bounded_queue(size_type max_elems, Range range);
|
||||
~sync_bounded_queue();
|
||||
|
||||
// Observers
|
||||
bool empty() const;
|
||||
bool full() const;
|
||||
size_type capacity() const;
|
||||
size_type size() const;
|
||||
bool closed() const;
|
||||
|
||||
// Modifiers
|
||||
void push(const value_type& x);
|
||||
void push(value_type&& x);
|
||||
bool try_push(const value_type& x);
|
||||
bool try_push(value_type&& x);
|
||||
bool try_push(no_block_tag, const value_type& x);
|
||||
bool try_push(no_block_tag, value_type&& x);
|
||||
|
||||
void pull(value_type&);
|
||||
// enable_if is_nothrow_movable<value_type>
|
||||
value_type pull();
|
||||
shared_ptr<ValueType> ptr_pull();
|
||||
bool try_pull(value_type&);
|
||||
bool try_pull(no_block_tag,value_type&);
|
||||
shared_ptr<ValueType> try_pull();
|
||||
|
||||
void close();
|
||||
};
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:stream_out_operators Non-Member Function `operator<<()`]
|
||||
|
||||
#include <boost/thread/sync_bounded_queue.hpp>
|
||||
namespace boost
|
||||
{
|
||||
template <typename ValueType>
|
||||
sync_bounded_queue<ValueType>& operator<<(sync_bounded_queue<ValueType>& sbq, ValueType&& elem);
|
||||
template <typename ValueType>
|
||||
sync_bounded_queue<ValueType>& operator<<(sync_bounded_queue<ValueType>& sbq, ValueType const&elem);
|
||||
}
|
||||
|
||||
[endsect]
|
||||
[section:stream_in_operators Non-Member Function `operator>>()`]
|
||||
|
||||
#include <boost/thread/sync_bounded_queue.hpp>
|
||||
namespace boost
|
||||
{
|
||||
template <typename ValueType>
|
||||
sync_bounded_queue<ValueType>& operator>>(sync_bounded_queue<ValueType>& sbq, ValueType &elem);
|
||||
}
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section:sync_queue_ref Synchronized Unbounded Queue]
|
||||
|
||||
#include <boost/thread/sync_queue.hpp>
|
||||
namespace boost
|
||||
{
|
||||
template <typename ValueType>
|
||||
class sync_queue;
|
||||
|
||||
// Stream-like operators
|
||||
template <typename ValueType>
|
||||
sync_queue<ValueType>& operator<<(sync_queue<ValueType>& sbq, ValueType&& elem);
|
||||
template <typename ValueType>
|
||||
sync_queue<ValueType>& operator<<(sync_queue<ValueType>& sbq, ValueType const&elem);
|
||||
template <typename ValueType>
|
||||
sync_queue<ValueType>& operator>>(sync_queue<ValueType>& sbq, ValueType &elem);
|
||||
}
|
||||
|
||||
[section:sync_queue Class template `sync_queue<>`]
|
||||
|
||||
#include <boost/thread/sync_queue.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template <typename ValueType>
|
||||
class sync_queue
|
||||
{
|
||||
public:
|
||||
typedef ValueType value_type;
|
||||
typedef std::size_t size_type;
|
||||
|
||||
sync_queue(sync_queue const&) = delete;
|
||||
sync_queue& operator=(sync_queue const&) = delete;
|
||||
sync_queue();
|
||||
explicit template <typename Range>
|
||||
sync_queue(Range range);
|
||||
~sync_queue();
|
||||
|
||||
// Observers
|
||||
bool empty() const;
|
||||
bool full() const;
|
||||
size_type size() const;
|
||||
bool closed() const;
|
||||
|
||||
// Modifiers
|
||||
void push(const value_type& x);
|
||||
void push(value_type&& x);
|
||||
bool try_push(const value_type& x);
|
||||
bool try_push(value_type&&) x);
|
||||
bool try_push(no_block_tag, const value_type& x);
|
||||
bool try_push(no_block_tag, value_type&& x);
|
||||
|
||||
void pull(value_type&);
|
||||
// enable_if is_nothrow_movable<value_type>
|
||||
value_type pull();
|
||||
shared_ptr<ValueType> ptr_pull();
|
||||
bool try_pull(value_type&);
|
||||
bool try_pull(no_block_tag,value_type&);
|
||||
shared_ptr<ValueType> try_pull();
|
||||
|
||||
void close();
|
||||
};
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:stream_out_operators Non-Member Function `operator<<()`]
|
||||
|
||||
#include <boost/thread/sync_queue.hpp>
|
||||
namespace boost
|
||||
{
|
||||
template <typename ValueType>
|
||||
sync_queue<ValueType>& operator<<(sync_queue<ValueType>& sbq, ValueType&& elem);
|
||||
template <typename ValueType>
|
||||
sync_queue<ValueType>& operator<<(sync_queue<ValueType>& sbq, ValueType const&elem);
|
||||
}
|
||||
|
||||
[endsect]
|
||||
[section:stream_in_operators Non-Member Function `operator>>()`]
|
||||
|
||||
#include <boost/thread/sync_queue.hpp>
|
||||
namespace boost
|
||||
{
|
||||
template <typename ValueType>
|
||||
sync_queue<ValueType>& operator>>(sync_queue<ValueType>& sbq, ValueType &elem);
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
193
doc/sync_streams.qbk
Normal file
193
doc/sync_streams.qbk
Normal file
@@ -0,0 +1,193 @@
|
||||
[/
|
||||
/ Copyright (c) 2013 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:ext_locked_streams Externally Locked Streams - EXPERIMENTAL]
|
||||
|
||||
[warning These features are experimental and subject to change in future versions. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
|
||||
|
||||
[note These features are based on the [@http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3535.html [*N3535 - C++ Streams Mutex]] C++1y proposal, even if the library proposes al alternative interface.]
|
||||
|
||||
[section:tutorial Tutorial]
|
||||
|
||||
[endsect] [/tutorial]
|
||||
|
||||
[/////////////////////]
|
||||
[section:ref Reference]
|
||||
|
||||
#include <boost/thread/externally_locked_stream.hpp>
|
||||
namespace boost
|
||||
{
|
||||
template <typename Stream, typename RecursiveMutex=recursive_mutex>
|
||||
class externally_locked_stream;
|
||||
template <class Stream, typename RecursiveMutex=recursive_mutex>
|
||||
class stream_guard;
|
||||
template <typename Stream, typename RecursiveMutex>
|
||||
struct is_strict_lock_sur_parole<stream_guard<Stream, RecursiveMutex> > : true_type {};
|
||||
|
||||
// Stream-like operators
|
||||
template <typename Stream, typename RecursiveMutex, typename T>
|
||||
const stream_guard<Stream, RecursiveMutex>& operator<<(const stream_guard<Stream, RecursiveMutex>& lck, T arg);
|
||||
template <typename Stream, typename RecursiveMutex>
|
||||
const stream_guard<Stream, RecursiveMutex>&
|
||||
operator<<(const stream_guard<Stream, RecursiveMutex>& lck, Stream& (*arg)(Stream&));
|
||||
template <typename Stream, typename RecursiveMutex, typename T>
|
||||
const stream_guard<Stream, RecursiveMutex>&
|
||||
operator>>(const stream_guard<Stream, RecursiveMutex>& lck, T& arg);
|
||||
template <typename Stream, typename RecursiveMutex, typename T>
|
||||
stream_guard<Stream, RecursiveMutex>
|
||||
operator<<(externally_locked_stream<Stream, RecursiveMutex>& mtx, T arg);
|
||||
template <typename Stream, typename RecursiveMutex>
|
||||
stream_guard<Stream, RecursiveMutex>
|
||||
operator<<(externally_locked_stream<Stream, RecursiveMutex>& mtx, Stream& (*arg)(Stream&));
|
||||
template <typename Stream, typename RecursiveMutex, typename T>
|
||||
stream_guard<Stream, RecursiveMutex>
|
||||
operator>>(externally_locked_stream<Stream, RecursiveMutex>& mtx, T& arg);
|
||||
}
|
||||
|
||||
[/////////////////////////////////////////]
|
||||
[section:stream_guard Class `stream_guard`]
|
||||
|
||||
#include <boost/thread/externally_locked_stream.hpp>
|
||||
namespace boost
|
||||
{
|
||||
template <class Stream, typename RecursiveMutex=recursive_mutex>
|
||||
class stream_guard
|
||||
{
|
||||
public:
|
||||
typedef typename externally_locked_stream<Stream, RecursiveMutex>::mutex_type mutex_type;
|
||||
|
||||
// Constructors, Assignment and Destructors
|
||||
stream_guard(stream_guard const&) = delete;
|
||||
stream_guard& operator=(stream_guard const&) = delete;
|
||||
stream_guard(externally_locked_stream<Stream, RecursiveMutex>& mtx);
|
||||
stream_guard(externally_locked_stream<Stream, RecursiveMutex>& mtx, adopt_lock_t);
|
||||
stream_guard(stream_guard&& rhs);
|
||||
~stream_guard();
|
||||
|
||||
// Observers
|
||||
bool owns_lock(mutex_type const* l) const BOOST_NOEXCEPT;
|
||||
Stream& get() const;
|
||||
Stream& bypass() const;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
`stream_guard` is a model of __StrictLock.
|
||||
|
||||
[//////////////////////////////////////////////////]
|
||||
[section:constructor `stream_guard(mutex_type & m)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Stores a reference to `m`. Invokes [lock_ref_link `m.lock()`].]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the call to [lock_ref_link `m.lock()`].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[////////////////////////////////////////////////////////////////////////////]
|
||||
[section:constructor_adopt `stream_guard(mutex_type & m,boost::adopt_lock_t)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Precondition:] [The current thread owns a lock on `m` equivalent to one
|
||||
obtained by a call to [lock_ref_link `m.lock()`].]]
|
||||
|
||||
[[Effects:] [Stores a reference to `m`. Takes ownership of the lock state of
|
||||
`m`.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[//////////////////////////////////////////////////////////]
|
||||
[section:move_constructor `stream_guard(stream_guard && m)`]
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Stores a reference to `m`. Invokes [lock_ref_link `m.lock()`].]]
|
||||
|
||||
[[Throws:] [Any exception thrown by the call to [lock_ref_link `m.lock()`].]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[////////////////////////////////////]
|
||||
[section:destructor `~stream_guard()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Invokes [unlock_ref_link `m.unlock()`] on the __lockable_concept_type__
|
||||
object passed to the constructor.]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
[//////////////////////////////////////////////////////////////////]
|
||||
[section:externally_locked_stream Class `externally_locked_stream `]
|
||||
|
||||
#include <boost/thread/externally_locked_stream.hpp>
|
||||
namespace boost
|
||||
{
|
||||
template <typename Stream, typename RecursiveMutex>
|
||||
class externally_locked_stream: public externally_locked<Stream&, RecursiveMutex>
|
||||
{
|
||||
public:
|
||||
// Constructors, Assignment and Destructors
|
||||
externally_locked_stream(externally_locked_stream const&) = delete;
|
||||
externally_locked_stream& operator=(externally_locked_stream const&) = delete;
|
||||
externally_locked_stream(Stream& stream, RecursiveMutex& mtx);
|
||||
|
||||
// Modifiers
|
||||
stream_guard<Stream, RecursiveMutex> hold();
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
`externally_locked_stream` cloaks a reference to an stream of type `Stream`, and actually
|
||||
provides full access to that object through the `get` member functions, provided you
|
||||
pass a reference to a strict lock object.
|
||||
|
||||
|
||||
[////////////////////////////////////////////////////////////////////////]
|
||||
[section:constructor `externally_locked_stream(Stream&, RecursiveMutex&)`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Effects:] [Constructs an externally locked object storing the cloaked reference object and its locking mutex.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[/////////////////////]
|
||||
[section:hold `hold()`]
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [A stream_guard which will hold the mutex during it lifetime .]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[endsect] [/ref]
|
||||
|
||||
[endsect] [/Externally Locked Streams]
|
||||
@@ -23,16 +23,16 @@ In addition to the C++11 standard locks, Boost.Thread provides other locks and s
|
||||
In particular, the library provides some lock factories.
|
||||
|
||||
template <class Lockable, class Function>
|
||||
auto with_lock_guard(Lockable& m, Function f) -> decltype(fn())
|
||||
auto with_lock_guard(Lockable& m, Function f) -> decltype(f())
|
||||
{
|
||||
auto&& _ = boost::make_lock_guard(f);
|
||||
auto&& _ = boost::make_lock_guard(m);
|
||||
f();
|
||||
}
|
||||
|
||||
|
||||
that can be used as
|
||||
|
||||
int i = with_lock_guard(mtx, {}() -> bool
|
||||
int i = with_lock_guard(mtx, []()
|
||||
{
|
||||
// access the protected state
|
||||
return true;
|
||||
|
||||
147
doc/synchronized_value.qbk
Normal file
147
doc/synchronized_value.qbk
Normal file
@@ -0,0 +1,147 @@
|
||||
[/
|
||||
/ Copyright (c) 2013 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:synchronized_valuesxxx Synchronized Values - EXPERIMENTAL]
|
||||
|
||||
[warning These features are experimental and subject to change in future versions. There are not too much tests yet, so it is possible that you can find out some trivial bugs :(]
|
||||
|
||||
[section:tutorial Tutorial]
|
||||
|
||||
|
||||
[note This tutorial is an adaptation of the paper of Anthony Williams "Enforcing Correct Mutex Usage with Synchronized Values" to the Boost library.]
|
||||
|
||||
[section The Problem with Mutexes]
|
||||
|
||||
The key problem with protecting shared data with a mutex is that there is no easy way to associate the mutex with the data. It is thus relatively easy to accidentally write code that fails to lock the right mutex - or even locks the wrong mutex - and the compiler will not help you.
|
||||
|
||||
|
||||
std::mutex m1;
|
||||
int value1;
|
||||
std::mutex m2;
|
||||
int value2;
|
||||
|
||||
int readValue1()
|
||||
{
|
||||
boost::lock_guard<boost::mutex> lk(m1);
|
||||
return value1;
|
||||
}
|
||||
int readValue2()
|
||||
{
|
||||
boost::lock_guard<boost::mutex> lk(m1); // oops: wrong mutex
|
||||
return value2;
|
||||
}
|
||||
|
||||
Moreover, managing the mutex lock also clutters the source code, making it harder to see what is really going on.
|
||||
|
||||
The use of synchronized_value solves both these problems - the mutex is intimately tied to the value, so you cannot access it without a lock, and yet access semantics are still straightforward. For simple accesses, synchronized_value behaves like a pointer-to-T; for example:
|
||||
|
||||
|
||||
boost::synchronized_value<std::string> value3;
|
||||
std::string readValue3()
|
||||
{
|
||||
return *value3;
|
||||
}
|
||||
void setValue3(std::string const& newVal)
|
||||
{
|
||||
*value3=newVal;
|
||||
}
|
||||
void appendToValue3(std::string const& extra)
|
||||
{
|
||||
value3->append(extra);
|
||||
}
|
||||
|
||||
Both forms of pointer dereference return a proxy object rather than a real reference, to ensure that the lock on the mutex is held across the assignment or method call, but this is transparent to the user.
|
||||
|
||||
[endsect] [/The Problem with Mutexes]
|
||||
|
||||
[section Beyond Simple Accesses]
|
||||
|
||||
The pointer-like semantics work very well for simple accesses such as assignment and calls to member functions. However, sometimes you need to perform an operation that requires multiple accesses under protection of the same lock, and that's what the synchronize() method provides.
|
||||
|
||||
By calling synchronize() you obtain an strict_lock_ptr object that holds a lock on the mutex protecting the data, and which can be used to access the protected data. The lock is held until the strict_lock_ptr object is destroyed, so you can safely perform multi-part operations. The strict_lock_ptr object also acts as a pointer-to-T, just like synchronized_value does, but this time the lock is already held. For example, the following function adds a trailing slash to a path held in a synchronized_value. The use of the strict_lock_ptr object ensures that the string hasn't changed in between the query and the update.
|
||||
|
||||
void addTrailingSlashIfMissing(boost::synchronized_value<std::string> & path)
|
||||
{
|
||||
boost::strict_lock_ptr<std::string> u=path.synchronize();
|
||||
|
||||
if(u->empty() || (*u->rbegin()!='/'))
|
||||
{
|
||||
*u+='/';
|
||||
}
|
||||
}
|
||||
|
||||
[endsect] [/Beyond Simple Accesses]
|
||||
|
||||
[section Operations Across Multiple Objects]
|
||||
|
||||
Though synchronized_value works very well for protecting a single object of type T, nothing that we've seen so far solves the problem of operations that require atomic access to multiple objects unless those objects can be combined within a single structure protected by a single mutex.
|
||||
|
||||
One way to protect access to two synchronized_value objects is to construct a strict_lock_ptr for each object and use those to access the respective protected values; for instance:
|
||||
|
||||
synchronized_value<std::queue<MessageType> > q1,q2;
|
||||
void transferMessage()
|
||||
{
|
||||
strict_lock_ptr<std::queue<MessageType> > u1 = q1.synchronize();
|
||||
strict_lock_ptr<std::queue<MessageType> > u2 = q2.synchronize();
|
||||
|
||||
if(!u1->empty())
|
||||
{
|
||||
u2->push_back(u1->front());
|
||||
u1->pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
This works well in some scenarios, but not all -- if the same two objects are updated together in different sections of code then you need to take care to ensure that the strict_lock_ptr objects are constructed in the same sequence in all cases, otherwise you have the potential for deadlock. This is just the same as when acquiring any two mutexes.
|
||||
|
||||
In order to be able to use the dead-lock free lock algorithms we need to use instead unique_lock_ptr, which is Lockable.
|
||||
|
||||
synchronized_value<std::queue<MessageType> > q1,q2;
|
||||
void transferMessage()
|
||||
{
|
||||
unique_lock_ptr<std::queue<MessageType> > u1 = q1.unique_synchronize(boost::defer_lock);
|
||||
unique_lock_ptr<std::queue<MessageType> > u2 = q2.unique_synchronize(boost::defer_lock);
|
||||
boost::lock(u1,u2); // dead-lock free algorithm
|
||||
|
||||
if(!u1->empty())
|
||||
{
|
||||
u2->push_back(u1->front());
|
||||
u1->pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
While the preceding takes care of dead-lock, the access to the synchronized_value via unique_lock_ptr requires a lock that is not forced by the interface.
|
||||
An alternative on compilers providing a standard library that supports movable std::tuple is to use the free synchronize function, which will lock all the mutexes associated to the synchronized values and return a tuple os strict_lock_ptr.
|
||||
|
||||
synchronized_value<std::queue<MessageType> > q1,q2;
|
||||
void transferMessage()
|
||||
{
|
||||
auto lks = synchronize(u1,u2); // dead-lock free algorithm
|
||||
|
||||
if(!std::get<1>(lks)->empty())
|
||||
{
|
||||
std::get<2>(lks)->push_back(u1->front());
|
||||
std::get<1>(lks)->pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[endsect] [/Operations Across Multiple Objects]
|
||||
|
||||
[section Value semantics]
|
||||
|
||||
synchronized_value has value semantics even if the syntax lets is close to a pointer (this is just because we are unable to define smart references).
|
||||
|
||||
[endsect] [/Value semantics]
|
||||
|
||||
|
||||
[endsect] [/tutorial]
|
||||
|
||||
[include synchronized_value_ref.qbk]
|
||||
|
||||
[endsect] [/Synchronized values]
|
||||
|
||||
415
doc/synchronized_value_ref.qbk
Normal file
415
doc/synchronized_value_ref.qbk
Normal file
@@ -0,0 +1,415 @@
|
||||
[/
|
||||
/ Copyright (c) 2013 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:synchronized_value_ref Reference ]
|
||||
|
||||
|
||||
#include <boost/thread/synchronized_value.hpp>
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template<typename T, typename Lockable = mutex>
|
||||
class synchronized_value;
|
||||
|
||||
// Specialized swap algorithm
|
||||
template <typename T, typename L>
|
||||
void swap(synchronized_value<T,L> & lhs, synchronized_value<T,L> & rhs);
|
||||
template <typename T, typename L>
|
||||
void swap(synchronized_value<T,L> & lhs, T & rhs);
|
||||
template <typename T, typename L>
|
||||
void swap(T & lhs, synchronized_value<T,L> & rhs);
|
||||
|
||||
// Hash support
|
||||
template<typename T, typename L>
|
||||
struct hash<synchronized_value<T,L> >;
|
||||
|
||||
// Comparison
|
||||
template <typename T, typename L>
|
||||
bool operator==(synchronized_value<T,L> const&lhs, synchronized_value<T,L> const& rhs)
|
||||
template <typename T, typename L>
|
||||
bool operator!=(synchronized_value<T,L> const&lhs, synchronized_value<T,L> const& rhs)
|
||||
template <typename T, typename L>
|
||||
bool operator<(synchronized_value<T,L> const&lhs, synchronized_value<T,L> const& rhs)
|
||||
template <typename T, typename L>
|
||||
bool operator<=(synchronized_value<T,L> const&lhs, synchronized_value<T,L> const& rhs)
|
||||
template <typename T, typename L>
|
||||
bool operator>(synchronized_value<T,L> const&lhs, synchronized_value<T,L> const& rhs)
|
||||
template <typename T, typename L>
|
||||
bool operator>=(synchronized_value<T,L> const&lhs, synchronized_value<T,L> const& rhs)
|
||||
|
||||
// Comparison with T
|
||||
template <typename T, typename L>
|
||||
bool operator==(T const& lhs, synchronized_value<T,L> const&rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator!=(T const& lhs, synchronized_value<T,L> const&rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator<(T const& lhs, synchronized_value<T,L> const&rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator<=(T const& lhs, synchronized_value<T,L> const&rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator>(T const& lhs, synchronized_value<T,L> const&rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator>=(T const& lhs, synchronized_value<T,L> const&rhs);
|
||||
|
||||
template <typename T, typename L>
|
||||
bool operator==(synchronized_value<T,L> const& lhs, T const& rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator!=(synchronized_value<T,L> const& lhs, T const& rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator<(synchronized_value<T,L> const& lhs, T const& rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator<=(synchronized_value<T,L> const& lhs, T const& rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator>(synchronized_value<T,L> const& lhs, T const& rhs);
|
||||
template <typename T, typename L>
|
||||
bool operator>=(synchronized_value<T,L> const& lhs, T const& rhs);
|
||||
|
||||
#if ! defined(BOOST_THREAD_NO_SYNCHRONIZE)
|
||||
template <typename ...SV>
|
||||
std::tuple<typename synchronized_value_strict_lock_ptr<SV>::type ...> synchronize(SV& ...sv);
|
||||
#endif
|
||||
}
|
||||
|
||||
[section:synchronized_value Class `synchronized_value`]
|
||||
|
||||
#include <boost/thread/synchronized_value.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template<typename T, typename Lockable = mutex>
|
||||
class synchronized_value
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef Lockable mutex_type;
|
||||
|
||||
synchronized_value() noexept(is_nothrow_default_constructible<T>::value);
|
||||
synchronized_value(T const& other) noexept(is_nothrow_copy_constructible<T>::value);
|
||||
synchronized_value(T&& other) noexept(is_nothrow_move_constructible<T>::value);
|
||||
synchronized_value(synchronized_value const& rhs);
|
||||
synchronized_value(synchronized_value&& other);
|
||||
|
||||
// mutation
|
||||
synchronized_value& operator=(synchronized_value const& rhs);
|
||||
synchronized_value& operator=(value_type const& val);
|
||||
void swap(synchronized_value & rhs);
|
||||
void swap(value_type & rhs);
|
||||
|
||||
//observers
|
||||
T get() const;
|
||||
#if ! defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
explicit operator T() const;
|
||||
#endif
|
||||
|
||||
strict_lock_ptr<T,Lockable> operator->();
|
||||
const_strict_lock_ptr<T,Lockable> operator->() const;
|
||||
strict_lock_ptr<T,Lockable> synchronize();
|
||||
const_strict_lock_ptr<T,Lockable> synchronize() const;
|
||||
|
||||
deref_value operator*();;
|
||||
const_deref_value operator*() const;
|
||||
|
||||
private:
|
||||
T value_; // for exposition only
|
||||
mutable mutex_type mtx_; // for exposition only
|
||||
};
|
||||
}
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`Lockable` is `Lockable`.]]
|
||||
|
||||
]
|
||||
|
||||
|
||||
[section:constructor `synchronized_value()`]
|
||||
|
||||
synchronized_value() noexept(is_nothrow_default_constructible<T>::value);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `DefaultConstructible`.]]
|
||||
[[Effects:] [Default constructs the cloaked value_type]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:constructor_vt `synchronized_value(T const&)`]
|
||||
|
||||
synchronized_value(T const& other) noexept(is_nothrow_copy_constructible<T>::value);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `CopyConstructible`.]]
|
||||
[[Effects:] [Copy constructs the cloaked value_type using the parameter `other`]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type(other)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:copy_cons `synchronized_value(synchronized_value const&)`]
|
||||
|
||||
synchronized_value(synchronized_value const& rhs);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `DefaultConstructible` and `Assignable`.]]
|
||||
[[Effects:] [Assigns the value on a scope protected by the mutex of the rhs. The mutex is not copied.]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type()` or `value_type& operator=(value_type&)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move_vt `synchronized_value(T&&)`]
|
||||
|
||||
synchronized_value(T&& other) noexept(is_nothrow_move_constructible<T>::value);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `CopyMovable `.]]
|
||||
[[Effects:] [Move constructs the cloaked value_type]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type(value_type&&)`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:move `synchronized_value(synchronized_value&&)`]
|
||||
|
||||
synchronized_value(synchronized_value&& other);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `CopyMovable `.]]
|
||||
[[Effects:] [Move constructs the cloaked value_type]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type(value_type&&)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:assign `operator=(synchronized_value const&)`]
|
||||
|
||||
synchronized_value& operator=(synchronized_value const& rhs);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `Assignale`.]]
|
||||
[[Effects:] [Copies the underlying value on a scope protected by the two mutexes. The mutex is not copied. The locks are acquired avoiding deadlock. For example, there is no problem if one thread assigns `a = b` and the other assigns `b = a`.]]
|
||||
[[Return:] [`*this`]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type& operator(value_type const&)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:assign_vt `operator=(T const&)`]
|
||||
|
||||
synchronized_value& operator=(value_type const& val);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `Assignale`.]]
|
||||
[[Effects:] [Copies the value on a scope protected by the mutex.]]
|
||||
[[Return:] [`*this`]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type& operator(value_type const&)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:get `get() const`]
|
||||
|
||||
T get() const;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `CopyConstructible`.]]
|
||||
[[Return:] [`A copy of the protected value obtained on a scope protected by the mutex.`]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type(value_type const&)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:T `operator T() const`]
|
||||
|
||||
#if ! defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
explicit operator T() const;
|
||||
#endif
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `CopyConstructible`.]]
|
||||
[[Return:] [`A copy of the protected value obtained on a scope protected by the mutex.`]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `value_type(value_type const&)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:swap `swap(synchronized_value&)`]
|
||||
|
||||
void swap(synchronized_value & rhs);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `Assignale`.]]
|
||||
[[Effects:] [Swaps the data on a scope protected by both mutex. Both mutex are acquired to avoid dead-lock. The mutexes are not swapped.]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `swap(value_, rhs.value)` or `mtx_.lock()` or `rhs_.mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:swap_vt `swap(synchronized_value&)`]
|
||||
|
||||
void swap(value_type & rhs);
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`T` is `Swapable`.]]
|
||||
[[Effects:] [Swaps the data on a scope protected by both mutex. Both mutex are acquired to avoid dead-lock. The mutexes are not swapped.]]
|
||||
|
||||
[[Throws:] [Any exception thrown by `swap(value_, rhs)` or `mtx_.lock()`.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:indir `operator->()`]
|
||||
|
||||
strict_lock_ptr<T,Lockable> operator->();
|
||||
|
||||
|
||||
Essentially calling a method `obj->foo(x, y, z)` calls the method `foo(x, y, z)` inside a critical section as long-lived as the call itself.
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [`A strict_lock_ptr<>.`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:indir_const `operator->() const`]
|
||||
|
||||
const_strict_lock_ptr<T,Lockable> operator->() const;
|
||||
|
||||
|
||||
If the `synchronized_value` object involved is const-qualified, then you'll only be able to call const methods
|
||||
through `operator->`. So, for example, `vec->push_back("xyz")` won't work if `vec` were const-qualified.
|
||||
The locking mechanism capitalizes on the assumption that const methods don't modify their underlying data.
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [`A const_strict_lock_ptr <>.`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:synchronize `synchronize()`]
|
||||
|
||||
strict_lock_ptr<T,Lockable> synchronize();
|
||||
|
||||
The synchronize() factory make easier to lock on a scope. As discussed, `operator->` can only lock over the duration of a call, so it is insufficient for complex operations. With `synchronize()` you get to lock the object in a scoped and to directly access the object inside that scope.
|
||||
|
||||
[*Example:]
|
||||
|
||||
void fun(synchronized_value<vector<int>> & vec) {
|
||||
auto vec2=vec.synchronize();
|
||||
vec2.push_back(42);
|
||||
assert(vec2.back() == 42);
|
||||
}
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [`A strict_lock_ptr <>.`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:synchronize_const `synchronize() const`]
|
||||
|
||||
const_strict_lock_ptr<T,Lockable> synchronize() const;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [`A const_strict_lock_ptr <>.`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:deref `operator*()`]
|
||||
|
||||
deref_value operator*();;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [`A an instance of a class that locks the mutex on construction and unlocks it on destruction and provides implicit conversion to a reference to the protected value.`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[section:deref_const `operator*() const`]
|
||||
|
||||
const_deref_value operator*() const;
|
||||
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Return:] [`A an instance of a class that locks the mutex on construction and unlocks it on destruction and provides implicit conversion to a constant reference to the protected value.`]]
|
||||
|
||||
[[Throws:] [Nothing.]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
|
||||
[endsect]
|
||||
[section:synchronize Non-Member Function `synchronize`]
|
||||
|
||||
#include <boost/thread/synchronized_value.hpp>
|
||||
namespace boost
|
||||
{
|
||||
#if ! defined(BOOST_THREAD_NO_SYNCHRONIZE)
|
||||
template <typename ...SV>
|
||||
std::tuple<typename synchronized_value_strict_lock_ptr<SV>::type ...> synchronize(SV& ...sv);
|
||||
#endif
|
||||
}
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
[library Thread
|
||||
[quickbook 1.5]
|
||||
[version 4.0.0]
|
||||
[version 4.2.0]
|
||||
[authors [Williams, Anthony] [Botet Escriba, Vicente J.]]
|
||||
[copyright 2007-11 Anthony Williams]
|
||||
[copyright 2011-12 Vicente J. Botet Escriba]
|
||||
[copyright 2011-13 Vicente J. Botet Escriba]
|
||||
[purpose C++ Library for launching threads and synchronizing data between them]
|
||||
[category text]
|
||||
[license
|
||||
@@ -203,6 +203,7 @@
|
||||
[def __thread_resource_error__ `boost::thread_resource_error`]
|
||||
[def __thread_interrupted__ `boost::thread_interrupted`]
|
||||
[def __barrier__ [link thread.synchronization.barriers.barrier `boost::barrier`]]
|
||||
[def __latch__ [link thread.synchronization.latches.latch `latch`]]
|
||||
|
||||
[template cond_wait_link[link_text] [link thread.synchronization.condvar_ref.condition_variable.wait [link_text]]]
|
||||
[def __cond_wait__ [cond_wait_link `wait()`]]
|
||||
@@ -238,11 +239,20 @@
|
||||
[include condition_variables.qbk]
|
||||
[include once.qbk]
|
||||
[include barrier.qbk]
|
||||
[/include latch.qbk]
|
||||
[include futures.qbk]
|
||||
[/include async_executors.qbk]
|
||||
[endsect]
|
||||
|
||||
|
||||
[include tss.qbk]
|
||||
|
||||
[section:sds Synchronized Data Structures]
|
||||
[include synchronized_value.qbk]
|
||||
[include sync_queues_ref.qbk]
|
||||
[/include sync_streams.qbk]
|
||||
[endsect]
|
||||
|
||||
[include time.qbk]
|
||||
|
||||
[include emulations.qbk]
|
||||
|
||||
@@ -201,7 +201,7 @@ __thread_interrupted__, `std::terminate()` is called.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:detac Detaching thread]
|
||||
[section:detach Detaching thread]
|
||||
|
||||
A thread can be detached by explicitly invoking the __detach__ member function on the __thread__
|
||||
object. In this case, the __thread__ object ceases to represent the now-detached thread, and instead represents __not_a_thread__.
|
||||
@@ -470,6 +470,7 @@ This behavior is incompatible with the current Boost.Thread design, so the use o
|
||||
void detach();
|
||||
|
||||
static unsigned hardware_concurrency() noexcept;
|
||||
static unsigned physical_concurrency() noexcept;
|
||||
|
||||
typedef platform-specific-type native_handle_type;
|
||||
native_handle_type native_handle();
|
||||
@@ -568,7 +569,7 @@ any) to `*this`.
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Requires:] [`Callable` must by Copyable and `func()` must be a valid expression.]]
|
||||
[[Requires:] [`Callable` must be Copyable and `func()` must be a valid expression.]]
|
||||
|
||||
[[Effects:] [`func` is copied into storage managed internally by the thread library, and that copy is invoked on a newly-created
|
||||
thread of execution. If this invocation results in an exception being propagated into the internals of the thread library that is
|
||||
@@ -595,7 +596,7 @@ not of type __thread_interrupted__, then `std::terminate()` will be called. Any
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Preconditions:] [`Callable` must by copyable.]]
|
||||
[[Preconditions:] [`Callable` must be copyable.]]
|
||||
|
||||
[[Effects:] [`func` is copied into storage managed internally by the thread library, and that copy is invoked on a newly-created
|
||||
thread of execution with the specified attributes. If this invocation results in an exception being propagated into the internals of the thread library that is
|
||||
@@ -623,7 +624,7 @@ If the attributes declare the native thread as detached, the boost::thread will
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Preconditions:] [`Callable` must by Movable.]]
|
||||
[[Preconditions:] [`Callable` must be Movable.]]
|
||||
|
||||
[[Effects:] [`func` is moved into storage managed internally by the thread library, and that copy is invoked on a newly-created
|
||||
thread of execution. If this invocation results in an exception being propagated into the internals of the thread library that is
|
||||
@@ -650,7 +651,7 @@ not of type __thread_interrupted__, then `std::terminate()` will be called. Any
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Preconditions:] [`Callable` must by copyable.]]
|
||||
[[Preconditions:] [`Callable` must be copyable.]]
|
||||
|
||||
[[Effects:] [`func` is copied into storage managed internally by the thread library, and that copy is invoked on a newly-created
|
||||
thread of execution with the specified attributes. If this invocation results in an exception being propagated into the internals of the thread library that is
|
||||
@@ -679,7 +680,7 @@ If the attributes declare the native thread as detached, the boost::thread will
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Preconditions:] [`F` and each `A`n must by copyable or movable.]]
|
||||
[[Preconditions:] [`F` and each `A`n must be copyable or movable.]]
|
||||
|
||||
[[Effects:] [As if [link
|
||||
thread.thread_management.thread.callable_constructor
|
||||
@@ -991,6 +992,21 @@ or 0 if this information is not available.]]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:physical_concurrency Static member function `physical_concurrency()`]
|
||||
|
||||
unsigned physical_concurrency() noexecpt;
|
||||
|
||||
[variablelist
|
||||
|
||||
[[Returns:] [The number of physical cores available on the current system. In contrast to `hardware_concurrency()` it does not return
|
||||
the number of virtual cores, but it counts only physical cores.]]
|
||||
|
||||
[[Throws:] [Nothing]]
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:nativehandle Member function `native_handle()`]
|
||||
|
||||
typedef platform-specific-type native_handle_type;
|
||||
@@ -1708,7 +1724,6 @@ registered with `at_thread_exit()`]]
|
||||
[section:threadgroup Class `thread_group` EXTENSION]
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_group.hpp>
|
||||
|
||||
class thread_group
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <vector>
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include "../test/remove_error_code_unused_warning.hpp"
|
||||
|
||||
class bounded_buffer : private boost::noncopyable
|
||||
@@ -16,7 +16,7 @@ class bounded_buffer : private boost::noncopyable
|
||||
public:
|
||||
typedef boost::unique_lock<boost::mutex> lock;
|
||||
|
||||
bounded_buffer(int n) : begin(0), end(0), buffered(0), circular_buf(n) { }
|
||||
bounded_buffer(int n) : boost::noncopyable(), begin(0), end(0), buffered(0), circular_buf(n) { }
|
||||
|
||||
void send (int m) {
|
||||
lock lk(monitor);
|
||||
|
||||
78
example/future_fallback_to.cpp
Normal file
78
example/future_fallback_to.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright (C) 2012-2013 Vicente Botet
|
||||
//
|
||||
// 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_VERSION 4
|
||||
#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
|
||||
#include <boost/thread/detail/log.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
|
||||
|
||||
int p1_ex()
|
||||
{
|
||||
BOOST_THREAD_LOG << "P1" << BOOST_THREAD_END_LOG;
|
||||
throw std::logic_error("kk");
|
||||
}
|
||||
|
||||
int p1()
|
||||
{
|
||||
BOOST_THREAD_LOG << "P1" << BOOST_THREAD_END_LOG;
|
||||
return 1;;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_THREAD_LOG << "<MAIN" << BOOST_THREAD_END_LOG;
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
|
||||
boost::future<int> f2 = f1.fallback_to(-1);
|
||||
assert(f2.get()==1);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, &p1_ex);
|
||||
boost::future<int> f2 = f1.fallback_to(-1);
|
||||
assert(f2.get()==-1);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
BOOST_THREAD_LOG << "MAIN>" << BOOST_THREAD_END_LOG;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -1,12 +1,11 @@
|
||||
// Copyright (C) 2012 Vicente Botet
|
||||
// Copyright (C) 2012-2013 Vicente Botet
|
||||
//
|
||||
// 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_VERSION 4
|
||||
//#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
//#define BOOST_THREAD_DONT_PROVIDE_FUTURE_INVALID_AFTER_GET
|
||||
|
||||
#include <boost/thread/detail/log.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
@@ -20,7 +19,26 @@ int p1()
|
||||
return 123;
|
||||
}
|
||||
|
||||
int p2(boost::future<int>& f)
|
||||
int p2(boost::future<int> f)
|
||||
{
|
||||
BOOST_THREAD_LOG << "<P2" << BOOST_THREAD_END_LOG;
|
||||
try
|
||||
{
|
||||
return 2 * f.get();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
BOOST_THREAD_LOG << "P2>" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
int p2s(boost::shared_future<int> f)
|
||||
{
|
||||
BOOST_THREAD_LOG << "<P2" << BOOST_THREAD_END_LOG;
|
||||
try
|
||||
@@ -43,13 +61,12 @@ int p2(boost::future<int>& f)
|
||||
int main()
|
||||
{
|
||||
BOOST_THREAD_LOG << "<MAIN" << BOOST_THREAD_END_LOG;
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::future<int> f1 = boost::async(&p1);
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
|
||||
boost::future<int> f2 = f1.then(&p2);
|
||||
BOOST_THREAD_LOG << BOOST_THREAD_END_LOG;
|
||||
BOOST_THREAD_LOG << f2.get() << BOOST_THREAD_END_LOG;
|
||||
(void)f2.get();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
@@ -61,6 +78,25 @@ int main()
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::shared_future<int> f1 = boost::async(boost::launch::async, &p1).share();
|
||||
boost::future<int> f2 = f1.then(&p2s);
|
||||
(void)f2.get();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
BOOST_THREAD_LOG << "MAIN>" << BOOST_THREAD_END_LOG;
|
||||
return 0;
|
||||
}
|
||||
|
||||
59
example/future_unwrap.cpp
Normal file
59
example/future_unwrap.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright (C) 2012-2013 Vicente Botet
|
||||
//
|
||||
// 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_VERSION 4
|
||||
#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
|
||||
#include <boost/thread/detail/log.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <string>
|
||||
#if defined BOOST_THREAD_PROVIDES_FUTURE_UNWRAP
|
||||
|
||||
int p1()
|
||||
{
|
||||
BOOST_THREAD_LOG << "P1" << BOOST_THREAD_END_LOG;
|
||||
return 123;
|
||||
}
|
||||
|
||||
boost::future<int> p2()
|
||||
{
|
||||
BOOST_THREAD_LOG << "<P2" << BOOST_THREAD_END_LOG;
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, &p1);
|
||||
BOOST_THREAD_LOG << "P2>" << BOOST_THREAD_END_LOG;
|
||||
return boost::move(f1);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_THREAD_LOG << "<MAIN" << BOOST_THREAD_END_LOG;
|
||||
try
|
||||
{
|
||||
boost::future<boost::future<int> > outer_future = boost::async(boost::launch::async, &p2);
|
||||
boost::future<int> inner_future = outer_future.unwrap();
|
||||
int i = inner_future.get();
|
||||
BOOST_THREAD_LOG << "i= "<< i << "" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
BOOST_THREAD_LOG << "MAIN>" << BOOST_THREAD_END_LOG;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
60
example/lambda_future.cpp
Normal file
60
example/lambda_future.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright (C) 2013 Vicente Botet
|
||||
//
|
||||
// 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>
|
||||
#if ! defined BOOST_NO_CXX11_DECLTYPE
|
||||
#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||
#endif
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
|
||||
#include <boost/thread/detail/log.hpp>
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <string>
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION \
|
||||
&& ! defined BOOST_NO_CXX11_LAMBDAS
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_THREAD_LOG << "<MAIN" << BOOST_THREAD_END_LOG;
|
||||
|
||||
try
|
||||
{
|
||||
{
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, []() {return 123;});
|
||||
int result = f1.get();
|
||||
BOOST_THREAD_LOG << "f1 " << result << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
{
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, []() {return 123;});
|
||||
boost::future<int> f2 = f1.then([](boost::future<int> f) {return 2*f.get(); });
|
||||
int result = f2.get();
|
||||
BOOST_THREAD_LOG << "f2 " << result << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG << "ERRORRRRR "<<ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG << " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
BOOST_THREAD_LOG << "MAIN>" << BOOST_THREAD_END_LOG;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -8,20 +8,40 @@
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
exception_ptr make_exception_ptr(T v)
|
||||
{
|
||||
return copy_exception(v);
|
||||
}
|
||||
}
|
||||
|
||||
int p1() { return 5; }
|
||||
|
||||
void p() { }
|
||||
|
||||
#if defined BOOST_THREAD_USES_MOVE
|
||||
boost::future<void> void_compute()
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF(boost::make_ready_future());
|
||||
}
|
||||
#endif
|
||||
|
||||
boost::future<int> compute(int x)
|
||||
{
|
||||
if (x == 0) return boost::make_future(0);
|
||||
if (x < 0) return boost::make_future(-1);
|
||||
if (x == 0) return boost::make_ready_future(0);
|
||||
//if (x < 0) return boost::make_ready_future<int>(boost::make_exception_ptr(std::logic_error("Error")));
|
||||
if (x < 0) return boost::make_ready_future<int>(std::logic_error("Error"));
|
||||
//boost::future<int> f1 = boost::async([]() { return x+1; });
|
||||
boost::future<int> f1 = boost::async(boost::launch::async, p1);
|
||||
return boost::move(f1);
|
||||
}
|
||||
boost::shared_future<int> shared_compute(int x)
|
||||
{
|
||||
if (x == 0) return boost::make_shared_future(0);
|
||||
if (x < 0) return boost::make_shared_future(-1);
|
||||
if (x == 0) return boost::make_ready_future(0).share();
|
||||
if (x < 0) return boost::make_ready_future<int>(std::logic_error("Error")).share();
|
||||
//boost::future<int> f1 = boost::async([]() { return x+1; });
|
||||
boost::shared_future<int> f1 = boost::async(p1).share();
|
||||
return boost::move(f1);
|
||||
@@ -30,10 +50,20 @@ boost::shared_future<int> shared_compute(int x)
|
||||
|
||||
int main()
|
||||
{
|
||||
#if defined BOOST_THREAD_USES_MOVE
|
||||
{
|
||||
boost::future<void> f = void_compute();
|
||||
f.get();
|
||||
}
|
||||
#endif
|
||||
{
|
||||
boost::future<int> f = compute(2);
|
||||
std::cout << f.get() << std::endl;
|
||||
}
|
||||
{
|
||||
boost::future<int> f = compute(0);
|
||||
std::cout << f.get() << std::endl;
|
||||
}
|
||||
{
|
||||
boost::shared_future<int> f = shared_compute(2);
|
||||
std::cout << f.get() << std::endl;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
|
||||
namespace {
|
||||
const int ITERS = 100;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
void use_cerr(boost::externally_locked_stream<std::ostream> &mcerr)
|
||||
{
|
||||
using namespace boost;
|
||||
auto tf = chrono::steady_clock::now() + chrono::seconds(10);
|
||||
chrono::steady_clock::time_point tf = chrono::steady_clock::now() + chrono::seconds(10);
|
||||
while (chrono::steady_clock::now() < tf)
|
||||
{
|
||||
mcerr << "logging data to cerr\n";
|
||||
@@ -26,7 +26,7 @@ void use_cerr(boost::externally_locked_stream<std::ostream> &mcerr)
|
||||
void use_cout(boost::externally_locked_stream<std::ostream> &mcout)
|
||||
{
|
||||
using namespace boost;
|
||||
auto tf = chrono::steady_clock::now() + chrono::seconds(5);
|
||||
chrono::steady_clock::time_point tf = chrono::steady_clock::now() + chrono::seconds(5);
|
||||
while (chrono::steady_clock::now() < tf)
|
||||
{
|
||||
mcout << "logging data to cout\n";
|
||||
@@ -44,20 +44,20 @@ int main()
|
||||
externally_locked_stream<std::ostream> mcout(std::cout, terminal_mutex);
|
||||
externally_locked_stream<std::istream> mcin(std::cin, terminal_mutex);
|
||||
|
||||
scoped_thread<> t1(thread(use_cerr, boost::ref(mcerr)));
|
||||
scoped_thread<> t2(thread(use_cout, boost::ref(mcout)));
|
||||
scoped_thread<> t1(boost::thread(use_cerr, boost::ref(mcerr)));
|
||||
scoped_thread<> t2(boost::thread(use_cout, boost::ref(mcout)));
|
||||
this_thread::sleep_for(chrono::seconds(2));
|
||||
std::string nm;
|
||||
{
|
||||
strict_lock<recursive_mutex> lk(terminal_mutex);
|
||||
auto& gcout = mcout.hold(lk);
|
||||
auto& gcin = mcin.hold(lk);
|
||||
std::ostream & gcout = mcout.get(lk);
|
||||
//std::istream & gcin = mcin.get(lk);
|
||||
gcout << "Enter name: ";
|
||||
//gcin >> nm;
|
||||
}
|
||||
t1.join();
|
||||
t2.join();
|
||||
mcout << nm << '\n';
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
61
example/not_interleaved2.cpp
Normal file
61
example/not_interleaved2.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// (C) Copyright 2012 Howard Hinnant
|
||||
// (C) Copyright 2012 Vicente Botet
|
||||
//
|
||||
// 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)
|
||||
|
||||
// adapted from the example given by Howard Hinnant in
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/thread/scoped_thread.hpp>
|
||||
#include <boost/thread/ostream_buffer.hpp>
|
||||
|
||||
void use_cerr()
|
||||
{
|
||||
using namespace boost;
|
||||
chrono::steady_clock::time_point tf = chrono::steady_clock::now() + chrono::seconds(5);
|
||||
int i = 0;
|
||||
while (chrono::steady_clock::now() < tf)
|
||||
{
|
||||
ostream_buffer<std::ostream> mcerr(std::cerr);
|
||||
mcerr.stream() << "logging data to cerr " << i++ << "\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
|
||||
void use_cout()
|
||||
{
|
||||
using namespace boost;
|
||||
chrono::steady_clock::time_point tf = chrono::steady_clock::now() + chrono::seconds(5);
|
||||
int i = 0;
|
||||
while (chrono::steady_clock::now() < tf)
|
||||
{
|
||||
ostream_buffer<std::ostream> mcout(std::cout);
|
||||
mcout.stream() << "logging data to cout " << i++ << "\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(500));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost;
|
||||
|
||||
scoped_thread<> t1(&use_cerr);
|
||||
scoped_thread<> t2(&use_cout);
|
||||
this_thread::sleep_for(chrono::seconds(2));
|
||||
std::string nm = "he, he\n";
|
||||
{
|
||||
ostream_buffer<std::ostream> mcout(std::cout);
|
||||
mcout.stream() << "Enter name: \n";
|
||||
}
|
||||
t1.join();
|
||||
t2.join();
|
||||
{
|
||||
ostream_buffer<std::ostream> mcout(std::cout);
|
||||
mcout.stream() << nm;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -12,10 +12,11 @@
|
||||
|
||||
int value=0;
|
||||
#ifdef BOOST_THREAD_PROVIDES_ONCE_CXX11
|
||||
boost::once_flag once;
|
||||
static boost::once_flag once;
|
||||
//static boost::once_flag once2 = BOOST_ONCE_INIT;
|
||||
#else
|
||||
boost::once_flag once = BOOST_ONCE_INIT;
|
||||
boost::once_flag once2 = once;
|
||||
static boost::once_flag once = BOOST_ONCE_INIT;
|
||||
//static boost::once_flag once2 = once;
|
||||
#endif
|
||||
|
||||
void init()
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace
|
||||
{
|
||||
typedef SharedData<Types> S;
|
||||
|
||||
auto best_producer_time = std::numeric_limits<Stopwatch::rep>::max();
|
||||
auto best_producer_time = std::numeric_limits<Stopwatch::rep>::max BOOST_PREVENT_MACRO_SUBSTITUTION ();
|
||||
|
||||
std::vector<std::thread> consumers
|
||||
{ consumer_count };
|
||||
@@ -165,7 +165,7 @@ namespace
|
||||
for (unsigned i = 0; i < consumer_count; ++i)
|
||||
consumers[i].join();
|
||||
|
||||
best_producer_time = std::min(best_producer_time, shared_data.producer_time);
|
||||
best_producer_time = std::min BOOST_PREVENT_MACRO_SUBSTITUTION (best_producer_time, shared_data.producer_time);
|
||||
|
||||
}
|
||||
|
||||
|
||||
72
example/perf_shared_mutex.cpp
Normal file
72
example/perf_shared_mutex.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
// (C) Copyright 2013 Andrey
|
||||
// (C) Copyright 2013 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)
|
||||
//
|
||||
// This performance test is based on the performance test provided by maxim.yegorushkin
|
||||
// at https://svn.boost.org/trac/boost/ticket/7422
|
||||
|
||||
#define BOOST_THREAD_USES_CHRONO
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/thread/lock_types.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <boost/chrono/chrono_io.hpp>
|
||||
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
|
||||
using namespace boost;
|
||||
|
||||
shared_mutex mtx;
|
||||
const int cycles = 10000;
|
||||
|
||||
void shared()
|
||||
{
|
||||
int cycle(0);
|
||||
while (++cycle < cycles)
|
||||
{
|
||||
shared_lock<shared_mutex> lock(mtx);
|
||||
}
|
||||
}
|
||||
|
||||
void unique()
|
||||
{
|
||||
int cycle(0);
|
||||
while (++cycle < cycles)
|
||||
{
|
||||
unique_lock<shared_mutex> lock(mtx);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::chrono::high_resolution_clock::duration best_time(std::numeric_limits<boost::chrono::high_resolution_clock::duration::rep>::max BOOST_PREVENT_MACRO_SUBSTITUTION ());
|
||||
for (int i =100; i>0; --i) {
|
||||
boost::chrono::high_resolution_clock clock;
|
||||
boost::chrono::high_resolution_clock::time_point s1 = clock.now();
|
||||
thread t0(shared);
|
||||
thread t1(shared);
|
||||
thread t2(unique);
|
||||
//thread t11(shared);
|
||||
//thread t12(shared);
|
||||
//thread t13(shared);
|
||||
|
||||
t0.join();
|
||||
t1.join();
|
||||
t2.join();
|
||||
//t11.join();
|
||||
// t12.join();
|
||||
// t13.join();
|
||||
boost::chrono::high_resolution_clock::time_point f1 = clock.now();
|
||||
//std::cout << " Time spent:" << (f1 - s1) << std::endl;
|
||||
best_time = std::min BOOST_PREVENT_MACRO_SUBSTITUTION (best_time, f1 - s1);
|
||||
|
||||
}
|
||||
std::cout << "Best Time spent:" << best_time << std::endl;
|
||||
std::cout << "Time spent/cycle:" << best_time/cycles/3 << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
127
example/producer_consumer.cpp
Normal file
127
example/producer_consumer.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
// (C) Copyright 2012 Howard Hinnant
|
||||
// (C) Copyright 2012 Vicente Botet
|
||||
//
|
||||
// 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)
|
||||
|
||||
// adapted from the example given by Howard Hinnant in
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/thread/scoped_thread.hpp>
|
||||
#include <boost/thread/externally_locked_stream.hpp>
|
||||
#include <boost/thread/sync_queue.hpp>
|
||||
|
||||
void producer(boost::externally_locked_stream<std::ostream> &mos, boost::sync_queue<int> & sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
//sbq.push(i);
|
||||
sbq << i;
|
||||
mos << "push(" << i << ") "<< sbq.size()<<"\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(200));
|
||||
}
|
||||
}
|
||||
catch(sync_queue_is_closed&)
|
||||
{
|
||||
mos << "closed !!!\n";
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
|
||||
void consumer(boost::externally_locked_stream<std::ostream> &mos, boost::sync_queue<int> & sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
int r;
|
||||
//sbq.pull(r);
|
||||
sbq >> r;
|
||||
mos << i << " pull(" << r << ") "<< sbq.size()<<"\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
catch(sync_queue_is_closed&)
|
||||
{
|
||||
mos << "closed !!!\n";
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
void consumer2(boost::externally_locked_stream<std::ostream> &mos, boost::sync_queue<int> & sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
bool closed=false;
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
int r;
|
||||
sbq.pull(r, closed);
|
||||
if (closed) break;
|
||||
mos << i << " pull(" << r << ")\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
//void consumer3(boost::externally_locked_stream<std::ostream> &mos, boost::sync_queue<int> & sbq)
|
||||
//{
|
||||
// using namespace boost;
|
||||
// bool closed=false;
|
||||
// try {
|
||||
// for(int i=0; ;++i)
|
||||
// {
|
||||
// int r;
|
||||
// queue_op_status res = sbq.wait_and_pull(r);
|
||||
// if (res==queue_op_status::closed) break;
|
||||
// mos << i << " wait_and_pull(" << r << ")\n";
|
||||
// this_thread::sleep_for(chrono::milliseconds(250));
|
||||
// }
|
||||
// }
|
||||
// catch(...)
|
||||
// {
|
||||
// mos << "exception !!!\n";
|
||||
// }
|
||||
//}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost;
|
||||
|
||||
recursive_mutex terminal_mutex;
|
||||
|
||||
externally_locked_stream<std::ostream> mcerr(std::cerr, terminal_mutex);
|
||||
externally_locked_stream<std::ostream> mcout(std::cout, terminal_mutex);
|
||||
externally_locked_stream<std::istream> mcin(std::cin, terminal_mutex);
|
||||
|
||||
sync_queue<int> sbq;
|
||||
|
||||
{
|
||||
mcout << "begin of main" << std::endl;
|
||||
scoped_thread<> t11(boost::thread(producer, boost::ref(mcerr), boost::ref(sbq)));
|
||||
scoped_thread<> t12(boost::thread(producer, boost::ref(mcerr), boost::ref(sbq)));
|
||||
scoped_thread<> t2(boost::thread(consumer, boost::ref(mcout), boost::ref(sbq)));
|
||||
|
||||
this_thread::sleep_for(chrono::seconds(1));
|
||||
|
||||
mcout << "closed()" << std::endl;
|
||||
sbq.close();
|
||||
mcout << "closed()" << std::endl;
|
||||
|
||||
} // all threads joined here.
|
||||
mcout << "end of main" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
126
example/producer_consumer_bounded.cpp
Normal file
126
example/producer_consumer_bounded.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
// (C) Copyright 2012 Howard Hinnant
|
||||
// (C) Copyright 2012 Vicente Botet
|
||||
//
|
||||
// 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)
|
||||
|
||||
// adapted from the example given by Howard Hinnant in
|
||||
|
||||
#define BOOST_THREAD_VERSION 4
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/thread/scoped_thread.hpp>
|
||||
#include <boost/thread/externally_locked_stream.hpp>
|
||||
#include <boost/thread/sync_bounded_queue.hpp>
|
||||
|
||||
void producer(boost::externally_locked_stream<std::ostream> &mos, boost::sync_bounded_queue<int> & sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
//sbq.push(i);
|
||||
sbq << i;
|
||||
mos << "push(" << i << ") "<< sbq.size()<<"\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(200));
|
||||
}
|
||||
}
|
||||
catch(sync_queue_is_closed&)
|
||||
{
|
||||
mos << "closed !!!\n";
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
|
||||
void consumer(boost::externally_locked_stream<std::ostream> &mos, boost::sync_bounded_queue<int> & sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
int r;
|
||||
//sbq.pull(r);
|
||||
sbq >> r;
|
||||
mos << i << " pull(" << r << ") "<< sbq.size()<<"\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
catch(sync_queue_is_closed&)
|
||||
{
|
||||
mos << "closed !!!\n";
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
void consumer2(boost::externally_locked_stream<std::ostream> &mos, boost::sync_bounded_queue<int> & sbq)
|
||||
{
|
||||
using namespace boost;
|
||||
try {
|
||||
bool closed=false;
|
||||
for(int i=0; ;++i)
|
||||
{
|
||||
int r;
|
||||
sbq.pull(r, closed);
|
||||
if (closed) break;
|
||||
mos << i << " pull(" << r << ")\n";
|
||||
this_thread::sleep_for(chrono::milliseconds(250));
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
mos << "exception !!!\n";
|
||||
}
|
||||
}
|
||||
//void consumer3(boost::externally_locked_stream<std::ostream> &mos, boost::sync_bounded_queue<int> & sbq)
|
||||
//{
|
||||
// using namespace boost;
|
||||
// bool closed=false;
|
||||
// try {
|
||||
// for(int i=0; ;++i)
|
||||
// {
|
||||
// int r;
|
||||
// queue_op_status res = sbq.wait_and_pull(r);
|
||||
// if (res==queue_op_status::closed) break;
|
||||
// mos << i << " wait_and_pull(" << r << ")\n";
|
||||
// this_thread::sleep_for(chrono::milliseconds(250));
|
||||
// }
|
||||
// }
|
||||
// catch(...)
|
||||
// {
|
||||
// mos << "exception !!!\n";
|
||||
// }
|
||||
//}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost;
|
||||
|
||||
recursive_mutex terminal_mutex;
|
||||
|
||||
externally_locked_stream<std::ostream> mcerr(std::cerr, terminal_mutex);
|
||||
externally_locked_stream<std::ostream> mcout(std::cout, terminal_mutex);
|
||||
externally_locked_stream<std::istream> mcin(std::cin, terminal_mutex);
|
||||
|
||||
sync_bounded_queue<int> sbq(10);
|
||||
|
||||
{
|
||||
mcout << "begin of main" << std::endl;
|
||||
scoped_thread<> t11(boost::thread(producer, boost::ref(mcerr), boost::ref(sbq)));
|
||||
scoped_thread<> t12(boost::thread(producer, boost::ref(mcerr), boost::ref(sbq)));
|
||||
scoped_thread<> t2(boost::thread(consumer, boost::ref(mcout), boost::ref(sbq)));
|
||||
|
||||
this_thread::sleep_for(chrono::seconds(1));
|
||||
|
||||
sbq.close();
|
||||
mcout << "closed()" << std::endl;
|
||||
|
||||
} // all threads joined here.
|
||||
mcout << "end of main" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ void do_something(int& i)
|
||||
{
|
||||
++i;
|
||||
}
|
||||
void f(int, int)
|
||||
{
|
||||
}
|
||||
|
||||
struct func
|
||||
{
|
||||
@@ -64,6 +67,27 @@ int main()
|
||||
// do_something_in_current_thread();
|
||||
// do_something_with_current_thread(boost::thread(g));
|
||||
// }
|
||||
{
|
||||
int some_local_state;
|
||||
boost::scoped_thread<> t( (boost::thread(func(some_local_state))));
|
||||
|
||||
if (t.joinable())
|
||||
t.join();
|
||||
else
|
||||
do_something_in_current_thread();
|
||||
}
|
||||
{
|
||||
int some_local_state;
|
||||
boost::thread t(( func(some_local_state) ));
|
||||
boost::scoped_thread<> g( (boost::move(t)) );
|
||||
t.detach();
|
||||
|
||||
do_something_in_current_thread();
|
||||
}
|
||||
{
|
||||
boost::scoped_thread<> g( &f, 1, 2 );
|
||||
do_something_in_current_thread();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/lock_algorithms.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#if defined BOOST_THREAD_DONT_USE_CHRONO
|
||||
#include <boost/chrono/chrono_io.hpp>
|
||||
#endif
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <boost/thread/lock_algorithms.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <vector>
|
||||
|
||||
#if defined BOOST_THREAD_USES_CHRONO
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/condition.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
#include <iostream>
|
||||
#include <time.h>
|
||||
|
||||
@@ -255,5 +255,28 @@ int main()
|
||||
lk2->SetName("Javier");
|
||||
lk3->SetName("Matias");
|
||||
}
|
||||
#if ! defined BOOST_NO_CXX11_AUTO_DECLARATIONS \
|
||||
&& ! defined(BOOST_THREAD_NO_SYNCHRONIZE)
|
||||
{
|
||||
Person3_ts p1(1);
|
||||
Person3_ts p2(2);
|
||||
Person3_ts p3(3);
|
||||
|
||||
auto t = boost::synchronize(p1,p2,p3);
|
||||
std::get<0>(t)->SetName("Carmen");
|
||||
std::get<1>(t)->SetName("Javier");
|
||||
std::get<2>(t)->SetName("Matias");
|
||||
}
|
||||
{
|
||||
const Person3_ts p1(1);
|
||||
Person3_ts p2(2);
|
||||
const Person3_ts p3(3);
|
||||
|
||||
auto t = boost::synchronize(p1,p2,p3);
|
||||
//std::get<0>(t)->SetName("Carmen");
|
||||
std::get<1>(t)->SetName("Javier");
|
||||
//std::get<2>(t)->SetName("Matias");
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -10,15 +10,15 @@
|
||||
#include <string>
|
||||
#include <boost/thread/synchronized_value.hpp>
|
||||
|
||||
void addTrailingSlashIfMissing(boost::synchronized_value<std::string> & path)
|
||||
{
|
||||
boost::strict_lock_ptr<std::string> u=path.synchronize();
|
||||
|
||||
if(u->empty() || (*u->rbegin()!='/'))
|
||||
void addTrailingSlashIfMissing(boost::synchronized_value<std::string> & path)
|
||||
{
|
||||
*u+='/';
|
||||
boost::strict_lock_ptr<std::string> u=path.synchronize();
|
||||
|
||||
if(u->empty() || (*u->rbegin()!='/'))
|
||||
{
|
||||
*u+='/';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void f(const boost::synchronized_value<int> &v) {
|
||||
std::cout<<"v="<<*v<<std::endl;
|
||||
@@ -80,6 +80,68 @@ int main()
|
||||
addTrailingSlashIfMissing(s);
|
||||
std::cout<<"s="<<std::string(*s)<<std::endl;
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<std::string> s;
|
||||
s = std::string("foo/");
|
||||
std::cout<<"ss="<< s << std::endl;
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<std::string> s;
|
||||
s = "foo/";
|
||||
std::cout<<"ss="<< s << std::endl;
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<std::string> s1("a");
|
||||
boost::synchronized_value<std::string> s2;
|
||||
s2=s1;
|
||||
std::cout<<"s1="<< s1 << std::endl;
|
||||
std::cout<<"s2="<< s2 << std::endl;
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<std::string> s1("a");
|
||||
boost::synchronized_value<std::string> s2("b");
|
||||
std::cout<<"s1="<< s1 << std::endl;
|
||||
std::cout<<"s2="<< s2 << std::endl;
|
||||
swap(s1,s2);
|
||||
std::cout<<"s1="<< s1 << std::endl;
|
||||
std::cout<<"s2="<< s2 << std::endl;
|
||||
}
|
||||
#if ! defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
|
||||
{
|
||||
boost::synchronized_value<std::string> sts("a");
|
||||
std::string s(sts);
|
||||
std::cout<<"ssts="<< s << std::endl;
|
||||
}
|
||||
#endif
|
||||
{
|
||||
boost::synchronized_value<int> s1(1);
|
||||
boost::synchronized_value<int> s2(1);
|
||||
BOOST_ASSERT(s1==s2);
|
||||
BOOST_ASSERT(s1<=s2);
|
||||
BOOST_ASSERT(s1>=s2);
|
||||
BOOST_ASSERT(s1==1);
|
||||
BOOST_ASSERT(s1<=1);
|
||||
BOOST_ASSERT(s1>=1);
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<int> s1(1);
|
||||
boost::synchronized_value<int> s2(2);
|
||||
BOOST_ASSERT(s1!=s2);
|
||||
BOOST_ASSERT(s1!=2);
|
||||
BOOST_ASSERT(2!=s1);
|
||||
}
|
||||
{
|
||||
boost::synchronized_value<int> s1(1);
|
||||
boost::synchronized_value<int> s2(2);
|
||||
BOOST_ASSERT(s1<s2);
|
||||
BOOST_ASSERT(s1<=s2);
|
||||
BOOST_ASSERT(s2>s1);
|
||||
BOOST_ASSERT(s2>=s1);
|
||||
BOOST_ASSERT(s1<2);
|
||||
BOOST_ASSERT(s1<=2);
|
||||
BOOST_ASSERT(s2>1);
|
||||
BOOST_ASSERT(s2>=1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
// 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)
|
||||
|
||||
#undef BOOST_THREAD_VERSION
|
||||
#define BOOST_THREAD_VERSION 2
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/condition.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
#include <iostream>
|
||||
|
||||
@@ -29,7 +32,7 @@ int state;
|
||||
boost::mutex mutex;
|
||||
boost::condition cond;
|
||||
|
||||
char* player_name(int state)
|
||||
const char* player_name(int state)
|
||||
{
|
||||
if (state == PLAYER_A)
|
||||
return "PLAYER-A";
|
||||
@@ -39,11 +42,10 @@ char* player_name(int state)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void player(void* param)
|
||||
void player(int active)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lock(mutex);
|
||||
|
||||
int active = (int)param;
|
||||
int other = active == PLAYER_A ? PLAYER_B : PLAYER_A;
|
||||
|
||||
while (state < GAME_OVER)
|
||||
@@ -96,12 +98,12 @@ private:
|
||||
void* _param;
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main()
|
||||
{
|
||||
state = START;
|
||||
|
||||
boost::thread thrda(thread_adapter(&player, (void*)PLAYER_A));
|
||||
boost::thread thrdb(thread_adapter(&player, (void*)PLAYER_B));
|
||||
boost::thread thrda(&player, PLAYER_A);
|
||||
boost::thread thrdb(&player, PLAYER_B);
|
||||
|
||||
boost::xtime xt;
|
||||
boost::xtime_get(&xt, boost::TIME_UTC_);
|
||||
@@ -112,7 +114,7 @@ int main(int argc, char* argv[])
|
||||
std::cout << "---Noise ON..." << std::endl;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1000000000; ++i)
|
||||
for (int i = 0; i < 10; ++i)
|
||||
cond.notify_all();
|
||||
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#define BOOST_THREAD_VERSION 2
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <boost/thread/thread_guard.hpp>
|
||||
|
||||
void do_something(int& i)
|
||||
|
||||
147
example/thread_pool.cpp
Normal file
147
example/thread_pool.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
// Copyright (C) 2012-2013 Vicente Botet
|
||||
//
|
||||
// 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_VERSION 4
|
||||
#define BOOST_THREAD_USES_LOG
|
||||
#define BOOST_THREAD_USES_LOG_THREAD_ID
|
||||
|
||||
#include <boost/thread/detail/log.hpp>
|
||||
#include <boost/thread/thread_pool.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <string>
|
||||
|
||||
void p1()
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " P1" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
|
||||
void p2()
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " P2" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
|
||||
void push(boost::container::deque<boost::detail::function_wrapper> &data_, BOOST_THREAD_RV_REF(boost::detail::function_wrapper) closure)
|
||||
{
|
||||
try
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
|
||||
boost::detail::function_wrapper v;
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
|
||||
//v = boost::move(closure);
|
||||
//v = boost::forward<boost::detail::function_wrapper>(closure);
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
|
||||
|
||||
data_.push_back(boost::move(closure));
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
|
||||
|
||||
//data_.push_back(boost::forward<boost::detail::function_wrapper>(closure));
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
|
||||
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Closure>
|
||||
void submit(boost::container::deque<boost::detail::function_wrapper> &data_, BOOST_THREAD_FWD_REF(Closure) closure)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
|
||||
//work w =boost::move(closure);
|
||||
//work_queue.push(boost::move(w));
|
||||
//push(data_, boost::detail::function_wrapper(boost::forward<Closure>(closure)));
|
||||
boost::detail::function_wrapper v =boost::forward<Closure>(closure);
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
|
||||
push(data_, boost::move(v));
|
||||
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
|
||||
#if 0
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::detail::function_wrapper f(&p1);
|
||||
|
||||
boost::container::deque<boost::detail::function_wrapper> data_;
|
||||
data_.push_back(boost::move(f));
|
||||
data_.push_back(boost::detail::function_wrapper(&p1));
|
||||
submit(data_, &p1);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
}
|
||||
|
||||
typedef boost::container::vector<boost::thread> thread_vector;
|
||||
thread_vector threads;
|
||||
|
||||
}
|
||||
#endif
|
||||
#if 1
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::thread_pool tp;
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
|
||||
tp.submit(&p1);
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << " <MAIN" << BOOST_THREAD_END_LOG;
|
||||
tp.submit(&p2);
|
||||
tp.submit(&p1);
|
||||
tp.submit(&p2);
|
||||
tp.submit(&p1);
|
||||
tp.submit(&p2);
|
||||
tp.submit(&p1);
|
||||
tp.submit(&p2);
|
||||
tp.submit(&p1);
|
||||
tp.submit(&p2);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< "ERRORRRRR " << ex.what() << "" << BOOST_THREAD_END_LOG;
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BOOST_THREAD_LOG
|
||||
<< " ERRORRRRR exception thrown" << BOOST_THREAD_END_LOG;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
BOOST_THREAD_LOG
|
||||
<< boost::this_thread::get_id() << "MAIN>" << BOOST_THREAD_END_LOG;
|
||||
return 0;
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#define BOOST_THREAD_VERSION 2
|
||||
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
|
||||
int main()
|
||||
|
||||
19
include/boost/detail/atomic_redef_macros.hpp
Normal file
19
include/boost/detail/atomic_redef_macros.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright (C) 2013 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)
|
||||
|
||||
|
||||
#if defined(BOOST_INTEL)
|
||||
|
||||
#pragma pop_macro("atomic_compare_exchange")
|
||||
#pragma pop_macro("atomic_compare_exchange_explicit")
|
||||
#pragma pop_macro("atomic_exchange")
|
||||
#pragma pop_macro("atomic_exchange_explicit")
|
||||
#pragma pop_macro("atomic_is_lock_free")
|
||||
#pragma pop_macro("atomic_load")
|
||||
#pragma pop_macro("atomic_load_explicit")
|
||||
#pragma pop_macro("atomic_store")
|
||||
#pragma pop_macro("atomic_store_explicit")
|
||||
|
||||
#endif // #if defined(BOOST_INTEL)
|
||||
39
include/boost/detail/atomic_undef_macros.hpp
Normal file
39
include/boost/detail/atomic_undef_macros.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2013 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)
|
||||
|
||||
|
||||
#if defined(BOOST_INTEL)
|
||||
|
||||
#pragma push_macro("atomic_compare_exchange")
|
||||
#undef atomic_compare_exchange
|
||||
|
||||
#pragma push_macro("atomic_compare_exchange_explicit")
|
||||
#undef atomic_compare_exchange_explicit
|
||||
|
||||
#pragma push_macro("atomic_exchange")
|
||||
#undef atomic_exchange
|
||||
|
||||
#pragma push_macro("atomic_exchange_explicit")
|
||||
#undef atomic_exchange_explicit
|
||||
|
||||
#pragma push_macro("atomic_is_lock_free")
|
||||
#undef atomic_is_lock_free
|
||||
|
||||
#pragma push_macro("atomic_load")
|
||||
#undef atomic_load
|
||||
|
||||
#pragma push_macro("atomic_load_explicit")
|
||||
#undef atomic_load_explicit
|
||||
|
||||
#pragma push_macro("atomic_store")
|
||||
#undef atomic_store
|
||||
|
||||
#pragma push_macro("atomic_store_explicit")
|
||||
#undef atomic_store_explicit
|
||||
|
||||
|
||||
#endif // #if defined(BOOST_INTEL)
|
||||
|
||||
|
||||
@@ -9,56 +9,205 @@
|
||||
#define BOOST_BARRIER_JDM030602_HPP
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/lock_types.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#ifdef BOOST_NO_CXX11_HDR_FUNCTIONAL
|
||||
#include <boost/function.hpp>
|
||||
#else
|
||||
#include <functional>
|
||||
#endif
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/is_void.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/utility/result_of.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace thread_detail
|
||||
{
|
||||
#ifdef BOOST_NO_CXX11_HDR_FUNCTIONAL
|
||||
typedef function<void()> void_completion_function;
|
||||
typedef function<size_t()> size_completion_function;
|
||||
#else
|
||||
typedef std::function<void()> void_completion_function;
|
||||
typedef std::function<size_t()> size_completion_function;
|
||||
#endif
|
||||
|
||||
class barrier
|
||||
struct default_barrier_reseter
|
||||
{
|
||||
public:
|
||||
barrier(unsigned int count)
|
||||
: m_threshold(count), m_count(count), m_generation(0)
|
||||
{
|
||||
if (count == 0)
|
||||
boost::throw_exception(thread_exception(system::errc::invalid_argument, "barrier constructor: count cannot be zero."));
|
||||
}
|
||||
|
||||
bool wait()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lock(m_mutex);
|
||||
unsigned int gen = m_generation;
|
||||
|
||||
if (--m_count == 0)
|
||||
{
|
||||
m_generation++;
|
||||
m_count = m_threshold;
|
||||
m_cond.notify_all();
|
||||
return true;
|
||||
}
|
||||
|
||||
while (gen == m_generation)
|
||||
m_cond.wait(lock);
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
mutex m_mutex;
|
||||
condition_variable m_cond;
|
||||
unsigned int m_threshold;
|
||||
unsigned int m_count;
|
||||
unsigned int m_generation;
|
||||
unsigned int size_;
|
||||
default_barrier_reseter(unsigned int size) :
|
||||
size_(size)
|
||||
{
|
||||
}
|
||||
unsigned int operator()()
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
struct void_functor_barrier_reseter
|
||||
{
|
||||
unsigned int size_;
|
||||
void_completion_function fct_;
|
||||
template <typename F>
|
||||
#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
|
||||
void_functor_barrier_reseter(unsigned int size, BOOST_THREAD_RV_REF(F) funct)
|
||||
: size_(size), fct_(boost::move(funct))
|
||||
{}
|
||||
#else
|
||||
void_functor_barrier_reseter(unsigned int size, F funct)
|
||||
: size_(size), fct_(funct)
|
||||
{}
|
||||
#endif
|
||||
unsigned int operator()()
|
||||
{
|
||||
fct_();
|
||||
return size_;
|
||||
}
|
||||
};
|
||||
struct void_fct_ptr_barrier_reseter
|
||||
{
|
||||
unsigned int size_;
|
||||
void(*fct_)();
|
||||
void_fct_ptr_barrier_reseter(unsigned int size, void(*funct)()) :
|
||||
size_(size), fct_(funct)
|
||||
{
|
||||
}
|
||||
unsigned int operator()()
|
||||
{
|
||||
fct_();
|
||||
return size_;
|
||||
}
|
||||
};
|
||||
}
|
||||
class barrier
|
||||
{
|
||||
static inline unsigned int check_counter(unsigned int count)
|
||||
{
|
||||
if (count == 0) boost::throw_exception(
|
||||
thread_exception(system::errc::invalid_argument, "barrier constructor: count cannot be zero."));
|
||||
return count;
|
||||
}
|
||||
struct dummy
|
||||
{
|
||||
};
|
||||
|
||||
public:
|
||||
BOOST_THREAD_NO_COPYABLE( barrier)
|
||||
|
||||
explicit barrier(unsigned int count) :
|
||||
m_count(check_counter(count)), m_generation(0), fct_(thread_detail::default_barrier_reseter(count))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
barrier(
|
||||
unsigned int count,
|
||||
#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
|
||||
BOOST_THREAD_RV_REF(F) funct,
|
||||
#else
|
||||
F funct,
|
||||
#endif
|
||||
typename enable_if<
|
||||
typename is_void<typename result_of<F>::type>::type, dummy*
|
||||
>::type=0
|
||||
)
|
||||
: m_count(check_counter(count)),
|
||||
m_generation(0),
|
||||
fct_(thread_detail::void_functor_barrier_reseter(count,
|
||||
#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
|
||||
boost::move(funct)
|
||||
#else
|
||||
funct
|
||||
#endif
|
||||
)
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
barrier(
|
||||
unsigned int count,
|
||||
#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
|
||||
BOOST_THREAD_RV_REF(F) funct,
|
||||
#else
|
||||
F funct,
|
||||
#endif
|
||||
typename enable_if<
|
||||
typename is_same<typename result_of<F>::type, unsigned int>::type, dummy*
|
||||
>::type=0
|
||||
)
|
||||
: m_count(check_counter(count)),
|
||||
m_generation(0),
|
||||
fct_(
|
||||
#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
|
||||
boost::move(funct)
|
||||
#else
|
||||
funct
|
||||
#endif
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
barrier(unsigned int count, void(*funct)()) :
|
||||
m_count(check_counter(count)), m_generation(0),
|
||||
fct_(funct
|
||||
? thread_detail::size_completion_function(thread_detail::void_fct_ptr_barrier_reseter(count, funct))
|
||||
: thread_detail::size_completion_function(thread_detail::default_barrier_reseter(count))
|
||||
)
|
||||
{
|
||||
}
|
||||
barrier(unsigned int count, unsigned int(*funct)()) :
|
||||
m_count(check_counter(count)), m_generation(0),
|
||||
fct_(funct
|
||||
? thread_detail::size_completion_function(funct)
|
||||
: thread_detail::size_completion_function(thread_detail::default_barrier_reseter(count))
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
bool wait()
|
||||
{
|
||||
boost::unique_lock < boost::mutex > lock(m_mutex);
|
||||
unsigned int gen = m_generation;
|
||||
|
||||
if (--m_count == 0)
|
||||
{
|
||||
m_generation++;
|
||||
m_count = static_cast<unsigned int>(fct_());
|
||||
BOOST_ASSERT(m_count != 0);
|
||||
m_cond.notify_all();
|
||||
return true;
|
||||
}
|
||||
|
||||
while (gen == m_generation)
|
||||
m_cond.wait(lock);
|
||||
return false;
|
||||
}
|
||||
|
||||
void count_down_and_wait()
|
||||
{
|
||||
wait();
|
||||
}
|
||||
|
||||
private:
|
||||
mutex m_mutex;
|
||||
condition_variable m_cond;
|
||||
unsigned int m_count;
|
||||
unsigned int m_generation;
|
||||
thread_detail::size_completion_function fct_;
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
|
||||
233
include/boost/thread/completion_latch.hpp
Normal file
233
include/boost/thread/completion_latch.hpp
Normal file
@@ -0,0 +1,233 @@
|
||||
// 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 2013 Vicente J. Botet Escriba
|
||||
|
||||
#ifndef BOOST_THREAD_COMPLETION_LATCH_HPP
|
||||
#define BOOST_THREAD_COMPLETION_LATCH_HPP
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
#include <boost/thread/detail/counter.hpp>
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/lock_types.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/chrono/duration.hpp>
|
||||
#include <boost/chrono/time_point.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#ifdef BOOST_NO_CXX11_HDR_FUNCTIONAL
|
||||
#include <boost/function.hpp>
|
||||
#else
|
||||
#include <functional>
|
||||
#endif
|
||||
//#include <boost/thread/latch.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace thread_detail
|
||||
{
|
||||
void noop()
|
||||
{
|
||||
}
|
||||
}
|
||||
class completion_latch
|
||||
{
|
||||
public:
|
||||
/// the implementation defined completion function type
|
||||
#ifdef BOOST_NO_CXX11_HDR_FUNCTIONAL
|
||||
typedef function<void()> completion_function;
|
||||
#else
|
||||
typedef std::function<void()> completion_function;
|
||||
#endif
|
||||
/// noop completion function factory
|
||||
static completion_function noop()
|
||||
{
|
||||
return completion_function(&thread_detail::noop);
|
||||
}
|
||||
|
||||
private:
|
||||
struct around_wait;
|
||||
friend struct around_wait;
|
||||
struct around_wait
|
||||
{
|
||||
completion_latch &that_;
|
||||
boost::unique_lock<boost::mutex> &lk_;
|
||||
around_wait(completion_latch &that, boost::unique_lock<boost::mutex> &lk)
|
||||
: that_(that), lk_(lk)
|
||||
{
|
||||
that_.leavers_.cond_.wait(lk, detail::counter_is_zero(that_.leavers_));
|
||||
that_.waiters_.inc_and_notify_all();
|
||||
that_.leavers_.cond_.wait(lk, detail::counter_is_not_zero(that_.leavers_));
|
||||
}
|
||||
~around_wait()
|
||||
{
|
||||
that_.waiters_.dec_and_notify_all();
|
||||
}
|
||||
};
|
||||
|
||||
bool count_down(unique_lock<mutex> &lk)
|
||||
{
|
||||
BOOST_ASSERT(count_ > 0);
|
||||
if (--count_ == 0)
|
||||
{
|
||||
waiters_.cond_.wait(lk, detail::counter_is_not_zero(waiters_));
|
||||
leavers_.assign_and_notify_all(waiters_);
|
||||
count_.cond_.notify_all();
|
||||
waiters_.cond_.wait(lk, detail::counter_is_zero(waiters_));
|
||||
leavers_.assign_and_notify_all(0);
|
||||
lk.unlock();
|
||||
funct_();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
BOOST_THREAD_NO_COPYABLE( completion_latch )
|
||||
|
||||
/// Constructs a latch with a given count.
|
||||
completion_latch(std::size_t count) :
|
||||
count_(count), funct_(noop()), waiters_(0), leavers_(0)
|
||||
{
|
||||
}
|
||||
|
||||
/// Constructs a latch with a given count and a completion function.
|
||||
template <typename F>
|
||||
completion_latch(std::size_t count, BOOST_THREAD_RV_REF(F) funct) :
|
||||
count_(count),
|
||||
funct_(boost::move(funct)),
|
||||
waiters_(0),
|
||||
leavers_(0)
|
||||
{
|
||||
}
|
||||
template <typename F>
|
||||
completion_latch(std::size_t count, void(*funct)()) :
|
||||
count_(count), funct_(funct), waiters_(0), leavers_(0)
|
||||
{
|
||||
}
|
||||
|
||||
///
|
||||
~completion_latch()
|
||||
{
|
||||
}
|
||||
|
||||
/// Blocks until the latch has counted down to zero.
|
||||
void wait()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mutex_);
|
||||
around_wait aw(*this, lk);
|
||||
count_.cond_.wait(lk, detail::counter_is_zero(count_));
|
||||
}
|
||||
|
||||
/// @return true if the internal counter is already 0, false otherwise
|
||||
bool try_wait()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mutex_);
|
||||
around_wait aw(*this, lk);
|
||||
return (count_ == 0);
|
||||
}
|
||||
|
||||
/// try to wait for a specified amount of time
|
||||
/// @return whether there is a timeout or not.
|
||||
template <class Rep, class Period>
|
||||
cv_status wait_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mutex_);
|
||||
around_wait aw(*this, lk);
|
||||
return count_.cond_.wait_for(lk, rel_time, detail::counter_is_zero(count_))
|
||||
? cv_status::no_timeout
|
||||
: cv_status::timeout;
|
||||
}
|
||||
|
||||
/// try to wait until the specified time_point is reached
|
||||
/// @return whether there is a timeout or not.
|
||||
template <class Clock, class Duration>
|
||||
cv_status wait_until(const chrono::time_point<Clock, Duration>& abs_time)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mutex_);
|
||||
around_wait aw(*this, lk);
|
||||
return count_.cond_.wait_until(lk, abs_time, detail::counter_is_zero(count_))
|
||||
? cv_status::no_timeout
|
||||
: cv_status::timeout;
|
||||
}
|
||||
|
||||
/// Decrement the count and notify anyone waiting if we reach zero.
|
||||
/// @Requires count must be greater than 0
|
||||
void count_down()
|
||||
{
|
||||
unique_lock<mutex> lk(mutex_);
|
||||
count_down(lk);
|
||||
}
|
||||
void signal()
|
||||
{
|
||||
count_down();
|
||||
}
|
||||
|
||||
/// Decrement the count and notify anyone waiting if we reach zero.
|
||||
/// Blocks until the latch has counted down to zero.
|
||||
/// @Requires count must be greater than 0
|
||||
void count_down_and_wait()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mutex_);
|
||||
if (count_down(lk))
|
||||
{
|
||||
return;
|
||||
}
|
||||
around_wait aw(*this, lk);
|
||||
count_.cond_.wait(lk, detail::counter_is_zero(count_));
|
||||
}
|
||||
void sync()
|
||||
{
|
||||
count_down_and_wait();
|
||||
}
|
||||
|
||||
/// Reset the counter
|
||||
/// #Requires This method may only be invoked when there are no other threads currently inside the count_down_and_wait() method.
|
||||
void reset(std::size_t count)
|
||||
{
|
||||
boost::lock_guard<boost::mutex> lk(mutex_);
|
||||
//BOOST_ASSERT(count_ == 0);
|
||||
count_ = count;
|
||||
}
|
||||
|
||||
/// Resets the latch with the new completion function.
|
||||
/// The next time the internal count reaches 0, this function will be invoked.
|
||||
/// This completion function may only be invoked when there are no other threads
|
||||
/// currently inside the count_down and wait related functions.
|
||||
/// It may also be invoked from within the registered completion function.
|
||||
/// @Returns the old completion function if any or noop if
|
||||
|
||||
#ifdef BOOST_NO_CXX11_HDR_FUNCTIONAL
|
||||
template <typename F>
|
||||
completion_function then(BOOST_THREAD_RV_REF(F) funct)
|
||||
{
|
||||
boost::lock_guard<boost::mutex> lk(mutex_);
|
||||
completion_function tmp(funct_);
|
||||
funct_ = boost::move(funct);
|
||||
return tmp;
|
||||
}
|
||||
#endif
|
||||
completion_function then(void(*funct)())
|
||||
{
|
||||
boost::lock_guard<boost::mutex> lk(mutex_);
|
||||
completion_function tmp(funct_);
|
||||
funct_ = completion_function(funct);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
private:
|
||||
mutex mutex_;
|
||||
detail::counter count_;
|
||||
completion_function funct_;
|
||||
detail::counter waiters_;
|
||||
detail::counter leavers_;
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,13 @@
|
||||
// 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)
|
||||
|
||||
// 2013/04 Vicente J. Botet Escriba
|
||||
// Provide implementation up to 9 parameters when BOOST_NO_CXX11_VARIADIC_TEMPLATES is defined.
|
||||
// Make use of Boost.Move
|
||||
// Make use of Boost.Tuple (movable)
|
||||
// 2012/11 Vicente J. Botet Escriba
|
||||
// Adapt to boost libc++ implementation
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
@@ -23,8 +30,11 @@
|
||||
#include <boost/thread/detail/invoke.hpp>
|
||||
#include <boost/thread/detail/make_tuple_indices.hpp>
|
||||
|
||||
#if ! defined(BOOST_NO_CXX11_HDR_TUPLE)
|
||||
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
|
||||
! defined(BOOST_NO_CXX11_HDR_TUPLE)
|
||||
#include <tuple>
|
||||
#else
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
@@ -33,68 +43,528 @@ namespace boost
|
||||
{
|
||||
|
||||
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
|
||||
! defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
|
||||
! defined(BOOST_NO_CXX11_HDR_TUPLE)
|
||||
|
||||
template <class Fp, class... Args>
|
||||
template <class Fp, class ... Args>
|
||||
class async_func
|
||||
{
|
||||
std::tuple<Fp, Args...> f_;
|
||||
std::tuple<Fp, Args...> f_;
|
||||
|
||||
public:
|
||||
//typedef typename invoke_of<_Fp, _Args...>::type Rp;
|
||||
typedef typename result_of<Fp(Args...)>::type result_type;
|
||||
BOOST_THREAD_MOVABLE_ONLY( async_func)
|
||||
//typedef typename invoke_of<_Fp, _Args...>::type Rp;
|
||||
typedef typename result_of<Fp(Args...)>::type result_type;
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
explicit async_func(Fp&& f, Args&&... args)
|
||||
: f_(boost::move(f), boost::move(args)...) {}
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
explicit async_func(BOOST_THREAD_RV_REF(Fp) f, BOOST_THREAD_RV_REF(Args)... args)
|
||||
: f_(boost::move(f), boost::move(args)...)
|
||||
{}
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
async_func(async_func&& f) : f_(boost::move(f.f_)) {}
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
async_func(BOOST_THREAD_RV_REF(async_func) f) : f_(boost::move(f.f_))
|
||||
{}
|
||||
|
||||
result_type operator()()
|
||||
{
|
||||
typedef typename make_tuple_indices<1+sizeof...(Args), 1>::type Index;
|
||||
return execute(Index());
|
||||
}
|
||||
result_type operator()()
|
||||
{
|
||||
typedef typename make_tuple_indices<1+sizeof...(Args), 1>::type Index;
|
||||
return execute(Index());
|
||||
}
|
||||
private:
|
||||
template <size_t ...Indices>
|
||||
result_type
|
||||
execute(tuple_indices<Indices...>)
|
||||
{
|
||||
return invoke(boost::move(std::get<0>(f_)), boost::move(std::get<Indices>(f_))...);
|
||||
}
|
||||
template <size_t ...Indices>
|
||||
result_type
|
||||
execute(tuple_indices<Indices...>)
|
||||
{
|
||||
return invoke(boost::move(std::get<0>(f_)), boost::move(std::get<Indices>(f_))...);
|
||||
}
|
||||
};
|
||||
//BOOST_THREAD_DCL_MOVABLE_BEG(X) async_func<Fp> BOOST_THREAD_DCL_MOVABLE_END
|
||||
#else
|
||||
template <class Fp>
|
||||
class async_func
|
||||
template <class Fp,
|
||||
class T0 = tuples::null_type, class T1 = tuples::null_type, class T2 = tuples::null_type,
|
||||
class T3 = tuples::null_type, class T4 = tuples::null_type, class T5 = tuples::null_type,
|
||||
class T6 = tuples::null_type, class T7 = tuples::null_type, class T8 = tuples::null_type
|
||||
, class T9 = tuples::null_type
|
||||
>
|
||||
class async_func;
|
||||
|
||||
template <class Fp,
|
||||
class T0 , class T1 , class T2 ,
|
||||
class T3 , class T4 , class T5 ,
|
||||
class T6 , class T7 , class T8 >
|
||||
class async_func<Fp, T0, T1, T2, T3, T4, T5, T6, T7, T8>
|
||||
{
|
||||
Fp f_;
|
||||
Fp fp_;
|
||||
T0 v0_;
|
||||
T1 v1_;
|
||||
T2 v2_;
|
||||
T3 v3_;
|
||||
T4 v4_;
|
||||
T5 v5_;
|
||||
T6 v6_;
|
||||
T7 v7_;
|
||||
T8 v8_;
|
||||
//::boost::tuple<Fp, T0, T1, T2, T3, T4, T5, T6, T7, T8> f_;
|
||||
|
||||
public:
|
||||
BOOST_THREAD_COPYABLE_AND_MOVABLE(async_func)
|
||||
BOOST_THREAD_MOVABLE_ONLY(async_func)
|
||||
typedef typename result_of<Fp(T0, T1, T2, T3, T4, T5, T6, T7, T8)>::type result_type;
|
||||
|
||||
typedef typename result_of<Fp()>::type result_type;
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
explicit async_func(BOOST_THREAD_RV_REF(Fp) f
|
||||
, BOOST_THREAD_RV_REF(T0) a0
|
||||
, BOOST_THREAD_RV_REF(T1) a1
|
||||
, BOOST_THREAD_RV_REF(T2) a2
|
||||
, BOOST_THREAD_RV_REF(T3) a3
|
||||
, BOOST_THREAD_RV_REF(T4) a4
|
||||
, BOOST_THREAD_RV_REF(T5) a5
|
||||
, BOOST_THREAD_RV_REF(T6) a6
|
||||
, BOOST_THREAD_RV_REF(T7) a7
|
||||
, BOOST_THREAD_RV_REF(T8) a8
|
||||
)
|
||||
: fp_(boost::move(f))
|
||||
, v0_(boost::move(a0))
|
||||
, v1_(boost::move(a1))
|
||||
, v2_(boost::move(a2))
|
||||
, v3_(boost::move(a3))
|
||||
, v4_(boost::move(a4))
|
||||
, v5_(boost::move(a5))
|
||||
, v6_(boost::move(a6))
|
||||
, v7_(boost::move(a7))
|
||||
, v8_(boost::move(a8))
|
||||
{}
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
explicit async_func(BOOST_THREAD_FWD_REF(Fp) f)
|
||||
: f_(boost::move(f)) {}
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
async_func(BOOST_THREAD_RV_REF(async_func) f)
|
||||
: fp_(boost::move(f.fp))
|
||||
, v0_(boost::move(f.a0))
|
||||
, v1_(boost::move(f.a1))
|
||||
, v2_(boost::move(f.a2))
|
||||
, v3_(boost::move(f.a3))
|
||||
, v4_(boost::move(f.a4))
|
||||
, v5_(boost::move(f.a5))
|
||||
, v6_(boost::move(f.a6))
|
||||
, v7_(boost::move(f.a7))
|
||||
, v8_(boost::move(f.a8))
|
||||
{}
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
async_func(BOOST_THREAD_FWD_REF(async_func) f) : f_(boost::move(f.f_)) {}
|
||||
result_type operator()()
|
||||
{
|
||||
return invoke(boost::move(fp_)
|
||||
, boost::move(v0_)
|
||||
, boost::move(v1_)
|
||||
, boost::move(v2_)
|
||||
, boost::move(v3_)
|
||||
, boost::move(v4_)
|
||||
, boost::move(v5_)
|
||||
, boost::move(v6_)
|
||||
, boost::move(v7_)
|
||||
, boost::move(v8_)
|
||||
);
|
||||
}
|
||||
};
|
||||
template <class Fp, class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7 >
|
||||
class async_func<Fp, T0, T1, T2, T3, T4, T5, T6, T7>
|
||||
{
|
||||
Fp fp_;
|
||||
T0 v0_;
|
||||
T1 v1_;
|
||||
T2 v2_;
|
||||
T3 v3_;
|
||||
T4 v4_;
|
||||
T5 v5_;
|
||||
T6 v6_;
|
||||
T7 v7_;
|
||||
public:
|
||||
BOOST_THREAD_MOVABLE_ONLY(async_func)
|
||||
typedef typename result_of<Fp(T0, T1, T2, T3, T4, T5, T6, T7)>::type result_type;
|
||||
|
||||
result_type operator()()
|
||||
{
|
||||
return execute();
|
||||
}
|
||||
private:
|
||||
result_type
|
||||
execute()
|
||||
{
|
||||
return f_();
|
||||
}
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
explicit async_func(BOOST_THREAD_RV_REF(Fp) f
|
||||
, BOOST_THREAD_RV_REF(T0) a0
|
||||
, BOOST_THREAD_RV_REF(T1) a1
|
||||
, BOOST_THREAD_RV_REF(T2) a2
|
||||
, BOOST_THREAD_RV_REF(T3) a3
|
||||
, BOOST_THREAD_RV_REF(T4) a4
|
||||
, BOOST_THREAD_RV_REF(T5) a5
|
||||
, BOOST_THREAD_RV_REF(T6) a6
|
||||
, BOOST_THREAD_RV_REF(T7) a7
|
||||
)
|
||||
: fp_(boost::move(f))
|
||||
, v0_(boost::move(a0))
|
||||
, v1_(boost::move(a1))
|
||||
, v2_(boost::move(a2))
|
||||
, v3_(boost::move(a3))
|
||||
, v4_(boost::move(a4))
|
||||
, v5_(boost::move(a5))
|
||||
, v6_(boost::move(a6))
|
||||
, v7_(boost::move(a7))
|
||||
{}
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
async_func(BOOST_THREAD_RV_REF(async_func) f)
|
||||
: fp_(boost::move(f.fp))
|
||||
, v0_(boost::move(f.a0))
|
||||
, v1_(boost::move(f.a1))
|
||||
, v2_(boost::move(f.a2))
|
||||
, v3_(boost::move(f.a3))
|
||||
, v4_(boost::move(f.a4))
|
||||
, v5_(boost::move(f.a5))
|
||||
, v6_(boost::move(f.a6))
|
||||
, v7_(boost::move(f.a7))
|
||||
{}
|
||||
|
||||
result_type operator()()
|
||||
{
|
||||
return invoke(boost::move(fp_)
|
||||
, boost::move(v0_)
|
||||
, boost::move(v1_)
|
||||
, boost::move(v2_)
|
||||
, boost::move(v3_)
|
||||
, boost::move(v4_)
|
||||
, boost::move(v5_)
|
||||
, boost::move(v6_)
|
||||
, boost::move(v7_)
|
||||
);
|
||||
}
|
||||
};
|
||||
template <class Fp, class T0, class T1, class T2, class T3, class T4, class T5, class T6>
|
||||
class async_func<Fp, T0, T1, T2, T3, T4, T5, T6>
|
||||
{
|
||||
Fp fp_;
|
||||
T0 v0_;
|
||||
T1 v1_;
|
||||
T2 v2_;
|
||||
T3 v3_;
|
||||
T4 v4_;
|
||||
T5 v5_;
|
||||
T6 v6_;
|
||||
public:
|
||||
BOOST_THREAD_MOVABLE_ONLY(async_func)
|
||||
typedef typename result_of<Fp(T0, T1, T2, T3, T4, T5, T6)>::type result_type;
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
explicit async_func(BOOST_THREAD_RV_REF(Fp) f
|
||||
, BOOST_THREAD_RV_REF(T0) a0
|
||||
, BOOST_THREAD_RV_REF(T1) a1
|
||||
, BOOST_THREAD_RV_REF(T2) a2
|
||||
, BOOST_THREAD_RV_REF(T3) a3
|
||||
, BOOST_THREAD_RV_REF(T4) a4
|
||||
, BOOST_THREAD_RV_REF(T5) a5
|
||||
, BOOST_THREAD_RV_REF(T6) a6
|
||||
)
|
||||
: fp_(boost::move(f))
|
||||
, v0_(boost::move(a0))
|
||||
, v1_(boost::move(a1))
|
||||
, v2_(boost::move(a2))
|
||||
, v3_(boost::move(a3))
|
||||
, v4_(boost::move(a4))
|
||||
, v5_(boost::move(a5))
|
||||
, v6_(boost::move(a6))
|
||||
{}
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
async_func(BOOST_THREAD_RV_REF(async_func) f)
|
||||
: fp_(boost::move(f.fp))
|
||||
, v0_(boost::move(f.a0))
|
||||
, v1_(boost::move(f.a1))
|
||||
, v2_(boost::move(f.a2))
|
||||
, v3_(boost::move(f.a3))
|
||||
, v4_(boost::move(f.a4))
|
||||
, v5_(boost::move(f.a5))
|
||||
, v6_(boost::move(f.a6))
|
||||
{}
|
||||
|
||||
result_type operator()()
|
||||
{
|
||||
return invoke(boost::move(fp_)
|
||||
, boost::move(v0_)
|
||||
, boost::move(v1_)
|
||||
, boost::move(v2_)
|
||||
, boost::move(v3_)
|
||||
, boost::move(v4_)
|
||||
, boost::move(v5_)
|
||||
, boost::move(v6_)
|
||||
);
|
||||
}
|
||||
};
|
||||
template <class Fp, class T0, class T1, class T2, class T3, class T4, class T5>
|
||||
class async_func<Fp, T0, T1, T2, T3, T4, T5>
|
||||
{
|
||||
Fp fp_;
|
||||
T0 v0_;
|
||||
T1 v1_;
|
||||
T2 v2_;
|
||||
T3 v3_;
|
||||
T4 v4_;
|
||||
T5 v5_;
|
||||
public:
|
||||
BOOST_THREAD_MOVABLE_ONLY(async_func)
|
||||
typedef typename result_of<Fp(T0, T1, T2, T3, T4, T5)>::type result_type;
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
explicit async_func(BOOST_THREAD_RV_REF(Fp) f
|
||||
, BOOST_THREAD_RV_REF(T0) a0
|
||||
, BOOST_THREAD_RV_REF(T1) a1
|
||||
, BOOST_THREAD_RV_REF(T2) a2
|
||||
, BOOST_THREAD_RV_REF(T3) a3
|
||||
, BOOST_THREAD_RV_REF(T4) a4
|
||||
, BOOST_THREAD_RV_REF(T5) a5
|
||||
)
|
||||
: fp_(boost::move(f))
|
||||
, v0_(boost::move(a0))
|
||||
, v1_(boost::move(a1))
|
||||
, v2_(boost::move(a2))
|
||||
, v3_(boost::move(a3))
|
||||
, v4_(boost::move(a4))
|
||||
, v5_(boost::move(a5))
|
||||
{}
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
async_func(BOOST_THREAD_RV_REF(async_func) f)
|
||||
: fp_(boost::move(f.fp))
|
||||
, v0_(boost::move(f.a0))
|
||||
, v1_(boost::move(f.a1))
|
||||
, v2_(boost::move(f.a2))
|
||||
, v3_(boost::move(f.a3))
|
||||
, v4_(boost::move(f.a4))
|
||||
, v5_(boost::move(f.a5))
|
||||
{}
|
||||
|
||||
result_type operator()()
|
||||
{
|
||||
return invoke(boost::move(fp_)
|
||||
, boost::move(v0_)
|
||||
, boost::move(v1_)
|
||||
, boost::move(v2_)
|
||||
, boost::move(v3_)
|
||||
, boost::move(v4_)
|
||||
, boost::move(v5_)
|
||||
);
|
||||
}
|
||||
};
|
||||
template <class Fp, class T0, class T1, class T2, class T3, class T4>
|
||||
class async_func<Fp, T0, T1, T2, T3, T4>
|
||||
{
|
||||
Fp fp_;
|
||||
T0 v0_;
|
||||
T1 v1_;
|
||||
T2 v2_;
|
||||
T3 v3_;
|
||||
T4 v4_;
|
||||
public:
|
||||
BOOST_THREAD_MOVABLE_ONLY(async_func)
|
||||
typedef typename result_of<Fp(T0, T1, T2, T3, T4)>::type result_type;
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
explicit async_func(BOOST_THREAD_RV_REF(Fp) f
|
||||
, BOOST_THREAD_RV_REF(T0) a0
|
||||
, BOOST_THREAD_RV_REF(T1) a1
|
||||
, BOOST_THREAD_RV_REF(T2) a2
|
||||
, BOOST_THREAD_RV_REF(T3) a3
|
||||
, BOOST_THREAD_RV_REF(T4) a4
|
||||
)
|
||||
: fp_(boost::move(f))
|
||||
, v0_(boost::move(a0))
|
||||
, v1_(boost::move(a1))
|
||||
, v2_(boost::move(a2))
|
||||
, v3_(boost::move(a3))
|
||||
, v4_(boost::move(a4))
|
||||
{}
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
async_func(BOOST_THREAD_RV_REF(async_func) f)
|
||||
: fp_(boost::move(f.fp))
|
||||
, v0_(boost::move(f.a0))
|
||||
, v1_(boost::move(f.a1))
|
||||
, v2_(boost::move(f.a2))
|
||||
, v3_(boost::move(f.a3))
|
||||
, v4_(boost::move(f.a4))
|
||||
{}
|
||||
|
||||
result_type operator()()
|
||||
{
|
||||
return invoke(boost::move(fp_)
|
||||
, boost::move(v0_)
|
||||
, boost::move(v1_)
|
||||
, boost::move(v2_)
|
||||
, boost::move(v3_)
|
||||
, boost::move(v4_)
|
||||
);
|
||||
}
|
||||
};
|
||||
template <class Fp, class T0, class T1, class T2, class T3>
|
||||
class async_func<Fp, T0, T1, T2, T3>
|
||||
{
|
||||
Fp fp_;
|
||||
T0 v0_;
|
||||
T1 v1_;
|
||||
T2 v2_;
|
||||
T3 v3_;
|
||||
public:
|
||||
BOOST_THREAD_MOVABLE_ONLY(async_func)
|
||||
typedef typename result_of<Fp(T0, T1, T2, T3)>::type result_type;
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
explicit async_func(BOOST_THREAD_RV_REF(Fp) f
|
||||
, BOOST_THREAD_RV_REF(T0) a0
|
||||
, BOOST_THREAD_RV_REF(T1) a1
|
||||
, BOOST_THREAD_RV_REF(T2) a2
|
||||
, BOOST_THREAD_RV_REF(T3) a3
|
||||
)
|
||||
: fp_(boost::move(f))
|
||||
, v0_(boost::move(a0))
|
||||
, v1_(boost::move(a1))
|
||||
, v2_(boost::move(a2))
|
||||
, v3_(boost::move(a3))
|
||||
{}
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
async_func(BOOST_THREAD_RV_REF(async_func) f)
|
||||
: fp_(boost::move(f.fp))
|
||||
, v0_(boost::move(f.a0))
|
||||
, v1_(boost::move(f.a1))
|
||||
, v2_(boost::move(f.a2))
|
||||
, v3_(boost::move(f.a3))
|
||||
{}
|
||||
|
||||
result_type operator()()
|
||||
{
|
||||
return invoke(boost::move(fp_)
|
||||
, boost::move(v0_)
|
||||
, boost::move(v1_)
|
||||
, boost::move(v2_)
|
||||
, boost::move(v3_)
|
||||
);
|
||||
}
|
||||
};
|
||||
template <class Fp, class T0, class T1, class T2>
|
||||
class async_func<Fp, T0, T1, T2>
|
||||
{
|
||||
Fp fp_;
|
||||
T0 v0_;
|
||||
T1 v1_;
|
||||
T2 v2_;
|
||||
public:
|
||||
BOOST_THREAD_MOVABLE_ONLY(async_func)
|
||||
typedef typename result_of<Fp(T0, T1, T2)>::type result_type;
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
explicit async_func(BOOST_THREAD_RV_REF(Fp) f
|
||||
, BOOST_THREAD_RV_REF(T0) a0
|
||||
, BOOST_THREAD_RV_REF(T1) a1
|
||||
, BOOST_THREAD_RV_REF(T2) a2
|
||||
)
|
||||
: fp_(boost::move(f))
|
||||
, v0_(boost::move(a0))
|
||||
, v1_(boost::move(a1))
|
||||
, v2_(boost::move(a2))
|
||||
{}
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
async_func(BOOST_THREAD_RV_REF(async_func) f)
|
||||
: fp_(boost::move(f.fp))
|
||||
, v0_(boost::move(f.a0))
|
||||
, v1_(boost::move(f.a1))
|
||||
, v2_(boost::move(f.a2))
|
||||
{}
|
||||
|
||||
result_type operator()()
|
||||
{
|
||||
return invoke(boost::move(fp_)
|
||||
, boost::move(v0_)
|
||||
, boost::move(v1_)
|
||||
, boost::move(v2_)
|
||||
);
|
||||
}
|
||||
};
|
||||
template <class Fp, class T0, class T1>
|
||||
class async_func<Fp, T0, T1>
|
||||
{
|
||||
Fp fp_;
|
||||
T0 v0_;
|
||||
T1 v1_;
|
||||
public:
|
||||
BOOST_THREAD_MOVABLE_ONLY(async_func)
|
||||
typedef typename result_of<Fp(T0, T1)>::type result_type;
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
explicit async_func(BOOST_THREAD_RV_REF(Fp) f
|
||||
, BOOST_THREAD_RV_REF(T0) a0
|
||||
, BOOST_THREAD_RV_REF(T1) a1
|
||||
)
|
||||
: fp_(boost::move(f))
|
||||
, v0_(boost::move(a0))
|
||||
, v1_(boost::move(a1))
|
||||
{}
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
async_func(BOOST_THREAD_RV_REF(async_func) f)
|
||||
: fp_(boost::move(f.fp))
|
||||
, v0_(boost::move(f.a0))
|
||||
, v1_(boost::move(f.a1))
|
||||
{}
|
||||
|
||||
result_type operator()()
|
||||
{
|
||||
return invoke(boost::move(fp_)
|
||||
, boost::move(v0_)
|
||||
, boost::move(v1_)
|
||||
);
|
||||
}
|
||||
};
|
||||
template <class Fp, class T0>
|
||||
class async_func<Fp, T0>
|
||||
{
|
||||
Fp fp_;
|
||||
T0 v0_;
|
||||
public:
|
||||
BOOST_THREAD_MOVABLE_ONLY(async_func)
|
||||
typedef typename result_of<Fp(T0)>::type result_type;
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
explicit async_func(BOOST_THREAD_RV_REF(Fp) f
|
||||
, BOOST_THREAD_RV_REF(T0) a0
|
||||
)
|
||||
: fp_(boost::move(f))
|
||||
, v0_(boost::move(a0))
|
||||
{}
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
async_func(BOOST_THREAD_RV_REF(async_func) f)
|
||||
: fp_(boost::move(f.fp))
|
||||
, v0_(boost::move(f.a0))
|
||||
{}
|
||||
|
||||
result_type operator()()
|
||||
{
|
||||
return invoke(boost::move(fp_)
|
||||
, boost::move(v0_)
|
||||
);
|
||||
}
|
||||
};
|
||||
template <class Fp>
|
||||
class async_func<Fp>
|
||||
{
|
||||
Fp fp_;
|
||||
public:
|
||||
BOOST_THREAD_COPYABLE_AND_MOVABLE(async_func)
|
||||
typedef typename result_of<Fp()>::type result_type;
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
explicit async_func(BOOST_THREAD_FWD_REF(Fp) f)
|
||||
: fp_(boost::move(f))
|
||||
{}
|
||||
|
||||
BOOST_SYMBOL_VISIBLE
|
||||
async_func(BOOST_THREAD_FWD_REF(async_func) f)
|
||||
: fp_(boost::move(f.fp_))
|
||||
{}
|
||||
result_type operator()()
|
||||
{
|
||||
return fp_();
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
// Copyright (C) 2011-2012 Vicente J. Botet Escriba
|
||||
// Copyright (C) 2011-2013 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)
|
||||
@@ -8,23 +8,26 @@
|
||||
#ifndef BOOST_THREAD_CONFIG_WEK01032003_HPP
|
||||
#define BOOST_THREAD_CONFIG_WEK01032003_HPP
|
||||
|
||||
// Force SIG_ATOMIC_MAX to be defined
|
||||
//#ifndef __STDC_LIMIT_MACROS
|
||||
//#define __STDC_LIMIT_MACROS
|
||||
//#endif
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/thread/detail/platform.hpp>
|
||||
|
||||
#if ! defined BOOST_THREAD_NOEXCEPT_OR_THROW
|
||||
#ifdef BOOST_NO_CXX11_NOEXCEPT
|
||||
# define BOOST_THREAD_NOEXCEPT_OR_THROW throw()
|
||||
//#define BOOST_THREAD_DONT_PROVIDE_INTERRUPTIONS
|
||||
// ATTRIBUTE_MAY_ALIAS
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) > 302 \
|
||||
&& !defined(__INTEL_COMPILER)
|
||||
|
||||
// GCC since 3.3 has may_alias attribute that helps to alleviate optimizer issues with
|
||||
// regard to violation of the strict aliasing rules.
|
||||
|
||||
#define BOOST_THREAD_DETAIL_USE_ATTRIBUTE_MAY_ALIAS
|
||||
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS __attribute__((__may_alias__))
|
||||
#else
|
||||
# define BOOST_THREAD_NOEXCEPT_OR_THROW noexcept
|
||||
#endif
|
||||
#define BOOST_THREAD_ATTRIBUTE_MAY_ALIAS
|
||||
#endif
|
||||
|
||||
|
||||
#if defined BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED
|
||||
#define BOOST_THREAD_ASSERT_PRECONDITION(EXPR, EX) \
|
||||
if (EXPR) {} else boost::throw_exception(EX)
|
||||
@@ -44,8 +47,8 @@
|
||||
#if defined __IBMCPP__ && (__IBMCPP__ < 1100) \
|
||||
&& ! defined BOOST_THREAD_DONT_USE_CHRONO
|
||||
#define BOOST_THREAD_DONT_USE_CHRONO
|
||||
#if ! defined BOOST_THREAD_USE_DATE
|
||||
#define BOOST_THREAD_USE_DATE
|
||||
#if ! defined BOOST_THREAD_USES_DATETIME
|
||||
#define BOOST_THREAD_USES_DATETIME
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -76,22 +79,23 @@
|
||||
|
||||
#if defined(BOOST_NO_CXX11_HDR_TUPLE) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
#define BOOST_THREAD_NO_MAKE_UNIQUE_LOCKS
|
||||
#define BOOST_THREAD_NO_SYNCHRONIZE
|
||||
#elif defined _MSC_VER && _MSC_VER <= 1600
|
||||
// C++ features supported by VC++ 10 (aka 2010)
|
||||
#define BOOST_THREAD_NO_MAKE_UNIQUE_LOCKS
|
||||
#define BOOST_THREAD_NO_SYNCHRONIZE
|
||||
#endif
|
||||
|
||||
/// BASIC_THREAD_ID
|
||||
// todo to be removed for 1.54
|
||||
#if ! defined BOOST_THREAD_DONT_PROVIDE_BASIC_THREAD_ID \
|
||||
&& ! defined BOOST_THREAD_PROVIDES_BASIC_THREAD_ID
|
||||
#define BOOST_THREAD_PROVIDES_BASIC_THREAD_ID
|
||||
#endif
|
||||
|
||||
/// RVALUE_REFERENCES_DONT_MATCH_FUNTION_PTR
|
||||
#if defined BOOST_NO_CXX11_RVALUE_REFERENCES || defined BOOST_MSVC
|
||||
//#if defined BOOST_NO_CXX11_RVALUE_REFERENCES || defined BOOST_MSVC
|
||||
#define BOOST_THREAD_RVALUE_REFERENCES_DONT_MATCH_FUNTION_PTR
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
// Default version
|
||||
#if !defined BOOST_THREAD_VERSION
|
||||
@@ -109,6 +113,20 @@
|
||||
#define BOOST_THREAD_USES_CHRONO
|
||||
#endif
|
||||
|
||||
#if ! defined BOOST_THREAD_DONT_USE_ATOMIC \
|
||||
&& ! defined BOOST_THREAD_USES_ATOMIC
|
||||
#define BOOST_THREAD_USES_ATOMIC
|
||||
//#define BOOST_THREAD_DONT_USE_ATOMIC
|
||||
#endif
|
||||
|
||||
#if defined BOOST_THREAD_USES_ATOMIC
|
||||
// Andrey Semashev
|
||||
#define BOOST_THREAD_ONCE_ATOMIC
|
||||
#else
|
||||
//#elif ! defined BOOST_NO_CXX11_THREAD_LOCAL && ! defined BOOST_NO_THREAD_LOCAL && ! defined BOOST_THREAD_NO_UINT32_PSEUDO_ATOMIC
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2444.html#Appendix
|
||||
#define BOOST_THREAD_ONCE_FAST_EPOCH
|
||||
#endif
|
||||
#if BOOST_THREAD_VERSION==2
|
||||
|
||||
// PROVIDE_PROMISE_LAZY
|
||||
@@ -230,12 +248,27 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// MAKE_READY_AT_THREAD_EXIT
|
||||
#if ! defined BOOST_THREAD_PROVIDES_MAKE_READY_AT_THREAD_EXIT \
|
||||
&& ! defined BOOST_THREAD_DONT_PROVIDE_MAKE_READY_AT_THREAD_EXIT
|
||||
|
||||
//#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
|
||||
#define BOOST_THREAD_PROVIDES_MAKE_READY_AT_THREAD_EXIT
|
||||
//#endif
|
||||
#endif
|
||||
|
||||
// FUTURE_CONTINUATION
|
||||
#if ! defined BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION \
|
||||
&& ! defined BOOST_THREAD_DONT_PROVIDE_FUTURE_CONTINUATION
|
||||
#define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
|
||||
#endif
|
||||
|
||||
#if ! defined BOOST_THREAD_PROVIDES_FUTURE_UNWRAP \
|
||||
&& ! defined BOOST_THREAD_DONT_PROVIDE_FUTURE_UNWRAP
|
||||
#define BOOST_THREAD_PROVIDES_FUTURE_UNWRAP
|
||||
#endif
|
||||
|
||||
// FUTURE_INVALID_AFTER_GET
|
||||
#if ! defined BOOST_THREAD_PROVIDES_FUTURE_INVALID_AFTER_GET \
|
||||
&& ! defined BOOST_THREAD_DONT_PROVIDE_FUTURE_INVALID_AFTER_GET
|
||||
@@ -277,7 +310,25 @@
|
||||
#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN
|
||||
#endif
|
||||
|
||||
// BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0 defined by default up to Boost 1.52
|
||||
// For C++11 call_once interface the compiler MUST support constexpr.
|
||||
// Otherwise once_flag would be initialized during dynamic initialization stage, which is not thread-safe.
|
||||
#if defined(BOOST_THREAD_PROVIDES_ONCE_CXX11)
|
||||
#if defined(BOOST_NO_CXX11_CONSTEXPR)
|
||||
#undef BOOST_THREAD_PROVIDES_ONCE_CXX11
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_THREAD_PLATFORM_WIN32) && defined BOOST_THREAD_DONT_USE_DATETIME
|
||||
#undef BOOST_THREAD_DONT_USE_DATETIME
|
||||
#define BOOST_THREAD_USES_DATETIME
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_THREAD_PLATFORM_WIN32) && defined BOOST_THREAD_DONT_USE_CHRONO
|
||||
#undef BOOST_THREAD_DONT_USE_CHRONO
|
||||
#define BOOST_THREAD_USES_CHRONO
|
||||
#endif
|
||||
|
||||
// BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0 defined by default up to Boost 1.55
|
||||
// BOOST_THREAD_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V3_0_0 defined by default up to Boost 1.55
|
||||
#if defined BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0
|
||||
|
||||
@@ -321,8 +372,9 @@
|
||||
#elif defined(BOOST_THREAD_USE_LIB) //Use lib
|
||||
#else //Use default
|
||||
# if defined(BOOST_THREAD_PLATFORM_WIN32)
|
||||
# if defined(BOOST_MSVC) || defined(BOOST_INTEL_WIN)
|
||||
//For compilers supporting auto-tss cleanup
|
||||
# if defined(BOOST_MSVC) || defined(BOOST_INTEL_WIN) \
|
||||
|| defined(__MINGW32__) || defined(MINGW32) || defined(BOOST_MINGW32)
|
||||
//For compilers supporting auto-tss cleanup
|
||||
//with Boost.Threads lib, use Boost.Threads lib
|
||||
# define BOOST_THREAD_USE_LIB
|
||||
# else
|
||||
|
||||
106
include/boost/thread/detail/counter.hpp
Normal file
106
include/boost/thread/detail/counter.hpp
Normal file
@@ -0,0 +1,106 @@
|
||||
// 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 2013 Vicente J. Botet Escriba
|
||||
|
||||
#ifndef BOOST_THREAD_COUNTER_HPP
|
||||
#define BOOST_THREAD_COUNTER_HPP
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
|
||||
//#include <boost/thread/mutex.hpp>
|
||||
//#include <boost/thread/lock_types.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/chrono/duration.hpp>
|
||||
#include <boost/chrono/time_point.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail {
|
||||
struct counter
|
||||
{
|
||||
condition_variable cond_;
|
||||
std::size_t value_;
|
||||
|
||||
counter(std::size_t value)
|
||||
: value_(value)
|
||||
{
|
||||
|
||||
}
|
||||
counter& operator=(counter const& rhs)
|
||||
{
|
||||
value_ = rhs.value_;
|
||||
return *this;
|
||||
}
|
||||
counter& operator=(std::size_t value)
|
||||
{
|
||||
value_ = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator std::size_t() const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
operator std::size_t&()
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
void inc_and_notify_all()
|
||||
{
|
||||
++value_;
|
||||
cond_.notify_all();
|
||||
}
|
||||
|
||||
void dec_and_notify_all()
|
||||
{
|
||||
--value_;
|
||||
cond_.notify_all();
|
||||
}
|
||||
void assign_and_notify_all(counter const& rhs)
|
||||
{
|
||||
value_ = rhs.value_;
|
||||
cond_.notify_all();
|
||||
}
|
||||
void assign_and_notify_all(std::size_t value)
|
||||
{
|
||||
value_ = value;
|
||||
cond_.notify_all();
|
||||
}
|
||||
};
|
||||
struct counter_is_not_zero
|
||||
{
|
||||
counter_is_not_zero(counter const& count) : count_(count) {}
|
||||
bool operator()() const { return count_ != 0; }
|
||||
counter const& count_;
|
||||
};
|
||||
struct counter_is_zero
|
||||
{
|
||||
counter_is_zero(counter const& count) : count_(count) {}
|
||||
bool operator()() const { return count_ == 0; }
|
||||
counter const& count_;
|
||||
};
|
||||
struct is_zero
|
||||
{
|
||||
is_zero(std::size_t& count) : count_(count) {}
|
||||
bool operator()() const { return count_ == 0; }
|
||||
std::size_t& count_;
|
||||
};
|
||||
struct not_equal
|
||||
{
|
||||
not_equal(std::size_t& x, std::size_t& y) : x_(x), y_(y) {}
|
||||
bool operator()() const { return x_ != y_; }
|
||||
std::size_t& x_;
|
||||
std::size_t& y_;
|
||||
};
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif
|
||||
@@ -23,6 +23,17 @@
|
||||
CLASS& operator=(CLASS const&) = delete;
|
||||
|
||||
#else // BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
#if defined(BOOST_MSVC) && _MSC_VER >= 1600
|
||||
#define BOOST_THREAD_DELETE_COPY_CTOR(CLASS) \
|
||||
private: \
|
||||
CLASS(CLASS const&); \
|
||||
public:
|
||||
|
||||
#define BOOST_THREAD_DELETE_COPY_ASSIGN(CLASS) \
|
||||
private: \
|
||||
CLASS& operator=(CLASS const&); \
|
||||
public:
|
||||
#else
|
||||
#define BOOST_THREAD_DELETE_COPY_CTOR(CLASS) \
|
||||
private: \
|
||||
CLASS(CLASS&); \
|
||||
@@ -32,6 +43,7 @@
|
||||
private: \
|
||||
CLASS& operator=(CLASS&); \
|
||||
public:
|
||||
#endif
|
||||
#endif // BOOST_NO_CXX11_DELETED_FUNCTIONS
|
||||
|
||||
/**
|
||||
|
||||
94
include/boost/thread/detail/function_wrapper.hpp
Normal file
94
include/boost/thread/detail/function_wrapper.hpp
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright (C) 2013 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)
|
||||
//
|
||||
// 2013/09 Vicente J. Botet Escriba
|
||||
// Adapt to boost from CCIA C++11 implementation
|
||||
// Make use of Boost.Move
|
||||
|
||||
#ifndef BOOST_THREAD_DETAIL_FUNCTION_WRAPPER_HPP
|
||||
#define BOOST_THREAD_DETAIL_FUNCTION_WRAPPER_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/thread/detail/memory.hpp>
|
||||
#include <boost/thread/detail/move.hpp>
|
||||
|
||||
#include <boost/interprocess/smart_ptr/unique_ptr.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class function_wrapper
|
||||
{
|
||||
struct impl_base
|
||||
{
|
||||
virtual void call()=0;
|
||||
virtual ~impl_base()
|
||||
{
|
||||
}
|
||||
};
|
||||
//typedef boost::interprocess::unique_ptr<impl_base, boost::default_delete<impl_base> > impl_base_type;
|
||||
impl_base* impl;
|
||||
template <typename F>
|
||||
struct impl_type: impl_base
|
||||
{
|
||||
F f;
|
||||
impl_type(F const &f_)
|
||||
: f(f_)
|
||||
{}
|
||||
impl_type(BOOST_THREAD_RV_REF(F) f_)
|
||||
: f(boost::move(f_))
|
||||
{}
|
||||
|
||||
void call()
|
||||
{
|
||||
f();
|
||||
}
|
||||
};
|
||||
public:
|
||||
BOOST_THREAD_MOVABLE_ONLY(function_wrapper)
|
||||
|
||||
//#if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
template<typename F>
|
||||
function_wrapper(F const& f):
|
||||
impl(new impl_type<F>(f))
|
||||
{}
|
||||
//#endif
|
||||
template<typename F>
|
||||
function_wrapper(BOOST_THREAD_RV_REF(F) f):
|
||||
impl(new impl_type<F>(boost::forward<F>(f)))
|
||||
{}
|
||||
function_wrapper(BOOST_THREAD_RV_REF(function_wrapper) other) BOOST_NOEXCEPT :
|
||||
impl(other.impl)
|
||||
{
|
||||
other.impl = 0;
|
||||
}
|
||||
function_wrapper()
|
||||
: impl(0)
|
||||
{
|
||||
}
|
||||
~function_wrapper()
|
||||
{
|
||||
delete impl;
|
||||
}
|
||||
|
||||
function_wrapper& operator=(BOOST_THREAD_RV_REF(function_wrapper) other) BOOST_NOEXCEPT
|
||||
{
|
||||
impl=other.impl;
|
||||
other.impl=0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{ impl->call();}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // header
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,9 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright 2011-2012 Vicente J. Botet Escriba
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
// Copyright (C) 2011-2013 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/thread for documentation.
|
||||
//
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
// Copyright (C) 2012 Vicente J. Botet Escriba
|
||||
// Copyright (C) 2012-2013 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)
|
||||
|
||||
// 2013/04 Vicente J. Botet Escriba
|
||||
// Provide implementation up to 10 parameters when BOOST_NO_CXX11_VARIADIC_TEMPLATES is defined.
|
||||
// 2012/11 Vicente J. Botet Escriba
|
||||
// Adapt to boost libc++ implementation
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
@@ -10,7 +15,7 @@
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
// The make_tuple_indices code is based on the one from libcxx.
|
||||
// The make_tuple_indices C++11 code is based on the one from libcxx.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef BOOST_THREAD_DETAIL_MAKE_TUPLE_INDICES_HPP
|
||||
@@ -24,9 +29,7 @@ namespace boost
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
|
||||
! defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
|
||||
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
// make_tuple_indices
|
||||
|
||||
template <std::size_t...> struct tuple_indices
|
||||
@@ -53,6 +56,167 @@ namespace boost
|
||||
BOOST_STATIC_ASSERT_MSG(Sp <= Ep, "make_tuple_indices input error");
|
||||
typedef typename make_indices_imp<Sp, tuple_indices<>, Ep>::type type;
|
||||
};
|
||||
#else
|
||||
|
||||
// - tuple forward declaration -----------------------------------------------
|
||||
template <
|
||||
std::size_t T0 = 0, std::size_t T1 = 0, std::size_t T2 = 0,
|
||||
std::size_t T3 = 0, std::size_t T4 = 0, std::size_t T5 = 0,
|
||||
std::size_t T6 = 0, std::size_t T7 = 0, std::size_t T8 = 0,
|
||||
std::size_t T9 = 0>
|
||||
class tuple_indices {};
|
||||
|
||||
template <std::size_t Sp, class IntTuple, std::size_t Ep>
|
||||
struct make_indices_imp;
|
||||
|
||||
template <std::size_t Sp, std::size_t Ep>
|
||||
struct make_indices_imp<Sp, tuple_indices<>, Ep>
|
||||
{
|
||||
typedef typename make_indices_imp<Sp+1, tuple_indices<Sp>, Ep>::type type;
|
||||
};
|
||||
template <std::size_t Sp, std::size_t I0, std::size_t Ep>
|
||||
struct make_indices_imp<Sp, tuple_indices<I0>, Ep>
|
||||
{
|
||||
typedef typename make_indices_imp<Sp+1, tuple_indices<I0, Sp>, Ep>::type type;
|
||||
};
|
||||
template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t Ep>
|
||||
struct make_indices_imp<Sp, tuple_indices<I0, I1>, Ep>
|
||||
{
|
||||
typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, Sp>, Ep>::type type;
|
||||
};
|
||||
template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t Ep>
|
||||
struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2>, Ep>
|
||||
{
|
||||
typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, Sp>, Ep>::type type;
|
||||
};
|
||||
template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t Ep>
|
||||
struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3>, Ep>
|
||||
{
|
||||
typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, Sp>, Ep>::type type;
|
||||
};
|
||||
template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t Ep>
|
||||
struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3, I4>, Ep>
|
||||
{
|
||||
typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, I4, Sp>, Ep>::type type;
|
||||
};
|
||||
template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5, std::size_t Ep>
|
||||
struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3, I4, I5>, Ep>
|
||||
{
|
||||
typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, I4, I5, Sp>, Ep>::type type;
|
||||
};
|
||||
template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
|
||||
, std::size_t I6
|
||||
, std::size_t Ep>
|
||||
struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3, I4, I5, I6>, Ep>
|
||||
{
|
||||
typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, I4, I5, I6, Sp>, Ep>::type type;
|
||||
};
|
||||
template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
|
||||
, std::size_t I6
|
||||
, std::size_t I7
|
||||
, std::size_t Ep>
|
||||
struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3, I4, I5, I6, I7>, Ep>
|
||||
{
|
||||
typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, Sp>, Ep>::type type;
|
||||
};
|
||||
template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
|
||||
, std::size_t I6
|
||||
, std::size_t I7
|
||||
, std::size_t I8
|
||||
, std::size_t Ep>
|
||||
struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3, I4, I5, I6, I7, I8>, Ep>
|
||||
{
|
||||
typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, I8, Sp>, Ep>::type type;
|
||||
};
|
||||
// template <std::size_t Sp, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
|
||||
// , std::size_t I6
|
||||
// , std::size_t I7
|
||||
// , std::size_t I8
|
||||
// , std::size_t I9
|
||||
// , std::size_t Ep>
|
||||
// struct make_indices_imp<Sp, tuple_indices<I0, I1 , I2, I3, I4, I5, I6, I7, I8, I9>, Ep>
|
||||
// {
|
||||
// typedef typename make_indices_imp<Sp+1, tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, I8, I9, Sp>, Ep>::type type;
|
||||
// };
|
||||
|
||||
template <std::size_t Ep>
|
||||
struct make_indices_imp<Ep, tuple_indices<>, Ep>
|
||||
{
|
||||
typedef tuple_indices<> type;
|
||||
};
|
||||
template <std::size_t Ep, std::size_t I0>
|
||||
struct make_indices_imp<Ep, tuple_indices<I0>, Ep>
|
||||
{
|
||||
typedef tuple_indices<I0> type;
|
||||
};
|
||||
template <std::size_t Ep, std::size_t I0, std::size_t I1>
|
||||
struct make_indices_imp<Ep, tuple_indices<I0, I1>, Ep>
|
||||
{
|
||||
typedef tuple_indices<I0, I1> type;
|
||||
};
|
||||
template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2>
|
||||
struct make_indices_imp<Ep, tuple_indices<I0, I1, I2>, Ep>
|
||||
{
|
||||
typedef tuple_indices<I0, I1, I2> type;
|
||||
};
|
||||
template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3>
|
||||
struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3>, Ep>
|
||||
{
|
||||
typedef tuple_indices<I0, I1, I2, I3> type;
|
||||
};
|
||||
template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4>
|
||||
struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3, I4>, Ep>
|
||||
{
|
||||
typedef tuple_indices<I0, I1, I2, I3, I4> type;
|
||||
};
|
||||
template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5>
|
||||
struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3, I4, I5>, Ep>
|
||||
{
|
||||
typedef tuple_indices<I0, I1, I2, I3, I4, I5> type;
|
||||
};
|
||||
template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
|
||||
, std::size_t I6
|
||||
>
|
||||
struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3, I4, I5, I6>, Ep>
|
||||
{
|
||||
typedef tuple_indices<I0, I1, I2, I3, I4, I5, I6> type;
|
||||
};
|
||||
template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
|
||||
, std::size_t I6
|
||||
, std::size_t I7
|
||||
>
|
||||
struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7>, Ep>
|
||||
{
|
||||
typedef tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7> type;
|
||||
};
|
||||
template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
|
||||
, std::size_t I6
|
||||
, std::size_t I7
|
||||
, std::size_t I8
|
||||
>
|
||||
struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, I8>, Ep>
|
||||
{
|
||||
typedef tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, I8> type;
|
||||
};
|
||||
|
||||
template <std::size_t Ep, std::size_t I0, std::size_t I1, std::size_t I2, std::size_t I3, std::size_t I4, std::size_t I5
|
||||
, std::size_t I6
|
||||
, std::size_t I7
|
||||
, std::size_t I8
|
||||
, std::size_t I9
|
||||
>
|
||||
struct make_indices_imp<Ep, tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, I8, I9>, Ep>
|
||||
{
|
||||
typedef tuple_indices<I0, I1, I2, I3, I4, I5, I6, I7, I8, I9> type;
|
||||
};
|
||||
|
||||
template <std::size_t Ep, std::size_t Sp = 0>
|
||||
struct make_tuple_indices
|
||||
{
|
||||
BOOST_STATIC_ASSERT_MSG(Sp <= Ep, "make_tuple_indices input error");
|
||||
typedef typename make_indices_imp<Sp, tuple_indices<>, Ep>::type type;
|
||||
};
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright 2011-2012 Vicente J. Botet Escriba
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
// Copyright (C) 2011-2013 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/thread for documentation.
|
||||
//
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
#include <boost/move/utility.hpp>
|
||||
#include <boost/move/traits.hpp>
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
|
||||
@@ -476,8 +476,13 @@ namespace boost
|
||||
{
|
||||
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));
|
||||
bool joined= false;
|
||||
do {
|
||||
typename Clock::duration d = ceil<nanoseconds>(t-Clock::now());
|
||||
if (d <= Clock::duration::zero()) return false; // in case the Clock::time_point t is already reached
|
||||
joined = try_join_until(s_now + d);
|
||||
} while (! joined);
|
||||
return true;
|
||||
}
|
||||
template <class Duration>
|
||||
bool try_join_until(const chrono::time_point<chrono::system_clock, Duration>& t)
|
||||
@@ -541,6 +546,7 @@ namespace boost
|
||||
void detach();
|
||||
|
||||
static unsigned hardware_concurrency() BOOST_NOEXCEPT;
|
||||
static unsigned physical_concurrency() BOOST_NOEXCEPT;
|
||||
|
||||
#define BOOST_THREAD_DEFINES_THREAD_NATIVE_HANDLE
|
||||
typedef detail::thread_data_base::native_handle_type native_handle_type;
|
||||
@@ -821,6 +827,19 @@ namespace boost
|
||||
};
|
||||
|
||||
void BOOST_THREAD_DECL add_thread_exit_function(thread_exit_function_base*);
|
||||
struct shared_state_base;
|
||||
#if defined(BOOST_THREAD_PLATFORM_WIN32)
|
||||
inline void make_ready_at_thread_exit(shared_ptr<shared_state_base> as)
|
||||
{
|
||||
detail::thread_data_base* const current_thread_data(detail::get_current_thread_data());
|
||||
if(current_thread_data)
|
||||
{
|
||||
current_thread_data->make_ready_at_thread_exit(as);
|
||||
}
|
||||
}
|
||||
#else
|
||||
void BOOST_THREAD_DECL make_ready_at_thread_exit(shared_ptr<shared_state_base> as);
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace this_thread
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace boost
|
||||
|
||||
//[externally_locked
|
||||
template <typename T, typename MutexType = boost::mutex>
|
||||
class externally_locked;
|
||||
template <typename T, typename MutexType>
|
||||
class externally_locked
|
||||
{
|
||||
//BOOST_CONCEPT_ASSERT(( CopyConstructible<T> ));
|
||||
@@ -46,7 +48,7 @@ namespace boost
|
||||
* Requires: T is a model of CopyConstructible.
|
||||
* Effects: Constructs an externally locked object copying the cloaked type.
|
||||
*/
|
||||
BOOST_CONSTEXPR externally_locked(mutex_type& mtx, const T& obj) :
|
||||
externally_locked(mutex_type& mtx, const T& obj) :
|
||||
obj_(obj), mtx_(&mtx)
|
||||
{
|
||||
}
|
||||
@@ -55,7 +57,7 @@ namespace boost
|
||||
* Requires: T is a model of Movable.
|
||||
* Effects: Constructs an externally locked object by moving the cloaked type.
|
||||
*/
|
||||
BOOST_CONSTEXPR externally_locked(mutex_type& mtx, BOOST_THREAD_RV_REF(T) obj) :
|
||||
externally_locked(mutex_type& mtx, BOOST_THREAD_RV_REF(T) obj) :
|
||||
obj_(move(obj)), mtx_(&mtx)
|
||||
{
|
||||
}
|
||||
@@ -64,18 +66,46 @@ namespace boost
|
||||
* Requires: T is a model of DefaultConstructible.
|
||||
* Effects: Constructs an externally locked object initializing the cloaked type with the default constructor.
|
||||
*/
|
||||
externally_locked(mutex_type& mtx) :
|
||||
obj_(), mtx_(&mtx)
|
||||
externally_locked(mutex_type& mtx) // BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(T()))
|
||||
: obj_(), mtx_(&mtx)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*/
|
||||
externally_locked(externally_locked const& rhs) //BOOST_NOEXCEPT
|
||||
: obj_(rhs.obj_), mtx_(rhs.mtx_)
|
||||
{
|
||||
}
|
||||
/**
|
||||
* Move constructor
|
||||
*/
|
||||
externally_locked(BOOST_THREAD_RV_REF(externally_locked) rhs) :
|
||||
obj_(move(rhs.obj_)), mtx_(rhs.mtx_)
|
||||
externally_locked(BOOST_THREAD_RV_REF(externally_locked) rhs) //BOOST_NOEXCEPT
|
||||
: obj_(move(rhs.obj_)), mtx_(rhs.mtx_)
|
||||
{
|
||||
rhs.mtx_=0;
|
||||
}
|
||||
|
||||
/// assignment
|
||||
externally_locked& operator=(externally_locked const& rhs) //BOOST_NOEXCEPT
|
||||
{
|
||||
obj_=rhs.obj_;
|
||||
mtx_=rhs.mtx_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// move assignment
|
||||
externally_locked& operator=(BOOST_THREAD_RV_REF(externally_locked) rhs) // BOOST_NOEXCEPT
|
||||
{
|
||||
obj_=move(rhs.obj_);
|
||||
mtx_=rhs.mtx_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(externally_locked& rhs) //BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR)
|
||||
{
|
||||
swap(obj_, rhs.obj_);
|
||||
swap(mtx_, rhs.mtx_);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,13 +156,12 @@ namespace boost
|
||||
BOOST_STATIC_ASSERT( (is_strict_lock<Lock>::value)); /*< lk is a strict lock "sur parolle" >*/
|
||||
BOOST_STATIC_ASSERT( (is_same<mutex_type, typename Lock::mutex_type>::value)); /*< that locks the same type >*/
|
||||
|
||||
BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(), lock_error() ); /*< run time check throw if no locked >*/
|
||||
BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/
|
||||
|
||||
return obj_;
|
||||
}
|
||||
|
||||
mutex_type* mutex()
|
||||
mutex_type* mutex() const BOOST_NOEXCEPT
|
||||
{
|
||||
return mtx_;
|
||||
}
|
||||
@@ -175,25 +204,45 @@ namespace boost
|
||||
public:
|
||||
typedef MutexType mutex_type;
|
||||
|
||||
BOOST_THREAD_MOVABLE_ONLY( externally_locked )
|
||||
BOOST_THREAD_COPYABLE_AND_MOVABLE( externally_locked )
|
||||
|
||||
/**
|
||||
* Effects: Constructs an externally locked object storing the cloaked reference object.
|
||||
*/
|
||||
externally_locked(T& obj, mutex_type& mtx) :
|
||||
externally_locked(T& obj, mutex_type& mtx) BOOST_NOEXCEPT :
|
||||
obj_(&obj), mtx_(&mtx)
|
||||
{
|
||||
}
|
||||
|
||||
/// move constructor
|
||||
externally_locked(BOOST_THREAD_RV_REF(externally_locked) rhs) :
|
||||
/// copy constructor
|
||||
externally_locked(externally_locked const& rhs) BOOST_NOEXCEPT :
|
||||
obj_(rhs.obj_), mtx_(rhs.mtx_)
|
||||
{
|
||||
rhs.obj_=0;
|
||||
rhs.mtx_=0;
|
||||
}
|
||||
|
||||
void swap(externally_locked& rhs)
|
||||
/// move constructor
|
||||
externally_locked(BOOST_THREAD_RV_REF(externally_locked) rhs) BOOST_NOEXCEPT :
|
||||
obj_(rhs.obj_), mtx_(rhs.mtx_)
|
||||
{
|
||||
}
|
||||
|
||||
/// assignment
|
||||
externally_locked& operator=(externally_locked const& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
obj_=rhs.obj_;
|
||||
mtx_=rhs.mtx_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// move assignment
|
||||
externally_locked& operator=(BOOST_THREAD_RV_REF(externally_locked) rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
obj_=rhs.obj_;
|
||||
mtx_=rhs.mtx_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(externally_locked& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
swap(obj_, rhs.obj_);
|
||||
swap(mtx_, rhs.mtx_);
|
||||
@@ -245,7 +294,6 @@ namespace boost
|
||||
BOOST_CONCEPT_ASSERT(( StrictLock<Lock> ));
|
||||
BOOST_STATIC_ASSERT( (is_strict_lock<Lock>::value)); /*< lk is a strict lock "sur parolle" >*/
|
||||
BOOST_STATIC_ASSERT( (is_same<mutex_type, typename Lock::mutex_type>::value)); /*< that locks the same type >*/
|
||||
//BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(), lock_error() ); /*< run time check throw if no locked >*/
|
||||
BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/
|
||||
return *obj_;
|
||||
}
|
||||
@@ -262,11 +310,10 @@ namespace boost
|
||||
BOOST_CONCEPT_ASSERT(( StrictLock<Lock> ));
|
||||
BOOST_STATIC_ASSERT( (is_strict_lock<Lock>::value)); /*< lk is a strict lock "sur parolle" >*/
|
||||
BOOST_STATIC_ASSERT( (is_same<mutex_type, typename Lock::mutex_type>::value)); /*< that locks the same type >*/
|
||||
//BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(), lock_error() ); /*< run time check throw if no locked >*/
|
||||
BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/
|
||||
return *obj_;
|
||||
}
|
||||
mutex_type* mutex()
|
||||
mutex_type* mutex() const BOOST_NOEXCEPT
|
||||
{
|
||||
return mtx_;
|
||||
}
|
||||
@@ -292,7 +339,7 @@ namespace boost
|
||||
//]
|
||||
|
||||
template <typename T, typename MutexType>
|
||||
void swap(externally_locked<T, MutexType> & lhs, externally_locked<T, MutexType> & rhs)
|
||||
void swap(externally_locked<T, MutexType> & lhs, externally_locked<T, MutexType> & rhs) // BOOST_NOEXCEPT
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
@@ -21,12 +21,6 @@
|
||||
namespace boost
|
||||
{
|
||||
|
||||
// inline static recursive_mutex& terminal_mutex()
|
||||
// {
|
||||
// static recursive_mutex mtx;
|
||||
// return mtx;
|
||||
// }
|
||||
|
||||
template <typename Stream, typename RecursiveMutex=recursive_mutex>
|
||||
class externally_locked_stream;
|
||||
|
||||
@@ -51,7 +45,7 @@ namespace boost
|
||||
{
|
||||
}
|
||||
|
||||
stream_guard(BOOST_THREAD_RV_REF(stream_guard) rhs)
|
||||
stream_guard(BOOST_THREAD_RV_REF(stream_guard) rhs) BOOST_NOEXCEPT
|
||||
: mtx_(rhs.mtx_)
|
||||
{
|
||||
rhs.mtx_= 0;
|
||||
@@ -62,22 +56,31 @@ namespace boost
|
||||
if (mtx_ != 0) mtx_->unlock();
|
||||
}
|
||||
|
||||
bool owns_lock(mutex_type const* l) const BOOST_NOEXCEPT
|
||||
bool owns_lock(const mutex_type * l) const BOOST_NOEXCEPT
|
||||
{
|
||||
return l == mtx_->mutex();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Requires mtx_
|
||||
*/
|
||||
Stream& get() const
|
||||
{
|
||||
BOOST_THREAD_ASSERT_PRECONDITION( mtx_, lock_error() );
|
||||
return mtx_->get(*this);
|
||||
}
|
||||
Stream& bypass() const
|
||||
{
|
||||
return get();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
externally_locked_stream<Stream, RecursiveMutex>* mtx_;
|
||||
};
|
||||
|
||||
template <typename Stream, typename RecursiveMutex>
|
||||
struct is_strict_lock_sur_parolle<stream_guard<Stream, RecursiveMutex> > : true_type
|
||||
struct is_strict_lock_sur_parole<stream_guard<Stream, RecursiveMutex> > : true_type
|
||||
{
|
||||
};
|
||||
|
||||
@@ -98,22 +101,20 @@ namespace boost
|
||||
/**
|
||||
* Effects: Constructs an externally locked object storing the cloaked reference object.
|
||||
*/
|
||||
externally_locked_stream(Stream& stream, RecursiveMutex& mtx) :
|
||||
externally_locked_stream(Stream& stream, RecursiveMutex& mtx) BOOST_NOEXCEPT :
|
||||
base_type(stream, mtx)
|
||||
{
|
||||
}
|
||||
|
||||
stream_guard<Stream, RecursiveMutex> hold()
|
||||
stream_guard<Stream, RecursiveMutex> hold() BOOST_NOEXCEPT
|
||||
{
|
||||
return stream_guard<Stream, RecursiveMutex> (*this);
|
||||
}
|
||||
|
||||
Stream& hold(strict_lock<RecursiveMutex>& lk)
|
||||
Stream& bypass() const
|
||||
{
|
||||
return this->get(lk);
|
||||
stream_guard<Stream, RecursiveMutex> lk(*this);
|
||||
return get(lk);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
//]
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -25,7 +25,7 @@ namespace boost
|
||||
template <typename Lockable>
|
||||
bool is_locked_by_this_thread(testable_mutex<Lockable> const& mtx)
|
||||
{
|
||||
return mtx.is_locked();
|
||||
return mtx.is_locked_by_this_thread();
|
||||
}
|
||||
template <typename Lockable>
|
||||
bool is_locked_by_this_thread(Lockable const&)
|
||||
|
||||
167
include/boost/thread/latch.hpp
Normal file
167
include/boost/thread/latch.hpp
Normal file
@@ -0,0 +1,167 @@
|
||||
// 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 2013 Vicente J. Botet Escriba
|
||||
|
||||
#ifndef BOOST_THREAD_LATCH_HPP
|
||||
#define BOOST_THREAD_LATCH_HPP
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
#include <boost/thread/detail/counter.hpp>
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/lock_types.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/chrono/duration.hpp>
|
||||
#include <boost/chrono/time_point.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class latch
|
||||
{
|
||||
/// @Requires: count_ must be greater than 0
|
||||
/// Effect: Decrement the count. Unlocks the lock and notify anyone waiting if we reached zero.
|
||||
/// Returns: true if count_ reached the value 0.
|
||||
/// @ThreadSafe ensured by the @c lk parameter
|
||||
bool count_down(unique_lock<mutex> &lk)
|
||||
/// pre_condition (count_ > 0)
|
||||
{
|
||||
BOOST_ASSERT(count_ > 0);
|
||||
if (--count_ == 0)
|
||||
{
|
||||
++generation_;
|
||||
lk.unlock();
|
||||
cond_.notify_all();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// Effect: Decrement the count is > 0. Unlocks the lock notify anyone waiting if we reached zero.
|
||||
/// Returns: true if count_ is 0.
|
||||
/// @ThreadSafe ensured by the @c lk parameter
|
||||
bool try_count_down(unique_lock<mutex> &lk)
|
||||
{
|
||||
if (count_ > 0)
|
||||
{
|
||||
return count_down(lk);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
BOOST_THREAD_NO_COPYABLE( latch)
|
||||
|
||||
/// Constructs a latch with a given count.
|
||||
latch(std::size_t count) :
|
||||
count_(count), generation_(0)
|
||||
{
|
||||
}
|
||||
|
||||
/// Destructor
|
||||
/// Precondition: No threads are waiting or invoking count_down on @c *this.
|
||||
|
||||
~latch()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// Blocks until the latch has counted down to zero.
|
||||
void wait()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mutex_);
|
||||
std::size_t generation(generation_);
|
||||
cond_.wait(lk, detail::not_equal(generation, generation_));
|
||||
}
|
||||
|
||||
/// @return true if the internal counter is already 0, false otherwise
|
||||
bool try_wait()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mutex_);
|
||||
return (count_ == 0);
|
||||
}
|
||||
|
||||
/// try to wait for a specified amount of time is elapsed.
|
||||
/// @return whether there is a timeout or not.
|
||||
template <class Rep, class Period>
|
||||
cv_status wait_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mutex_);
|
||||
std::size_t generation(generation_);
|
||||
return cond_.wait_for(lk, rel_time, detail::not_equal(generation, generation_))
|
||||
? cv_status::no_timeout
|
||||
: cv_status::timeout;
|
||||
}
|
||||
|
||||
/// try to wait until the specified time_point is reached
|
||||
/// @return whether there were a timeout or not.
|
||||
template <class Clock, class Duration>
|
||||
cv_status wait_until(const chrono::time_point<Clock, Duration>& abs_time)
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mutex_);
|
||||
std::size_t generation(generation_);
|
||||
return cond_.wait_until(lk, abs_time, detail::not_equal(generation, generation_))
|
||||
? cv_status::no_timeout
|
||||
: cv_status::timeout;
|
||||
}
|
||||
|
||||
/// Decrement the count and notify anyone waiting if we reach zero.
|
||||
/// @Requires count must be greater than 0
|
||||
void count_down()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mutex_);
|
||||
count_down(lk);
|
||||
}
|
||||
/// Effect: Decrement the count if it is > 0 and notify anyone waiting if we reached zero.
|
||||
/// Returns: true if count_ was 0 or reached 0.
|
||||
bool try_count_down()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mutex_);
|
||||
return try_count_down(lk);
|
||||
}
|
||||
void signal()
|
||||
{
|
||||
count_down();
|
||||
}
|
||||
|
||||
/// Decrement the count and notify anyone waiting if we reach zero.
|
||||
/// Blocks until the latch has counted down to zero.
|
||||
/// @Requires count must be greater than 0
|
||||
void count_down_and_wait()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(mutex_);
|
||||
std::size_t generation(generation_);
|
||||
if (count_down(lk))
|
||||
{
|
||||
return;
|
||||
}
|
||||
cond_.wait(lk, detail::not_equal(generation, generation_));
|
||||
}
|
||||
void sync()
|
||||
{
|
||||
count_down_and_wait();
|
||||
}
|
||||
|
||||
/// Reset the counter
|
||||
/// #Requires This method may only be invoked when there are no other threads currently inside the count_down_and_wait() method.
|
||||
void reset(std::size_t count)
|
||||
{
|
||||
boost::lock_guard<boost::mutex> lk(mutex_);
|
||||
//BOOST_ASSERT(count_ == 0);
|
||||
count_ = count;
|
||||
}
|
||||
|
||||
private:
|
||||
mutex mutex_;
|
||||
condition_variable cond_;
|
||||
std::size_t count_;
|
||||
std::size_t generation_;
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif
|
||||
@@ -30,7 +30,7 @@ namespace boost
|
||||
struct BasicLock
|
||||
{
|
||||
typedef typename Lk::mutex_type mutex_type;
|
||||
void cvt_mutex_ptr(mutex_type*);
|
||||
void cvt_mutex_ptr(mutex_type*) {}
|
||||
BOOST_CONCEPT_ASSERT(( BasicLockable<mutex_type> ));
|
||||
|
||||
BOOST_CONCEPT_USAGE(BasicLock)
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace boost
|
||||
* An strict lock is a lock ensuring the mutex is locked on the scope of the lock
|
||||
* There is no single way to define a strict lock as the strict_lock and
|
||||
* nesteed_strict_lock shows. So we need a metafunction that states if a
|
||||
* lock is a strict lock "sur parolle".
|
||||
* lock is a strict lock "sur parole".
|
||||
*/
|
||||
|
||||
template <typename Lock>
|
||||
@@ -34,7 +34,10 @@ struct is_strict_lock_sur_parolle : false_type {};
|
||||
|
||||
|
||||
template <typename Lock>
|
||||
struct is_strict_lock : is_strict_lock_sur_parolle<Lock> {};
|
||||
struct is_strict_lock_sur_parole : is_strict_lock_sur_parolle<Lock> {};
|
||||
|
||||
template <typename Lock>
|
||||
struct is_strict_lock : is_strict_lock_sur_parole<Lock> {};
|
||||
|
||||
}
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
@@ -174,7 +174,8 @@ namespace boost
|
||||
BOOST_THREAD_EXPLICIT_LOCK_CONVERSION unique_lock(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other);
|
||||
|
||||
#ifndef BOOST_THREAD_PROVIDES_EXPLICIT_LOCK_CONVERSION
|
||||
unique_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT
|
||||
//std-2104 unique_lock move-assignment should not be noexcept
|
||||
unique_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other) //BOOST_NOEXCEPT
|
||||
{
|
||||
unique_lock temp(::boost::move(other));
|
||||
swap(temp);
|
||||
@@ -182,7 +183,8 @@ namespace boost
|
||||
}
|
||||
#endif
|
||||
|
||||
unique_lock& operator=(BOOST_THREAD_RV_REF(unique_lock) other) BOOST_NOEXCEPT
|
||||
//std-2104 unique_lock move-assignment should not be noexcept
|
||||
unique_lock& operator=(BOOST_THREAD_RV_REF(unique_lock) other) //BOOST_NOEXCEPT
|
||||
{
|
||||
unique_lock temp(::boost::move(other));
|
||||
swap(temp);
|
||||
@@ -581,7 +583,8 @@ namespace boost
|
||||
BOOST_THREAD_RV(other).m=0;
|
||||
}
|
||||
|
||||
shared_lock& operator=(BOOST_THREAD_RV_REF_BEG shared_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT
|
||||
//std-2104 unique_lock move-assignment should not be noexcept
|
||||
shared_lock& operator=(BOOST_THREAD_RV_REF_BEG shared_lock<Mutex> BOOST_THREAD_RV_REF_END other) //BOOST_NOEXCEPT
|
||||
{
|
||||
shared_lock temp(::boost::move(other));
|
||||
swap(temp);
|
||||
@@ -826,7 +829,8 @@ namespace boost
|
||||
BOOST_THREAD_RV(other).m=0;
|
||||
}
|
||||
|
||||
upgrade_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT
|
||||
//std-2104 unique_lock move-assignment should not be noexcept
|
||||
upgrade_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_lock<Mutex> BOOST_THREAD_RV_REF_END other) //BOOST_NOEXCEPT
|
||||
{
|
||||
upgrade_lock temp(::boost::move(other));
|
||||
swap(temp);
|
||||
@@ -1073,7 +1077,8 @@ namespace boost
|
||||
BOOST_THREAD_RV(other).source=0;
|
||||
}
|
||||
|
||||
upgrade_to_unique_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_to_unique_lock<Mutex> BOOST_THREAD_RV_REF_END other) BOOST_NOEXCEPT
|
||||
//std-2104 unique_lock move-assignment should not be noexcept
|
||||
upgrade_to_unique_lock& operator=(BOOST_THREAD_RV_REF_BEG upgrade_to_unique_lock<Mutex> BOOST_THREAD_RV_REF_END other) //BOOST_NOEXCEPT
|
||||
{
|
||||
upgrade_to_unique_lock temp(other);
|
||||
swap(temp);
|
||||
@@ -1107,6 +1112,10 @@ namespace boost
|
||||
{
|
||||
return exclusive.owns_lock();
|
||||
}
|
||||
Mutex* mutex() const BOOST_NOEXCEPT
|
||||
{
|
||||
return exclusive.mutex();
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_THREAD_DCL_MOVABLE_BEG(Mutex) upgrade_to_unique_lock<Mutex> BOOST_THREAD_DCL_MOVABLE_END
|
||||
@@ -1182,7 +1191,7 @@ private unique_lock<Mutex>
|
||||
{
|
||||
return base::owns_lock();
|
||||
}
|
||||
Mutex* mutex() const
|
||||
Mutex* mutex() const BOOST_NOEXCEPT
|
||||
{
|
||||
return base::mutex();
|
||||
}
|
||||
|
||||
@@ -173,10 +173,15 @@ namespace boost
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
struct is_recursive_mutex_sur_parolle
|
||||
struct is_recursive_mutex_sur_parole
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
template<typename T>
|
||||
struct is_recursive_mutex_sur_parolle : is_recursive_mutex_sur_parole<T>
|
||||
{
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct is_recursive_basic_lockable
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#ifndef BOOST_THREAD_NULL_MUTEX_HPP
|
||||
#define BOOST_THREAD_NULL_MUTEX_HPP
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
#include <boost/chrono/chrono.hpp>
|
||||
|
||||
@@ -28,6 +29,8 @@ namespace boost
|
||||
|
||||
BOOST_THREAD_NO_COPYABLE( null_mutex) /*< no copyable >*/
|
||||
|
||||
null_mutex() {}
|
||||
|
||||
/// Simulates a mutex lock() operation. Empty function.
|
||||
void lock()
|
||||
{
|
||||
|
||||
@@ -9,11 +9,18 @@
|
||||
// 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/detail/platform.hpp>
|
||||
#if defined(BOOST_THREAD_PLATFORM_WIN32)
|
||||
#include <boost/thread/win32/once.hpp>
|
||||
#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
|
||||
#if defined BOOST_THREAD_ONCE_FAST_EPOCH
|
||||
#include <boost/thread/pthread/once.hpp>
|
||||
#elif defined BOOST_THREAD_ONCE_ATOMIC
|
||||
#include <boost/thread/pthread/once_atomic.hpp>
|
||||
#else
|
||||
#error "Once Not Implemented"
|
||||
#endif
|
||||
#else
|
||||
#error "Boost threads unavailable on this platform"
|
||||
#endif
|
||||
@@ -24,7 +31,9 @@ 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)
|
||||
template<typename Function>
|
||||
inline void call_once(Function func,once_flag& flag)
|
||||
//inline void call_once(void (*func)(),once_flag& flag)
|
||||
{
|
||||
call_once(flag,func);
|
||||
}
|
||||
|
||||
35
include/boost/thread/ostream_buffer.hpp
Normal file
35
include/boost/thread/ostream_buffer.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// (C) Copyright 2013 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_OSTREAM_BUFFER_HPP
|
||||
#define BOOST_THREAD_OSTREAM_BUFFER_HPP
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template <typename OStream>
|
||||
class ostream_buffer
|
||||
{
|
||||
public:
|
||||
typedef std::basic_ostringstream<typename OStream::char_type, typename OStream::traits_type> stream_type;
|
||||
ostream_buffer(OStream& os) : os_(os) {}
|
||||
~ostream_buffer() { os_ << o_str_.str(); }
|
||||
stream_type& stream() { return o_str_; }
|
||||
private:
|
||||
OStream& os_;
|
||||
stream_type o_str_;
|
||||
};
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif // header
|
||||
@@ -200,15 +200,15 @@ namespace boost
|
||||
|
||||
#if defined BOOST_THREAD_USES_DATETIME
|
||||
template<typename lock_type>
|
||||
bool timed_wait(lock_type& m,boost::system_time const& wait_until)
|
||||
bool timed_wait(lock_type& m,boost::system_time const& abs_time)
|
||||
{
|
||||
struct timespec const timeout=detail::to_timespec(wait_until);
|
||||
struct timespec const timeout=detail::to_timespec(abs_time);
|
||||
return do_wait_until(m, timeout);
|
||||
}
|
||||
template<typename lock_type>
|
||||
bool timed_wait(lock_type& m,xtime const& wait_until)
|
||||
bool timed_wait(lock_type& m,xtime const& abs_time)
|
||||
{
|
||||
return timed_wait(m,system_time(wait_until));
|
||||
return timed_wait(m,system_time(abs_time));
|
||||
}
|
||||
|
||||
template<typename lock_type,typename duration_type>
|
||||
@@ -218,20 +218,20 @@ namespace boost
|
||||
}
|
||||
|
||||
template<typename lock_type,typename predicate_type>
|
||||
bool timed_wait(lock_type& m,boost::system_time const& wait_until,predicate_type pred)
|
||||
bool timed_wait(lock_type& m,boost::system_time const& abs_time, predicate_type pred)
|
||||
{
|
||||
while (!pred())
|
||||
{
|
||||
if(!timed_wait(m, wait_until))
|
||||
if(!timed_wait(m, abs_time))
|
||||
return pred();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename lock_type,typename predicate_type>
|
||||
bool timed_wait(lock_type& m,xtime const& wait_until,predicate_type pred)
|
||||
bool timed_wait(lock_type& m,xtime const& abs_time, predicate_type pred)
|
||||
{
|
||||
return timed_wait(m,system_time(wait_until),pred);
|
||||
return timed_wait(m,system_time(abs_time),pred);
|
||||
}
|
||||
|
||||
template<typename lock_type,typename duration_type,typename predicate_type>
|
||||
|
||||
@@ -98,21 +98,21 @@ namespace boost
|
||||
#if defined BOOST_THREAD_USES_DATETIME
|
||||
inline bool timed_wait(
|
||||
unique_lock<mutex>& m,
|
||||
boost::system_time const& wait_until)
|
||||
boost::system_time const& abs_time)
|
||||
{
|
||||
#if defined BOOST_THREAD_WAIT_BUG
|
||||
struct timespec const timeout=detail::to_timespec(wait_until + BOOST_THREAD_WAIT_BUG);
|
||||
struct timespec const timeout=detail::to_timespec(abs_time + BOOST_THREAD_WAIT_BUG);
|
||||
return do_wait_until(m, timeout);
|
||||
#else
|
||||
struct timespec const timeout=detail::to_timespec(wait_until);
|
||||
struct timespec const timeout=detail::to_timespec(abs_time);
|
||||
return do_wait_until(m, timeout);
|
||||
#endif
|
||||
}
|
||||
bool timed_wait(
|
||||
unique_lock<mutex>& m,
|
||||
xtime const& wait_until)
|
||||
xtime const& abs_time)
|
||||
{
|
||||
return timed_wait(m,system_time(wait_until));
|
||||
return timed_wait(m,system_time(abs_time));
|
||||
}
|
||||
|
||||
template<typename duration_type>
|
||||
@@ -126,11 +126,11 @@ namespace boost
|
||||
template<typename predicate_type>
|
||||
bool timed_wait(
|
||||
unique_lock<mutex>& m,
|
||||
boost::system_time const& wait_until,predicate_type pred)
|
||||
boost::system_time const& abs_time,predicate_type pred)
|
||||
{
|
||||
while (!pred())
|
||||
{
|
||||
if(!timed_wait(m, wait_until))
|
||||
if(!timed_wait(m, abs_time))
|
||||
return pred();
|
||||
}
|
||||
return true;
|
||||
@@ -139,9 +139,9 @@ namespace boost
|
||||
template<typename predicate_type>
|
||||
bool timed_wait(
|
||||
unique_lock<mutex>& m,
|
||||
xtime const& wait_until,predicate_type pred)
|
||||
xtime const& abs_time,predicate_type pred)
|
||||
{
|
||||
return timed_wait(m,system_time(wait_until),pred);
|
||||
return timed_wait(m,system_time(abs_time),pred);
|
||||
}
|
||||
|
||||
template<typename duration_type,typename predicate_type>
|
||||
|
||||
@@ -26,15 +26,68 @@
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
|
||||
#ifdef _POSIX_TIMEOUTS
|
||||
#if _POSIX_TIMEOUTS >= 0 && _POSIX_C_SOURCE>=200112L
|
||||
#if _POSIX_TIMEOUTS >= 0 && _POSIX_TIMEOUTS>=200112L
|
||||
#ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
#define BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
#ifndef BOOST_THREAD_HAS_NO_EINTR_BUG
|
||||
#define BOOST_THREAD_HAS_EINTR_BUG
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace posix {
|
||||
#ifdef BOOST_THREAD_HAS_EINTR_BUG
|
||||
BOOST_FORCEINLINE int pthread_mutex_destroy(pthread_mutex_t* m)
|
||||
{
|
||||
int ret;
|
||||
do
|
||||
{
|
||||
ret = ::pthread_mutex_destroy(m);
|
||||
} while (ret == EINTR);
|
||||
return ret;
|
||||
}
|
||||
BOOST_FORCEINLINE int pthread_mutex_lock(pthread_mutex_t* m)
|
||||
{
|
||||
int ret;
|
||||
do
|
||||
{
|
||||
ret = ::pthread_mutex_lock(m);
|
||||
} while (ret == EINTR);
|
||||
return ret;
|
||||
}
|
||||
BOOST_FORCEINLINE int pthread_mutex_unlock(pthread_mutex_t* m)
|
||||
{
|
||||
int ret;
|
||||
do
|
||||
{
|
||||
ret = ::pthread_mutex_unlock(m);
|
||||
} while (ret == EINTR);
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
BOOST_FORCEINLINE int pthread_mutex_destroy(pthread_mutex_t* m)
|
||||
{
|
||||
return ::pthread_mutex_destroy(m);
|
||||
}
|
||||
BOOST_FORCEINLINE int pthread_mutex_lock(pthread_mutex_t* m)
|
||||
{
|
||||
return ::pthread_mutex_lock(m);
|
||||
}
|
||||
BOOST_FORCEINLINE int pthread_mutex_unlock(pthread_mutex_t* m)
|
||||
{
|
||||
return ::pthread_mutex_unlock(m);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
class mutex
|
||||
{
|
||||
private:
|
||||
@@ -52,20 +105,12 @@ namespace boost
|
||||
}
|
||||
~mutex()
|
||||
{
|
||||
int ret;
|
||||
do
|
||||
{
|
||||
ret = pthread_mutex_destroy(&m);
|
||||
} while (ret == EINTR);
|
||||
BOOST_VERIFY(!posix::pthread_mutex_destroy(&m));
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
int res;
|
||||
do
|
||||
{
|
||||
res = pthread_mutex_lock(&m);
|
||||
} while (res == EINTR);
|
||||
int res = posix::pthread_mutex_lock(&m);
|
||||
if (res)
|
||||
{
|
||||
boost::throw_exception(lock_error(res,"boost: mutex lock failed in pthread_mutex_lock"));
|
||||
@@ -74,14 +119,10 @@ namespace boost
|
||||
|
||||
void unlock()
|
||||
{
|
||||
int res;
|
||||
do
|
||||
{
|
||||
res = pthread_mutex_unlock(&m);
|
||||
} while (res == EINTR);
|
||||
int res = posix::pthread_mutex_unlock(&m);
|
||||
if (res)
|
||||
{
|
||||
boost::throw_exception(lock_error(res,"boost: mutex unlock failed in pthread_mutex_lock"));
|
||||
boost::throw_exception(lock_error(res,"boost: mutex unlock failed in pthread_mutex_unlock"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +177,8 @@ namespace boost
|
||||
int const res2=pthread_cond_init(&cond,NULL);
|
||||
if(res2)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_destroy(&m));
|
||||
BOOST_VERIFY(!posix::pthread_mutex_destroy(&m));
|
||||
//BOOST_VERIFY(!pthread_mutex_destroy(&m));
|
||||
boost::throw_exception(thread_resource_error(res2, "boost:: timed_mutex constructor failed in pthread_cond_init"));
|
||||
}
|
||||
is_locked=false;
|
||||
@@ -144,7 +186,7 @@ namespace boost
|
||||
}
|
||||
~timed_mutex()
|
||||
{
|
||||
BOOST_VERIFY(!pthread_mutex_destroy(&m));
|
||||
BOOST_VERIFY(!posix::pthread_mutex_destroy(&m));
|
||||
#ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
BOOST_VERIFY(!pthread_cond_destroy(&cond));
|
||||
#endif
|
||||
@@ -164,11 +206,7 @@ namespace boost
|
||||
#ifdef BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
void lock()
|
||||
{
|
||||
int res;
|
||||
do
|
||||
{
|
||||
res = pthread_mutex_lock(&m);
|
||||
} while (res == EINTR);
|
||||
int res = posix::pthread_mutex_lock(&m);
|
||||
if (res)
|
||||
{
|
||||
boost::throw_exception(lock_error(res,"boost: mutex lock failed in pthread_mutex_lock"));
|
||||
@@ -177,14 +215,10 @@ namespace boost
|
||||
|
||||
void unlock()
|
||||
{
|
||||
int res;
|
||||
do
|
||||
{
|
||||
res = pthread_mutex_unlock(&m);
|
||||
} while (res == EINTR);
|
||||
int res = posix::pthread_mutex_unlock(&m);
|
||||
if (res)
|
||||
{
|
||||
boost::throw_exception(lock_error(res,"boost: mutex unlock failed in pthread_mutex_lock"));
|
||||
boost::throw_exception(lock_error(res,"boost: mutex unlock failed in pthread_mutex_unlock"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,14 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/thread/detail/move.hpp>
|
||||
#include <boost/thread/detail/invoke.hpp>
|
||||
|
||||
#include <boost/thread/pthread/pthread_mutex_scoped_lock.hpp>
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
#include <boost/detail/no_exceptions_support.hpp>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
@@ -26,21 +29,32 @@
|
||||
namespace boost
|
||||
{
|
||||
|
||||
#define BOOST_ONCE_INITIAL_FLAG_VALUE 0
|
||||
struct once_flag;
|
||||
|
||||
#define BOOST_ONCE_INITIAL_FLAG_VALUE 0
|
||||
|
||||
namespace thread_detail
|
||||
{
|
||||
//#ifdef SIG_ATOMIC_MAX
|
||||
// typedef sig_atomic_t uintmax_atomic_t;
|
||||
// #define BOOST_THREAD_DETAIL_UINTMAX_ATOMIC_MAX_C SIG_ATOMIC_MAX
|
||||
//#else
|
||||
typedef unsigned long uintmax_atomic_t;
|
||||
#define BOOST_THREAD_DETAIL_UINTMAX_ATOMIC_C2(value) value##ul
|
||||
typedef boost::uint32_t uintmax_atomic_t;
|
||||
#define BOOST_THREAD_DETAIL_UINTMAX_ATOMIC_C2(value) value##u
|
||||
#define BOOST_THREAD_DETAIL_UINTMAX_ATOMIC_MAX_C BOOST_THREAD_DETAIL_UINTMAX_ATOMIC_C2(~0)
|
||||
//#endif
|
||||
|
||||
}
|
||||
|
||||
#ifdef BOOST_THREAD_PROVIDES_ONCE_CXX11
|
||||
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
||||
template<typename Function, class ...ArgTypes>
|
||||
inline void call_once(once_flag& flag, BOOST_THREAD_RV_REF(Function) f, BOOST_THREAD_RV_REF(ArgTypes)... args);
|
||||
#else
|
||||
template<typename Function>
|
||||
inline void call_once(once_flag& flag, Function f);
|
||||
template<typename Function, typename T1>
|
||||
inline void call_once(once_flag& flag, Function f, T1 p1);
|
||||
template<typename Function, typename T1, typename T2>
|
||||
inline void call_once(once_flag& flag, Function f, T1 p1, T2 p2);
|
||||
template<typename Function, typename T1, typename T2, typename T3>
|
||||
inline void call_once(once_flag& flag, Function f, T1 p1, T2 p2, T3 p3);
|
||||
#endif
|
||||
|
||||
struct once_flag
|
||||
{
|
||||
@@ -50,11 +64,26 @@ namespace boost
|
||||
{}
|
||||
private:
|
||||
volatile thread_detail::uintmax_atomic_t epoch;
|
||||
|
||||
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
||||
template<typename Function, class ...ArgTypes>
|
||||
friend void call_once(once_flag& flag, BOOST_THREAD_RV_REF(Function) f, BOOST_THREAD_RV_REF(ArgTypes)... args);
|
||||
#else
|
||||
template<typename Function>
|
||||
friend
|
||||
void call_once(once_flag& flag,Function f);
|
||||
friend void call_once(once_flag& flag, Function f);
|
||||
template<typename Function, typename T1>
|
||||
friend void call_once(once_flag& flag, Function f, T1 p1);
|
||||
template<typename Function, typename T1, typename T2>
|
||||
friend void call_once(once_flag& flag, Function f, T1 p1, T2 p2);
|
||||
template<typename Function, typename T1, typename T2, typename T3>
|
||||
friend void call_once(once_flag& flag, Function f, T1 p1, T2 p2, T3 p3);
|
||||
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#define BOOST_ONCE_INIT once_flag()
|
||||
|
||||
#else // BOOST_THREAD_PROVIDES_ONCE_CXX11
|
||||
|
||||
struct once_flag
|
||||
@@ -65,59 +94,445 @@ namespace boost
|
||||
#define BOOST_ONCE_INIT {BOOST_ONCE_INITIAL_FLAG_VALUE}
|
||||
#endif // BOOST_THREAD_PROVIDES_ONCE_CXX11
|
||||
|
||||
namespace detail
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_INVOKE
|
||||
#define BOOST_THREAD_INVOKE_RET_VOID detail::invoke
|
||||
#define BOOST_THREAD_INVOKE_RET_VOID_CALL
|
||||
#elif defined BOOST_THREAD_PROVIDES_INVOKE_RET
|
||||
#define BOOST_THREAD_INVOKE_RET_VOID detail::invoke<void>
|
||||
#define BOOST_THREAD_INVOKE_RET_VOID_CALL
|
||||
#else
|
||||
#define BOOST_THREAD_INVOKE_RET_VOID boost::bind
|
||||
#define BOOST_THREAD_INVOKE_RET_VOID_CALL ()
|
||||
#endif
|
||||
|
||||
namespace thread_detail
|
||||
{
|
||||
BOOST_THREAD_DECL thread_detail::uintmax_atomic_t& get_once_per_thread_epoch();
|
||||
BOOST_THREAD_DECL extern thread_detail::uintmax_atomic_t once_global_epoch;
|
||||
BOOST_THREAD_DECL uintmax_atomic_t& get_once_per_thread_epoch();
|
||||
BOOST_THREAD_DECL extern uintmax_atomic_t once_global_epoch;
|
||||
BOOST_THREAD_DECL extern pthread_mutex_t once_epoch_mutex;
|
||||
BOOST_THREAD_DECL extern pthread_cond_t once_epoch_cv;
|
||||
}
|
||||
|
||||
// Based on Mike Burrows fast_pthread_once algorithm as described in
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2444.html
|
||||
template<typename Function>
|
||||
void call_once(once_flag& flag,Function f)
|
||||
|
||||
|
||||
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
||||
|
||||
|
||||
template<typename Function, class ...ArgTypes>
|
||||
inline void call_once(once_flag& flag, BOOST_THREAD_RV_REF(Function) f, BOOST_THREAD_RV_REF(ArgTypes)... args)
|
||||
{
|
||||
static thread_detail::uintmax_atomic_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE;
|
||||
static thread_detail::uintmax_atomic_t const being_initialized=uninitialized_flag+1;
|
||||
thread_detail::uintmax_atomic_t const epoch=flag.epoch;
|
||||
thread_detail::uintmax_atomic_t& this_thread_epoch=thread_detail::get_once_per_thread_epoch();
|
||||
|
||||
if(epoch<this_thread_epoch)
|
||||
{
|
||||
static thread_detail::uintmax_atomic_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE;
|
||||
static thread_detail::uintmax_atomic_t const being_initialized=uninitialized_flag+1;
|
||||
thread_detail::uintmax_atomic_t const epoch=flag.epoch;
|
||||
thread_detail::uintmax_atomic_t& this_thread_epoch=detail::get_once_per_thread_epoch();
|
||||
pthread::pthread_mutex_scoped_lock lk(&thread_detail::once_epoch_mutex);
|
||||
|
||||
if(epoch<this_thread_epoch)
|
||||
while(flag.epoch<=being_initialized)
|
||||
{
|
||||
pthread::pthread_mutex_scoped_lock lk(&detail::once_epoch_mutex);
|
||||
|
||||
while(flag.epoch<=being_initialized)
|
||||
if(flag.epoch==uninitialized_flag)
|
||||
{
|
||||
if(flag.epoch==uninitialized_flag)
|
||||
flag.epoch=being_initialized;
|
||||
BOOST_TRY
|
||||
{
|
||||
flag.epoch=being_initialized;
|
||||
BOOST_TRY
|
||||
{
|
||||
pthread::pthread_mutex_scoped_unlock relocker(&detail::once_epoch_mutex);
|
||||
f();
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
flag.epoch=uninitialized_flag;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&detail::once_epoch_cv));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
flag.epoch=--detail::once_global_epoch;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&detail::once_epoch_cv));
|
||||
pthread::pthread_mutex_scoped_unlock relocker(&thread_detail::once_epoch_mutex);
|
||||
BOOST_THREAD_INVOKE_RET_VOID(
|
||||
thread_detail::decay_copy(boost::forward<Function>(f)),
|
||||
thread_detail::decay_copy(boost::forward<ArgTypes>(args))...
|
||||
) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
}
|
||||
else
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
while(flag.epoch==being_initialized)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_cond_wait(&detail::once_epoch_cv,&detail::once_epoch_mutex));
|
||||
}
|
||||
flag.epoch=uninitialized_flag;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
flag.epoch=--thread_detail::once_global_epoch;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
}
|
||||
else
|
||||
{
|
||||
while(flag.epoch==being_initialized)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_cond_wait(&thread_detail::once_epoch_cv,&thread_detail::once_epoch_mutex));
|
||||
}
|
||||
}
|
||||
this_thread_epoch=detail::once_global_epoch;
|
||||
}
|
||||
this_thread_epoch=thread_detail::once_global_epoch;
|
||||
|
||||
}
|
||||
}
|
||||
#else
|
||||
template<typename Function>
|
||||
inline void call_once(once_flag& flag, Function f)
|
||||
{
|
||||
static thread_detail::uintmax_atomic_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE;
|
||||
static thread_detail::uintmax_atomic_t const being_initialized=uninitialized_flag+1;
|
||||
thread_detail::uintmax_atomic_t const epoch=flag.epoch;
|
||||
thread_detail::uintmax_atomic_t& this_thread_epoch=thread_detail::get_once_per_thread_epoch();
|
||||
|
||||
if(epoch<this_thread_epoch)
|
||||
{
|
||||
pthread::pthread_mutex_scoped_lock lk(&thread_detail::once_epoch_mutex);
|
||||
|
||||
while(flag.epoch<=being_initialized)
|
||||
{
|
||||
if(flag.epoch==uninitialized_flag)
|
||||
{
|
||||
flag.epoch=being_initialized;
|
||||
BOOST_TRY
|
||||
{
|
||||
pthread::pthread_mutex_scoped_unlock relocker(&thread_detail::once_epoch_mutex);
|
||||
f();
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
flag.epoch=uninitialized_flag;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
flag.epoch=--thread_detail::once_global_epoch;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
}
|
||||
else
|
||||
{
|
||||
while(flag.epoch==being_initialized)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_cond_wait(&thread_detail::once_epoch_cv,&thread_detail::once_epoch_mutex));
|
||||
}
|
||||
}
|
||||
}
|
||||
this_thread_epoch=thread_detail::once_global_epoch;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Function, typename T1>
|
||||
inline void call_once(once_flag& flag, Function f, T1 p1)
|
||||
{
|
||||
static thread_detail::uintmax_atomic_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE;
|
||||
static thread_detail::uintmax_atomic_t const being_initialized=uninitialized_flag+1;
|
||||
thread_detail::uintmax_atomic_t const epoch=flag.epoch;
|
||||
thread_detail::uintmax_atomic_t& this_thread_epoch=thread_detail::get_once_per_thread_epoch();
|
||||
|
||||
if(epoch<this_thread_epoch)
|
||||
{
|
||||
pthread::pthread_mutex_scoped_lock lk(&thread_detail::once_epoch_mutex);
|
||||
|
||||
while(flag.epoch<=being_initialized)
|
||||
{
|
||||
if(flag.epoch==uninitialized_flag)
|
||||
{
|
||||
flag.epoch=being_initialized;
|
||||
BOOST_TRY
|
||||
{
|
||||
pthread::pthread_mutex_scoped_unlock relocker(&thread_detail::once_epoch_mutex);
|
||||
BOOST_THREAD_INVOKE_RET_VOID(f,p1) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
flag.epoch=uninitialized_flag;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
flag.epoch=--thread_detail::once_global_epoch;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
}
|
||||
else
|
||||
{
|
||||
while(flag.epoch==being_initialized)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_cond_wait(&thread_detail::once_epoch_cv,&thread_detail::once_epoch_mutex));
|
||||
}
|
||||
}
|
||||
}
|
||||
this_thread_epoch=thread_detail::once_global_epoch;
|
||||
}
|
||||
}
|
||||
template<typename Function, typename T1, typename T2>
|
||||
inline void call_once(once_flag& flag, Function f, T1 p1, T2 p2)
|
||||
{
|
||||
static thread_detail::uintmax_atomic_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE;
|
||||
static thread_detail::uintmax_atomic_t const being_initialized=uninitialized_flag+1;
|
||||
thread_detail::uintmax_atomic_t const epoch=flag.epoch;
|
||||
thread_detail::uintmax_atomic_t& this_thread_epoch=thread_detail::get_once_per_thread_epoch();
|
||||
|
||||
if(epoch<this_thread_epoch)
|
||||
{
|
||||
pthread::pthread_mutex_scoped_lock lk(&thread_detail::once_epoch_mutex);
|
||||
|
||||
while(flag.epoch<=being_initialized)
|
||||
{
|
||||
if(flag.epoch==uninitialized_flag)
|
||||
{
|
||||
flag.epoch=being_initialized;
|
||||
BOOST_TRY
|
||||
{
|
||||
pthread::pthread_mutex_scoped_unlock relocker(&thread_detail::once_epoch_mutex);
|
||||
BOOST_THREAD_INVOKE_RET_VOID(f,p1, p2) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
flag.epoch=uninitialized_flag;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
flag.epoch=--thread_detail::once_global_epoch;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
}
|
||||
else
|
||||
{
|
||||
while(flag.epoch==being_initialized)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_cond_wait(&thread_detail::once_epoch_cv,&thread_detail::once_epoch_mutex));
|
||||
}
|
||||
}
|
||||
}
|
||||
this_thread_epoch=thread_detail::once_global_epoch;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Function, typename T1, typename T2, typename T3>
|
||||
inline void call_once(once_flag& flag, Function f, T1 p1, T2 p2, T3 p3)
|
||||
{
|
||||
static thread_detail::uintmax_atomic_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE;
|
||||
static thread_detail::uintmax_atomic_t const being_initialized=uninitialized_flag+1;
|
||||
thread_detail::uintmax_atomic_t const epoch=flag.epoch;
|
||||
thread_detail::uintmax_atomic_t& this_thread_epoch=thread_detail::get_once_per_thread_epoch();
|
||||
|
||||
if(epoch<this_thread_epoch)
|
||||
{
|
||||
pthread::pthread_mutex_scoped_lock lk(&thread_detail::once_epoch_mutex);
|
||||
|
||||
while(flag.epoch<=being_initialized)
|
||||
{
|
||||
if(flag.epoch==uninitialized_flag)
|
||||
{
|
||||
flag.epoch=being_initialized;
|
||||
BOOST_TRY
|
||||
{
|
||||
pthread::pthread_mutex_scoped_unlock relocker(&thread_detail::once_epoch_mutex);
|
||||
BOOST_THREAD_INVOKE_RET_VOID(f,p1, p2, p3) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
flag.epoch=uninitialized_flag;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
flag.epoch=--thread_detail::once_global_epoch;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
}
|
||||
else
|
||||
{
|
||||
while(flag.epoch==being_initialized)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_cond_wait(&thread_detail::once_epoch_cv,&thread_detail::once_epoch_mutex));
|
||||
}
|
||||
}
|
||||
}
|
||||
this_thread_epoch=thread_detail::once_global_epoch;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Function>
|
||||
inline void call_once(once_flag& flag, BOOST_THREAD_RV_REF(Function) f)
|
||||
{
|
||||
static thread_detail::uintmax_atomic_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE;
|
||||
static thread_detail::uintmax_atomic_t const being_initialized=uninitialized_flag+1;
|
||||
thread_detail::uintmax_atomic_t const epoch=flag.epoch;
|
||||
thread_detail::uintmax_atomic_t& this_thread_epoch=thread_detail::get_once_per_thread_epoch();
|
||||
|
||||
if(epoch<this_thread_epoch)
|
||||
{
|
||||
pthread::pthread_mutex_scoped_lock lk(&thread_detail::once_epoch_mutex);
|
||||
|
||||
while(flag.epoch<=being_initialized)
|
||||
{
|
||||
if(flag.epoch==uninitialized_flag)
|
||||
{
|
||||
flag.epoch=being_initialized;
|
||||
BOOST_TRY
|
||||
{
|
||||
pthread::pthread_mutex_scoped_unlock relocker(&thread_detail::once_epoch_mutex);
|
||||
f();
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
flag.epoch=uninitialized_flag;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
flag.epoch=--thread_detail::once_global_epoch;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
}
|
||||
else
|
||||
{
|
||||
while(flag.epoch==being_initialized)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_cond_wait(&thread_detail::once_epoch_cv,&thread_detail::once_epoch_mutex));
|
||||
}
|
||||
}
|
||||
}
|
||||
this_thread_epoch=thread_detail::once_global_epoch;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Function, typename T1>
|
||||
inline void call_once(once_flag& flag, BOOST_THREAD_RV_REF(Function) f, BOOST_THREAD_RV_REF(T1) p1)
|
||||
{
|
||||
static thread_detail::uintmax_atomic_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE;
|
||||
static thread_detail::uintmax_atomic_t const being_initialized=uninitialized_flag+1;
|
||||
thread_detail::uintmax_atomic_t const epoch=flag.epoch;
|
||||
thread_detail::uintmax_atomic_t& this_thread_epoch=thread_detail::get_once_per_thread_epoch();
|
||||
|
||||
if(epoch<this_thread_epoch)
|
||||
{
|
||||
pthread::pthread_mutex_scoped_lock lk(&thread_detail::once_epoch_mutex);
|
||||
|
||||
while(flag.epoch<=being_initialized)
|
||||
{
|
||||
if(flag.epoch==uninitialized_flag)
|
||||
{
|
||||
flag.epoch=being_initialized;
|
||||
BOOST_TRY
|
||||
{
|
||||
pthread::pthread_mutex_scoped_unlock relocker(&thread_detail::once_epoch_mutex);
|
||||
BOOST_THREAD_INVOKE_RET_VOID(
|
||||
thread_detail::decay_copy(boost::forward<Function>(f)),
|
||||
thread_detail::decay_copy(boost::forward<T1>(p1))
|
||||
) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
flag.epoch=uninitialized_flag;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
flag.epoch=--thread_detail::once_global_epoch;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
}
|
||||
else
|
||||
{
|
||||
while(flag.epoch==being_initialized)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_cond_wait(&thread_detail::once_epoch_cv,&thread_detail::once_epoch_mutex));
|
||||
}
|
||||
}
|
||||
}
|
||||
this_thread_epoch=thread_detail::once_global_epoch;
|
||||
}
|
||||
}
|
||||
template<typename Function, typename T1, typename T2>
|
||||
inline void call_once(once_flag& flag, BOOST_THREAD_RV_REF(Function) f, BOOST_THREAD_RV_REF(T1) p1, BOOST_THREAD_RV_REF(T2) p2)
|
||||
{
|
||||
static thread_detail::uintmax_atomic_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE;
|
||||
static thread_detail::uintmax_atomic_t const being_initialized=uninitialized_flag+1;
|
||||
thread_detail::uintmax_atomic_t const epoch=flag.epoch;
|
||||
thread_detail::uintmax_atomic_t& this_thread_epoch=thread_detail::get_once_per_thread_epoch();
|
||||
|
||||
if(epoch<this_thread_epoch)
|
||||
{
|
||||
pthread::pthread_mutex_scoped_lock lk(&thread_detail::once_epoch_mutex);
|
||||
|
||||
while(flag.epoch<=being_initialized)
|
||||
{
|
||||
if(flag.epoch==uninitialized_flag)
|
||||
{
|
||||
flag.epoch=being_initialized;
|
||||
BOOST_TRY
|
||||
{
|
||||
pthread::pthread_mutex_scoped_unlock relocker(&thread_detail::once_epoch_mutex);
|
||||
BOOST_THREAD_INVOKE_RET_VOID(
|
||||
thread_detail::decay_copy(boost::forward<Function>(f)),
|
||||
thread_detail::decay_copy(boost::forward<T1>(p1)),
|
||||
thread_detail::decay_copy(boost::forward<T1>(p2))
|
||||
) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
flag.epoch=uninitialized_flag;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
flag.epoch=--thread_detail::once_global_epoch;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
}
|
||||
else
|
||||
{
|
||||
while(flag.epoch==being_initialized)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_cond_wait(&thread_detail::once_epoch_cv,&thread_detail::once_epoch_mutex));
|
||||
}
|
||||
}
|
||||
}
|
||||
this_thread_epoch=thread_detail::once_global_epoch;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Function, typename T1, typename T2, typename T3>
|
||||
inline void call_once(once_flag& flag, BOOST_THREAD_RV_REF(Function) f, BOOST_THREAD_RV_REF(T1) p1, BOOST_THREAD_RV_REF(T2) p2, BOOST_THREAD_RV_REF(T3) p3)
|
||||
{
|
||||
static thread_detail::uintmax_atomic_t const uninitialized_flag=BOOST_ONCE_INITIAL_FLAG_VALUE;
|
||||
static thread_detail::uintmax_atomic_t const being_initialized=uninitialized_flag+1;
|
||||
thread_detail::uintmax_atomic_t const epoch=flag.epoch;
|
||||
thread_detail::uintmax_atomic_t& this_thread_epoch=thread_detail::get_once_per_thread_epoch();
|
||||
|
||||
if(epoch<this_thread_epoch)
|
||||
{
|
||||
pthread::pthread_mutex_scoped_lock lk(&thread_detail::once_epoch_mutex);
|
||||
|
||||
while(flag.epoch<=being_initialized)
|
||||
{
|
||||
if(flag.epoch==uninitialized_flag)
|
||||
{
|
||||
flag.epoch=being_initialized;
|
||||
BOOST_TRY
|
||||
{
|
||||
pthread::pthread_mutex_scoped_unlock relocker(&thread_detail::once_epoch_mutex);
|
||||
BOOST_THREAD_INVOKE_RET_VOID(
|
||||
thread_detail::decay_copy(boost::forward<Function>(f)),
|
||||
thread_detail::decay_copy(boost::forward<T1>(p1)),
|
||||
thread_detail::decay_copy(boost::forward<T1>(p2)),
|
||||
thread_detail::decay_copy(boost::forward<T1>(p3))
|
||||
) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
flag.epoch=uninitialized_flag;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
flag.epoch=--thread_detail::once_global_epoch;
|
||||
BOOST_VERIFY(!pthread_cond_broadcast(&thread_detail::once_epoch_cv));
|
||||
}
|
||||
else
|
||||
{
|
||||
while(flag.epoch==being_initialized)
|
||||
{
|
||||
BOOST_VERIFY(!pthread_cond_wait(&thread_detail::once_epoch_cv,&thread_detail::once_epoch_mutex));
|
||||
}
|
||||
}
|
||||
}
|
||||
this_thread_epoch=thread_detail::once_global_epoch;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
313
include/boost/thread/pthread/once_atomic.hpp
Normal file
313
include/boost/thread/pthread/once_atomic.hpp
Normal file
@@ -0,0 +1,313 @@
|
||||
#ifndef BOOST_THREAD_PTHREAD_ONCE_ATOMIC_HPP
|
||||
#define BOOST_THREAD_PTHREAD_ONCE_ATOMIC_HPP
|
||||
|
||||
// once.hpp
|
||||
//
|
||||
// (C) Copyright 2013 Andrey Semashev
|
||||
// (C) Copyright 2013 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 <boost/thread/detail/config.hpp>
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/thread/detail/move.hpp>
|
||||
#include <boost/thread/detail/invoke.hpp>
|
||||
#include <boost/detail/no_exceptions_support.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/atomic.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
struct once_flag;
|
||||
|
||||
namespace thread_detail
|
||||
{
|
||||
|
||||
#if BOOST_ATOMIC_INT_LOCK_FREE == 2
|
||||
typedef unsigned int atomic_int_type;
|
||||
#elif BOOST_ATOMIC_SHORT_LOCK_FREE == 2
|
||||
typedef unsigned short atomic_int_type;
|
||||
#elif BOOST_ATOMIC_CHAR_LOCK_FREE == 2
|
||||
typedef unsigned char atomic_int_type;
|
||||
#elif BOOST_ATOMIC_LONG_LOCK_FREE == 2
|
||||
typedef unsigned long atomic_int_type;
|
||||
#elif defined(BOOST_HAS_LONG_LONG) && BOOST_ATOMIC_LLONG_LOCK_FREE == 2
|
||||
typedef ulong_long_type atomic_int_type;
|
||||
#else
|
||||
// All tested integer types are not atomic, the spinlock pool will be used
|
||||
typedef unsigned int atomic_int_type;
|
||||
#endif
|
||||
|
||||
typedef boost::atomic<atomic_int_type> atomic_type;
|
||||
|
||||
BOOST_THREAD_DECL bool enter_once_region(once_flag& flag) BOOST_NOEXCEPT;
|
||||
BOOST_THREAD_DECL void commit_once_region(once_flag& flag) BOOST_NOEXCEPT;
|
||||
BOOST_THREAD_DECL void rollback_once_region(once_flag& flag) BOOST_NOEXCEPT;
|
||||
inline atomic_type& get_atomic_storage(once_flag& flag) BOOST_NOEXCEPT;
|
||||
}
|
||||
|
||||
#ifdef BOOST_THREAD_PROVIDES_ONCE_CXX11
|
||||
|
||||
struct once_flag
|
||||
{
|
||||
BOOST_THREAD_NO_COPYABLE(once_flag)
|
||||
BOOST_CONSTEXPR once_flag() BOOST_NOEXCEPT : storage(0)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
thread_detail::atomic_type storage;
|
||||
|
||||
friend BOOST_THREAD_DECL bool thread_detail::enter_once_region(once_flag& flag) BOOST_NOEXCEPT;
|
||||
friend BOOST_THREAD_DECL void thread_detail::commit_once_region(once_flag& flag) BOOST_NOEXCEPT;
|
||||
friend BOOST_THREAD_DECL void thread_detail::rollback_once_region(once_flag& flag) BOOST_NOEXCEPT;
|
||||
friend thread_detail::atomic_type& thread_detail::get_atomic_storage(once_flag& flag) BOOST_NOEXCEPT;
|
||||
};
|
||||
|
||||
#define BOOST_ONCE_INIT boost::once_flag()
|
||||
|
||||
namespace thread_detail
|
||||
{
|
||||
inline atomic_type& get_atomic_storage(once_flag& flag) BOOST_NOEXCEPT
|
||||
{
|
||||
//return reinterpret_cast< atomic_type& >(flag.storage);
|
||||
return flag.storage;
|
||||
}
|
||||
}
|
||||
|
||||
#else // BOOST_THREAD_PROVIDES_ONCE_CXX11
|
||||
struct once_flag
|
||||
{
|
||||
// The thread_detail::atomic_int_type storage is marked
|
||||
// with this attribute in order to let the compiler know that it will alias this member
|
||||
// and silence compilation warnings.
|
||||
BOOST_THREAD_ATTRIBUTE_MAY_ALIAS thread_detail::atomic_int_type storage;
|
||||
};
|
||||
|
||||
#define BOOST_ONCE_INIT {0}
|
||||
|
||||
namespace thread_detail
|
||||
{
|
||||
inline atomic_type& get_atomic_storage(once_flag& flag) BOOST_NOEXCEPT
|
||||
{
|
||||
return reinterpret_cast< atomic_type& >(flag.storage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // BOOST_THREAD_PROVIDES_ONCE_CXX11
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_INVOKE
|
||||
#define BOOST_THREAD_INVOKE_RET_VOID detail::invoke
|
||||
#define BOOST_THREAD_INVOKE_RET_VOID_CALL
|
||||
#elif defined BOOST_THREAD_PROVIDES_INVOKE_RET
|
||||
#define BOOST_THREAD_INVOKE_RET_VOID detail::invoke<void>
|
||||
#define BOOST_THREAD_INVOKE_RET_VOID_CALL
|
||||
#else
|
||||
#define BOOST_THREAD_INVOKE_RET_VOID boost::bind
|
||||
#define BOOST_THREAD_INVOKE_RET_VOID_CALL ()
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
||||
|
||||
template<typename Function, class ...ArgTypes>
|
||||
inline void call_once(once_flag& flag, BOOST_THREAD_RV_REF(Function) f, BOOST_THREAD_RV_REF(ArgTypes)... args)
|
||||
{
|
||||
if (thread_detail::enter_once_region(flag))
|
||||
{
|
||||
BOOST_TRY
|
||||
{
|
||||
BOOST_THREAD_INVOKE_RET_VOID(
|
||||
thread_detail::decay_copy(boost::forward<Function>(f)),
|
||||
thread_detail::decay_copy(boost::forward<ArgTypes>(args))...
|
||||
) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
thread_detail::rollback_once_region(flag);
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
thread_detail::commit_once_region(flag);
|
||||
}
|
||||
}
|
||||
#else
|
||||
template<typename Function>
|
||||
inline void call_once(once_flag& flag, Function f)
|
||||
{
|
||||
if (thread_detail::enter_once_region(flag))
|
||||
{
|
||||
BOOST_TRY
|
||||
{
|
||||
f();
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
thread_detail::rollback_once_region(flag);
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
thread_detail::commit_once_region(flag);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Function, typename T1>
|
||||
inline void call_once(once_flag& flag, Function f, T1 p1)
|
||||
{
|
||||
if (thread_detail::enter_once_region(flag))
|
||||
{
|
||||
BOOST_TRY
|
||||
{
|
||||
BOOST_THREAD_INVOKE_RET_VOID(f, p1) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
thread_detail::rollback_once_region(flag);
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
thread_detail::commit_once_region(flag);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Function, typename T1, typename T2>
|
||||
inline void call_once(once_flag& flag, Function f, T1 p1, T2 p2)
|
||||
{
|
||||
if (thread_detail::enter_once_region(flag))
|
||||
{
|
||||
BOOST_TRY
|
||||
{
|
||||
BOOST_THREAD_INVOKE_RET_VOID(f, p1, p2) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
thread_detail::rollback_once_region(flag);
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
thread_detail::commit_once_region(flag);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Function, typename T1, typename T2, typename T3>
|
||||
inline void call_once(once_flag& flag, Function f, T1 p1, T2 p2, T3 p3)
|
||||
{
|
||||
if (thread_detail::enter_once_region(flag))
|
||||
{
|
||||
BOOST_TRY
|
||||
{
|
||||
BOOST_THREAD_INVOKE_RET_VOID(f, p1, p2, p3) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
thread_detail::rollback_once_region(flag);
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
thread_detail::commit_once_region(flag);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Function>
|
||||
inline void call_once(once_flag& flag, BOOST_THREAD_RV_REF(Function) f)
|
||||
{
|
||||
if (thread_detail::enter_once_region(flag))
|
||||
{
|
||||
BOOST_TRY
|
||||
{
|
||||
f();
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
thread_detail::rollback_once_region(flag);
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
thread_detail::commit_once_region(flag);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Function, typename T1>
|
||||
inline void call_once(once_flag& flag, BOOST_THREAD_RV_REF(Function) f, BOOST_THREAD_RV_REF(T1) p1)
|
||||
{
|
||||
if (thread_detail::enter_once_region(flag))
|
||||
{
|
||||
BOOST_TRY
|
||||
{
|
||||
BOOST_THREAD_INVOKE_RET_VOID(
|
||||
thread_detail::decay_copy(boost::forward<Function>(f)),
|
||||
thread_detail::decay_copy(boost::forward<T1>(p1))
|
||||
) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
thread_detail::rollback_once_region(flag);
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
thread_detail::commit_once_region(flag);
|
||||
}
|
||||
}
|
||||
template<typename Function, typename T1, typename T2>
|
||||
inline void call_once(once_flag& flag, BOOST_THREAD_RV_REF(Function) f, BOOST_THREAD_RV_REF(T1) p1, BOOST_THREAD_RV_REF(T2) p2)
|
||||
{
|
||||
if (thread_detail::enter_once_region(flag))
|
||||
{
|
||||
BOOST_TRY
|
||||
{
|
||||
BOOST_THREAD_INVOKE_RET_VOID(
|
||||
thread_detail::decay_copy(boost::forward<Function>(f)),
|
||||
thread_detail::decay_copy(boost::forward<T1>(p1)),
|
||||
thread_detail::decay_copy(boost::forward<T1>(p2))
|
||||
) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
thread_detail::rollback_once_region(flag);
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
thread_detail::commit_once_region(flag);
|
||||
}
|
||||
}
|
||||
template<typename Function, typename T1, typename T2, typename T3>
|
||||
inline void call_once(once_flag& flag, BOOST_THREAD_RV_REF(Function) f, BOOST_THREAD_RV_REF(T1) p1, BOOST_THREAD_RV_REF(T2) p2, BOOST_THREAD_RV_REF(T3) p3)
|
||||
{
|
||||
if (thread_detail::enter_once_region(flag))
|
||||
{
|
||||
BOOST_TRY
|
||||
{
|
||||
BOOST_THREAD_INVOKE_RET_VOID(
|
||||
thread_detail::decay_copy(boost::forward<Function>(f)),
|
||||
thread_detail::decay_copy(boost::forward<T1>(p1)),
|
||||
thread_detail::decay_copy(boost::forward<T1>(p2)),
|
||||
thread_detail::decay_copy(boost::forward<T1>(p3))
|
||||
) BOOST_THREAD_INVOKE_RET_VOID_CALL;
|
||||
|
||||
}
|
||||
BOOST_CATCH (...)
|
||||
{
|
||||
thread_detail::rollback_once_region(flag);
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
thread_detail::commit_once_region(flag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,10 +28,13 @@
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
|
||||
#ifdef _POSIX_TIMEOUTS
|
||||
#if _POSIX_TIMEOUTS >= 0
|
||||
#if _POSIX_TIMEOUTS >= 0 && _POSIX_TIMEOUTS>=200112L
|
||||
#ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
#define BOOST_PTHREAD_HAS_TIMEDLOCK
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE) && defined(BOOST_PTHREAD_HAS_TIMEDLOCK)
|
||||
#define BOOST_USE_PTHREAD_RECURSIVE_TIMEDLOCK
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <boost/chrono/ceil.hpp>
|
||||
#endif
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
@@ -28,8 +29,125 @@ namespace boost
|
||||
class shared_mutex
|
||||
{
|
||||
private:
|
||||
struct state_data
|
||||
class state_data
|
||||
{
|
||||
public:
|
||||
state_data () :
|
||||
shared_count(0),
|
||||
exclusive(false),
|
||||
upgrade(false),
|
||||
exclusive_waiting_blocked(false)
|
||||
{}
|
||||
|
||||
void assert_free() const
|
||||
{
|
||||
BOOST_ASSERT( ! exclusive );
|
||||
BOOST_ASSERT( ! upgrade );
|
||||
BOOST_ASSERT( shared_count==0 );
|
||||
}
|
||||
|
||||
void assert_locked() const
|
||||
{
|
||||
BOOST_ASSERT( exclusive );
|
||||
BOOST_ASSERT( shared_count==0 );
|
||||
BOOST_ASSERT( ! upgrade );
|
||||
}
|
||||
|
||||
void assert_lock_shared () const
|
||||
{
|
||||
BOOST_ASSERT( ! exclusive );
|
||||
BOOST_ASSERT( shared_count>0 );
|
||||
//BOOST_ASSERT( (! upgrade) || (shared_count>1));
|
||||
// if upgraded there are at least 2 threads sharing the mutex,
|
||||
// except when unlock_upgrade_and_lock has decreased the number of readers but has not taken yet exclusive ownership.
|
||||
}
|
||||
|
||||
void assert_lock_upgraded () const
|
||||
{
|
||||
BOOST_ASSERT( ! exclusive );
|
||||
BOOST_ASSERT( upgrade );
|
||||
BOOST_ASSERT( shared_count>0 );
|
||||
}
|
||||
|
||||
void assert_lock_not_upgraded () const
|
||||
{
|
||||
BOOST_ASSERT( ! upgrade );
|
||||
}
|
||||
|
||||
bool can_lock () const
|
||||
{
|
||||
return ! (shared_count || exclusive);
|
||||
}
|
||||
|
||||
void exclusive_blocked (bool blocked)
|
||||
{
|
||||
exclusive_waiting_blocked = blocked;
|
||||
}
|
||||
|
||||
void lock ()
|
||||
{
|
||||
exclusive = true;
|
||||
}
|
||||
|
||||
void unlock ()
|
||||
{
|
||||
exclusive = false;
|
||||
exclusive_waiting_blocked = false;
|
||||
}
|
||||
|
||||
bool can_lock_shared () const
|
||||
{
|
||||
return ! (exclusive || exclusive_waiting_blocked);
|
||||
}
|
||||
|
||||
bool more_shared () const
|
||||
{
|
||||
return shared_count > 0 ;
|
||||
}
|
||||
unsigned get_shared_count () const
|
||||
{
|
||||
return shared_count ;
|
||||
}
|
||||
unsigned lock_shared ()
|
||||
{
|
||||
return ++shared_count;
|
||||
}
|
||||
|
||||
|
||||
void unlock_shared ()
|
||||
{
|
||||
--shared_count;
|
||||
}
|
||||
|
||||
bool unlock_shared_downgrades()
|
||||
{
|
||||
if (upgrade) {
|
||||
upgrade=false;
|
||||
exclusive=true;
|
||||
return true;
|
||||
} else {
|
||||
exclusive_waiting_blocked=false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void lock_upgrade ()
|
||||
{
|
||||
++shared_count;
|
||||
upgrade=true;
|
||||
}
|
||||
bool can_lock_upgrade () const
|
||||
{
|
||||
return ! (exclusive || exclusive_waiting_blocked || upgrade);
|
||||
}
|
||||
|
||||
void unlock_upgrade ()
|
||||
{
|
||||
upgrade=false;
|
||||
--shared_count;
|
||||
}
|
||||
|
||||
//private:
|
||||
unsigned shared_count;
|
||||
bool exclusive;
|
||||
bool upgrade;
|
||||
@@ -51,12 +169,11 @@ namespace boost
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
BOOST_THREAD_NO_COPYABLE(shared_mutex)
|
||||
|
||||
shared_mutex()
|
||||
{
|
||||
state_data state_={0,0,0,0};
|
||||
state=state_;
|
||||
}
|
||||
|
||||
~shared_mutex()
|
||||
@@ -69,27 +186,23 @@ namespace boost
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
|
||||
while(state.exclusive || state.exclusive_waiting_blocked)
|
||||
while(!state.can_lock_shared())
|
||||
{
|
||||
shared_cond.wait(lk);
|
||||
}
|
||||
++state.shared_count;
|
||||
state.lock_shared();
|
||||
}
|
||||
|
||||
bool try_lock_shared()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
|
||||
if(state.exclusive || state.exclusive_waiting_blocked)
|
||||
if(!state.can_lock_shared())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
++state.shared_count;
|
||||
return true;
|
||||
}
|
||||
state.lock_shared();
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined BOOST_THREAD_USES_DATETIME
|
||||
@@ -100,14 +213,14 @@ namespace boost
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
|
||||
while(state.exclusive || state.exclusive_waiting_blocked)
|
||||
while(!state.can_lock_shared())
|
||||
{
|
||||
if(!shared_cond.timed_wait(lk,timeout))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
++state.shared_count;
|
||||
state.lock_shared();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -131,33 +244,38 @@ namespace boost
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
|
||||
while(state.exclusive || state.exclusive_waiting_blocked)
|
||||
while(!state.can_lock_shared())
|
||||
//while(state.exclusive || state.exclusive_waiting_blocked)
|
||||
{
|
||||
if(cv_status::timeout==shared_cond.wait_until(lk,abs_time))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
++state.shared_count;
|
||||
state.lock_shared();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
void unlock_shared()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
bool const last_reader=!--state.shared_count;
|
||||
|
||||
if(last_reader)
|
||||
state.assert_lock_shared();
|
||||
state.unlock_shared();
|
||||
if (! state.more_shared())
|
||||
{
|
||||
if(state.upgrade)
|
||||
if (state.upgrade)
|
||||
{
|
||||
// As there is a thread doing a unlock_upgrade_and_lock that is waiting for ! state.more_shared()
|
||||
// avoid other threads to lock, lock_upgrade or lock_shared, so only this thread is notified.
|
||||
state.upgrade=false;
|
||||
state.exclusive=true;
|
||||
lk.unlock();
|
||||
upgrade_cond.notify_one();
|
||||
}
|
||||
else
|
||||
{
|
||||
state.exclusive_waiting_blocked=false;
|
||||
lk.unlock();
|
||||
}
|
||||
release_waiters();
|
||||
}
|
||||
@@ -170,7 +288,7 @@ namespace boost
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
|
||||
while(state.shared_count || state.exclusive)
|
||||
while (state.shared_count || state.exclusive)
|
||||
{
|
||||
state.exclusive_waiting_blocked=true;
|
||||
exclusive_cond.wait(lk);
|
||||
@@ -262,8 +380,10 @@ namespace boost
|
||||
void unlock()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_locked();
|
||||
state.exclusive=false;
|
||||
state.exclusive_waiting_blocked=false;
|
||||
state.assert_free();
|
||||
release_waiters();
|
||||
}
|
||||
|
||||
@@ -277,7 +397,7 @@ namespace boost
|
||||
{
|
||||
shared_cond.wait(lk);
|
||||
}
|
||||
++state.shared_count;
|
||||
state.lock_shared();
|
||||
state.upgrade=true;
|
||||
}
|
||||
|
||||
@@ -299,7 +419,7 @@ namespace boost
|
||||
break;
|
||||
}
|
||||
}
|
||||
++state.shared_count;
|
||||
state.lock_shared();
|
||||
state.upgrade=true;
|
||||
return true;
|
||||
}
|
||||
@@ -334,7 +454,7 @@ namespace boost
|
||||
break;
|
||||
}
|
||||
}
|
||||
++state.shared_count;
|
||||
state.lock_shared();
|
||||
state.upgrade=true;
|
||||
return true;
|
||||
}
|
||||
@@ -348,8 +468,9 @@ namespace boost
|
||||
}
|
||||
else
|
||||
{
|
||||
++state.shared_count;
|
||||
state.lock_shared();
|
||||
state.upgrade=true;
|
||||
state.assert_lock_upgraded();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -357,15 +478,14 @@ namespace boost
|
||||
void unlock_upgrade()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.upgrade=false;
|
||||
bool const last_reader=!--state.shared_count;
|
||||
|
||||
if(last_reader)
|
||||
//state.upgrade=false;
|
||||
state.unlock_upgrade();
|
||||
if(! state.more_shared() )
|
||||
{
|
||||
state.exclusive_waiting_blocked=false;
|
||||
release_waiters();
|
||||
} else {
|
||||
shared_cond.notify_all();
|
||||
shared_cond.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,28 +496,33 @@ namespace boost
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
--state.shared_count;
|
||||
while(state.shared_count)
|
||||
state.assert_lock_upgraded();
|
||||
state.unlock_shared();
|
||||
while (state.more_shared())
|
||||
{
|
||||
upgrade_cond.wait(lk);
|
||||
}
|
||||
state.upgrade=false;
|
||||
state.exclusive=true;
|
||||
state.assert_locked();
|
||||
}
|
||||
|
||||
void unlock_and_lock_upgrade()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_locked();
|
||||
state.exclusive=false;
|
||||
state.upgrade=true;
|
||||
++state.shared_count;
|
||||
state.lock_shared();
|
||||
state.exclusive_waiting_blocked=false;
|
||||
state.assert_lock_upgraded();
|
||||
release_waiters();
|
||||
}
|
||||
|
||||
bool try_unlock_upgrade_and_lock()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_upgraded();
|
||||
if( !state.exclusive
|
||||
&& !state.exclusive_waiting_blocked
|
||||
&& state.upgrade
|
||||
@@ -406,6 +531,7 @@ namespace boost
|
||||
state.shared_count=0;
|
||||
state.exclusive=true;
|
||||
state.upgrade=false;
|
||||
state.assert_locked();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -428,6 +554,7 @@ namespace boost
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_upgraded();
|
||||
if (state.shared_count != 1)
|
||||
{
|
||||
for (;;)
|
||||
@@ -451,8 +578,9 @@ namespace boost
|
||||
void unlock_and_lock_shared()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_locked();
|
||||
state.exclusive=false;
|
||||
++state.shared_count;
|
||||
state.lock_shared();
|
||||
state.exclusive_waiting_blocked=false;
|
||||
release_waiters();
|
||||
}
|
||||
@@ -461,6 +589,7 @@ namespace boost
|
||||
bool try_unlock_shared_and_lock()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_shared();
|
||||
if( !state.exclusive
|
||||
&& !state.exclusive_waiting_blocked
|
||||
&& !state.upgrade
|
||||
@@ -490,6 +619,7 @@ namespace boost
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_shared();
|
||||
if (state.shared_count != 1)
|
||||
{
|
||||
for (;;)
|
||||
@@ -514,6 +644,7 @@ namespace boost
|
||||
void unlock_upgrade_and_lock_shared()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_upgraded();
|
||||
state.upgrade=false;
|
||||
state.exclusive_waiting_blocked=false;
|
||||
release_waiters();
|
||||
@@ -523,6 +654,7 @@ namespace boost
|
||||
bool try_unlock_shared_and_lock_upgrade()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_shared();
|
||||
if( !state.exclusive
|
||||
&& !state.exclusive_waiting_blocked
|
||||
&& !state.upgrade
|
||||
@@ -551,6 +683,7 @@ namespace boost
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_shared();
|
||||
if( state.exclusive
|
||||
|| state.exclusive_waiting_blocked
|
||||
|| state.upgrade
|
||||
|
||||
724
include/boost/thread/pthread/shared_mutex_assert.hpp
Normal file
724
include/boost/thread/pthread/shared_mutex_assert.hpp
Normal file
@@ -0,0 +1,724 @@
|
||||
#ifndef BOOST_THREAD_PTHREAD_SHARED_MUTEX_HPP
|
||||
#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
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
#include <boost/thread/detail/thread_interruption.hpp>
|
||||
#endif
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
#include <boost/chrono/system_clocks.hpp>
|
||||
#include <boost/chrono/ceil.hpp>
|
||||
#endif
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class shared_mutex
|
||||
{
|
||||
private:
|
||||
class state_data
|
||||
{
|
||||
public:
|
||||
state_data () :
|
||||
shared_count(0),
|
||||
exclusive(false),
|
||||
upgrade(false),
|
||||
exclusive_waiting_blocked(false)
|
||||
{}
|
||||
|
||||
void assert_free() const
|
||||
{
|
||||
BOOST_ASSERT( ! exclusive );
|
||||
BOOST_ASSERT( ! upgrade );
|
||||
BOOST_ASSERT( shared_count==0 );
|
||||
}
|
||||
|
||||
void assert_locked() const
|
||||
{
|
||||
BOOST_ASSERT( exclusive );
|
||||
BOOST_ASSERT( shared_count==0 );
|
||||
BOOST_ASSERT( ! upgrade );
|
||||
}
|
||||
|
||||
void assert_lock_shared () const
|
||||
{
|
||||
BOOST_ASSERT( ! exclusive );
|
||||
BOOST_ASSERT( shared_count>0 );
|
||||
//BOOST_ASSERT( (! upgrade) || (shared_count>1));
|
||||
// if upgraded there are at least 2 threads sharing the mutex,
|
||||
// except when unlock_upgrade_and_lock has decreased the number of readers but has not taken yet exclusive ownership.
|
||||
}
|
||||
|
||||
void assert_lock_upgraded () const
|
||||
{
|
||||
BOOST_ASSERT( ! exclusive );
|
||||
BOOST_ASSERT( upgrade );
|
||||
BOOST_ASSERT( shared_count>0 );
|
||||
}
|
||||
|
||||
void assert_lock_not_upgraded () const
|
||||
{
|
||||
BOOST_ASSERT( ! upgrade );
|
||||
}
|
||||
|
||||
bool can_lock () const
|
||||
{
|
||||
return ! (shared_count || exclusive);
|
||||
}
|
||||
|
||||
void exclusive_blocked (bool blocked)
|
||||
{
|
||||
exclusive_waiting_blocked = blocked;
|
||||
}
|
||||
|
||||
void lock ()
|
||||
{
|
||||
exclusive = true;
|
||||
}
|
||||
|
||||
void unlock ()
|
||||
{
|
||||
exclusive = false;
|
||||
exclusive_waiting_blocked = false;
|
||||
}
|
||||
|
||||
bool can_lock_shared () const
|
||||
{
|
||||
return ! (exclusive || exclusive_waiting_blocked);
|
||||
}
|
||||
|
||||
bool is_last_shared () const
|
||||
{
|
||||
return !shared_count ;
|
||||
}
|
||||
unsigned get_shared_count () const
|
||||
{
|
||||
return shared_count ;
|
||||
}
|
||||
unsigned lock_shared ()
|
||||
{
|
||||
return ++shared_count;
|
||||
}
|
||||
|
||||
|
||||
void unlock_shared ()
|
||||
{
|
||||
--shared_count;
|
||||
}
|
||||
|
||||
bool unlock_shared_downgrades()
|
||||
{
|
||||
if (upgrade) {
|
||||
upgrade=false;
|
||||
exclusive=true;
|
||||
return true;
|
||||
} else {
|
||||
exclusive_waiting_blocked=false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void lock_upgrade ()
|
||||
{
|
||||
lock_shared ();
|
||||
upgrade=true;
|
||||
}
|
||||
bool can_lock_upgrade () const
|
||||
{
|
||||
return ! (exclusive || exclusive_waiting_blocked || upgrade);
|
||||
}
|
||||
|
||||
void unlock_upgrade ()
|
||||
{
|
||||
upgrade=false;
|
||||
unlock_shared();
|
||||
}
|
||||
|
||||
//private:
|
||||
unsigned shared_count;
|
||||
bool exclusive;
|
||||
bool upgrade;
|
||||
bool exclusive_waiting_blocked;
|
||||
};
|
||||
|
||||
|
||||
|
||||
state_data state;
|
||||
boost::mutex state_change;
|
||||
boost::condition_variable shared_cond;
|
||||
boost::condition_variable exclusive_cond;
|
||||
boost::condition_variable upgrade_cond;
|
||||
|
||||
void release_waiters()
|
||||
{
|
||||
exclusive_cond.notify_one();
|
||||
shared_cond.notify_all();
|
||||
}
|
||||
|
||||
public:
|
||||
BOOST_THREAD_NO_COPYABLE(shared_mutex)
|
||||
|
||||
shared_mutex()
|
||||
{
|
||||
}
|
||||
|
||||
~shared_mutex()
|
||||
{
|
||||
}
|
||||
|
||||
void lock_shared()
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
|
||||
while(!state.can_lock_shared())
|
||||
{
|
||||
shared_cond.wait(lk);
|
||||
}
|
||||
state.lock_shared();
|
||||
}
|
||||
|
||||
bool try_lock_shared()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
if(!state.can_lock_shared())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
state.lock_shared();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined BOOST_THREAD_USES_DATETIME
|
||||
bool timed_lock_shared(system_time const& timeout)
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
|
||||
while(!state.can_lock_shared())
|
||||
{
|
||||
if(!shared_cond.timed_wait(lk,timeout))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
state.lock_shared();
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename TimeDuration>
|
||||
bool timed_lock_shared(TimeDuration const & relative_time)
|
||||
{
|
||||
return timed_lock_shared(get_system_time()+relative_time);
|
||||
}
|
||||
#endif
|
||||
#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)
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
|
||||
while(!state.can_lock_shared())
|
||||
{
|
||||
if(cv_status::timeout==shared_cond.wait_until(lk,abs_time))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
state.lock_shared();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
void unlock_shared()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_shared();
|
||||
state.unlock_shared();
|
||||
if (state.get_shared_count () == 0)
|
||||
{
|
||||
if (state.unlock_shared_downgrades())
|
||||
{
|
||||
lk.unlock();
|
||||
upgrade_cond.notify_one();
|
||||
} else {
|
||||
lk.unlock();
|
||||
}
|
||||
release_waiters();
|
||||
}
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
|
||||
while(!state.can_lock())
|
||||
{
|
||||
state.exclusive_blocked(true);
|
||||
exclusive_cond.wait(lk);
|
||||
}
|
||||
state.lock();
|
||||
}
|
||||
|
||||
#if defined BOOST_THREAD_USES_DATETIME
|
||||
bool timed_lock(system_time const& timeout)
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
|
||||
while(!state.can_lock())
|
||||
{
|
||||
state.exclusive_blocked(true);
|
||||
if(!exclusive_cond.timed_wait(lk,timeout))
|
||||
{
|
||||
if(!state.can_lock())
|
||||
{
|
||||
state.exclusive_blocked(false);
|
||||
release_waiters();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
state.exclusive=true;
|
||||
//state.lock();
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename TimeDuration>
|
||||
bool timed_lock(TimeDuration const & relative_time)
|
||||
{
|
||||
return timed_lock(get_system_time()+relative_time);
|
||||
}
|
||||
#endif
|
||||
#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)
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
|
||||
while(!state.can_lock())
|
||||
{
|
||||
state.exclusive_blocked(true);
|
||||
if(cv_status::timeout == exclusive_cond.wait_until(lk,abs_time))
|
||||
{
|
||||
if(!state.can_lock())
|
||||
{
|
||||
state.exclusive_blocked(false);
|
||||
release_waiters();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
state.exclusive=true;
|
||||
//state.lock();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
|
||||
if(!state.can_lock())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
state.lock();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_locked();
|
||||
state.unlock();
|
||||
state.assert_free();
|
||||
release_waiters();
|
||||
}
|
||||
|
||||
void lock_upgrade()
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
while(!state.can_lock_upgrade())
|
||||
{
|
||||
shared_cond.wait(lk);
|
||||
}
|
||||
state.lock_upgrade();
|
||||
}
|
||||
|
||||
#if defined BOOST_THREAD_USES_DATETIME
|
||||
bool timed_lock_upgrade(system_time const& timeout)
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
while(!state.can_lock_upgrade())
|
||||
{
|
||||
if(!shared_cond.timed_wait(lk,timeout))
|
||||
{
|
||||
if(!state.can_lock_upgrade())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
state.lock_upgrade();
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename TimeDuration>
|
||||
bool timed_lock_upgrade(TimeDuration const & relative_time)
|
||||
{
|
||||
return timed_lock_upgrade(get_system_time()+relative_time);
|
||||
}
|
||||
#endif
|
||||
#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)
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
while(!state.can_lock_upgrade())
|
||||
{
|
||||
if(cv_status::timeout == shared_cond.wait_until(lk,abs_time))
|
||||
{
|
||||
if(!state.can_lock_upgrade())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
state.lock_upgrade();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
bool try_lock_upgrade()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
if(!state.can_lock_upgrade())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
state.lock_upgrade();
|
||||
state.assert_lock_upgraded();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void unlock_upgrade()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_upgraded();
|
||||
state.unlock_upgrade();
|
||||
state.assert_lock_not_upgraded ();
|
||||
if(state.get_shared_count () == 0)
|
||||
{
|
||||
state.exclusive_blocked(false);
|
||||
lk.unlock();
|
||||
release_waiters();
|
||||
} else {
|
||||
lk.unlock();
|
||||
shared_cond.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
// Upgrade <-> Exclusive
|
||||
void unlock_upgrade_and_lock()
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_upgraded();
|
||||
// assert state.get_shared_count() >=1
|
||||
while(
|
||||
//! state.exclusive_waiting_blocked // Fixme: is this needed?
|
||||
//&&
|
||||
state.get_shared_count()!=1)
|
||||
{
|
||||
upgrade_cond.wait(lk);
|
||||
}
|
||||
state.unlock_upgrade();
|
||||
state.lock();
|
||||
state.assert_locked();
|
||||
}
|
||||
|
||||
void unlock_and_lock_upgrade()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_locked();
|
||||
state.unlock();
|
||||
state.lock_upgrade();
|
||||
state.assert_lock_upgraded();
|
||||
release_waiters();
|
||||
}
|
||||
|
||||
bool try_unlock_upgrade_and_lock()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_upgraded();
|
||||
if( //!state.exclusive // this should be removed once the assertion work
|
||||
! state.exclusive_waiting_blocked // Fixme: why this is needed?
|
||||
//&& state.upgrade // this should be removed once the assertion work
|
||||
&& state.get_shared_count()==1)
|
||||
{
|
||||
state.unlock_upgrade();
|
||||
state.lock();
|
||||
state.assert_locked();
|
||||
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)
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_upgraded();
|
||||
if (//state.exclusive // this should be removed once the assertion work
|
||||
state.exclusive_waiting_blocked // Fixme: is this needed?
|
||||
//|| ! state.upgrade // this should be removed once the assertion work
|
||||
|| state.get_shared_count() != 1)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
//cv_status status = shared_cond.wait_until(lk,abs_time);
|
||||
cv_status status = upgrade_cond.wait_until(lk,abs_time);
|
||||
if (//!state.exclusive // this should be removed once the assertion work
|
||||
! state.exclusive_waiting_blocked // Fixme: is this needed?
|
||||
//&& ! state.upgrade // this should be removed once the assertion work
|
||||
&& state.get_shared_count() == 1)
|
||||
break;
|
||||
if(status == cv_status::timeout)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
state.unlock_upgrade();
|
||||
state.lock();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Shared <-> Exclusive
|
||||
void unlock_and_lock_shared()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_locked();
|
||||
state.unlock();
|
||||
state.lock_shared();
|
||||
release_waiters();
|
||||
}
|
||||
|
||||
#ifdef BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS
|
||||
bool try_unlock_shared_and_lock()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_shared();
|
||||
if( //!state.exclusive // this should be removed once the assertion work
|
||||
! state.exclusive_waiting_blocked // Fixme: why this is needed?
|
||||
//&& ! state.upgrade // Fixme: why this is needed if state.get_shared_count()==1?
|
||||
&& state.get_shared_count()==1)
|
||||
{
|
||||
state.unlock_shared();
|
||||
state.lock();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool
|
||||
try_unlock_shared_and_lock_for(
|
||||
const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
return try_unlock_shared_and_lock_until(
|
||||
chrono::steady_clock::now() + rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool
|
||||
try_unlock_shared_and_lock_until(
|
||||
const chrono::time_point<Clock, Duration>& abs_time)
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_shared();
|
||||
if ( // !state.exclusive // this should be removed once the assertion work
|
||||
state.exclusive_waiting_blocked // Fixme: is this needed?
|
||||
//|| state.upgrade // Fixme: why this is needed if state.get_shared_count()==1?
|
||||
|| state.get_shared_count() != 1)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
cv_status status = shared_cond.wait_until(lk,abs_time);
|
||||
if ( //! state.exclusive // this should be removed once the assertion work
|
||||
! state.exclusive_waiting_blocked // Fixme: is this needed?
|
||||
//&& ! state.upgrade
|
||||
&& state.get_shared_count() == 1)
|
||||
break;
|
||||
if(status == cv_status::timeout)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
state.unlock_shared();
|
||||
state.lock();
|
||||
state.upgrade=false; // Is this absolutely needed?
|
||||
state.exclusive_waiting_blocked=false; // Is this absolutely needed?
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Shared <-> Upgrade
|
||||
void unlock_upgrade_and_lock_shared()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_upgraded();
|
||||
//state.unlock_upgrade();
|
||||
//state.lock_shared(); // less efficient
|
||||
state.upgrade=false;
|
||||
state.exclusive_waiting_blocked=false; // Is this absolutely needed?
|
||||
release_waiters();
|
||||
}
|
||||
|
||||
#ifdef BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS
|
||||
bool try_unlock_shared_and_lock_upgrade()
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_shared();
|
||||
if( //! state.exclusive // this should be removed once the assertion work
|
||||
! state.exclusive_waiting_blocked // Fixme: is this needed?
|
||||
&& ! state.upgrade
|
||||
)
|
||||
{
|
||||
state.upgrade=true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool
|
||||
try_unlock_shared_and_lock_upgrade_for(
|
||||
const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
return try_unlock_shared_and_lock_upgrade_until(
|
||||
chrono::steady_clock::now() + rel_time);
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool
|
||||
try_unlock_shared_and_lock_upgrade_until(
|
||||
const chrono::time_point<Clock, Duration>& abs_time)
|
||||
{
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
boost::this_thread::disable_interruption do_not_disturb;
|
||||
#endif
|
||||
boost::unique_lock<boost::mutex> lk(state_change);
|
||||
state.assert_lock_shared();
|
||||
if( //state.exclusive // this should be removed once the assertion work
|
||||
state.exclusive_waiting_blocked // Fixme: is this needed?
|
||||
|| state.upgrade
|
||||
)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
cv_status status = exclusive_cond.wait_until(lk,abs_time);
|
||||
if( //! state.exclusive // this should be removed once the assertion work
|
||||
! state.exclusive_waiting_blocked // Fixme: is this needed?
|
||||
&& ! state.upgrade
|
||||
)
|
||||
break;
|
||||
if(status == cv_status::timeout)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//state.unlock_shared();
|
||||
//state.lock_upgrade(); // less efficient
|
||||
state.upgrade=true;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef shared_mutex upgrade_mutex;
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif
|
||||
@@ -82,7 +82,7 @@ namespace boost
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct future_object_base;
|
||||
struct shared_state_base;
|
||||
struct tss_cleanup_function;
|
||||
struct thread_exit_callback_node;
|
||||
struct tss_data_node
|
||||
@@ -121,7 +121,7 @@ namespace boost
|
||||
> notify_list_t;
|
||||
notify_list_t notify;
|
||||
|
||||
typedef std::vector<shared_ptr<future_object_base> > async_states_t;
|
||||
typedef std::vector<shared_ptr<shared_state_base> > async_states_t;
|
||||
async_states_t async_states_;
|
||||
|
||||
//#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
@@ -132,8 +132,10 @@ namespace boost
|
||||
bool interrupt_requested;
|
||||
//#endif
|
||||
thread_data_base():
|
||||
thread_handle(0),
|
||||
done(false),join_started(false),joined(false),
|
||||
thread_exit_callbacks(0),
|
||||
cond_mutex(0),
|
||||
current_cond(0),
|
||||
notify(),
|
||||
async_states_()
|
||||
@@ -152,7 +154,7 @@ namespace boost
|
||||
notify.push_back(std::pair<condition_variable*, mutex*>(cv, m));
|
||||
}
|
||||
|
||||
void make_ready_at_thread_exit(shared_ptr<future_object_base> as)
|
||||
void make_ready_at_thread_exit(shared_ptr<shared_state_base> as)
|
||||
{
|
||||
async_states_.push_back(as);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
#include <boost/thread/detail/move.hpp>
|
||||
#include <boost/thread/thread_functors.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
@@ -38,10 +38,34 @@ namespace boost
|
||||
class strict_scoped_thread
|
||||
{
|
||||
thread t_;
|
||||
struct dummy;
|
||||
public:
|
||||
|
||||
BOOST_THREAD_NO_COPYABLE( strict_scoped_thread) /// non copyable
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template <class F, class ...Args, typename = typename disable_if<is_same<typename decay<F>::type, thread>, dummy* >::type>
|
||||
explicit strict_scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(Args)... args) :
|
||||
t_(boost::forward<F>(f), boost::forward<Args>(args)...) {}
|
||||
#else
|
||||
template <class F>
|
||||
explicit strict_scoped_thread(BOOST_THREAD_FWD_REF(F) f,
|
||||
typename disable_if<is_same<typename decay<F>::type, thread>, dummy* >::type=0) :
|
||||
t_(boost::forward<F>(f)) {}
|
||||
template <class F, class A1>
|
||||
strict_scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(A1) a1) :
|
||||
t_(boost::forward<F>(f), boost::forward<A1>(a1)) {}
|
||||
template <class F, class A1, class A2>
|
||||
strict_scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(A1) a1, BOOST_THREAD_FWD_REF(A2) a2) :
|
||||
t_(boost::forward<F>(f), boost::forward<A1>(a1), boost::forward<A2>(a2)) {}
|
||||
template <class F, class A1, class A2, class A3>
|
||||
strict_scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(A1) a1, BOOST_THREAD_FWD_REF(A2) a2, BOOST_THREAD_FWD_REF(A3) a3) :
|
||||
t_(boost::forward<F>(f), boost::forward<A1>(a1), boost::forward<A2>(a2), boost::forward<A3>(a3)) {}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Constructor from the thread to own.
|
||||
*
|
||||
@@ -91,6 +115,7 @@ namespace boost
|
||||
class scoped_thread
|
||||
{
|
||||
thread t_;
|
||||
struct dummy;
|
||||
public:
|
||||
|
||||
typedef thread::id id;
|
||||
@@ -107,6 +132,30 @@ namespace boost
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
#if ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template <class F, class ...Args, typename = typename disable_if<is_same<typename decay<F>::type, thread>, dummy* >::type>
|
||||
explicit scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(Args)... args) :
|
||||
t_(boost::forward<F>(f), boost::forward<Args>(args)...) {}
|
||||
#else
|
||||
template <class F>
|
||||
explicit scoped_thread(BOOST_THREAD_FWD_REF(F) f,
|
||||
typename disable_if<is_same<typename decay<F>::type, thread>, dummy* >::type=0) :
|
||||
t_(boost::forward<F>(f)) {}
|
||||
template <class F, class A1>
|
||||
scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(A1) a1) :
|
||||
t_(boost::forward<F>(f), boost::forward<A1>(a1)) {}
|
||||
template <class F, class A1, class A2>
|
||||
scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(A1) a1, BOOST_THREAD_FWD_REF(A2) a2) :
|
||||
t_(boost::forward<F>(f), boost::forward<A1>(a1), boost::forward<A2>(a2)) {}
|
||||
template <class F, class A1, class A2, class A3>
|
||||
scoped_thread(BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(A1) a1, BOOST_THREAD_FWD_REF(A2) a2, BOOST_THREAD_FWD_REF(A3) a3) :
|
||||
t_(boost::forward<F>(f), boost::forward<A1>(a1), boost::forward<A2>(a2), boost::forward<A3>(a3)) {}
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Constructor from the thread to own.
|
||||
*
|
||||
@@ -195,6 +244,11 @@ namespace boost
|
||||
return t_.native_handle();
|
||||
}
|
||||
|
||||
bool joinable() const BOOST_NOEXCEPT
|
||||
{
|
||||
return t_.joinable();
|
||||
}
|
||||
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
void interrupt()
|
||||
{
|
||||
@@ -207,11 +261,15 @@ namespace boost
|
||||
}
|
||||
#endif
|
||||
|
||||
static unsigned hardware_concurrency()BOOST_NOEXCEPT
|
||||
static unsigned hardware_concurrency() BOOST_NOEXCEPT
|
||||
{
|
||||
return thread::hardware_concurrency();
|
||||
}
|
||||
|
||||
static unsigned physical_concurrency() BOOST_NOEXCEPT
|
||||
{
|
||||
return thread::physical_concurrency();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <boost/thread/win32/shared_mutex.hpp>
|
||||
#endif
|
||||
#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
|
||||
//#include <boost/thread/v2/shared_mutex.hpp>
|
||||
#include <boost/thread/pthread/shared_mutex.hpp>
|
||||
#else
|
||||
#error "Boost threads unavailable on this platform"
|
||||
|
||||
@@ -73,21 +73,27 @@ namespace boost
|
||||
|
||||
|
||||
// observers
|
||||
private:
|
||||
|
||||
/**
|
||||
* @return the owned mutex.
|
||||
*/
|
||||
const mutex_type* mutex() const BOOST_NOEXCEPT
|
||||
mutex_type* mutex() const BOOST_NOEXCEPT
|
||||
{
|
||||
return &mtx_;
|
||||
}
|
||||
public:
|
||||
|
||||
/**
|
||||
* @return whether this lock is locking a mutex.
|
||||
*/
|
||||
bool owns_lock() const BOOST_NOEXCEPT
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether this lock is locking that mutex.
|
||||
*/
|
||||
bool owns_lock(mutex_type const* l) const BOOST_NOEXCEPT
|
||||
bool owns_lock(const mutex_type* l) const BOOST_NOEXCEPT
|
||||
{
|
||||
return l == mutex();
|
||||
} /*< strict locks specific function >*/
|
||||
@@ -102,7 +108,7 @@ namespace boost
|
||||
};
|
||||
//]
|
||||
template <typename Lockable>
|
||||
struct is_strict_lock_sur_parolle<strict_lock<Lockable> > : true_type
|
||||
struct is_strict_lock_sur_parole<strict_lock<Lockable> > : true_type
|
||||
{
|
||||
};
|
||||
|
||||
@@ -173,15 +179,22 @@ namespace boost
|
||||
}
|
||||
|
||||
// observers
|
||||
private:
|
||||
/**
|
||||
* return @c the owned mutex.
|
||||
*/
|
||||
const mutex_type* mutex() const BOOST_NOEXCEPT
|
||||
mutex_type* mutex() const BOOST_NOEXCEPT
|
||||
{
|
||||
return tmp_lk_.mutex();
|
||||
}
|
||||
public:
|
||||
|
||||
/**
|
||||
* @return whether this lock is locking a mutex.
|
||||
*/
|
||||
bool owns_lock() const BOOST_NOEXCEPT
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether if this lock is locking that mutex.
|
||||
*/
|
||||
@@ -200,7 +213,7 @@ public:
|
||||
//]
|
||||
|
||||
template <typename Lock>
|
||||
struct is_strict_lock_sur_parolle<nested_strict_lock<Lock> > : true_type
|
||||
struct is_strict_lock_sur_parole<nested_strict_lock<Lock> > : true_type
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
609
include/boost/thread/sync_bounded_queue.hpp
Normal file
609
include/boost/thread/sync_bounded_queue.hpp
Normal file
@@ -0,0 +1,609 @@
|
||||
#ifndef BOOST_THREAD_SYNC_BOUNDED_QUEUE_HPP
|
||||
#define BOOST_THREAD_SYNC_BOUNDED_QUEUE_HPP
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Vicente J. Botet Escriba 2013. 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/thread for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/detail/move.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
BOOST_SCOPED_ENUM_DECLARE_BEGIN(queue_op_status)
|
||||
{ success = 0, empty, full, closed, busy }
|
||||
BOOST_SCOPED_ENUM_DECLARE_END(queue_op_status)
|
||||
|
||||
struct no_block_tag{};
|
||||
BOOST_CONSTEXPR_OR_CONST no_block_tag no_block = {};
|
||||
|
||||
struct sync_queue_is_closed : std::exception
|
||||
{
|
||||
};
|
||||
|
||||
template <typename ValueType>
|
||||
class sync_bounded_queue
|
||||
{
|
||||
public:
|
||||
typedef ValueType value_type;
|
||||
typedef std::size_t size_type;
|
||||
|
||||
// Constructors/Assignment/Destructors
|
||||
BOOST_THREAD_NO_COPYABLE(sync_bounded_queue)
|
||||
explicit sync_bounded_queue(size_type max_elems);
|
||||
template <typename Range>
|
||||
sync_bounded_queue(size_type max_elems, Range range);
|
||||
~sync_bounded_queue();
|
||||
|
||||
// Observers
|
||||
inline bool empty() const;
|
||||
inline bool full() const;
|
||||
inline size_type capacity() const;
|
||||
inline size_type size() const;
|
||||
inline bool closed() const;
|
||||
|
||||
// Modifiers
|
||||
inline void close();
|
||||
|
||||
inline void push(const value_type& x);
|
||||
inline void push(BOOST_THREAD_RV_REF(value_type) x);
|
||||
inline bool try_push(const value_type& x);
|
||||
inline bool try_push(BOOST_THREAD_RV_REF(value_type) x);
|
||||
inline bool try_push(no_block_tag, const value_type& x);
|
||||
inline bool try_push(no_block_tag, BOOST_THREAD_RV_REF(value_type) x);
|
||||
|
||||
// Observers/Modifiers
|
||||
inline void pull(value_type&);
|
||||
inline void pull(ValueType& elem, bool & closed);
|
||||
// enable_if is_nothrow_copy_movable<value_type>
|
||||
inline value_type pull();
|
||||
inline shared_ptr<ValueType> ptr_pull();
|
||||
inline bool try_pull(value_type&);
|
||||
inline bool try_pull(no_block_tag,value_type&);
|
||||
inline shared_ptr<ValueType> try_pull();
|
||||
|
||||
private:
|
||||
mutable mutex mtx_;
|
||||
condition_variable not_empty_;
|
||||
condition_variable not_full_;
|
||||
size_type waiting_full_;
|
||||
size_type waiting_empty_;
|
||||
value_type* data_;
|
||||
size_type in_;
|
||||
size_type out_;
|
||||
size_type capacity_;
|
||||
bool closed_;
|
||||
|
||||
inline size_type inc(size_type idx) const BOOST_NOEXCEPT
|
||||
{
|
||||
return (idx + 1) % capacity_;
|
||||
}
|
||||
|
||||
inline bool empty(unique_lock<mutex>& ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return in_ == out_;
|
||||
}
|
||||
inline bool empty(lock_guard<mutex>& ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return in_ == out_;
|
||||
}
|
||||
inline bool full(unique_lock<mutex>& ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return (inc(in_) == out_);
|
||||
}
|
||||
inline bool full(lock_guard<mutex>& ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return (inc(in_) == out_);
|
||||
}
|
||||
inline size_type capacity(lock_guard<mutex>& ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return capacity_-1;
|
||||
}
|
||||
inline size_type size(lock_guard<mutex>& lk) const BOOST_NOEXCEPT
|
||||
{
|
||||
if (full(lk)) return capacity(lk);
|
||||
return ((out_+capacity(lk)-in_) % capacity(lk));
|
||||
}
|
||||
|
||||
inline void throw_if_closed(unique_lock<mutex>&);
|
||||
|
||||
inline bool try_pull(value_type& x, unique_lock<mutex>& lk);
|
||||
inline bool try_push(const value_type& x, unique_lock<mutex>& lk);
|
||||
inline bool try_push(BOOST_THREAD_RV_REF(value_type) x, unique_lock<mutex>& lk);
|
||||
inline shared_ptr<value_type> try_pull(unique_lock<mutex>& lk);
|
||||
|
||||
inline void wait_until_not_empty(unique_lock<mutex>& lk);
|
||||
inline void wait_until_not_empty(unique_lock<mutex>& lk, bool&);
|
||||
inline size_type wait_until_not_full(unique_lock<mutex>& lk);
|
||||
inline size_type wait_until_not_full(unique_lock<mutex>& lk, bool&);
|
||||
|
||||
|
||||
inline void notify_not_empty_if_needed(unique_lock<mutex>& lk)
|
||||
{
|
||||
if (waiting_empty_ > 0)
|
||||
{
|
||||
--waiting_empty_;
|
||||
lk.unlock();
|
||||
not_empty_.notify_one();
|
||||
}
|
||||
}
|
||||
inline void notify_not_full_if_needed(unique_lock<mutex>& lk)
|
||||
{
|
||||
if (waiting_full_ > 0)
|
||||
{
|
||||
--waiting_full_;
|
||||
lk.unlock();
|
||||
not_full_.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
inline void pull(value_type& elem, unique_lock<mutex>& lk)
|
||||
{
|
||||
elem = boost::move(data_[out_]);
|
||||
out_ = inc(out_);
|
||||
notify_not_full_if_needed(lk);
|
||||
}
|
||||
inline value_type pull(unique_lock<mutex>& lk)
|
||||
{
|
||||
value_type elem = boost::move(data_[out_]);
|
||||
out_ = inc(out_);
|
||||
notify_not_full_if_needed(lk);
|
||||
return boost::move(elem);
|
||||
}
|
||||
inline boost::shared_ptr<value_type> ptr_pull(unique_lock<mutex>& lk)
|
||||
{
|
||||
shared_ptr<value_type> res = make_shared<value_type>(boost::move(data_[out_]));
|
||||
out_ = inc(out_);
|
||||
notify_not_full_if_needed(lk);
|
||||
return res;
|
||||
}
|
||||
|
||||
inline void set_in(size_type in, unique_lock<mutex>& lk)
|
||||
{
|
||||
in_ = in;
|
||||
notify_not_empty_if_needed(lk);
|
||||
}
|
||||
|
||||
inline void push_at(const value_type& elem, size_type in_p_1, unique_lock<mutex>& lk)
|
||||
{
|
||||
data_[in_] = elem;
|
||||
set_in(in_p_1, lk);
|
||||
}
|
||||
|
||||
inline void push_at(BOOST_THREAD_RV_REF(value_type) elem, size_type in_p_1, unique_lock<mutex>& lk)
|
||||
{
|
||||
data_[in_] = boost::move(elem);
|
||||
set_in(in_p_1, lk);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ValueType>
|
||||
sync_bounded_queue<ValueType>::sync_bounded_queue(typename sync_bounded_queue<ValueType>::size_type max_elems) :
|
||||
waiting_full_(0), waiting_empty_(0), data_(new value_type[max_elems + 1]), in_(0), out_(0), capacity_(max_elems + 1),
|
||||
closed_(false)
|
||||
{
|
||||
BOOST_ASSERT_MSG(max_elems >= 1, "number of elements must be > 1");
|
||||
}
|
||||
|
||||
// template <typename ValueType>
|
||||
// template <typename Range>
|
||||
// sync_bounded_queue<ValueType>::sync_bounded_queue(size_type max_elems, Range range) :
|
||||
// waiting_full_(0), waiting_empty_(0), data_(new value_type[max_elems + 1]), in_(0), out_(0), capacity_(max_elems + 1),
|
||||
// closed_(false)
|
||||
// {
|
||||
// BOOST_ASSERT_MSG(max_elems >= 1, "number of elements must be > 1");
|
||||
// BOOST_ASSERT_MSG(max_elems == size(range), "number of elements must match range's size");
|
||||
// try
|
||||
// {
|
||||
// typedef typename Range::iterator iterator_t;
|
||||
// iterator_t first = boost::begin(range);
|
||||
// iterator_t end = boost::end(range);
|
||||
// size_type in = 0;
|
||||
// for (iterator_t cur = first; cur != end; ++cur, ++in)
|
||||
// {
|
||||
// data_[in] = *cur;
|
||||
// }
|
||||
// set_in(in);
|
||||
// }
|
||||
// catch (...)
|
||||
// {
|
||||
// delete[] data_;
|
||||
// }
|
||||
// }
|
||||
|
||||
template <typename ValueType>
|
||||
sync_bounded_queue<ValueType>::~sync_bounded_queue()
|
||||
{
|
||||
delete[] data_;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
void sync_bounded_queue<ValueType>::close()
|
||||
{
|
||||
{
|
||||
lock_guard<mutex> lk(mtx_);
|
||||
closed_ = true;
|
||||
}
|
||||
not_empty_.notify_all();
|
||||
not_full_.notify_all();
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_bounded_queue<ValueType>::closed() const
|
||||
{
|
||||
lock_guard<mutex> lk(mtx_);
|
||||
return closed_;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_bounded_queue<ValueType>::empty() const
|
||||
{
|
||||
lock_guard<mutex> lk(mtx_);
|
||||
return empty(lk);
|
||||
}
|
||||
template <typename ValueType>
|
||||
bool sync_bounded_queue<ValueType>::full() const
|
||||
{
|
||||
lock_guard<mutex> lk(mtx_);
|
||||
return full(lk);
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
typename sync_bounded_queue<ValueType>::size_type sync_bounded_queue<ValueType>::capacity() const
|
||||
{
|
||||
lock_guard<mutex> lk(mtx_);
|
||||
return capacity(lk);
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
typename sync_bounded_queue<ValueType>::size_type sync_bounded_queue<ValueType>::size() const
|
||||
{
|
||||
lock_guard<mutex> lk(mtx_);
|
||||
return size(lk);
|
||||
}
|
||||
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_bounded_queue<ValueType>::try_pull(ValueType& elem, unique_lock<mutex>& lk)
|
||||
{
|
||||
if (empty(lk))
|
||||
{
|
||||
throw_if_closed(lk);
|
||||
return false;
|
||||
}
|
||||
pull(elem, lk);
|
||||
return true;
|
||||
}
|
||||
template <typename ValueType>
|
||||
shared_ptr<ValueType> sync_bounded_queue<ValueType>::try_pull(unique_lock<mutex>& lk)
|
||||
{
|
||||
if (empty(lk))
|
||||
{
|
||||
throw_if_closed(lk);
|
||||
return shared_ptr<ValueType>();
|
||||
}
|
||||
return ptr_pull(lk);
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_bounded_queue<ValueType>::try_pull(ValueType& elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
return try_pull(elem, lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_bounded_queue<ValueType>::try_pull(no_block_tag,ValueType& elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_, try_to_lock);
|
||||
if (!lk.owns_lock())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return try_pull(elem, lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
template <typename ValueType>
|
||||
boost::shared_ptr<ValueType> sync_bounded_queue<ValueType>::try_pull()
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
return try_pull(lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
void sync_bounded_queue<ValueType>::throw_if_closed(unique_lock<mutex>&)
|
||||
{
|
||||
if (closed_)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION( sync_queue_is_closed() );
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
void sync_bounded_queue<ValueType>::wait_until_not_empty(unique_lock<mutex>& lk)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (out_ != in_) break;
|
||||
throw_if_closed(lk);
|
||||
++waiting_empty_;
|
||||
not_empty_.wait(lk);
|
||||
}
|
||||
}
|
||||
template <typename ValueType>
|
||||
void sync_bounded_queue<ValueType>::wait_until_not_empty(unique_lock<mutex>& lk, bool & closed)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (out_ != in_) break;
|
||||
if (closed_) {closed=true; return;}
|
||||
++waiting_empty_;
|
||||
not_empty_.wait(lk);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
void sync_bounded_queue<ValueType>::pull(ValueType& elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
wait_until_not_empty(lk);
|
||||
pull(elem, lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
template <typename ValueType>
|
||||
void sync_bounded_queue<ValueType>::pull(ValueType& elem, bool & closed)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
wait_until_not_empty(lk, closed);
|
||||
if (closed) {return;}
|
||||
pull(elem, lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// enable if ValueType is nothrow movable
|
||||
template <typename ValueType>
|
||||
ValueType sync_bounded_queue<ValueType>::pull()
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
wait_until_not_empty(lk);
|
||||
return pull(lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
template <typename ValueType>
|
||||
boost::shared_ptr<ValueType> sync_bounded_queue<ValueType>::ptr_pull()
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
wait_until_not_empty(lk);
|
||||
return ptr_pull(lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_bounded_queue<ValueType>::try_push(const ValueType& elem, unique_lock<mutex>& lk)
|
||||
{
|
||||
throw_if_closed(lk);
|
||||
size_type in_p_1 = inc(in_);
|
||||
if (in_p_1 == out_) // full()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
push_at(elem, in_p_1, lk);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_bounded_queue<ValueType>::try_push(const ValueType& elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
return try_push(elem, lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_bounded_queue<ValueType>::try_push(no_block_tag, const ValueType& elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_, try_to_lock);
|
||||
if (!lk.owns_lock()) return false;
|
||||
return try_push(elem, lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename ValueType>
|
||||
typename sync_bounded_queue<ValueType>::size_type sync_bounded_queue<ValueType>::wait_until_not_full(unique_lock<mutex>& lk)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
throw_if_closed(lk);
|
||||
size_type in_p_1 = inc(in_);
|
||||
if (in_p_1 != out_) // ! full()
|
||||
{
|
||||
return in_p_1;
|
||||
}
|
||||
++waiting_full_;
|
||||
not_full_.wait(lk);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
void sync_bounded_queue<ValueType>::push(const ValueType& elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
push_at(elem, wait_until_not_full(lk), lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_bounded_queue<ValueType>::try_push(BOOST_THREAD_RV_REF(ValueType) elem, unique_lock<mutex>& lk)
|
||||
{
|
||||
throw_if_closed(lk);
|
||||
size_type in_p_1 = inc(in_);
|
||||
if (in_p_1 == out_) // full()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
push_at(boost::move(elem), in_p_1, lk);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_bounded_queue<ValueType>::try_push(BOOST_THREAD_RV_REF(ValueType) elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
return try_push(boost::move(elem), lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_bounded_queue<ValueType>::try_push(no_block_tag, BOOST_THREAD_RV_REF(ValueType) elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_, try_to_lock);
|
||||
if (!lk.owns_lock())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return try_push(boost::move(elem), lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
void sync_bounded_queue<ValueType>::push(BOOST_THREAD_RV_REF(ValueType) elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
push_at(boost::move(elem), wait_until_not_full(lk), lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
sync_bounded_queue<ValueType>& operator<<(sync_bounded_queue<ValueType>& sbq, BOOST_THREAD_RV_REF(ValueType) elem)
|
||||
{
|
||||
sbq.push(boost::move(elem));
|
||||
return sbq;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
sync_bounded_queue<ValueType>& operator<<(sync_bounded_queue<ValueType>& sbq, ValueType const&elem)
|
||||
{
|
||||
sbq.push(elem);
|
||||
return sbq;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
sync_bounded_queue<ValueType>& operator>>(sync_bounded_queue<ValueType>& sbq, ValueType &elem)
|
||||
{
|
||||
sbq.pull(elem);
|
||||
return sbq;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif
|
||||
520
include/boost/thread/sync_queue.hpp
Normal file
520
include/boost/thread/sync_queue.hpp
Normal file
@@ -0,0 +1,520 @@
|
||||
#ifndef BOOST_THREAD_SYNC_QUEUE_HPP
|
||||
#define BOOST_THREAD_SYNC_QUEUE_HPP
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Vicente J. Botet Escriba 2013. 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)
|
||||
//
|
||||
// See http://www.boost.org/libs/thread for documentation.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/detail/move.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
|
||||
#include <boost/thread/sync_bounded_queue.hpp>
|
||||
#include <boost/container/deque.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
||||
template <typename ValueType>
|
||||
class sync_queue
|
||||
{
|
||||
public:
|
||||
typedef ValueType value_type;
|
||||
typedef std::size_t size_type;
|
||||
|
||||
// Constructors/Assignment/Destructors
|
||||
BOOST_THREAD_NO_COPYABLE(sync_queue)
|
||||
inline sync_queue();
|
||||
//template <typename Range>
|
||||
//inline explicit sync_queue(Range range);
|
||||
inline ~sync_queue();
|
||||
|
||||
// Observers
|
||||
inline bool empty() const;
|
||||
inline bool full() const;
|
||||
inline size_type size() const;
|
||||
inline bool closed() const;
|
||||
|
||||
// Modifiers
|
||||
inline void close();
|
||||
|
||||
inline void push(const value_type& x);
|
||||
inline bool try_push(const value_type& x);
|
||||
inline bool try_push(no_block_tag, const value_type& x);
|
||||
|
||||
inline void push(BOOST_THREAD_RV_REF(value_type) x);
|
||||
inline bool try_push(BOOST_THREAD_RV_REF(value_type) x);
|
||||
inline bool try_push(no_block_tag, BOOST_THREAD_RV_REF(value_type) x);
|
||||
|
||||
// Observers/Modifiers
|
||||
inline void pull(value_type&);
|
||||
inline void pull(ValueType& elem, bool & closed);
|
||||
// enable_if is_nothrow_copy_movable<value_type>
|
||||
inline value_type pull();
|
||||
inline shared_ptr<ValueType> ptr_pull();
|
||||
inline bool try_pull(value_type&);
|
||||
inline bool try_pull(no_block_tag,value_type&);
|
||||
inline shared_ptr<ValueType> try_pull();
|
||||
|
||||
private:
|
||||
mutable mutex mtx_;
|
||||
condition_variable not_empty_;
|
||||
size_type waiting_empty_;
|
||||
boost::container::deque<ValueType> data_;
|
||||
bool closed_;
|
||||
|
||||
inline bool empty(unique_lock<mutex>& ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return data_.empty();
|
||||
}
|
||||
inline bool empty(lock_guard<mutex>& ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return data_.empty();
|
||||
}
|
||||
|
||||
inline size_type size(lock_guard<mutex>& ) const BOOST_NOEXCEPT
|
||||
{
|
||||
return data_.size();
|
||||
}
|
||||
|
||||
inline void throw_if_closed(unique_lock<mutex>&);
|
||||
|
||||
inline bool try_pull(value_type& x, unique_lock<mutex>& lk);
|
||||
inline bool try_push(const value_type& x, unique_lock<mutex>& lk);
|
||||
inline bool try_push(BOOST_THREAD_RV_REF(value_type) x, unique_lock<mutex>& lk);
|
||||
inline shared_ptr<value_type> try_pull(unique_lock<mutex>& lk);
|
||||
|
||||
inline void wait_until_not_empty(unique_lock<mutex>& lk);
|
||||
inline void wait_until_not_empty(unique_lock<mutex>& lk, bool&);
|
||||
|
||||
inline void notify_not_empty_if_needed(unique_lock<mutex>& lk)
|
||||
{
|
||||
if (waiting_empty_ > 0)
|
||||
{
|
||||
--waiting_empty_;
|
||||
lk.unlock();
|
||||
not_empty_.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
inline void pull(value_type& elem, unique_lock<mutex>& )
|
||||
{
|
||||
elem = boost::move(data_.front());
|
||||
data_.pop_front();
|
||||
}
|
||||
inline value_type pull(unique_lock<mutex>& )
|
||||
{
|
||||
value_type e = boost::move(data_.front());
|
||||
data_.pop_front();
|
||||
return boost::move(e);
|
||||
}
|
||||
inline boost::shared_ptr<value_type> ptr_pull(unique_lock<mutex>& )
|
||||
{
|
||||
shared_ptr<value_type> res = make_shared<value_type>(boost::move(data_.front()));
|
||||
data_.pop_front();
|
||||
return res;
|
||||
}
|
||||
|
||||
inline void push(const value_type& elem, unique_lock<mutex>& lk)
|
||||
{
|
||||
data_.push_back(elem);
|
||||
notify_not_empty_if_needed(lk);
|
||||
}
|
||||
|
||||
inline void push(BOOST_THREAD_RV_REF(value_type) elem, unique_lock<mutex>& lk)
|
||||
{
|
||||
data_.push_back(boost::move(elem));
|
||||
notify_not_empty_if_needed(lk);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ValueType>
|
||||
sync_queue<ValueType>::sync_queue() :
|
||||
waiting_empty_(0), data_(), closed_(false)
|
||||
{
|
||||
BOOST_ASSERT(data_.empty());
|
||||
}
|
||||
|
||||
// template <typename ValueType>
|
||||
// template <typename Range>
|
||||
// explicit sync_queue<ValueType>::sync_queue(Range range) :
|
||||
// waiting_empty_(0), data_(), closed_(false)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// typedef typename Range::iterator iterator_t;
|
||||
// iterator_t first = boost::begin(range);
|
||||
// iterator_t end = boost::end(range);
|
||||
// for (iterator_t cur = first; cur != end; ++cur)
|
||||
// {
|
||||
// data_.push(boost::move(*cur));;
|
||||
// }
|
||||
// notify_not_empty_if_needed(lk);
|
||||
// }
|
||||
// catch (...)
|
||||
// {
|
||||
// delete[] data_;
|
||||
// }
|
||||
// }
|
||||
|
||||
template <typename ValueType>
|
||||
sync_queue<ValueType>::~sync_queue()
|
||||
{
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
void sync_queue<ValueType>::close()
|
||||
{
|
||||
{
|
||||
lock_guard<mutex> lk(mtx_);
|
||||
closed_ = true;
|
||||
}
|
||||
not_empty_.notify_all();
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_queue<ValueType>::closed() const
|
||||
{
|
||||
lock_guard<mutex> lk(mtx_);
|
||||
return closed_;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_queue<ValueType>::empty() const
|
||||
{
|
||||
lock_guard<mutex> lk(mtx_);
|
||||
return empty(lk);
|
||||
}
|
||||
template <typename ValueType>
|
||||
bool sync_queue<ValueType>::full() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
typename sync_queue<ValueType>::size_type sync_queue<ValueType>::size() const
|
||||
{
|
||||
lock_guard<mutex> lk(mtx_);
|
||||
return size(lk);
|
||||
}
|
||||
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_queue<ValueType>::try_pull(ValueType& elem, unique_lock<mutex>& lk)
|
||||
{
|
||||
if (empty(lk))
|
||||
{
|
||||
throw_if_closed(lk);
|
||||
return false;
|
||||
}
|
||||
pull(elem, lk);
|
||||
return true;
|
||||
}
|
||||
template <typename ValueType>
|
||||
shared_ptr<ValueType> sync_queue<ValueType>::try_pull(unique_lock<mutex>& lk)
|
||||
{
|
||||
if (empty(lk))
|
||||
{
|
||||
throw_if_closed(lk);
|
||||
return shared_ptr<ValueType>();
|
||||
}
|
||||
return ptr_pull(lk);
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_queue<ValueType>::try_pull(ValueType& elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
return try_pull(elem, lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_queue<ValueType>::try_pull(no_block_tag,ValueType& elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_, try_to_lock);
|
||||
if (!lk.owns_lock())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return try_pull(elem, lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
template <typename ValueType>
|
||||
boost::shared_ptr<ValueType> sync_queue<ValueType>::try_pull()
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
return try_pull(lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
void sync_queue<ValueType>::throw_if_closed(unique_lock<mutex>&)
|
||||
{
|
||||
if (closed_)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION( sync_queue_is_closed() );
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
void sync_queue<ValueType>::wait_until_not_empty(unique_lock<mutex>& lk)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (! empty(lk)) break;
|
||||
throw_if_closed(lk);
|
||||
++waiting_empty_;
|
||||
not_empty_.wait(lk);
|
||||
}
|
||||
}
|
||||
template <typename ValueType>
|
||||
void sync_queue<ValueType>::wait_until_not_empty(unique_lock<mutex>& lk, bool & closed)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (! empty(lk)) break;
|
||||
if (closed_) {closed=true; return;}
|
||||
++waiting_empty_;
|
||||
not_empty_.wait(lk);
|
||||
}
|
||||
closed=false;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
void sync_queue<ValueType>::pull(ValueType& elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
wait_until_not_empty(lk);
|
||||
pull(elem, lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
template <typename ValueType>
|
||||
void sync_queue<ValueType>::pull(ValueType& elem, bool & closed)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
wait_until_not_empty(lk, closed);
|
||||
if (closed) {return;}
|
||||
pull(elem, lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// enable if ValueType is nothrow movable
|
||||
template <typename ValueType>
|
||||
ValueType sync_queue<ValueType>::pull()
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
wait_until_not_empty(lk);
|
||||
return pull(lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
template <typename ValueType>
|
||||
boost::shared_ptr<ValueType> sync_queue<ValueType>::ptr_pull()
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
wait_until_not_empty(lk);
|
||||
return ptr_pull(lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_queue<ValueType>::try_push(const ValueType& elem, unique_lock<mutex>& lk)
|
||||
{
|
||||
throw_if_closed(lk);
|
||||
push(elem, lk);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_queue<ValueType>::try_push(const ValueType& elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
return try_push(elem, lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_queue<ValueType>::try_push(no_block_tag, const ValueType& elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_, try_to_lock);
|
||||
if (!lk.owns_lock()) return false;
|
||||
return try_push(elem, lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
void sync_queue<ValueType>::push(const ValueType& elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
throw_if_closed(lk);
|
||||
push(elem, lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_queue<ValueType>::try_push(BOOST_THREAD_RV_REF(ValueType) elem, unique_lock<mutex>& lk)
|
||||
{
|
||||
throw_if_closed(lk);
|
||||
push(boost::move(elem), lk);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_queue<ValueType>::try_push(BOOST_THREAD_RV_REF(ValueType) elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
return try_push(boost::move(elem), lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
bool sync_queue<ValueType>::try_push(no_block_tag, BOOST_THREAD_RV_REF(ValueType) elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_, try_to_lock);
|
||||
if (!lk.owns_lock())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return try_push(boost::move(elem), lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
void sync_queue<ValueType>::push(BOOST_THREAD_RV_REF(ValueType) elem)
|
||||
{
|
||||
try
|
||||
{
|
||||
unique_lock<mutex> lk(mtx_);
|
||||
throw_if_closed(lk);
|
||||
push(boost::move(elem), lk);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
sync_queue<ValueType>& operator<<(sync_queue<ValueType>& sbq, BOOST_THREAD_RV_REF(ValueType) elem)
|
||||
{
|
||||
sbq.push(boost::move(elem));
|
||||
return sbq;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
sync_queue<ValueType>& operator<<(sync_queue<ValueType>& sbq, ValueType const&elem)
|
||||
{
|
||||
sbq.push(elem);
|
||||
return sbq;
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
sync_queue<ValueType>& operator>>(sync_queue<ValueType>& sbq, ValueType &elem)
|
||||
{
|
||||
sbq.pull(elem);
|
||||
return sbq;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif
|
||||
@@ -18,6 +18,19 @@
|
||||
#include <boost/thread/lock_factories.hpp>
|
||||
#include <boost/thread/strict_lock.hpp>
|
||||
#include <boost/utility/swap.hpp>
|
||||
#include <boost/utility/declval.hpp>
|
||||
//#include <boost/type_traits.hpp>
|
||||
//#include <boost/thread/detail/is_nothrow_default_constructible.hpp>
|
||||
//#if ! defined BOOST_NO_CXX11_HDR_TYPE_TRAITS
|
||||
//#include <type_traits>
|
||||
//#endif
|
||||
|
||||
#if ! defined(BOOST_THREAD_NO_SYNCHRONIZE)
|
||||
#include <tuple> // todo change to <boost/tuple.hpp> once Boost.Tuple or Boost.Fusion provides Move semantics on C++98 compilers.
|
||||
#include <functional>
|
||||
#endif
|
||||
|
||||
#include <boost/utility/result_of.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
@@ -25,29 +38,44 @@ namespace boost
|
||||
{
|
||||
|
||||
/**
|
||||
* strict lock providing a const pointer access to the synchronized value type.
|
||||
*
|
||||
* @param T the value type.
|
||||
* @param Lockable the mutex type protecting the value type.
|
||||
*/
|
||||
template <typename T, typename Lockable = mutex>
|
||||
class const_strict_lock_ptr
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef Lockable lockable_type;
|
||||
typedef Lockable mutex_type;
|
||||
protected:
|
||||
|
||||
// this should be a strict_lock, but we need to be able to return it.
|
||||
boost::unique_lock<lockable_type> lk_;
|
||||
// this should be a strict_lock, but unique_lock is needed to be able to return it.
|
||||
boost::unique_lock<mutex_type> lk_;
|
||||
T const& value_;
|
||||
|
||||
public:
|
||||
BOOST_THREAD_MOVABLE_ONLY( const_strict_lock_ptr )
|
||||
|
||||
const_strict_lock_ptr(T const& value, Lockable & mtx) :
|
||||
lk_(mtx), value_(value)
|
||||
/**
|
||||
* @param value constant reference of the value to protect.
|
||||
* @param mtx reference to the mutex used to protect the value.
|
||||
* @effects locks the mutex @c mtx, stores a reference to it and to the value type @c value.
|
||||
*/
|
||||
const_strict_lock_ptr(T const& val, Lockable & mtx) :
|
||||
lk_(mtx), value_(val)
|
||||
{
|
||||
}
|
||||
|
||||
const_strict_lock_ptr(BOOST_THREAD_RV_REF(const_strict_lock_ptr) other)
|
||||
const_strict_lock_ptr(T const& val, Lockable & mtx, adopt_lock_t tag) BOOST_NOEXCEPT :
|
||||
lk_(mtx, tag), value_(val)
|
||||
{
|
||||
}
|
||||
/**
|
||||
* Move constructor.
|
||||
* @effects takes ownership of the mutex owned by @c other, stores a reference to the mutex and the value type of @c other.
|
||||
*/
|
||||
const_strict_lock_ptr(BOOST_THREAD_RV_REF(const_strict_lock_ptr) other) BOOST_NOEXCEPT
|
||||
: lk_(boost::move(BOOST_THREAD_RV(other).lk_)),value_(BOOST_THREAD_RV(other).value_)
|
||||
{
|
||||
}
|
||||
@@ -56,11 +84,17 @@ namespace boost
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a constant pointer to the protected value
|
||||
*/
|
||||
const T* operator->() const
|
||||
{
|
||||
return &value_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a constant reference to the protected value
|
||||
*/
|
||||
const T& operator*() const
|
||||
{
|
||||
return value_;
|
||||
@@ -69,7 +103,10 @@ namespace boost
|
||||
};
|
||||
|
||||
/**
|
||||
* strict lock providing a pointer access to the synchronized value type.
|
||||
*
|
||||
* @param T the value type.
|
||||
* @param Lockable the mutex type protecting the value type.
|
||||
*/
|
||||
template <typename T, typename Lockable = mutex>
|
||||
class strict_lock_ptr : public const_strict_lock_ptr<T,Lockable>
|
||||
@@ -78,11 +115,24 @@ namespace boost
|
||||
public:
|
||||
BOOST_THREAD_MOVABLE_ONLY( strict_lock_ptr )
|
||||
|
||||
strict_lock_ptr(T & value, Lockable & mtx) :
|
||||
base_type(value, mtx)
|
||||
/**
|
||||
* @param value reference of the value to protect.
|
||||
* @param mtx reference to the mutex used to protect the value.
|
||||
* @effects locks the mutex @c mtx, stores a reference to it and to the value type @c value.
|
||||
*/
|
||||
strict_lock_ptr(T & val, Lockable & mtx) :
|
||||
base_type(val, mtx)
|
||||
{
|
||||
}
|
||||
strict_lock_ptr(T & val, Lockable & mtx, adopt_lock_t tag) :
|
||||
base_type(val, mtx, tag)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Move constructor.
|
||||
* @effects takes ownership of the mutex owned by @c other, stores a reference to the mutex and the value type of @c other.
|
||||
*/
|
||||
strict_lock_ptr(BOOST_THREAD_RV_REF(strict_lock_ptr) other)
|
||||
: base_type(boost::move(static_cast<base_type&>(other)))
|
||||
{
|
||||
@@ -92,11 +142,17 @@ namespace boost
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a pointer to the protected value
|
||||
*/
|
||||
T* operator->()
|
||||
{
|
||||
return const_cast<T*>(&this->value_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a reference to the protected value
|
||||
*/
|
||||
T& operator*()
|
||||
{
|
||||
return const_cast<T&>(this->value_);
|
||||
@@ -104,8 +160,35 @@ namespace boost
|
||||
|
||||
};
|
||||
|
||||
template <typename SV>
|
||||
struct synchronized_value_strict_lock_ptr
|
||||
{
|
||||
typedef strict_lock_ptr<typename SV::value_type, typename SV::mutex_type> type;
|
||||
};
|
||||
|
||||
template <typename SV>
|
||||
struct synchronized_value_strict_lock_ptr<const SV>
|
||||
{
|
||||
typedef const_strict_lock_ptr<typename SV::value_type, typename SV::mutex_type> type;
|
||||
};
|
||||
/**
|
||||
* unique_lock providing a const pointer access to the synchronized value type.
|
||||
*
|
||||
* An object of type const_unique_lock_ptr is a unique_lock that provides a const pointer access to the synchronized value type.
|
||||
* As unique_lock controls the ownership of a lockable object within a scope.
|
||||
* Ownership of the lockable object may be acquired at construction or after construction,
|
||||
* and may be transferred, after acquisition, to another const_unique_lock_ptr object.
|
||||
* Objects of type const_unique_lock_ptr are not copyable but are movable.
|
||||
* The behavior of a program is undefined if the mutex and the value type
|
||||
* pointed do not exist for the entire remaining lifetime of the const_unique_lock_ptr object.
|
||||
* The supplied Mutex type shall meet the BasicLockable requirements.
|
||||
*
|
||||
* @note const_unique_lock_ptr<T, Lockable> meets the Lockable requirements.
|
||||
* If Lockable meets the TimedLockable requirements, const_unique_lock_ptr<T,Lockable>
|
||||
* also meets the TimedLockable requirements.
|
||||
*
|
||||
* @param T the value type.
|
||||
* @param Lockable the mutex type protecting the value type.
|
||||
*/
|
||||
template <typename T, typename Lockable = mutex>
|
||||
class const_unique_lock_ptr : public unique_lock<Lockable>
|
||||
@@ -113,44 +196,85 @@ namespace boost
|
||||
typedef unique_lock<Lockable> base_type;
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef Lockable lockable_type;
|
||||
typedef Lockable mutex_type;
|
||||
protected:
|
||||
T const& value_;
|
||||
|
||||
public:
|
||||
BOOST_THREAD_MOVABLE_ONLY(const_unique_lock_ptr)
|
||||
|
||||
const_unique_lock_ptr(T const& value, Lockable & mtx)
|
||||
: base_type(mtx), value_(value)
|
||||
/**
|
||||
* @param value reference of the value to protect.
|
||||
* @param mtx reference to the mutex used to protect the value.
|
||||
*
|
||||
* @requires If mutex_type is not a recursive mutex the calling thread does not own the mutex.
|
||||
*
|
||||
* @effects locks the mutex @c mtx, stores a reference to it and to the value type @c value.
|
||||
*/
|
||||
const_unique_lock_ptr(T const& val, Lockable & mtx)
|
||||
: base_type(mtx), value_(val)
|
||||
{
|
||||
}
|
||||
const_unique_lock_ptr(T const& value, Lockable & mtx, adopt_lock_t)
|
||||
: base_type(mtx, adopt_lock), value_(value)
|
||||
/**
|
||||
* @param value reference of the value to protect.
|
||||
* @param mtx reference to the mutex used to protect the value.
|
||||
* @param tag of type adopt_lock_t used to differentiate the constructor.
|
||||
* @requires The calling thread own the mutex.
|
||||
* @effects stores a reference to it and to the value type @c value taking ownership.
|
||||
*/
|
||||
const_unique_lock_ptr(T const& val, Lockable & mtx, adopt_lock_t) BOOST_NOEXCEPT
|
||||
: base_type(mtx, adopt_lock), value_(val)
|
||||
{
|
||||
}
|
||||
const_unique_lock_ptr(T const& value, Lockable & mtx, defer_lock_t)
|
||||
: base_type(mtx, defer_lock), value_(value)
|
||||
/**
|
||||
* @param value reference of the value to protect.
|
||||
* @param mtx reference to the mutex used to protect the value.
|
||||
* @param tag of type defer_lock_t used to differentiate the constructor.
|
||||
* @effects stores a reference to it and to the value type @c value c.
|
||||
*/
|
||||
const_unique_lock_ptr(T const& val, Lockable & mtx, defer_lock_t) BOOST_NOEXCEPT
|
||||
: base_type(mtx, defer_lock), value_(val)
|
||||
{
|
||||
}
|
||||
const_unique_lock_ptr(T const& value, Lockable & mtx, try_to_lock_t)
|
||||
: base_type(mtx, try_to_lock), value_(value)
|
||||
/**
|
||||
* @param value reference of the value to protect.
|
||||
* @param mtx reference to the mutex used to protect the value.
|
||||
* @param tag of type try_to_lock_t used to differentiate the constructor.
|
||||
* @requires If mutex_type is not a recursive mutex the calling thread does not own the mutex.
|
||||
* @effects try to lock the mutex @c mtx, stores a reference to it and to the value type @c value.
|
||||
*/
|
||||
const_unique_lock_ptr(T const& val, Lockable & mtx, try_to_lock_t) BOOST_NOEXCEPT
|
||||
: base_type(mtx, try_to_lock), value_(val)
|
||||
{
|
||||
}
|
||||
const_unique_lock_ptr(BOOST_THREAD_RV_REF(const_unique_lock_ptr) other)
|
||||
/**
|
||||
* Move constructor.
|
||||
* @effects takes ownership of the mutex owned by @c other, stores a reference to the mutex and the value type of @c other.
|
||||
*/
|
||||
const_unique_lock_ptr(BOOST_THREAD_RV_REF(const_unique_lock_ptr) other) BOOST_NOEXCEPT
|
||||
: base_type(boost::move(static_cast<base_type&>(other))), value_(BOOST_THREAD_RV(other).value_)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects If owns calls unlock() on the owned mutex.
|
||||
*/
|
||||
~const_unique_lock_ptr()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a constant pointer to the protected value
|
||||
*/
|
||||
const T* operator->() const
|
||||
{
|
||||
BOOST_ASSERT (this->owns_lock());
|
||||
return &value_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a constant reference to the protected value
|
||||
*/
|
||||
const T& operator*() const
|
||||
{
|
||||
BOOST_ASSERT (this->owns_lock());
|
||||
@@ -160,7 +284,10 @@ namespace boost
|
||||
};
|
||||
|
||||
/**
|
||||
* unique lock providing a pointer access to the synchronized value type.
|
||||
*
|
||||
* @param T the value type.
|
||||
* @param Lockable the mutex type protecting the value type.
|
||||
*/
|
||||
template <typename T, typename Lockable = mutex>
|
||||
class unique_lock_ptr : public const_unique_lock_ptr<T, Lockable>
|
||||
@@ -168,27 +295,54 @@ namespace boost
|
||||
typedef const_unique_lock_ptr<T, Lockable> base_type;
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef Lockable lockable_type;
|
||||
typedef Lockable mutex_type;
|
||||
|
||||
BOOST_THREAD_MOVABLE_ONLY(unique_lock_ptr)
|
||||
|
||||
unique_lock_ptr(T & value, Lockable & mtx)
|
||||
: base_type(value, mtx)
|
||||
/**
|
||||
* @param value reference of the value to protect.
|
||||
* @param mtx reference to the mutex used to protect the value.
|
||||
* @effects locks the mutex @c mtx, stores a reference to it and to the value type @c value.
|
||||
*/
|
||||
unique_lock_ptr(T & val, Lockable & mtx)
|
||||
: base_type(val, mtx)
|
||||
{
|
||||
}
|
||||
unique_lock_ptr(T & value, Lockable & mtx, adopt_lock_t)
|
||||
/**
|
||||
* @param value reference of the value to protect.
|
||||
* @param mtx reference to the mutex used to protect the value.
|
||||
* @param tag of type adopt_lock_t used to differentiate the constructor.
|
||||
* @effects stores a reference to it and to the value type @c value taking ownership.
|
||||
*/
|
||||
unique_lock_ptr(T & value, Lockable & mtx, adopt_lock_t) BOOST_NOEXCEPT
|
||||
: base_type(value, mtx, adopt_lock)
|
||||
{
|
||||
}
|
||||
unique_lock_ptr(T & value, Lockable & mtx, defer_lock_t)
|
||||
/**
|
||||
* @param value reference of the value to protect.
|
||||
* @param mtx reference to the mutex used to protect the value.
|
||||
* @param tag of type defer_lock_t used to differentiate the constructor.
|
||||
* @effects stores a reference to it and to the value type @c value c.
|
||||
*/
|
||||
unique_lock_ptr(T & value, Lockable & mtx, defer_lock_t) BOOST_NOEXCEPT
|
||||
: base_type(value, mtx, defer_lock)
|
||||
{
|
||||
}
|
||||
unique_lock_ptr(T & value, Lockable & mtx, try_to_lock_t)
|
||||
/**
|
||||
* @param value reference of the value to protect.
|
||||
* @param mtx reference to the mutex used to protect the value.
|
||||
* @param tag of type try_to_lock_t used to differentiate the constructor.
|
||||
* @effects try to lock the mutex @c mtx, stores a reference to it and to the value type @c value.
|
||||
*/
|
||||
unique_lock_ptr(T & value, Lockable & mtx, try_to_lock_t) BOOST_NOEXCEPT
|
||||
: base_type(value, mtx, try_to_lock)
|
||||
{
|
||||
}
|
||||
unique_lock_ptr(BOOST_THREAD_RV_REF(unique_lock_ptr) other)
|
||||
/**
|
||||
* Move constructor.
|
||||
* @effects takes ownership of the mutex owned by @c other, stores a reference to the mutex and the value type of @c other.
|
||||
*/
|
||||
unique_lock_ptr(BOOST_THREAD_RV_REF(unique_lock_ptr) other) BOOST_NOEXCEPT
|
||||
: base_type(boost::move(static_cast<base_type&>(other)))
|
||||
{
|
||||
}
|
||||
@@ -197,12 +351,18 @@ namespace boost
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a pointer to the protected value
|
||||
*/
|
||||
T* operator->()
|
||||
{
|
||||
BOOST_ASSERT (this->owns_lock());
|
||||
return const_cast<T*>(&this->value_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a reference to the protected value
|
||||
*/
|
||||
T& operator*()
|
||||
{
|
||||
BOOST_ASSERT (this->owns_lock());
|
||||
@@ -212,25 +372,62 @@ namespace boost
|
||||
|
||||
};
|
||||
|
||||
template <typename SV>
|
||||
struct synchronized_value_unique_lock_ptr
|
||||
{
|
||||
typedef unique_lock_ptr<typename SV::value_type, typename SV::mutex_type> type;
|
||||
};
|
||||
|
||||
template <typename SV>
|
||||
struct synchronized_value_unique_lock_ptr<const SV>
|
||||
{
|
||||
typedef const_unique_lock_ptr<typename SV::value_type, typename SV::mutex_type> type;
|
||||
};
|
||||
/**
|
||||
*
|
||||
* cloaks a value type and the mutex used to protect it together.
|
||||
* @param T the value type.
|
||||
* @param Lockable the mutex type protecting the value type.
|
||||
*/
|
||||
template <typename T, typename Lockable = mutex>
|
||||
class synchronized_value
|
||||
{
|
||||
|
||||
#if ! defined(BOOST_THREAD_NO_MAKE_UNIQUE_LOCKS)
|
||||
#if ! defined BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
||||
template <typename ...SV>
|
||||
friend std::tuple<typename synchronized_value_strict_lock_ptr<SV>::type ...> synchronize(SV& ...sv);
|
||||
#else
|
||||
template <typename SV1, typename SV2>
|
||||
friend std::tuple<
|
||||
typename synchronized_value_strict_lock_ptr<SV1>::type,
|
||||
typename synchronized_value_strict_lock_ptr<SV2>::type
|
||||
>
|
||||
synchronize(SV1& sv1, SV2& sv2);
|
||||
template <typename SV1, typename SV2, typename SV3>
|
||||
friend std::tuple<
|
||||
typename synchronized_value_strict_lock_ptr<SV1>::type,
|
||||
typename synchronized_value_strict_lock_ptr<SV2>::type,
|
||||
typename synchronized_value_strict_lock_ptr<SV3>::type
|
||||
>
|
||||
synchronize(SV1& sv1, SV2& sv2, SV3& sv3);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef Lockable lockable_type;
|
||||
typedef Lockable mutex_type;
|
||||
private:
|
||||
T value_;
|
||||
mutable lockable_type mtx_;
|
||||
mutable mutex_type mtx_;
|
||||
public:
|
||||
// construction/destruction
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* Requires: T is DefaultConstructible
|
||||
* @Requires: T is DefaultConstructible
|
||||
*/
|
||||
synchronized_value()
|
||||
//BOOST_NOEXCEPT_IF(is_nothrow_default_constructible<T>::value)
|
||||
: value_()
|
||||
{
|
||||
}
|
||||
@@ -241,47 +438,50 @@ namespace boost
|
||||
* Requires: T is CopyConstructible
|
||||
*/
|
||||
synchronized_value(T const& other)
|
||||
//BOOST_NOEXCEPT_IF(is_nothrow_copy_constructible<T>::value)
|
||||
: value_(other)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Move Constructor from movable value.
|
||||
* Move Constructor.
|
||||
*
|
||||
* Requires: T is Movable
|
||||
* Requires: T is CopyMovable
|
||||
*/
|
||||
synchronized_value(BOOST_THREAD_RV_REF(T) other)
|
||||
//BOOST_NOEXCEPT_IF(is_nothrow_move_constructible<T>::value)
|
||||
: value_(boost::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy Constructor.
|
||||
* Constructor from value type.
|
||||
*
|
||||
* Requires: T is DefaultConstructible and Assignable
|
||||
* Effects: Assigns the value on a scope protected by the mutex of the rhs. The mutex is not copied.
|
||||
*/
|
||||
synchronized_value(synchronized_value const& rhs)
|
||||
{
|
||||
strict_lock<lockable_type> lk(rhs.mtx_);
|
||||
strict_lock<mutex_type> lk(rhs.mtx_);
|
||||
value_ = rhs.value_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move Constructor.
|
||||
* Move Constructor from movable value type
|
||||
*
|
||||
*/
|
||||
synchronized_value(BOOST_THREAD_RV_REF(synchronized_value) other)
|
||||
{
|
||||
strict_lock<lockable_type> lk(other.mtx_);
|
||||
value_= boost::move(other);
|
||||
strict_lock<mutex_type> lk(other.mtx_);
|
||||
value_= boost::move(other.value_);
|
||||
}
|
||||
|
||||
// mutation
|
||||
/**
|
||||
* Assignment operator.
|
||||
*
|
||||
* Effects: Copies the underlying value on a scope protected by the two mutexes.
|
||||
* The mutexes are not copied. The locks are acquired using lock, so deadlock is avoided.
|
||||
* The mutex is not copied. The locks are acquired using lock, so deadlock is avoided.
|
||||
* For example, there is no problem if one thread assigns a = b and the other assigns b = a.
|
||||
*
|
||||
* Return: *this
|
||||
@@ -292,8 +492,8 @@ namespace boost
|
||||
if(&rhs != this)
|
||||
{
|
||||
// auto _ = make_unique_locks(mtx_, rhs.mtx_);
|
||||
unique_lock<lockable_type> lk1(mtx_, defer_lock);
|
||||
unique_lock<lockable_type> lk2(rhs.mtx_, defer_lock);
|
||||
unique_lock<mutex_type> lk1(mtx_, defer_lock);
|
||||
unique_lock<mutex_type> lk2(rhs.mtx_, defer_lock);
|
||||
lock(lk1,lk2);
|
||||
|
||||
value_ = rhs.value_;
|
||||
@@ -305,15 +505,16 @@ namespace boost
|
||||
* Effects: The operator copies the value on a scope protected by the mutex.
|
||||
* Return: *this
|
||||
*/
|
||||
synchronized_value& operator=(value_type const& value)
|
||||
synchronized_value& operator=(value_type const& val)
|
||||
{
|
||||
{
|
||||
strict_lock<lockable_type> lk(mtx_);
|
||||
value_ = value;
|
||||
strict_lock<mutex_type> lk(mtx_);
|
||||
value_ = val;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//observers
|
||||
/**
|
||||
* Explicit conversion to value type.
|
||||
*
|
||||
@@ -323,7 +524,7 @@ namespace boost
|
||||
*/
|
||||
T get() const
|
||||
{
|
||||
strict_lock<lockable_type> lk(mtx_);
|
||||
strict_lock<mutex_type> lk(mtx_);
|
||||
return value_;
|
||||
}
|
||||
/**
|
||||
@@ -340,6 +541,30 @@ namespace boost
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* value type getter.
|
||||
*
|
||||
* Return: A constant reference to the protected value.
|
||||
*
|
||||
* Note: Not thread safe
|
||||
*
|
||||
*/
|
||||
T const& value() const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
/**
|
||||
* mutex getter.
|
||||
*
|
||||
* Return: A constant reference to the protecting mutex.
|
||||
*
|
||||
* Note: Not thread safe
|
||||
*
|
||||
*/
|
||||
mutex_type const& mutex() const
|
||||
{
|
||||
return mtx_;
|
||||
}
|
||||
/**
|
||||
* Swap
|
||||
*
|
||||
@@ -354,24 +579,22 @@ namespace boost
|
||||
return;
|
||||
}
|
||||
// auto _ = make_unique_locks(mtx_, rhs.mtx_);
|
||||
unique_lock<lockable_type> lk1(mtx_, defer_lock);
|
||||
unique_lock<lockable_type> lk2(rhs.mtx_, defer_lock);
|
||||
unique_lock<mutex_type> lk1(mtx_, defer_lock);
|
||||
unique_lock<mutex_type> lk2(rhs.mtx_, defer_lock);
|
||||
lock(lk1,lk2);
|
||||
boost::swap(value_, rhs.value_);
|
||||
}
|
||||
/**
|
||||
* Swap with the underlying type
|
||||
* Swap with the underlying value type
|
||||
*
|
||||
* Effects: Swaps the data on a scope protected by the mutex.
|
||||
*/
|
||||
void swap(value_type & rhs)
|
||||
{
|
||||
strict_lock<lockable_type> lk(mtx_);
|
||||
boost::swap(value_, rhs.value_);
|
||||
strict_lock<mutex_type> lk(mtx_);
|
||||
boost::swap(value_, rhs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Essentially calling a method obj->foo(x, y, z) calls the method foo(x, y, z) inside a critical section as
|
||||
* long-lived as the call itself.
|
||||
@@ -390,14 +613,81 @@ namespace boost
|
||||
return BOOST_THREAD_MAKE_RV_REF((const_strict_lock_ptr<T,Lockable>(value_, mtx_)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Call function on a locked block.
|
||||
*
|
||||
* @requires fct(value_) is well formed.
|
||||
*
|
||||
* Example
|
||||
* void fun(synchronized_value<vector<int>> & v) {
|
||||
* v ( [](vector<int>> & vec)
|
||||
* {
|
||||
* vec.push_back(42);
|
||||
* assert(vec.back() == 42);
|
||||
* } );
|
||||
* }
|
||||
*/
|
||||
template <typename F>
|
||||
inline
|
||||
typename boost::result_of<F(value_type&)>::type
|
||||
operator()(BOOST_THREAD_RV_REF(F) fct)
|
||||
{
|
||||
strict_lock<mutex_type> lk(mtx_);
|
||||
return fct(value_);
|
||||
}
|
||||
template <typename F>
|
||||
inline
|
||||
typename boost::result_of<F(value_type const&)>::type
|
||||
operator()(BOOST_THREAD_RV_REF(F) fct) const
|
||||
{
|
||||
strict_lock<mutex_type> lk(mtx_);
|
||||
return fct(value_);
|
||||
}
|
||||
|
||||
|
||||
#if defined BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
template <typename F>
|
||||
inline
|
||||
typename boost::result_of<F(value_type&)>::type
|
||||
operator()(F const & fct)
|
||||
{
|
||||
strict_lock<mutex_type> lk(mtx_);
|
||||
return fct(value_);
|
||||
}
|
||||
template <typename F>
|
||||
inline
|
||||
typename boost::result_of<F(value_type const&)>::type
|
||||
operator()(F const & fct) const
|
||||
{
|
||||
strict_lock<mutex_type> lk(mtx_);
|
||||
return fct(value_);
|
||||
}
|
||||
|
||||
template <typename R>
|
||||
inline
|
||||
R operator()(R(*fct)(value_type&))
|
||||
{
|
||||
strict_lock<mutex_type> lk(mtx_);
|
||||
return fct(value_);
|
||||
}
|
||||
template <typename R>
|
||||
inline
|
||||
R operator()(R(*fct)(value_type const&)) const
|
||||
{
|
||||
strict_lock<mutex_type> lk(mtx_);
|
||||
return fct(value_);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* The synchronize() factory make easier to lock on a scope.
|
||||
* As discussed, operator-> can only lock over the duration of a call, so it is insufficient for complex operations.
|
||||
* With synchronize() you get to lock the object in a scoped and to directly access the object inside that scope.
|
||||
*
|
||||
* Example
|
||||
* void fun(synchronized_value<vector<int>> & vec) {
|
||||
* auto&& vec=vec.synchronize();
|
||||
* void fun(synchronized_value<vector<int>> & v) {
|
||||
* auto&& vec=v.synchronize();
|
||||
* vec.push_back(42);
|
||||
* assert(vec.back() == 42);
|
||||
* }
|
||||
@@ -415,27 +705,53 @@ namespace boost
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF((unique_lock_ptr<T,Lockable>(value_, mtx_)));
|
||||
}
|
||||
unique_lock_ptr<T,Lockable> unique_synchronize(defer_lock_t tag)
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF((unique_lock_ptr<T,Lockable>(value_, mtx_, tag)));
|
||||
}
|
||||
const_unique_lock_ptr<T,Lockable> unique_synchronize() const
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF((const_unique_lock_ptr<T,Lockable>(value_, mtx_)));
|
||||
}
|
||||
unique_lock_ptr<T,Lockable> unique_synchronize(defer_lock_t tag)
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF((unique_lock_ptr<T,Lockable>(value_, mtx_, tag)));
|
||||
}
|
||||
const_unique_lock_ptr<T,Lockable> unique_synchronize(defer_lock_t tag) const
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF((const_unique_lock_ptr<T,Lockable>(value_, mtx_, tag)));
|
||||
}
|
||||
unique_lock_ptr<T,Lockable> defer_synchronize() BOOST_NOEXCEPT
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF((unique_lock_ptr<T,Lockable>(value_, mtx_, defer_lock)));
|
||||
}
|
||||
const_unique_lock_ptr<T,Lockable> defer_synchronize() const BOOST_NOEXCEPT
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF((const_unique_lock_ptr<T,Lockable>(value_, mtx_, defer_lock)));
|
||||
}
|
||||
unique_lock_ptr<T,Lockable> try_to_synchronize() BOOST_NOEXCEPT
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF((unique_lock_ptr<T,Lockable>(value_, mtx_, try_to_lock)));
|
||||
}
|
||||
const_unique_lock_ptr<T,Lockable> try_to_synchronize() const BOOST_NOEXCEPT
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF((const_unique_lock_ptr<T,Lockable>(value_, mtx_, try_to_lock)));
|
||||
}
|
||||
unique_lock_ptr<T,Lockable> adopt_synchronize() BOOST_NOEXCEPT
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF((unique_lock_ptr<T,Lockable>(value_, mtx_, adopt_lock)));
|
||||
}
|
||||
const_unique_lock_ptr<T,Lockable> adopt_synchronize() const BOOST_NOEXCEPT
|
||||
{
|
||||
return BOOST_THREAD_MAKE_RV_REF((const_unique_lock_ptr<T,Lockable>(value_, mtx_, adopt_lock)));
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
#if ! defined __IBMCPP__
|
||||
private:
|
||||
#endif
|
||||
class deref_value
|
||||
{
|
||||
private:
|
||||
friend class synchronized_value;
|
||||
|
||||
boost::unique_lock<lockable_type> lk_;
|
||||
boost::unique_lock<mutex_type> lk_;
|
||||
T& value_;
|
||||
|
||||
explicit deref_value(synchronized_value& outer):
|
||||
@@ -448,7 +764,7 @@ namespace boost
|
||||
deref_value(BOOST_THREAD_RV_REF(deref_value) other):
|
||||
lk_(boost::move(BOOST_THREAD_RV(other).lk_)),value_(BOOST_THREAD_RV(other).value_)
|
||||
{}
|
||||
operator T()
|
||||
operator T&()
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
@@ -464,7 +780,7 @@ namespace boost
|
||||
private:
|
||||
friend class synchronized_value;
|
||||
|
||||
boost::unique_lock<lockable_type> lk_;
|
||||
boost::unique_lock<mutex_type> lk_;
|
||||
const T& value_;
|
||||
|
||||
explicit const_deref_value(synchronized_value const& outer):
|
||||
@@ -478,7 +794,7 @@ namespace boost
|
||||
lk_(boost::move(BOOST_THREAD_RV(other).lk_)), value_(BOOST_THREAD_RV(other).value_)
|
||||
{}
|
||||
|
||||
operator T()
|
||||
operator const T&()
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
@@ -495,8 +811,121 @@ namespace boost
|
||||
return BOOST_THREAD_MAKE_RV_REF(const_deref_value(*this));
|
||||
}
|
||||
|
||||
// io functions
|
||||
/**
|
||||
* @requires T is OutputStreamable
|
||||
* @effects saves the value type on the output stream @c os.
|
||||
*/
|
||||
template <typename OStream>
|
||||
void save(OStream& os) const
|
||||
{
|
||||
strict_lock<mutex_type> lk(mtx_);
|
||||
os << value_;
|
||||
}
|
||||
/**
|
||||
* @requires T is InputStreamable
|
||||
* @effects loads the value type from the input stream @c is.
|
||||
*/
|
||||
template <typename IStream>
|
||||
void load(IStream& is) const
|
||||
{
|
||||
strict_lock<mutex_type> lk(mtx_);
|
||||
is >> value_;
|
||||
}
|
||||
|
||||
// relational operators
|
||||
/**
|
||||
* @requires T is EqualityComparable
|
||||
*
|
||||
*/
|
||||
bool operator==(synchronized_value const& rhs) const
|
||||
{
|
||||
unique_lock<mutex_type> lk1(mtx_, defer_lock);
|
||||
unique_lock<mutex_type> lk2(rhs.mtx_, defer_lock);
|
||||
lock(lk1,lk2);
|
||||
|
||||
return value_ == rhs.value_;
|
||||
}
|
||||
/**
|
||||
* @requires T is LessThanComparable
|
||||
*
|
||||
*/
|
||||
bool operator<(synchronized_value const& rhs) const
|
||||
{
|
||||
unique_lock<mutex_type> lk1(mtx_, defer_lock);
|
||||
unique_lock<mutex_type> lk2(rhs.mtx_, defer_lock);
|
||||
lock(lk1,lk2);
|
||||
|
||||
return value_ < rhs.value_;
|
||||
}
|
||||
/**
|
||||
* @requires T is GreaterThanComparable
|
||||
*
|
||||
*/
|
||||
bool operator>(synchronized_value const& rhs) const
|
||||
{
|
||||
unique_lock<mutex_type> lk1(mtx_, defer_lock);
|
||||
unique_lock<mutex_type> lk2(rhs.mtx_, defer_lock);
|
||||
lock(lk1,lk2);
|
||||
|
||||
return value_ > rhs.value_;
|
||||
}
|
||||
bool operator<=(synchronized_value const& rhs) const
|
||||
{
|
||||
unique_lock<mutex_type> lk1(mtx_, defer_lock);
|
||||
unique_lock<mutex_type> lk2(rhs.mtx_, defer_lock);
|
||||
lock(lk1,lk2);
|
||||
|
||||
return value_ <= rhs.value_;
|
||||
}
|
||||
bool operator>=(synchronized_value const& rhs) const
|
||||
{
|
||||
unique_lock<mutex_type> lk1(mtx_, defer_lock);
|
||||
unique_lock<mutex_type> lk2(rhs.mtx_, defer_lock);
|
||||
lock(lk1,lk2);
|
||||
|
||||
return value_ >= rhs.value_;
|
||||
}
|
||||
bool operator==(value_type const& rhs) const
|
||||
{
|
||||
unique_lock<mutex_type> lk1(mtx_);
|
||||
|
||||
return value_ == rhs;
|
||||
}
|
||||
bool operator!=(value_type const& rhs) const
|
||||
{
|
||||
unique_lock<mutex_type> lk1(mtx_);
|
||||
|
||||
return value_ != rhs;
|
||||
}
|
||||
bool operator<(value_type const& rhs) const
|
||||
{
|
||||
unique_lock<mutex_type> lk1(mtx_);
|
||||
|
||||
return value_ < rhs;
|
||||
}
|
||||
bool operator<=(value_type const& rhs) const
|
||||
{
|
||||
unique_lock<mutex_type> lk1(mtx_);
|
||||
|
||||
return value_ <= rhs;
|
||||
}
|
||||
bool operator>(value_type const& rhs) const
|
||||
{
|
||||
unique_lock<mutex_type> lk1(mtx_);
|
||||
|
||||
return value_ > rhs;
|
||||
}
|
||||
bool operator>=(value_type const& rhs) const
|
||||
{
|
||||
unique_lock<mutex_type> lk1(mtx_);
|
||||
|
||||
return value_ >= rhs;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Specialized algorithms
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -505,7 +934,133 @@ namespace boost
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
template <typename T, typename L>
|
||||
inline void swap(synchronized_value<T,L> & lhs, T & rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
template <typename T, typename L>
|
||||
inline void swap(T & lhs, synchronized_value<T,L> & rhs)
|
||||
{
|
||||
rhs.swap(lhs);
|
||||
}
|
||||
|
||||
//Hash support
|
||||
|
||||
// template <class T> struct hash;
|
||||
// template <typename T, typename L>
|
||||
// struct hash<synchronized_value<T,L> >;
|
||||
|
||||
// Comparison with T
|
||||
template <typename T, typename L>
|
||||
bool operator!=(synchronized_value<T,L> const&lhs, synchronized_value<T,L> const& rhs)
|
||||
{
|
||||
return ! (lhs==rhs);
|
||||
}
|
||||
|
||||
template <typename T, typename L>
|
||||
bool operator==(T const& lhs, synchronized_value<T,L> const&rhs)
|
||||
{
|
||||
return rhs==lhs;
|
||||
}
|
||||
template <typename T, typename L>
|
||||
bool operator!=(T const& lhs, synchronized_value<T,L> const&rhs)
|
||||
{
|
||||
return rhs!=lhs;
|
||||
}
|
||||
template <typename T, typename L>
|
||||
bool operator<(T const& lhs, synchronized_value<T,L> const&rhs)
|
||||
{
|
||||
return rhs>=lhs;
|
||||
}
|
||||
template <typename T, typename L>
|
||||
bool operator<=(T const& lhs, synchronized_value<T,L> const&rhs)
|
||||
{
|
||||
return rhs>lhs;
|
||||
}
|
||||
template <typename T, typename L>
|
||||
bool operator>(T const& lhs, synchronized_value<T,L> const&rhs)
|
||||
{
|
||||
return rhs<=lhs;
|
||||
}
|
||||
template <typename T, typename L>
|
||||
bool operator>=(T const& lhs, synchronized_value<T,L> const&rhs)
|
||||
{
|
||||
return rhs<lhs;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
template <typename OStream, typename T, typename L>
|
||||
inline OStream& operator<<(OStream& os, synchronized_value<T,L> const& rhs)
|
||||
{
|
||||
rhs.save(os);
|
||||
return os;
|
||||
}
|
||||
template <typename IStream, typename T, typename L>
|
||||
inline IStream& operator>>(IStream& is, synchronized_value<T,L> const& rhs)
|
||||
{
|
||||
rhs.load(is);
|
||||
return is;
|
||||
}
|
||||
|
||||
#if ! defined(BOOST_THREAD_NO_SYNCHRONIZE)
|
||||
#if ! defined BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
||||
|
||||
template <typename ...SV>
|
||||
std::tuple<typename synchronized_value_strict_lock_ptr<SV>::type ...> synchronize(SV& ...sv)
|
||||
{
|
||||
boost::lock(sv.mtx_ ...);
|
||||
typedef std::tuple<typename synchronized_value_strict_lock_ptr<SV>::type ...> t_type;
|
||||
|
||||
return t_type(typename synchronized_value_strict_lock_ptr<SV>::type(sv.value_, sv.mtx_, adopt_lock) ...);
|
||||
}
|
||||
#else
|
||||
|
||||
template <typename SV1, typename SV2>
|
||||
std::tuple<
|
||||
typename synchronized_value_strict_lock_ptr<SV1>::type,
|
||||
typename synchronized_value_strict_lock_ptr<SV2>::type
|
||||
>
|
||||
synchronize(SV1& sv1, SV2& sv2)
|
||||
{
|
||||
boost::lock(sv1.mtx_, sv2.mtx_);
|
||||
typedef std::tuple<
|
||||
typename synchronized_value_strict_lock_ptr<SV1>::type,
|
||||
typename synchronized_value_strict_lock_ptr<SV2>::type
|
||||
> t_type;
|
||||
|
||||
return t_type(
|
||||
typename synchronized_value_strict_lock_ptr<SV1>::type(sv1.value_, sv1.mtx_, adopt_lock),
|
||||
typename synchronized_value_strict_lock_ptr<SV2>::type(sv2.value_, sv2.mtx_, adopt_lock)
|
||||
);
|
||||
|
||||
}
|
||||
template <typename SV1, typename SV2, typename SV3>
|
||||
std::tuple<
|
||||
typename synchronized_value_strict_lock_ptr<SV1>::type,
|
||||
typename synchronized_value_strict_lock_ptr<SV2>::type,
|
||||
typename synchronized_value_strict_lock_ptr<SV3>::type
|
||||
>
|
||||
synchronize(SV1& sv1, SV2& sv2, SV3& sv3)
|
||||
{
|
||||
boost::lock(sv1.mtx_, sv2.mtx_);
|
||||
typedef std::tuple<
|
||||
typename synchronized_value_strict_lock_ptr<SV1>::type,
|
||||
typename synchronized_value_strict_lock_ptr<SV2>::type,
|
||||
typename synchronized_value_strict_lock_ptr<SV3>::type
|
||||
> t_type;
|
||||
|
||||
return t_type(
|
||||
typename synchronized_value_strict_lock_ptr<SV1>::type(sv1.value_, sv1.mtx_, adopt_lock),
|
||||
typename synchronized_value_strict_lock_ptr<SV2>::type(sv2.value_, sv2.mtx_, adopt_lock),
|
||||
typename synchronized_value_strict_lock_ptr<SV3>::type(sv3.value_, sv3.mtx_, adopt_lock)
|
||||
);
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
|
||||
#include <boost/thread/detail/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
|
||||
#include <boost/atomic.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
@@ -26,7 +26,7 @@ namespace boost
|
||||
*
|
||||
* Many mutex services (including boost::mutex) don't provide a way to ask,
|
||||
* "Do I already hold a lock on this mutex?"
|
||||
* Sometimes it is needed to know if a method like is_held to be available.
|
||||
* Sometimes it is needed to know if a method like is_locked to be available.
|
||||
* This wrapper associates an arbitrary lockable type with a thread id that stores the ID of the thread that
|
||||
* currently holds the lockable. The thread id initially holds an invalid value that means no threads own the mutex.
|
||||
* When we acquire a lock, we set the thread id; and when we release a lock, we reset it back to its default no id state.
|
||||
@@ -44,21 +44,25 @@ namespace boost
|
||||
/// Non copyable
|
||||
BOOST_THREAD_NO_COPYABLE(testable_mutex)
|
||||
|
||||
testable_mutex() : id_(thread::id()) {}
|
||||
|
||||
void lock()
|
||||
{
|
||||
BOOST_ASSERT(! is_locked_by_this_thread());
|
||||
mtx_.lock();
|
||||
id_ = this_thread::get_id();
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
BOOST_ASSERT(is_locked(mtx_));
|
||||
BOOST_ASSERT(is_locked_by_this_thread());
|
||||
id_ = thread::id();
|
||||
mtx_.unlock();
|
||||
}
|
||||
|
||||
bool try_lock()
|
||||
{
|
||||
BOOST_ASSERT(! is_locked_by_this_thread());
|
||||
if (mtx_.try_lock())
|
||||
{
|
||||
id_ = this_thread::get_id();
|
||||
@@ -70,40 +74,46 @@ namespace boost
|
||||
}
|
||||
}
|
||||
#ifdef BOOST_THREAD_USES_CHRONO
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
if (mtx_.try_lock_for(rel_time))
|
||||
{
|
||||
id_ = this_thread::get_id();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time)
|
||||
{
|
||||
if (mtx_.try_lock_until(abs_time))
|
||||
{
|
||||
id_ = this_thread::get_id();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
|
||||
{
|
||||
BOOST_ASSERT(! is_locked_by_this_thread());
|
||||
if (mtx_.try_lock_for(rel_time))
|
||||
{
|
||||
id_ = this_thread::get_id();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time)
|
||||
{
|
||||
BOOST_ASSERT(! is_locked_by_this_thread());
|
||||
if (mtx_.try_lock_until(abs_time))
|
||||
{
|
||||
id_ = this_thread::get_id();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool is_locked_by_this_thread()
|
||||
bool is_locked_by_this_thread() const
|
||||
{
|
||||
return this_thread::get_id() == id_;
|
||||
}
|
||||
bool is_locked() const
|
||||
{
|
||||
return ! (thread::id() == id_);
|
||||
}
|
||||
|
||||
bool get_id()
|
||||
thread::id get_id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
@@ -9,22 +9,8 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/thread/detail/platform.hpp>
|
||||
|
||||
#if defined(BOOST_THREAD_PLATFORM_WIN32)
|
||||
#include <boost/thread/win32/thread_data.hpp>
|
||||
#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
|
||||
#include <boost/thread/pthread/thread_data.hpp>
|
||||
#else
|
||||
#error "Boost threads unavailable on this platform"
|
||||
#endif
|
||||
|
||||
#include <boost/thread/detail/thread.hpp>
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
#include <boost/thread/detail/thread_interruption.hpp>
|
||||
#endif
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
#include <boost/thread/detail/thread_group.hpp>
|
||||
#include <boost/thread/v2/thread.hpp>
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
#include <boost/thread/detail/move.hpp>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/thread_only.hpp>
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
|
||||
29
include/boost/thread/thread_only.hpp
Normal file
29
include/boost/thread/thread_only.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef BOOST_THREAD_THREAD_ONLY_HPP
|
||||
#define BOOST_THREAD_THREAD_ONLY_HPP
|
||||
|
||||
// thread.hpp
|
||||
//
|
||||
// (C) Copyright 2013 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 <boost/thread/detail/platform.hpp>
|
||||
|
||||
#if defined(BOOST_THREAD_PLATFORM_WIN32)
|
||||
#include <boost/thread/win32/thread_data.hpp>
|
||||
#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
|
||||
#include <boost/thread/pthread/thread_data.hpp>
|
||||
#else
|
||||
#error "Boost threads unavailable on this platform"
|
||||
#endif
|
||||
|
||||
#include <boost/thread/detail/thread.hpp>
|
||||
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
|
||||
#include <boost/thread/detail/thread_interruption.hpp>
|
||||
#endif
|
||||
#include <boost/thread/v2/thread.hpp>
|
||||
|
||||
|
||||
#endif
|
||||
192
include/boost/thread/thread_pool.hpp
Normal file
192
include/boost/thread/thread_pool.hpp
Normal file
@@ -0,0 +1,192 @@
|
||||
// Copyright (C) 2013 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)
|
||||
//
|
||||
// 2013/09 Vicente J. Botet Escriba
|
||||
// Adapt to boost from CCIA C++11 implementation
|
||||
// first implementation of a simple pool thread using a vector of threads and a sync_queue.
|
||||
|
||||
#ifndef BOOST_THREAD_THREAD_POOL_HPP
|
||||
#define BOOST_THREAD_THREAD_POOL_HPP
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#include <boost/thread/detail/delete.hpp>
|
||||
#include <boost/thread/detail/move.hpp>
|
||||
#include <boost/thread/scoped_thread.hpp>
|
||||
#include <boost/thread/sync_queue.hpp>
|
||||
#include <boost/thread/detail/function_wrapper.hpp>
|
||||
|
||||
#ifdef BOOST_NO_CXX11_HDR_FUNCTIONAL
|
||||
#include <boost/function.hpp>
|
||||
#else
|
||||
#include <functional>
|
||||
#endif
|
||||
|
||||
#if defined BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
#include <boost/container/vector.hpp>
|
||||
#else
|
||||
#include <vector>
|
||||
#endif
|
||||
|
||||
#include <boost/config/abi_prefix.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
class thread_pool
|
||||
{
|
||||
/// type-erasure to store the works to do
|
||||
typedef detail::function_wrapper work;
|
||||
/// the kind of stored threads are scoped threads to ensure that the threads are joined.
|
||||
/// A move aware vector type
|
||||
typedef scoped_thread<> thread_t;
|
||||
#if defined BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
typedef container::vector<thread_t> thread_vector;
|
||||
#else
|
||||
typedef std::vector<thread_t> thread_vector;
|
||||
#endif
|
||||
|
||||
/// the thread safe work queue
|
||||
sync_queue<work > work_queue;
|
||||
/// A move aware vector
|
||||
thread_vector threads;
|
||||
|
||||
/**
|
||||
* Effects: try to execute one task.
|
||||
* Returns: whether a task has been executed.
|
||||
* Throws: whatever the current task constructor throws or the task() throws.
|
||||
*/
|
||||
bool try_executing_one()
|
||||
{
|
||||
work task;
|
||||
try
|
||||
{
|
||||
if (work_queue.try_pull(task))
|
||||
{
|
||||
task();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Effects: schedule one task or yields
|
||||
* Throws: whatever the current task constructor throws or the task() throws.
|
||||
*/
|
||||
void schedule_one_or_yield()
|
||||
{
|
||||
if ( ! try_executing_one())
|
||||
{
|
||||
this_thread::yield();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The main loop of the worker threads
|
||||
*/
|
||||
void worker_thread()
|
||||
{
|
||||
while (!is_closed())
|
||||
{
|
||||
schedule_one_or_yield();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
/// thread_pool is not copyable.
|
||||
BOOST_THREAD_NO_COPYABLE(thread_pool)
|
||||
|
||||
/**
|
||||
* Effects: creates a thread pool that runs closures on @c thread_count threads.
|
||||
*/
|
||||
thread_pool(unsigned const thread_count = thread::hardware_concurrency())
|
||||
{
|
||||
try
|
||||
{
|
||||
for (unsigned i = 0; i < thread_count; ++i)
|
||||
{
|
||||
threads.push_back(thread_t(&thread_pool::worker_thread, this));
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Effects: Destroys the thread pool.
|
||||
* Synchronization: The completion of all the closures happen before the completion of the thread pool destructor.
|
||||
*/
|
||||
~thread_pool()
|
||||
{
|
||||
// signal to all the worker threads that there will be no more submissions.
|
||||
close();
|
||||
// joins all the threads as the threads were scoped_threads
|
||||
}
|
||||
|
||||
/**
|
||||
* Effects: close the thread_pool for submissions. The worker threads will work until
|
||||
*/
|
||||
void close()
|
||||
{
|
||||
work_queue.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns: whether the pool is closed for submissions.
|
||||
*/
|
||||
bool is_closed()
|
||||
{
|
||||
return work_queue.closed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Effects: The specified function will be scheduled for execution at some point in the future.
|
||||
* If invoking closure throws an exception the thread pool will call std::terminate, as is the case with threads.
|
||||
* Synchronization: completion of closure on a particular thread happens before destruction of thread's thread local variables.
|
||||
* Throws: sync_queue_is_closed if the thread pool is closed.
|
||||
*
|
||||
*/
|
||||
template <typename Closure>
|
||||
void submit(Closure const& closure)
|
||||
{
|
||||
work w ((closure));
|
||||
work_queue.push(boost::move(w));
|
||||
//work_queue.push(work(closure));
|
||||
}
|
||||
template <typename Closure>
|
||||
void submit(BOOST_THREAD_RV_REF(Closure) closure)
|
||||
{
|
||||
work w =boost::move(closure);
|
||||
work_queue.push(boost::move(w));
|
||||
//work_queue.push(work(boost::move(closure)));
|
||||
}
|
||||
|
||||
/**
|
||||
* This must be called from an scheduled task.
|
||||
* Effects: reschedule functions until pred()
|
||||
*/
|
||||
template <typename Pred>
|
||||
void reschedule_until(Pred const& pred)
|
||||
{
|
||||
do {
|
||||
schedule_one_or_yield();
|
||||
} while (! pred());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include <boost/config/abi_suffix.hpp>
|
||||
|
||||
#endif
|
||||
1062
include/boost/thread/v2/shared_mutex.hpp
Executable file
1062
include/boost/thread/v2/shared_mutex.hpp
Executable file
File diff suppressed because it is too large
Load Diff
@@ -68,11 +68,8 @@ namespace boost
|
||||
using namespace chrono;
|
||||
if (d > duration<Rep, Period>::zero())
|
||||
{
|
||||
steady_clock::time_point c_now = steady_clock::now();
|
||||
do
|
||||
{
|
||||
sleep_until(system_clock::now() + ceil<nanoseconds>(d));
|
||||
} while (steady_clock::now() - c_now < d );
|
||||
steady_clock::time_point c_timeout = steady_clock::now() + ceil<nanoseconds>(d);
|
||||
sleep_until(c_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,8 +81,10 @@ namespace boost
|
||||
|
||||
do
|
||||
{
|
||||
BOOST_VERIFY(win32::WaitForSingleObject(
|
||||
sem,::boost::detail::win32::infinite)==0);
|
||||
unsigned const retval(win32::WaitForSingleObject(sem, ::boost::detail::win32::infinite));
|
||||
BOOST_VERIFY(0 == retval || ::boost::detail::win32::wait_abandoned == retval);
|
||||
// BOOST_VERIFY(win32::WaitForSingleObject(
|
||||
// sem,::boost::detail::win32::infinite)==0);
|
||||
clear_waiting_and_try_lock(old_count);
|
||||
lock_acquired=!(old_count&lock_flag_value);
|
||||
}
|
||||
@@ -93,10 +95,13 @@ namespace boost
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
long const new_count=(old_count&lock_flag_value)?(old_count+1):(old_count|lock_flag_value);
|
||||
bool const was_locked=(old_count&lock_flag_value) ? true : false;
|
||||
long const new_count=was_locked?(old_count+1):(old_count|lock_flag_value);
|
||||
long const current=BOOST_INTERLOCKED_COMPARE_EXCHANGE(&active_count,new_count,old_count);
|
||||
if(current==old_count)
|
||||
{
|
||||
if(was_locked)
|
||||
old_count=new_count;
|
||||
break;
|
||||
}
|
||||
old_count=current;
|
||||
|
||||
@@ -191,18 +191,17 @@ namespace boost
|
||||
struct entry_manager
|
||||
{
|
||||
entry_ptr const entry;
|
||||
boost::mutex& internal_mutex;
|
||||
|
||||
BOOST_THREAD_NO_COPYABLE(entry_manager)
|
||||
entry_manager(entry_ptr const& entry_):
|
||||
entry(entry_)
|
||||
entry_manager(entry_ptr const& entry_, boost::mutex& mutex_):
|
||||
entry(entry_), internal_mutex(mutex_)
|
||||
{}
|
||||
|
||||
~entry_manager()
|
||||
{
|
||||
//if(! entry->is_notified()) // several regression #7657
|
||||
{
|
||||
boost::lock_guard<boost::mutex> internal_lock(internal_mutex);
|
||||
entry->remove_waiter();
|
||||
}
|
||||
}
|
||||
|
||||
list_entry* operator->()
|
||||
@@ -218,7 +217,7 @@ namespace boost
|
||||
{
|
||||
relocker<lock_type> locker(lock);
|
||||
|
||||
entry_manager entry(get_wait_entry());
|
||||
entry_manager entry(get_wait_entry(), internal_mutex);
|
||||
|
||||
locker.unlock();
|
||||
|
||||
@@ -366,7 +365,11 @@ namespace boost
|
||||
const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
do_wait(lock, ceil<milliseconds>(t-Clock::now()).count());
|
||||
chrono::time_point<Clock, Duration> now = Clock::now();
|
||||
if (t<=now) {
|
||||
return cv_status::timeout;
|
||||
}
|
||||
do_wait(lock, ceil<milliseconds>(t-now).count());
|
||||
return Clock::now() < t ? cv_status::no_timeout :
|
||||
cv_status::timeout;
|
||||
}
|
||||
@@ -378,6 +381,10 @@ namespace boost
|
||||
const chrono::duration<Rep, Period>& d)
|
||||
{
|
||||
using namespace chrono;
|
||||
if (d<=chrono::duration<Rep, Period>::zero()) {
|
||||
return cv_status::timeout;
|
||||
}
|
||||
|
||||
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 :
|
||||
@@ -479,7 +486,11 @@ namespace boost
|
||||
const chrono::time_point<Clock, Duration>& t)
|
||||
{
|
||||
using namespace chrono;
|
||||
do_wait(lock, ceil<milliseconds>(t-Clock::now()).count());
|
||||
chrono::time_point<Clock, Duration> now = Clock::now();
|
||||
if (t<=now) {
|
||||
return cv_status::timeout;
|
||||
}
|
||||
do_wait(lock, ceil<milliseconds>(t-now).count());
|
||||
return Clock::now() < t ? cv_status::no_timeout :
|
||||
cv_status::timeout;
|
||||
}
|
||||
@@ -491,6 +502,9 @@ namespace boost
|
||||
const chrono::duration<Rep, Period>& d)
|
||||
{
|
||||
using namespace chrono;
|
||||
if (d<=chrono::duration<Rep, Period>::zero()) {
|
||||
return cv_status::timeout;
|
||||
}
|
||||
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 :
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user