intel / cpp-baremetal-senders-and-receivers

An implementation of C++ "senders and receivers" async framework suitable for embedded platforms.
https://intel.github.io/cpp-baremetal-senders-and-receivers/
Boost Software License 1.0
180 stars 14 forks source link

possible to remove start_detached allocation #77

Open kirkshoop opened 4 months ago

kirkshoop commented 4 months ago

change the object returned by start_detached from optional<StopSource*> to an immovable object that has request_stop()

the immovable object constructor will connect and start the sender. request_stop will forward to the stop_src If needed, a copyable stop_ref type can store a pointer to the immovable object and forward calls to its request_stop to the immoveable object.

bdeane-intel commented 4 months ago

I don't think returning the operation state would help - I think this would just move the allocation responsibility to the caller. The operation state needs to live somewhere that outlives the entire call stack (an interrupt). That's the job of the static_allocator at the moment.

(Admittedly, It might be that returning an optional<StopSource*> is of limited use too - we might want instead to access the stop source through the same type tag used for the call to start_detached.)

kirkshoop commented 4 months ago

Delegating to the caller means that the result can stored in a global optional var. this guarantees the lifetime and removes the allocation.

kirkshoop commented 4 months ago

I built start_now() as a replacement for start_detached() This shows how the return value can be used to remove the allocation..

https://godbolt.org/z/Kx3a3Wq4s