C++ co-routines are coming soon...
Tom Joseph
rushtotom at gmail.com
Mon Nov 29 22:12:28 AEDT 2021
Thanks Patrick! Really excited to see C++20 features in action.
Regards,
Tom
On Mon, Nov 29, 2021 at 1:47 PM Andrei Kartashev <a.kartashev at yadro.com>
wrote:
> Thank you for your effort here!
> This three are really long waiting 'must have' things.
> I will try to test this proposal.
>
> On Sun, 2021-11-28 at 15:22 -0600, Patrick Williams wrote:
> > Hello,
> >
> > I just pushed up some code I've been working on for initial community
> > preview:
> > C++20 coroutine support in sdbusplus[1]. This code should be
> > considered
> > "experimental" for the time-being but a good preview of where I plan
> > to take the
> > sdbusplus bindings. I know there are complaints about the current
> > sdbusplus
> > support in one of three veins depending on your perspective of
> > importance:
> >
> > 1. The current sdbusplus server bindings in phosphor-dbus-
> > interfaces are
> > synchronous.
> > 2. There are no sdbusplus client bindings in phosphor-dbus-
> > interfaces.
> > 3. The code using the sdbusplus Boost/ASIO interfaces is very
> > callback
> > intensive (and difficult to read).
> >
> > I've been wanting to leverage C++20 coroutines for quite a while in
> > order to
> > address these shortcomings but haven't gotten around to it due to
> > lack of
> > understanding on my part (and lack of time to fix this) and lack of
> > maturity in
> > the library support. There is a proposal for C++23 (P2300)[2] which
> > attempts to
> > fix the "maturity" problem and the authors of that have been using
> > libunifex[3]
> > as their proving ground. Using libunifex and becoming enlightened by
> > Eric
> > Niebler's excellent talk at CppCon'21, I've finally been able to make
> > some good
> > progress on this.
> >
> > There will be more to come, but I wanted to give a taste of what a
> > C++20
> > co-routine-based sdbusplus agent might look like. This is an example
> > of a
> > task that reacts to D-Bus "NameOwnerChanged" signals:
> >
> > ```
> > auto watch_events(sdbusplus::async::context_t& ctx)
> > -> sdbusplus::execution::task<void>
> > {
> > using namespace sdbusplus::async::match;
> > auto m = match(ctx, rules::nameOwnerChanged());
> >
> > while (auto msg = co_await m.next())
> > {
> > std::string service, old_name, new_name;
> > msg.read(service, old_name, new_name);
> > if (!new_name.empty())
> > {
> > std::cout << new_name << " owns " << service <<
> > std::endl;
> > }
> > else
> > {
> > std::cout << service << " released" << std::endl;
> > }
> > };
> >
> > co_return;
> > }
> > ```
> >
> > I currently have `match` implemented and I plan to get `call` working
> > very soon.
> > Sometime between now and late January I'll probably do an educational
> > talk on
> > co-routines.
> >
> > 1. https://gerrit.openbmc-project.xyz/c/openbmc/sdbusplus/+/49117
> > 2. https://github.com/cplusplus/papers/issues/1054
> > 3. https://github.com/facebookexperimental/libunifex
> > 4. https://www.youtube.com/watch?v=xLboNIf7BTg
> >
>
> --
> Best regards,
> Andrei Kartashev
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20211129/0cecec0c/attachment.htm>
More information about the openbmc
mailing list