-
Notifications
You must be signed in to change notification settings - Fork 6
Conversation
What is |
* Already pending events may finish executing, but the queue will not | ||
* continue to loop indefinitely. | ||
*/ | ||
void break_(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rename this member function and clarify what is going on when invoked ?
@pan-, you're right the Is there an alternative name you think we should use instead? |
"cancel", like pthreads? (Okay, it's not a thread per se, but the effect is the same - "sends a cancellation request"). |
I don't think "break" is a good name, as AFACT it doesn't do what libevent's loopbreak or C break does - it doesn't stop as soon as possible. It's closer to libevent's loopexit(0) - exit after processing all active events. (Not that that's any better as a C analogue). So I'd suggest any of "cancel", "exit" or "loopexit". |
@kjbracey-arm, you make a good point, although even with the slightly different semantics, I'm not a fan of I'm leaning towards @pan-'s |
I'm okay with stop (or loopstop). But seeing libevent has chosen a meaning for (loop)break I'm loathe to use it for something else libevent already has a different name for. The loop would be a bit odd though in that you're using "dispatch" instead of "loop" as your base executor, unlike libevent. How about "stop_dispatch" or "dispatch_stop" or something along those lines? |
Instead I should have refered to That being said, you're right that it is odd having only a single loop* function. It sounds like we should just go with |
The EventLoop was an interesting concept: the combination of an EventQueue and a Thread. The idea was that the EventLoop would provide a convenient coupling of these two concepts for use in module boundaries, and the EventLoop could abstract out some of the complexities with running an event queue in a thread. However, with the addition of the chain function, event queues can be easily composed without threads or indirect references to event queues. Threads can still be spawned dynamically in default-constructors, although the overhead is much more explicit and tangible. Additionally, it turned out there weren't that many complexities with running an event queue in a thread. There were, surprisingly, several problems with just passing the EventQueue::dispatch function to mbed's Thread constructor. - Split EventQueue::dispatch into overloaded functions - Remove problematic template overloads in Thread constructor - Exposed break_dispatch - Renamed get_tick to tick to match the underlying C api - Renamed DEFAULT_QUEUE_SIZE to EVENTS_QUEUE_SIZE to avoid name possible name collisions
Actually, thoughts on |
Yeah, break_dispatch is good. |
The EventLoop was an interesting concept: the combination of an EventQueue and a Thread. The idea was that the EventLoop would provide a convenient coupling of these two concepts for use in module
boundaries, and the EventLoop could abstract out some of the complexities with running an event queue in a thread.
However, with the addition of the chain function, event queues can be easily composed without threads or indirect references to event queues. Threads can still be spawned dynamically in default-constructors, although the overhead is much more explicit and tangible.
Additionally, it turned out there weren't that many complexities with running an event queue in a thread.
There were, surprisingly, several problems with just passing the EventQueue::dispatch function to mbed's Thread constructor.
Split EventQueue::dispatch into overloaded functions
Apparently, default parameters don't create another target for infering member-function-pointers.
Remove problematic template overloads in Thread constructor
Issue is actually here Remove problematic templated overloads on callback-based functions mbed-os#2395.
The indirection in the nested callback templates prevented correct overload resolution and let to template-expansion errors.
Exposed break_dispatch
Allows threaded event queues to shutdown cleanly.
Renamed get_tick to tick
To match the C api
Renamed DEFAULT_QUEUE_SIZE to EVENTS_QUEUE_SIZE
To avoid possible name collisions
With these changes, this code:
Becomes:
Except now with 182 less lines to maintain