LCOV - code coverage report
Current view: top level - lib/reduce - queue_internal.h (source / functions) Hit Total Coverage
Test: ut_cov_unit.info Lines: 15 21 71.4 %
Date: 2024-12-05 04:40:47 Functions: 5 6 83.3 %

          Line data    Source code
       1             : /*   SPDX-License-Identifier: BSD-3-Clause
       2             :  *   Copyright (C) 2018 Intel Corporation.
       3             :  *   All rights reserved.
       4             :  *   Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
       5             :  */
       6             : 
       7             : #ifndef __REDUCE_STACK_H_
       8             : #define __REDUCE_STACK_H_
       9             : 
      10             : #include "spdk/stdinc.h"
      11             : 
      12             : #define REDUCE_QUEUE_CAPACITY_SIZE 32
      13             : 
      14             : struct reduce_queue {
      15             :         uint64_t items[REDUCE_QUEUE_CAPACITY_SIZE];
      16             :         uint32_t head;
      17             :         uint32_t tail;
      18             : };
      19             : 
      20             : static inline void
      21          52 : queue_init(struct reduce_queue *queue)
      22             : {
      23          52 :         queue->head = queue->tail = 0;
      24          52 : }
      25             : 
      26             : static inline bool
      27          44 : queue_empty(struct reduce_queue *queue)
      28             : {
      29          44 :         return queue->head == queue->tail;
      30             : }
      31             : 
      32             : static inline bool
      33          20 : queue_full(struct reduce_queue *queue)
      34             : {
      35          20 :         return (queue->head == ((queue->tail + 1) % REDUCE_QUEUE_CAPACITY_SIZE));
      36             : }
      37             : 
      38             : static inline bool
      39          20 : queue_enqueue(struct reduce_queue *queue, uint64_t value)
      40             : {
      41          20 :         if (queue_full(queue)) {
      42           0 :                 return false;
      43             :         }
      44             : 
      45          20 :         queue->items[queue->tail] = value;
      46          20 :         queue->tail = (queue->tail + 1) % REDUCE_QUEUE_CAPACITY_SIZE;
      47          20 :         return true;
      48             : }
      49             : 
      50             : static inline bool
      51          44 : queue_dequeue(struct reduce_queue *queue, uint64_t *value)
      52             : {
      53          44 :         if (queue_empty(queue)) {
      54          44 :                 return false;
      55             :         }
      56             : 
      57           0 :         *value = queue->items[queue->head];
      58           0 :         queue->head = (queue->head + 1) % REDUCE_QUEUE_CAPACITY_SIZE;
      59           0 :         return true;
      60             : }
      61             : 
      62             : static inline uint32_t
      63           0 : queue_size(struct reduce_queue *queue)
      64             : {
      65           0 :         return (queue->tail + REDUCE_QUEUE_CAPACITY_SIZE - queue->head) % REDUCE_QUEUE_CAPACITY_SIZE;
      66             : }
      67             : 
      68             : #endif /* __REDUCE_STACK_H_ */

Generated by: LCOV version 1.15