Commit 63ce7c6
Make unifex::async_scope::spawn return a unifex::future<> (#372)
* Make async_scope::spawn return a lazy<>
This diff changes `unifex::async_scope::spawn(Sender auto)` to return a
new type, `unifex::lazy<...>`. `lazy<>` is a _Sender_ that completes
with the result of the _Sender_ given to `spawn`.
* Fix memory leak
* Rationalize the names of some internal bits
* Fuse the promise and the operation state
This diff merges the spawned operation's promise with its operation
state so there's only one allocation.
One consequence of this change is that outstanding operations don't
record themselves as complete within their corresponding scope until the
associated `lazy<>` is either connected and started, or discarded.
* Fix build
Looks like our CI turns on exhaustive switch warnings, which I broke.
* Fix infinite hang in create_test.cpp
* Cleanup
* Last bit of cleanup before bed
* Try to fix ASAN failure
In the light of the morning, I think it's wrong to set the event before
requesting stop on the stop source because setting the event could lead
to destruction of the operation state, invalidating the stop source.
* Fix request_stop()
The callers of `request_stop()` are not owners so they may not call
`decref()`, which means I can't invoke `set_done()` from
`request_stop()`.
* Clean up, bug fixes, comments
Among other clean-up, this diff fixes a stack-use-after-return in
`future<>`'s `connect()`.
* Add constraints and run clang-format
* Comments, tests, bug fixes, and clang-format
* Restore nothrow assertion in detached_spawn_call_on
* Round out the async_scope tests
add async_scope::attach (#392)
* returned `Sender` needs to be connected and started
* avoids paying penalty of `future<>`
Fix `record_done` ordering in `async_scope::attach` (#424)
* `record_done`, which decrements outstanding operation count, must be called after `set_*`
* add regression test
fix cancellation race in async_scope::attach* (#425)
* use refcount to pass ownership of `deliver_result`
* replace `fused_stop_source` with `inplace_stop_source`
make `async_scope::attached_sender` copyable (#428)
* copy constructor calls `async_scope::try_record_start` internally
* copy of attached Sender will increment outstanding number of
operations on async_scope
`async_scope::attach` cleanup (#433)
* remove unused template argument
* add missing test case
update `async_scope` docs (#434)
* spawn() -> detached_spawn()
* spawn() returns a `future`
* add missing public methods
add `async_scope::attach` docs (#434)
fix `async_scope_test::attach_record_done` (#437)
fix `tag_invoke(CPO)` in `async_scope` (#462)
add `unifex::v2::async_scope` (#463)
* simpler than `unifex::v1::async_scope` (`nest()` and `join()`)
* does not support cancellation
Introduce unifex::nest() (#468)
`unifex::nest()` is a CPO that delegates to either a `tag_invoke`
customization taking a *Sender* and a "scope" reference, or to a
member function on the given scope that takes a *Sender*. This
diff wires `unifex::nest()` to the `nest()` member function on
`v2::async_scope` and to the `attach()` member function on
`v1::async_scope`.
Introduce spawn_detached(sender, scope, allocator) (#470)
This diff introduces a new algorithm, `unifex::spawn_detached()`.
`spawn_detached` takes a sender, an "async scope", and an optional
allocator. It nests the sender in the scope with `unifex::nest`,
allocates and operation state using the allocator, and starts that
operation. The given async scope may be anything that `nest()`
supports, which currently includes both `v1::async_scope` and
`v2::async_scope`.
Add an internal receiver to v2::async_scope's nest op (#484)
While writing `unifex::spawn_future()`, I discovered that waiting until
the destructor of the `v2::async_scope`'s `nest()` operation to drop the
scope reference is too late (it led to hangs). This diff adds an
internal receiver to the nest operation so we can detect when the
operation is complete (which is likely before the operation state is
destroyed) and drop the reference as soon as we reach that state.
Fix stop_when's handling of stop requests (#500)
* Fix stop_when's handling of stop requests
When trying to sync PR #495 into our internal repo, I discovered that
there's a lifetime issue in `stop_when()`. If the `stop_when()`
operation receives a stop request from its Receiver and the
last-to-finish child operation completes synchronously in response to
the stop request then `stop_when()`'s stop callback will access the
internal stop source after it's been destroyed.
This first diff just formats `test/stop_when_test.cpp` and
`include/unifex/stop_when.hpp` with `clang-format` in preparation for
fixing the above problem.
* Add a broken unit test
This diff adds a unit test to `test/stop_when_test.cpp` that crashes
when ASAN is enabled because it dereferences a destroyed
`inplace_stop_source`.
* Increment stop_when's refcount in its stop callback
This diff fixes the broken test from the previous diff by incrementing
the `stop_when` operation's refcount while processing a stop request
from the receiver.
Add spawn_future() (#489)
This diff adds `unifex::spawn_future(Sender, Scope)`.
Implement async_scope::spawn with spawn_future (#501)
This diff reimplements the `v1::async_scope::spawn()` method in terms of
the newly-added `unifex::spawn_future()` algorithm. I had to delete a
few tests that exercise behaviour that's no longer supported.
Work around an MSVC bug in C++20 mode (#492)
* merge unit test that depends on `v2/async_scope`
Co-authored-by: Ian Petersen <ispeters@gmail.com>1 parent 2b1f57b commit 63ce7c6
File tree
22 files changed
+5225
-476
lines changed- doc
- include/unifex
- v1
- v2
- test
22 files changed
+5225
-476
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
711 | 712 | | |
712 | 713 | | |
713 | 714 | | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
714 | 722 | | |
715 | 723 | | |
716 | 724 | | |
| |||
1201 | 1209 | | |
1202 | 1210 | | |
1203 | 1211 | | |
1204 | | - | |
1205 | | - | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
1206 | 1216 | | |
1207 | 1217 | | |
1208 | 1218 | | |
| |||
1212 | 1222 | | |
1213 | 1223 | | |
1214 | 1224 | | |
1215 | | - | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
1216 | 1254 | | |
1217 | 1255 | | |
1218 | 1256 | | |
1219 | 1257 | | |
1220 | 1258 | | |
1221 | 1259 | | |
1222 | 1260 | | |
1223 | | - | |
| 1261 | + | |
1224 | 1262 | | |
1225 | 1263 | | |
1226 | 1264 | | |
1227 | 1265 | | |
1228 | 1266 | | |
1229 | 1267 | | |
1230 | | - | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
1231 | 1280 | | |
1232 | | - | |
1233 | | - | |
| 1281 | + | |
| 1282 | + | |
1234 | 1283 | | |
1235 | 1284 | | |
1236 | | - | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
1237 | 1306 | | |
1238 | 1307 | | |
1239 | 1308 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| 179 | + | |
179 | 180 | | |
180 | 181 | | |
181 | 182 | | |
| |||
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
| 198 | + | |
| 199 | + | |
197 | 200 | | |
198 | 201 | | |
199 | 202 | | |
200 | 203 | | |
201 | 204 | | |
202 | 205 | | |
| 206 | + | |
203 | 207 | | |
204 | 208 | | |
205 | 209 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
0 commit comments