Skip to content

Commit 68612cb

Browse files
committed
Update EventQueue API to use chrono times
Main dispatch function is updated to take a Chrono duration instead of an integer milliseconds parameter. To allow for the instances of blocking and non wait versions, which previously were actioned by passing either -1 or 0 as the millisecond delay respectively, two other functions are now available. dispatch_once() - new dispatch_forever() - modified from the original version
1 parent 33a7e66 commit 68612cb

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

events/include/events/EventQueue.h

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,30 +89,28 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
8989
/** Dispatch events
9090
*
9191
* Executes events until the specified milliseconds have passed.
92-
* If ms is negative, the dispatch function will dispatch events
93-
* indefinitely or until break_dispatch is called on this queue.
9492
*
95-
* When called with a finite timeout, the dispatch function is guaranteed
96-
* to terminate. When called with a timeout of 0, the dispatch function
97-
* does not wait and is IRQ safe.
93+
* The dispatch function is guaranteed to terminate after the elapsed wait
9894
*
99-
* @param ms Time to wait for events in milliseconds, a negative
100-
* value will dispatch events indefinitely
101-
* (default to -1)
95+
* @param wait Time to wait for events in milliseconds, expressed as a
96+
* Chrono duration.
10297
*/
103-
void dispatch(int ms = -1);
98+
void dispatch(duration wait);
10499

105100
/** Dispatch events without a timeout
106-
*
107-
* This is equivalent to EventQueue::dispatch with no arguments, but
108-
* avoids overload ambiguities when passed as a callback.
109-
*
110-
* @see EventQueue::dispatch
101+
*
102+
* Executes events indefinitely unless the dispatch loop is forcibly broken.
103+
* See break_dispatch()
104+
*
111105
*/
112-
void dispatch_forever()
113-
{
114-
dispatch();
115-
}
106+
void dispatch_forever();
107+
108+
/** Dispatch currently queued events only and then terminate
109+
*
110+
* In this case, the dispatch function does not wait and is IRQ safe.
111+
*
112+
*/
113+
void dispatch_once();
116114

117115
/** Break out of a running event loop
118116
*

events/source/EventQueue.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,19 @@ EventQueue::~EventQueue()
4141
equeue_destroy(&_equeue);
4242
}
4343

44-
void EventQueue::dispatch(int ms)
44+
void EventQueue::dispatch(duration wait)
4545
{
46-
return equeue_dispatch(&_equeue, ms);
46+
return equeue_dispatch(&_equeue, wait.count());
47+
}
48+
49+
void EventQueue::dispatch_forever()
50+
{
51+
return equeue_dispatch(&_equeue, -1);
52+
}
53+
54+
void EventQueue::dispatch_once()
55+
{
56+
return equeue_dispatch(&_equeue, 0);
4757
}
4858

4959
void EventQueue::break_dispatch()

0 commit comments

Comments
 (0)