RE: [PATCH 5/6] gdb/continuations: use lambdas instead of function pointers

Aktemur, Tankut Baris via Gdb-patches
2021-04-22T14:08:15Z

On Thursday, April 22, 2021 2:50 PM, Tom Tromey wrote:
> >>>>> ">" == Aktemur, Tankut Baris <tankut.baris.aktemur@intel.com> writes:
>
> >> The continuations at the moment are rather plain, but just in case a
> >> continuation in the future adds more continuations, delaying the pop
> >> could cause a wrong element to be popped, I'm afraid. How about the
> >> following? (The same is to be used in Patch 6/6, too).
>
> >> @@ -122,7 +39,12 @@ void
> >> do_all_inferior_continuations ()
> >> {
> >> struct inferior *inf = current_inferior ();
> >> - do_my_continuations (&inf->continuations);
> >> + while (!inf->continuations.empty ())
> >> + {
> >> + auto iter = inf->continuations.begin ();
> >> + (*iter) ();
> >> + inf->continuations.erase (iter);
>
> It took me a minute to see what was going on here, at first I misread it
> a bit. But yeah, I see, I think this is fine.
>
> If elements are only ever added/popped from the front, maybe
> std::forward_list is preferable.

If you don't mind it much, I'd like keep std::list. With std::forward_list,
we would additionally have to use erase_after and before_begin, which make
the code uglier, in my opinion.

Thanks
-Baris

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928