@@ -51,12 +51,24 @@ struct basic_queue_impl {
51
51
[&]{ containers::emplace_back (m_container, OPERATORS_FORWARD (args)...); }
52
52
);
53
53
}
54
+ auto stoppable_emplace (std::stop_token token, auto && ... args) -> bool {
55
+ return generic_add (
56
+ std::move (token),
57
+ [&]{ containers::emplace_back (m_container, OPERATORS_FORWARD (args)...); }
58
+ );
59
+ }
54
60
auto push (value_type && value) -> void {
55
61
emplace (std::move (value));
56
62
}
57
63
auto push (value_type const & value) -> void {
58
64
emplace (value);
59
65
}
66
+ auto push (std::stop_token token, value_type && value) -> bool {
67
+ return stoppable_emplace (std::move (token), std::move (value));
68
+ }
69
+ auto push (std::stop_token token, value_type const & value) -> bool {
70
+ return stoppable_emplace (std::move (token), value);
71
+ }
60
72
61
73
auto non_blocking_emplace (auto && ... args) -> bool {
62
74
return generic_non_blocking_add (
@@ -249,6 +261,14 @@ struct basic_queue_impl {
249
261
derived ().handle_add (m_container, lock);
250
262
generic_add_impl (std::move (lock), add);
251
263
}
264
+ auto generic_add (std::stop_token token, auto const add) -> bool {
265
+ auto lock = lock_type (m_mutex);
266
+ auto const should_add = derived ().handle_add (m_container, std::move (token), lock);
267
+ if (should_add) {
268
+ generic_add_impl (std::move (lock), add);
269
+ }
270
+ return should_add;
271
+ }
252
272
253
273
auto generic_non_blocking_add (auto const add) -> bool {
254
274
auto lock = lock_type (m_mutex, std::try_to_lock);
@@ -366,6 +386,9 @@ struct basic_unbounded_queue : private basic_queue_impl<Container, Mutex, basic_
366
386
367
387
auto handle_add (Container &, std::unique_lock<Mutex> &) -> void {
368
388
}
389
+ auto handle_add (Container &, std::stop_token const &, std::unique_lock<Mutex> &) -> bool {
390
+ return true ;
391
+ }
369
392
auto handle_non_blocking_add (Container &, std::unique_lock<Mutex> &) -> bool {
370
393
return true ;
371
394
}
@@ -403,6 +426,7 @@ struct basic_blocking_queue : private basic_queue_impl<Container, Mutex, basic_b
403
426
using base::append;
404
427
using base::non_blocking_append;
405
428
using base::emplace;
429
+ using base::stoppable_emplace;
406
430
using base::non_blocking_emplace;
407
431
using base::push;
408
432
using base::non_blocking_push;
@@ -426,8 +450,8 @@ struct basic_blocking_queue : private basic_queue_impl<Container, Mutex, basic_b
426
450
[&]{ return containers::size (queue) < m_max_size; }
427
451
);
428
452
}
429
- auto handle_add (Container & queue, std::stop_token token, std::unique_lock<Mutex> & lock) -> void {
430
- m_notify_removal.wait (
453
+ auto handle_add (Container & queue, std::stop_token token, std::unique_lock<Mutex> & lock) -> bool {
454
+ return m_notify_removal.wait (
431
455
lock,
432
456
std::move (token),
433
457
[&]{ return containers::size (queue) < m_max_size; }
0 commit comments