kernel: queue: runtime error handling

Runtime error handling for k_queue_append_list and k_queue_merge_slist.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2019-06-16 09:53:55 -04:00
commit 756d8b03e2
2 changed files with 28 additions and 9 deletions

View file

@ -2073,9 +2073,11 @@ extern void k_queue_insert(struct k_queue *queue, void *prev, void *data);
* @param head Pointer to first node in singly-linked list.
* @param tail Pointer to last node in singly-linked list.
*
* @return N/A
* @retval 0 on success
* @retval -EINVAL on invalid supplied data
*
*/
extern void k_queue_append_list(struct k_queue *queue, void *head, void *tail);
extern int k_queue_append_list(struct k_queue *queue, void *head, void *tail);
/**
* @brief Atomically add a list of elements to a queue.
@ -2089,9 +2091,10 @@ extern void k_queue_append_list(struct k_queue *queue, void *head, void *tail);
* @param queue Address of the queue.
* @param list Pointer to sys_slist_t object.
*
* @return N/A
* @retval 0 on success
* @retval -EINVAL on invalid data
*/
extern void k_queue_merge_slist(struct k_queue *queue, sys_slist_t *list);
extern int k_queue_merge_slist(struct k_queue *queue, sys_slist_t *list);
/**
* @brief Get an element from a queue.

View file

@ -22,6 +22,7 @@
#include <init.h>
#include <syscall_handler.h>
#include <kernel_internal.h>
#include <sys/check.h>
struct alloc_node {
sys_sfnode_t node;
@ -229,9 +230,12 @@ static inline s32_t z_vrfy_k_queue_alloc_prepend(struct k_queue *queue,
#include <syscalls/k_queue_alloc_prepend_mrsh.c>
#endif
void k_queue_append_list(struct k_queue *queue, void *head, void *tail)
int k_queue_append_list(struct k_queue *queue, void *head, void *tail)
{
__ASSERT(head && tail, "invalid head or tail");
/* invalid head or tail of list */
CHECKIF(head == NULL || tail == NULL) {
return -EINVAL;
}
k_spinlock_key_t key = k_spin_lock(&queue->lock);
#if !defined(CONFIG_POLL)
@ -257,11 +261,18 @@ void k_queue_append_list(struct k_queue *queue, void *head, void *tail)
#endif /* !CONFIG_POLL */
z_reschedule(&queue->lock, key);
return 0;
}
void k_queue_merge_slist(struct k_queue *queue, sys_slist_t *list)
int k_queue_merge_slist(struct k_queue *queue, sys_slist_t *list)
{
__ASSERT(!sys_slist_is_empty(list), "list must not be empty");
int ret;
/* list must not be empty */
CHECKIF(sys_slist_is_empty(list)) {
return -EINVAL;
}
/*
* note: this works as long as:
@ -272,8 +283,13 @@ void k_queue_merge_slist(struct k_queue *queue, sys_slist_t *list)
* flag bytes in the lower order bits of the data pointer
* - source list is really an slist and not an sflist with flags set
*/
k_queue_append_list(queue, list->head, list->tail);
ret = k_queue_append_list(queue, list->head, list->tail);
CHECKIF(ret != 0) {
return ret;
}
sys_slist_init(list);
return 0;
}
#if defined(CONFIG_POLL)