LCOV - code coverage report
Current view: top level - spdk/lib/reduce - queue_internal.h (source / functions) Hit Total Coverage
Test: Combined Lines: 19 19 100.0 %
Date: 2024-11-19 11:06:52 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 4 100.0 %

           Branch data     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                 :        920 : queue_init(struct reduce_queue *queue)
      22                 :            : {
      23                 :        920 :         queue->head = queue->tail = 0;
      24                 :        920 : }
      25                 :            : 
      26                 :            : static inline bool
      27                 :    1032888 : queue_empty(struct reduce_queue *queue)
      28                 :            : {
      29                 :    1032888 :         return queue->head == queue->tail;
      30                 :            : }
      31                 :            : 
      32                 :            : static inline bool
      33                 :     908922 : queue_full(struct reduce_queue *queue)
      34                 :            : {
      35                 :     908922 :         return (queue->head == ((queue->tail + 1) % REDUCE_QUEUE_CAPACITY_SIZE));
      36                 :            : }
      37                 :            : 
      38                 :            : static inline bool
      39                 :     908922 : queue_enqueue(struct reduce_queue *queue, uint64_t value)
      40                 :            : {
      41         [ +  + ]:     908922 :         if (queue_full(queue)) {
      42                 :        528 :                 return false;
      43                 :            :         }
      44                 :            : 
      45                 :     908394 :         queue->items[queue->tail] = value;
      46                 :     908394 :         queue->tail = (queue->tail + 1) % REDUCE_QUEUE_CAPACITY_SIZE;
      47                 :     908394 :         return true;
      48                 :            : }
      49                 :            : 
      50                 :            : static inline bool
      51                 :    1032888 : queue_dequeue(struct reduce_queue *queue, uint64_t *value)
      52                 :            : {
      53         [ +  + ]:    1032888 :         if (queue_empty(queue)) {
      54                 :     124962 :                 return false;
      55                 :            :         }
      56                 :            : 
      57                 :     907926 :         *value = queue->items[queue->head];
      58                 :     907926 :         queue->head = (queue->head + 1) % REDUCE_QUEUE_CAPACITY_SIZE;
      59                 :     907926 :         return true;
      60                 :            : }
      61                 :            : 
      62                 :            : static inline uint32_t
      63                 :            : queue_size(struct reduce_queue *queue)
      64                 :            : {
      65                 :            :         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