Hi Tom,
I'm working on some alternatives, that I'm getting a better impression. I'll upload the example code this weekend, then we can discuss. One alternative are for instance stackless coroutines. I've also checked how you're using them in your code and have some ideas to modify that.
Thanks,
Torsten
@Edwin: Coroutines are not a replacement for threads. They *aren't*
there for improving performance, just to simplify event handling in
complex state machines. For example:
case 1) - without coroutines - we need to code a (possibly large) FSM
by hand. This doesn't scale well in terms of code complexity,
especially if there are nested state machines .
void handle_event(event)
{
switch(state)
{
case state1:
if (event == event1) {
do something();
state = state2;
}
case state2:
if (event == event2) {
do_something();
state = state3;
}
case state3:
/// and so on
}
}
case 2) - with coroutines - we can execute our FSM in sequential code
and receive events using a wait() function, which yields the current
coroutine (i.e. transfers the control to the master event loop in case
of pcbnew) and wakes up the execution of the tool that called wait()
when a matching event arrives:
void my_tool()
{
wait(event1);
do_something();
wait(event2);
do_something_else();
}
All of the stack switching "magic" is hidden. You can find an example in
include/tool/examples/coroutine_example.cpp
Concerning boost::context, I see two options:
- get rid of the coroutines (i.e. rewrite all event loops/calls in the
GAL tools). Painful but doable, I would prefer to spend my time doing
something more productive (e.g. porting the remaining tools to GAL).
- turn boost::context into a single .cpp file library that one can
just add to the project and forget about it (think of ClipperLib as an
example).
As a side comment, I'm not surprised that boost devs insist on using
MASM under Windows - the syntax of the GNU assembler on x86/x86_64
platforms is just disgusting.
Tom
_______________________________________________
Mailing list: https://launchpad.net/~kicad-developers
Post to : [email protected]
Unsubscribe : https://launchpad.net/~kicad-developers
More help : https://help.launchpad.net/ListHelp
there for improving performance, just to simplify event handling in
complex state machines. For example:
case 1) - without coroutines - we need to code a (possibly large) FSM
by hand. This doesn't scale well in terms of code complexity,
especially if there are nested state machines .
void handle_event(event)
{
switch(state)
{
case state1:
if (event == event1) {
do something();
state = state2;
}
case state2:
if (event == event2) {
do_something();
state = state3;
}
case state3:
/// and so on
}
}
case 2) - with coroutines - we can execute our FSM in sequential code
and receive events using a wait() function, which yields the current
coroutine (i.e. transfers the control to the master event loop in case
of pcbnew) and wakes up the execution of the tool that called wait()
when a matching event arrives:
void my_tool()
{
wait(event1);
do_something();
wait(event2);
do_something_else();
}
All of the stack switching "magic" is hidden. You can find an example in
include/tool/examples/coroutine_example.cpp
Concerning boost::context, I see two options:
- get rid of the coroutines (i.e. rewrite all event loops/calls in the
GAL tools). Painful but doable, I would prefer to spend my time doing
something more productive (e.g. porting the remaining tools to GAL).
- turn boost::context into a single .cpp file library that one can
just add to the project and forget about it (think of ClipperLib as an
example).
As a side comment, I'm not surprised that boost devs insist on using
MASM under Windows - the syntax of the GNU assembler on x86/x86_64
platforms is just disgusting.
Tom
_______________________________________________
Mailing list: https://launchpad.net/~kicad-developers
Post to : [email protected]
Unsubscribe : https://launchpad.net/~kicad-developers
More help : https://help.launchpad.net/ListHelp
_______________________________________________ Mailing list: https://launchpad.net/~kicad-developers Post to : [email protected] Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp

