Repository navigation
Abstract Coroutine interface - #36
mikael-s-persson wants to merge 11 commits into
Conversation
|
Would it be better to rename Unless that breaks you separation of concerns issue you are addressing. I am concerned about breaking existing code. |
|
Yeah, that might make more sense now. Originally, I tried to make Coroutine abstract so that all the code in toolbelt that takes A potential "redux" version of this PR could simply be to make the original Coroutine class inherit from Poller and split the toolbelt/coroutine dependency that way. Splitting the Coroutine class into two parts (in this PR: Coroutine and ScheduledCoroutine) is mostly nice in principle (and cleaner) but it's a hard breaking change with little practical effect. |
|
That sounds better. I will be slow to respond for a week unfortunately. Personal situation to deal with. |
|
Any progress on this Mik? |
|
Sorry for the delay. I've been busy and made changes on my side that made this change less critical. I updated the PR to the "redux" version. There should be no breaking changes on users now. The main changes are:
To merge, we probably first need to merge the PR on toolbelt, then update this PR with the correct git url and commit, and then after that is merged, update the same on toolbelt (which only depends on co for its test suite now). |
… compiler warning in c++20
|
I'll do proper ARM support. The issue with longjmp is that asan doesn't like the stack changing. It thinks there is a bug when longjmp is used for switching between coroutines. I guess it's kind of an abuse of setjmp/longjmp. I'll write an assembly language context switcher for it. |
Good to know. I guess the trampoline still makes sense in the meantime. |
|
I have added the ARM context switcher, along with some others. This conflicted with your change. Do you mind resolving it? |
|
Resolved the conflicts. I'm a bit skeptical of the arm assembly, are you sure this works in mixed mode between arm and thumb? |
|
Why are you skeptical about it? Do you see any failures? It was tested on colima on my mac. I asked an agent and it says: |
|
Just making sure. What caught my eye was the longjmp bit (that I had originally added): My version went through r12 and bx specifically in case of mixed mode, and my AI told me that was needed. I guess it's only need if |
|
I asked my agent (GPT 5.6 Sol) and this makes me sound smart: Good question. I checked the generated relocations. In Thumb mode, b longjmp produces R_ARM_THM_JUMP24; in ARM mode it produces R_ARM_JUMP24. These relocations allow the linker to insert an ARM/Thumb interworking veneer or route through the appropriate PLT stub when the target is in the opposite mode. Your r12/bx sequence explicitly performs the mode switch using bit 0 of the resolved address, so it is also valid. It would be necessary for an indirect address unknown to the linker, or with a linker that does not support normal EABI interworking. It is not generally necessary merely because longjmp was compiled in a different mode. Also, the current ARM configuration uses the custom context switcher, so this relay is not exercised in normal ARM builds. SInce we now support ARM context switches we won't use the longjmp. |
|
Sounds good. Who am I to question super intelligence. |
This PR (along with dallison/cpp_toolbelt#27) is about decoupling the coroutine interface that functions/lambdas that run in a coroutine need from the actual scheduler implementation. This is mostly separating concerns and to some extent helps hide implementation details and flags that don't affect the code that runs in a coroutine context, only how the coroutines are scheduled and switched.
This could be controversial change because it breaks users since the concrete coroutine class that you construct and tie to a scheduler is now called
ScheduledCoroutine, whileCoroutineis just an abstract class now.