Skip to content

Commit 2e063f5

Browse files
UserAllocatedEvent: set delay/period at event posting
Event delay/period can be modified by equeue so it has to be reset at every post.
1 parent a2e2fbb commit 2e063f5

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

events/UserAllocatedEvent.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class UserAllocatedEvent<F, void(ArgTs...)> {
8686
* @param f Function to execute when the event is dispatched
8787
* @param args Arguments to bind to the callback
8888
*/
89-
constexpr UserAllocatedEvent(F f, ArgTs... args) : _e(get_default_equeue_event()), _c(f, args...), _equeue(), _post_ref()
89+
constexpr UserAllocatedEvent(F f, ArgTs... args) : _e(get_default_equeue_event()), _c(f, args...), _delay(), _period(-1), _equeue(), _post_ref()
9090
{
9191
}
9292

@@ -100,7 +100,7 @@ class UserAllocatedEvent<F, void(ArgTs...)> {
100100
* @param f Function to execute when the event is dispatched
101101
* @param args Arguments to bind to the callback
102102
*/
103-
constexpr UserAllocatedEvent(EventQueue *queue, F f, ArgTs... args) : _e(get_default_equeue_event()), _c(f, args...), _equeue(&queue->_equeue), _post_ref()
103+
constexpr UserAllocatedEvent(EventQueue *queue, F f, ArgTs... args) : _e(get_default_equeue_event()), _c(f, args...), _delay(), _period(-1), _equeue(&queue->_equeue), _post_ref()
104104
{
105105
}
106106

@@ -215,7 +215,7 @@ class UserAllocatedEvent<F, void(ArgTs...)> {
215215
void delay(int delay)
216216
{
217217
MBED_ASSERT(!_post_ref);
218-
equeue_event_delay(&_e + 1, delay);
218+
_delay = delay;
219219
}
220220

221221
/** Configure the period of an event
@@ -225,7 +225,7 @@ class UserAllocatedEvent<F, void(ArgTs...)> {
225225
void period(int period)
226226
{
227227
MBED_ASSERT(!_post_ref);
228-
equeue_event_period(&_e + 1, period);
228+
_period = period;
229229
}
230230

231231
/** Cancels posted event
@@ -251,6 +251,8 @@ class UserAllocatedEvent<F, void(ArgTs...)> {
251251
friend class EventQueue;
252252
struct equeue_event _e;
253253
C _c;
254+
int _delay;
255+
int _period;
254256
struct equeue *_equeue;
255257
uint8_t _post_ref;
256258

@@ -260,17 +262,22 @@ class UserAllocatedEvent<F, void(ArgTs...)> {
260262
return false;
261263
}
262264
core_util_atomic_incr_u8(&_post_ref, 1);
265+
equeue_event_delay(&_e + 1, _delay);
266+
equeue_event_period(&_e + 1, _period);
263267
equeue_post_user_allocated(_equeue, &EventQueue::function_call<C>, &_e);
264268
return true;
265269
}
266270

267271
bool post_on(EventQueue *queue)
268272
{
273+
MBED_ASSERT(queue);
269274
if (_post_ref) {
270275
return false;
271276
}
272277
_equeue = &(queue->_equeue);
273278
core_util_atomic_incr_u8(&_post_ref, 1);
279+
equeue_event_delay(&_e + 1, _delay);
280+
equeue_event_period(&_e + 1, _period);
274281
equeue_post_user_allocated(_equeue, &EventQueue::function_call<C>, &_e);
275282
return true;
276283
}

0 commit comments

Comments
 (0)