@@ -119,7 +119,7 @@ private:
119119 // Wait for one of the futures in _incomplete to complete, and then
120120 // decide what to do: wait for another one, or deliver _result if all
121121 // are complete.
122- void wait_for_one () noexcept {
122+ void wait_for_one () {
123123 // Process from back to front, on the assumption that the front
124124 // futures are likely to complete earlier than the back futures.
125125 // If that's indeed the case, then the front futures will be
@@ -135,7 +135,7 @@ private:
135135
136136 // If there's an incompelete future, wait for it.
137137 if (!_incomplete.empty ()) {
138- internal::set_callback (_incomplete.back (), static_cast <continuation_base<>* >(this ));
138+ internal::set_callback (_incomplete.back (), std::unique_ptr <continuation_base<>>(this ));
139139 // This future's state will be collected in run_and_dispose(), so we can drop it.
140140 _incomplete.pop_back ();
141141 return ;
@@ -280,14 +280,13 @@ public:
280280 }
281281 future<> get_future () { return _promise.get_future (); }
282282 virtual void run_and_dispose () noexcept override {
283+ std::unique_ptr<repeater> zis{this };
283284 if (_state.failed ()) {
284285 _promise.set_exception (std::move (_state).get_exception ());
285- delete this ;
286286 return ;
287287 } else {
288288 if (std::get<0 >(_state.get ()) == stop_iteration::yes) {
289289 _promise.set_value ();
290- delete this ;
291290 return ;
292291 }
293292 _state = {};
@@ -296,22 +295,20 @@ public:
296295 do {
297296 auto f = futurator::apply (_action);
298297 if (!f.available ()) {
299- internal::set_callback (f, this );
298+ internal::set_callback (f, std::move (zis) );
300299 return ;
301300 }
302301 if (f.get0 () == stop_iteration::yes) {
303302 _promise.set_value ();
304- delete this ;
305303 return ;
306304 }
307305 } while (!need_preempt ());
308306 } catch (...) {
309307 _promise.set_exception (std::current_exception ());
310- delete this ;
311308 return ;
312309 }
313310 _state.set (stop_iteration::no);
314- schedule (this );
311+ schedule (std::move (zis) );
315312 }
316313};
317314
@@ -331,7 +328,7 @@ public:
331328template <typename AsyncAction>
332329GCC6_CONCEPT ( requires seastar::ApplyReturns<AsyncAction, stop_iteration> || seastar::ApplyReturns<AsyncAction, future<stop_iteration>> )
333330inline
334- future<> repeat (AsyncAction action) noexcept {
331+ future<> repeat (AsyncAction action) {
335332 using futurator = futurize<std::result_of_t <AsyncAction ()>>;
336333 static_assert (std::is_same<future<stop_iteration>, typename futurator::type>::value, " bad AsyncAction signature" );
337334 try {
@@ -342,9 +339,9 @@ future<> repeat(AsyncAction action) noexcept {
342339 if (!f.available ()) {
343340 return [&] () noexcept {
344341 memory::disable_failure_guard dfg;
345- auto repeater = new internal::repeater<AsyncAction>(std::move (action));
342+ auto repeater = std::make_unique< internal::repeater<AsyncAction> >(std::move (action));
346343 auto ret = repeater->get_future ();
347- internal::set_callback (f, repeater);
344+ internal::set_callback (f, std::move ( repeater) );
348345 return ret;
349346 }();
350347 }
@@ -354,9 +351,9 @@ future<> repeat(AsyncAction action) noexcept {
354351 }
355352 } while (!need_preempt ());
356353
357- auto repeater = new internal::repeater<AsyncAction>(stop_iteration::no, std::move (action));
354+ auto repeater = std::make_unique< internal::repeater<AsyncAction> >(stop_iteration::no, std::move (action));
358355 auto ret = repeater->get_future ();
359- schedule (repeater);
356+ schedule (std::move ( repeater) );
360357 return ret;
361358 } catch (...) {
362359 return make_exception_future (std::current_exception ());
@@ -400,15 +397,14 @@ public:
400397 }
401398 future<T> get_future () { return _promise.get_future (); }
402399 virtual void run_and_dispose () noexcept override {
400+ std::unique_ptr<repeat_until_value_state> zis{this };
403401 if (this ->_state .failed ()) {
404402 _promise.set_exception (std::move (this ->_state ).get_exception ());
405- delete this ;
406403 return ;
407404 } else {
408405 auto v = std::get<0 >(std::move (this ->_state ).get ());
409406 if (v) {
410407 _promise.set_value (std::move (*v));
411- delete this ;
412408 return ;
413409 }
414410 this ->_state = {};
@@ -417,23 +413,21 @@ public:
417413 do {
418414 auto f = futurator::apply (_action);
419415 if (!f.available ()) {
420- internal::set_callback (f, this );
416+ internal::set_callback (f, std::move (zis) );
421417 return ;
422418 }
423419 auto ret = f.get0 ();
424420 if (ret) {
425421 _promise.set_value (std::make_tuple (std::move (*ret)));
426- delete this ;
427422 return ;
428423 }
429424 } while (!need_preempt ());
430425 } catch (...) {
431426 _promise.set_exception (std::current_exception ());
432- delete this ;
433427 return ;
434428 }
435429 this ->_state .set (compat::nullopt );
436- schedule (this );
430+ schedule (std::move (zis) );
437431 }
438432};
439433
@@ -456,7 +450,7 @@ GCC6_CONCEPT( requires requires (AsyncAction aa) {
456450 futurize<std::result_of_t <AsyncAction ()>>::apply (aa).get0 ().value ();
457451} )
458452repeat_until_value_return_type<AsyncAction>
459- repeat_until_value (AsyncAction action) noexcept {
453+ repeat_until_value (AsyncAction action) {
460454 using futurator = futurize<std::result_of_t <AsyncAction ()>>;
461455 using type_helper = repeat_until_value_type_helper<typename futurator::type>;
462456 // the "T" in the documentation
@@ -468,9 +462,9 @@ repeat_until_value(AsyncAction action) noexcept {
468462 if (!f.available ()) {
469463 return [&] () noexcept {
470464 memory::disable_failure_guard dfg;
471- auto state = new internal::repeat_until_value_state<AsyncAction, value_type>(std::move (action));
465+ auto state = std::make_unique< internal::repeat_until_value_state<AsyncAction, value_type> >(std::move (action));
472466 auto ret = state->get_future ();
473- internal::set_callback (f, state);
467+ internal::set_callback (f, std::move ( state) );
474468 return ret;
475469 }();
476470 }
@@ -486,9 +480,9 @@ repeat_until_value(AsyncAction action) noexcept {
486480 } while (!need_preempt ());
487481
488482 try {
489- auto state = new internal::repeat_until_value_state<AsyncAction, value_type>(compat::nullopt , std::move (action));
483+ auto state = std::make_unique< internal::repeat_until_value_state<AsyncAction, value_type> >(compat::nullopt , std::move (action));
490484 auto f = state->get_future ();
491- schedule (state);
485+ schedule (std::move ( state) );
492486 return f;
493487 } catch (...) {
494488 return make_exception_future<value_type>(std::current_exception ());
@@ -506,10 +500,10 @@ public:
506500 explicit do_until_state (StopCondition stop, AsyncAction action) : _stop(std::move(stop)), _action(std::move(action)) {}
507501 future<> get_future () { return _promise.get_future (); }
508502 virtual void run_and_dispose () noexcept override {
503+ std::unique_ptr<do_until_state> zis{this };
509504 if (_state.available ()) {
510505 if (_state.failed ()) {
511506 _promise.set_urgent_state (std::move (_state));
512- delete this ;
513507 return ;
514508 }
515509 _state = {}; // allow next cycle to overrun state
@@ -518,26 +512,23 @@ public:
518512 do {
519513 if (_stop ()) {
520514 _promise.set_value ();
521- delete this ;
522515 return ;
523516 }
524517 auto f = _action ();
525518 if (!f.available ()) {
526- internal::set_callback (f, this );
519+ internal::set_callback (f, std::move (zis) );
527520 return ;
528521 }
529522 if (f.failed ()) {
530523 f.forward_to (std::move (_promise));
531- delete this ;
532524 return ;
533525 }
534526 } while (!need_preempt ());
535527 } catch (...) {
536528 _promise.set_exception (std::current_exception ());
537- delete this ;
538529 return ;
539530 }
540- schedule (this );
531+ schedule (std::move (zis) );
541532 }
542533};
543534
@@ -556,7 +547,7 @@ public:
556547template <typename AsyncAction, typename StopCondition>
557548GCC6_CONCEPT ( requires seastar::ApplyReturns<StopCondition, bool > && seastar::ApplyReturns<AsyncAction, future<>> )
558549inline
559- future<> do_until (StopCondition stop_cond, AsyncAction action) noexcept {
550+ future<> do_until (StopCondition stop_cond, AsyncAction action) {
560551 using namespace internal ;
561552 using futurator = futurize<void >;
562553 do {
@@ -567,9 +558,9 @@ future<> do_until(StopCondition stop_cond, AsyncAction action) noexcept {
567558 if (!f.available ()) {
568559 return [&] () noexcept {
569560 memory::disable_failure_guard dfg;
570- auto task = new do_until_state<StopCondition, AsyncAction>(std::move (stop_cond), std::move (action));
561+ auto task = std::make_unique< do_until_state<StopCondition, AsyncAction> >(std::move (stop_cond), std::move (action));
571562 auto ret = task->get_future ();
572- internal::set_callback (f, task);
563+ internal::set_callback (f, std::move ( task) );
573564 return ret;
574565 }();
575566 }
@@ -578,9 +569,9 @@ future<> do_until(StopCondition stop_cond, AsyncAction action) noexcept {
578569 }
579570 } while (!need_preempt ());
580571
581- auto task = new do_until_state<StopCondition, AsyncAction>(std::move (stop_cond), std::move (action));
572+ auto task = std::make_unique< do_until_state<StopCondition, AsyncAction> >(std::move (stop_cond), std::move (action));
582573 auto f = task->get_future ();
583- schedule (task);
574+ schedule (std::move ( task) );
584575 return f;
585576}
586577
@@ -746,7 +737,7 @@ public:
746737 return true ;
747738 } else {
748739 auto c = new (continuation) when_all_state_component (wasb, f);
749- set_callback (*f, c );
740+ set_callback (*f, std::unique_ptr<when_all_state_component>(c) );
750741 return false ;
751742 }
752743 }
0 commit comments