UserAllocatedEvent: set delay/period at event posting

Event delay/period can be modified by equeue so it has to be reset at every post.
pull/12319/head
Maciej Bocianski 2020-01-24 13:14:31 +01:00
parent b4fac71325
commit bc89974462
1 changed files with 11 additions and 4 deletions

View File

@ -86,7 +86,7 @@ public:
* @param f Function to execute when the event is dispatched
* @param args Arguments to bind to the callback
*/
constexpr UserAllocatedEvent(F f, ArgTs... args) : _e(get_default_equeue_event()), _c(f, args...), _equeue(), _post_ref()
constexpr UserAllocatedEvent(F f, ArgTs... args) : _e(get_default_equeue_event()), _c(f, args...), _delay(), _period(-1), _equeue(), _post_ref()
{
}
@ -100,7 +100,7 @@ public:
* @param f Function to execute when the event is dispatched
* @param args Arguments to bind to the callback
*/
constexpr UserAllocatedEvent(EventQueue *queue, F f, ArgTs... args) : _e(get_default_equeue_event()), _c(f, args...), _equeue(&queue->_equeue), _post_ref()
constexpr UserAllocatedEvent(EventQueue *queue, F f, ArgTs... args) : _e(get_default_equeue_event()), _c(f, args...), _delay(), _period(-1), _equeue(&queue->_equeue), _post_ref()
{
}
@ -215,7 +215,7 @@ public:
void delay(int delay)
{
MBED_ASSERT(!_post_ref);
equeue_event_delay(&_e + 1, delay);
_delay = delay;
}
/** Configure the period of an event
@ -225,7 +225,7 @@ public:
void period(int period)
{
MBED_ASSERT(!_post_ref);
equeue_event_period(&_e + 1, period);
_period = period;
}
/** Cancels posted event
@ -251,6 +251,8 @@ private:
friend class EventQueue;
struct equeue_event _e;
C _c;
int _delay;
int _period;
struct equeue *_equeue;
uint8_t _post_ref;
@ -260,17 +262,22 @@ private:
return false;
}
core_util_atomic_incr_u8(&_post_ref, 1);
equeue_event_delay(&_e + 1, _delay);
equeue_event_period(&_e + 1, _period);
equeue_post_user_allocated(_equeue, &EventQueue::function_call<C>, &_e);
return true;
}
bool post_on(EventQueue *queue)
{
MBED_ASSERT(queue);
if (_post_ref) {
return false;
}
_equeue = &(queue->_equeue);
core_util_atomic_incr_u8(&_post_ref, 1);
equeue_event_delay(&_e + 1, _delay);
equeue_event_period(&_e + 1, _period);
equeue_post_user_allocated(_equeue, &EventQueue::function_call<C>, &_e);
return true;
}