Files
TencentOS-tiny/kernel/core/include/tos_ring_queue.h
daishengdong d0b8d0675e add ring queue/message queue/mail queue, binary heap/priority queue/priority message queue/priority mail queue
1. remove the old msg queue and queue:
i. msg queue is not a common and reusable/flexible component(need user to config the msg pool size and this componet can only be used by tos_queue)
ii. tos_queue can only deliver the pointer message(cannot do a memory buffer deliver)

2. add ring queue(tos_ring_q) componet
rinq queue can be reused by tos_chr_fifi/tos_msg_q/tos_mail_q as the foundational data container

3. add message queue(tos_msg_q)
a little like the old queue mechanism, supply the capability to deliver a pointer message

4. add mail queue(tos_mail_q)
supply the capability to deliver a memory buffer

5. add binary heap(tos_bin_heap)
the basement componet to implement priority queue

6. add priority queue(tos_prio_q)
can be reused by the priority message/mail queue  as the foundational data container.

7. add priority message queue(tos_prio_msg_q)
a message(pointer) deliver mechanism, supply the capability of delivering the message with priority(message with higher priority comes faster to the pender than with lower)

8. add priority mail queue(tos_prio_mail_q)
a mail(memory buffer) deliver mechanism, supply the capability of delivering the mail with priority(mail with higher priority comes faster to the pender than with lower)
2019-10-28 15:50:46 +08:00

145 lines
4.6 KiB
C

/*----------------------------------------------------------------------------
* Tencent is pleased to support the open source community by making TencentOS
* available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* If you have downloaded a copy of the TencentOS binary from Tencent, please
* note that the TencentOS binary is licensed under the BSD 3-Clause License.
*
* If you have downloaded a copy of the TencentOS source code from Tencent,
* please note that TencentOS source code is licensed under the BSD 3-Clause
* License, except for the third-party components listed below which are
* subject to different license terms. Your integration of TencentOS into your
* own projects may require compliance with the BSD 3-Clause License, as well
* as the other licenses applicable to the third-party components included
* within TencentOS.
*---------------------------------------------------------------------------*/
#ifndef _TOS_RING_QUEUE_H_
#define _TOS_RING_QUEUE_H_
typedef struct k_ring_queue_st {
#if TOS_CFG_OBJECT_VERIFY_EN > 0u
knl_obj_t knl_obj;
#endif
uint16_t head;
uint16_t tail;
size_t total;
uint8_t *pool;
size_t item_size;
size_t item_cnt;
} k_ring_q_t;
#define RING_HEAD_ITEM(ring_q) (uint8_t *)(&ring_q->pool[ring_q->head * ring_q->item_size])
#define RING_TAIL_ITEM(ring_q) (uint8_t *)(&ring_q->pool[ring_q->tail * ring_q->item_size])
#define RING_NEXT(ring_q, index) ((index + 1) % ring_q->item_cnt)
/**
* @brief Create a ring queue.
* create a ring queue.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
* @param[in] pool pool buffer of the ring queue.
* @param[in] item_cnt item count of the ring queue.
* @param[in] item_size size of each item of the ring queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_ring_q_create(k_ring_q_t *ring_q, void *pool, size_t item_cnt, size_t item_size);
/**
* @brief Destroy a ring queue.
* destroy a ring queue.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_ring_q_destroy(k_ring_q_t *ring_q);
/**
* @brief Enqueue an item.
* enqueue an item into the ring queue.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
* @param[in] item the item to be enqueued.
* @param[in] item_size size of the item(should be consistent with the item_size passed to tos_ring_q_create).
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_RING_Q_ITEM_SIZE_NOT_MATCH the item_size is not consistent with the item_size passed to tos_ring_q_create.
* @retval #K_ERR_RING_Q_FULL the ring queue is full.
*/
__API__ k_err_t tos_ring_q_enqueue(k_ring_q_t *ring_q, void *item, size_t item_size);
/**
* @brief Dequeue an item.
* dequeue an item from the ring queue.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
* @param[out] item buffer to hold the item dequeued.
* @param[out] item_size size of the item dequeued(should be consistent with the item_size passed to tos_ring_q_create).
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
* @retval #K_ERR_RING_Q_EMPTY the ring queue is empty.
*/
__API__ k_err_t tos_ring_q_dequeue(k_ring_q_t *ring_q, void *item, size_t *item_size);
/**
* @brief Flush the ring queue.
* flush the ring queue.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
*
* @return errcode
* @retval #K_ERR_NONE return successfully.
*/
__API__ k_err_t tos_ring_q_flush(k_ring_q_t *ring_q);
/**
* @brief Whether the ring queue is empty.
* Whether the ring queue is empty.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
*
* @return whether the ring queue is emtpy.
* @retval #0 the ring queue is not empty.
* @retval #Not 0 the ring queue is empty.
*/
__API__ int tos_ring_q_is_empty(k_ring_q_t *ring_q);
/**
* @brief Whether the ring queue is full.
* Whether the ring queue is full.
*
* @attention None
*
* @param[in] ring_q pointer to the handler of the ring queue.
*
* @return whether the ring queue is full.
* @retval #0 the ring queue is not full.
* @retval #Not 0 the ring queue is full.
*/
__API__ int tos_ring_q_is_full(k_ring_q_t *ring_q);
#endif