All of lore.kernel.org
 help / color / mirror / Atom feed
* C++ co-routines are coming soon...
@ 2021-11-28 21:22 Patrick Williams
  2021-11-29  8:16 ` Andrei Kartashev
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Williams @ 2021-11-28 21:22 UTC (permalink / raw)
  To: OpenBMC List

[-- Attachment #1: Type: text/plain, Size: 2514 bytes --]

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

-- 
Patrick Williams

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C++ co-routines are coming soon...
  2021-11-28 21:22 C++ co-routines are coming soon Patrick Williams
@ 2021-11-29  8:16 ` Andrei Kartashev
  2021-11-29 11:12   ` Tom Joseph
  0 siblings, 1 reply; 3+ messages in thread
From: Andrei Kartashev @ 2021-11-29  8:16 UTC (permalink / raw)
  To: Patrick Williams, OpenBMC List

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C++ co-routines are coming soon...
  2021-11-29  8:16 ` Andrei Kartashev
@ 2021-11-29 11:12   ` Tom Joseph
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Joseph @ 2021-11-29 11:12 UTC (permalink / raw)
  To: Andrei Kartashev; +Cc: OpenBMC List

[-- Attachment #1: Type: text/plain, Size: 3145 bytes --]

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@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
>
>
>

[-- Attachment #2: Type: text/html, Size: 4693 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-29 11:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-28 21:22 C++ co-routines are coming soon Patrick Williams
2021-11-29  8:16 ` Andrei Kartashev
2021-11-29 11:12   ` Tom Joseph

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.