diff --git a/include/kernel.h b/include/kernel.h index 040c7c00251..d2003d06095 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -1815,6 +1815,9 @@ __syscall void k_queue_init(struct k_queue *queue); * * This routine causes first thread pending on @a queue, if any, to * return from k_queue_get() call with NULL value (as if timeout expired). + * If the queue is being waited on by k_poll(), it will return with + * -EINTR and K_POLL_STATE_CANCELLED state (and per above, subsequent + * k_queue_get() will return NULL). * * @note Can be called by ISRs. * @@ -4242,6 +4245,9 @@ enum _poll_states_bits { /* data is available to read on queue/fifo/lifo */ _POLL_STATE_DATA_AVAILABLE, + /* queue/fifo/lifo wait was cancelled */ + _POLL_STATE_CANCELLED, + _POLL_NUM_STATES }; @@ -4287,6 +4293,7 @@ enum k_poll_modes { #define K_POLL_STATE_SEM_AVAILABLE _POLL_STATE_BIT(_POLL_STATE_SEM_AVAILABLE) #define K_POLL_STATE_DATA_AVAILABLE _POLL_STATE_BIT(_POLL_STATE_DATA_AVAILABLE) #define K_POLL_STATE_FIFO_DATA_AVAILABLE K_POLL_STATE_DATA_AVAILABLE +#define K_POLL_STATE_CANCELLED _POLL_STATE_BIT(_POLL_STATE_CANCELLED) /* public - poll signal object */ struct k_poll_signal { @@ -4418,7 +4425,11 @@ extern void k_poll_event_init(struct k_poll_event *event, u32_t type, * * @retval 0 One or more events are ready. * @retval -EAGAIN Waiting period timed out. - * @retval -EINTR Poller thread has been interrupted. + * @retval -EINTR Polling has been interrupted, e.g. with + * k_queue_cancel_wait(). All output events are still set and valid, + * cancelled event(s) will be set to K_POLL_STATE_CANCELLED. In other + * words, -EINTR status means that at least one of output events is + * K_POLL_STATE_CANCELLED. * @retval -ENOMEM Thread resource pool insufficient memory (user mode only) * @retval -EINVAL Bad parameters (user mode only) * @req K-POLL-001 diff --git a/kernel/poll.c b/kernel/poll.c index 7ba173edccb..916cea36605 100644 --- a/kernel/poll.c +++ b/kernel/poll.c @@ -337,7 +337,7 @@ static int signal_poll_event(struct k_poll_event *event, u32_t state) _unpend_thread(thread); _set_thread_return_value(thread, - state == K_POLL_STATE_NOT_READY ? -EINTR : 0); + state == K_POLL_STATE_CANCELLED ? -EINTR : 0); if (!_is_thread_ready(thread)) { goto ready_event; diff --git a/kernel/queue.c b/kernel/queue.c index 292b23c2c8a..f9f7931df82 100644 --- a/kernel/queue.c +++ b/kernel/queue.c @@ -131,7 +131,7 @@ void _impl_k_queue_cancel_wait(struct k_queue *queue) prepare_thread_to_run(first_pending_thread, NULL); } #else - handle_poll_events(queue, K_POLL_STATE_NOT_READY); + handle_poll_events(queue, K_POLL_STATE_CANCELLED); #endif /* !CONFIG_POLL */ _reschedule(key);