1 /* 2 * Copyright (c) 2016-2017 Nordic Semiconductor ASA 3 * Copyright (c) 2016 Vinayak Kariappa Chettimada 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 /** 9 * @brief Element of a memory-queue 10 * @details Elements form a linked list, and as payload carries a pointer 11 */ 12 struct _memq_link { 13 struct _memq_link *next; /* permit chaining */ 14 void *mem; /* payload */ 15 }; 16 17 typedef struct _memq_link memq_link_t; 18 19 #define MEMQ_DECLARE(name) \ 20 struct { \ 21 memq_link_t *head; \ 22 memq_link_t *tail; \ 23 } memq_##name 24 25 memq_link_t *memq_init(memq_link_t *link, memq_link_t **head, 26 memq_link_t **tail); 27 28 #define MEMQ_INIT(name, link) \ 29 memq_init(link, &memq_##name.head, &memq_##name.tail) 30 31 memq_link_t *memq_deinit(memq_link_t **head, memq_link_t **tail); 32 memq_link_t *memq_enqueue(memq_link_t *link, void *mem, memq_link_t **tail); 33 memq_link_t *memq_peek(memq_link_t *head, memq_link_t *tail, void **mem); 34 memq_link_t *memq_dequeue(memq_link_t *tail, memq_link_t **head, void **mem); 35