LCOV - code coverage report
Current view: top level - lib/stack - rte_stack_std.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 14 14 100.0 %
Date: 2026-11-01 19:11:22 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 21 56 37.5 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2019 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef _RTE_STACK_STD_H_
       6                 :            : #define _RTE_STACK_STD_H_
       7                 :            : 
       8                 :            : #include <rte_branch_prediction.h>
       9                 :            : 
      10                 :            : /**
      11                 :            :  * @internal Push several objects on the stack (MT-safe).
      12                 :            :  *
      13                 :            :  * @param s
      14                 :            :  *   A pointer to the stack structure.
      15                 :            :  * @param obj_table
      16                 :            :  *   A pointer to a table of void * pointers (objects).
      17                 :            :  * @param n
      18                 :            :  *   The number of objects to push on the stack from the obj_table.
      19                 :            :  * @return
      20                 :            :  *   Actual number of objects pushed (either 0 or *n*).
      21                 :            :  */
      22                 :            : static __rte_always_inline unsigned int
      23                 :            : __rte_stack_std_push(struct rte_stack *s, void * const *obj_table,
      24                 :            :                      unsigned int n)
      25                 :            : {
      26                 :            :         struct rte_stack_std *stack = &s->stack_std;
      27                 :            :         unsigned int index;
      28                 :            :         void **stack_objs;
      29                 :            : 
      30                 :     166721 :         rte_spinlock_lock(&stack->lock);
      31                 :     166725 :         stack_objs = &stack->objs[stack->len];
      32                 :            : 
      33   [ -  +  -  +  :     166725 :         if (unlikely((stack->len + n) > s->capacity)) {
          +  -  -  -  -  
             -  -  -  -  
                      + ]
      34                 :            :                 /* Insufficient space in the stack. */
      35                 :            :                 rte_spinlock_unlock(&stack->lock);
      36                 :            :                 return 0;
      37                 :            :         }
      38                 :            : 
      39                 :            :         /* Push objects to the stack */
      40   [ +  +  +  +  :   25922559 :         for (index = 0; index < n; ++index, obj_table++)
          -  -  -  -  -  
             -  -  -  +  
                      + ]
      41                 :   25755835 :                 stack_objs[index] = *obj_table;
      42                 :            : 
      43                 :     166724 :         stack->len += n;
      44                 :            : 
      45                 :            :         rte_spinlock_unlock(&stack->lock);
      46                 :            :         return n;
      47                 :            : }
      48                 :            : 
      49                 :            : /**
      50                 :            :  * @internal Pop several objects from the stack (MT-safe).
      51                 :            :  *
      52                 :            :  * @param s
      53                 :            :  *   A pointer to the stack structure.
      54                 :            :  * @param obj_table
      55                 :            :  *   A pointer to a table of void * pointers (objects).
      56                 :            :  * @param n
      57                 :            :  *   The number of objects to pull from the stack.
      58                 :            :  * @return
      59                 :            :  *   Actual number of objects popped (either 0 or *n*).
      60                 :            :  */
      61                 :            : static __rte_always_inline unsigned int
      62                 :            : __rte_stack_std_pop(struct rte_stack *s, void **obj_table, unsigned int n)
      63                 :            : {
      64                 :            :         struct rte_stack_std *stack = &s->stack_std;
      65                 :            :         unsigned int index, len;
      66                 :            :         void **stack_objs;
      67                 :            : 
      68                 :     166787 :         rte_spinlock_lock(&stack->lock);
      69                 :            : 
      70   [ +  +  -  +  :     166787 :         if (unlikely(n > stack->len)) {
          +  -  -  -  -  
             -  -  -  -  
                      + ]
      71                 :            :                 /* Insufficient objects in the stack. */
      72                 :            :                 rte_spinlock_unlock(&stack->lock);
      73                 :            :                 return 0;
      74                 :            :         }
      75                 :            : 
      76                 :     166755 :         stack_objs = stack->objs;
      77                 :            : 
      78                 :            :         /* Pop objects from the stack */
      79   [ +  +  +  +  :   25922590 :         for (index = 0, len = stack->len - 1; index < n;
          -  -  -  -  -  
             -  -  -  +  
                      + ]
      80                 :   25755835 :                         ++index, len--, obj_table++)
      81                 :   25755835 :                 *obj_table = stack_objs[len];
      82                 :            : 
      83                 :     166755 :         stack->len -= n;
      84                 :            :         rte_spinlock_unlock(&stack->lock);
      85                 :            : 
      86                 :            :         return n;
      87                 :            : }
      88                 :            : 
      89                 :            : /**
      90                 :            :  * @internal Return the number of used entries in a stack.
      91                 :            :  *
      92                 :            :  * @param s
      93                 :            :  *   A pointer to the stack structure.
      94                 :            :  * @return
      95                 :            :  *   The number of used entries in the stack.
      96                 :            :  */
      97                 :            : static __rte_always_inline unsigned int
      98                 :            : __rte_stack_std_count(struct rte_stack *s)
      99                 :            : {
     100                 :     262666 :         return (unsigned int)s->stack_std.len;
     101                 :            : }
     102                 :            : 
     103                 :            : /**
     104                 :            :  * @internal Initialize a standard stack.
     105                 :            :  *
     106                 :            :  * @param s
     107                 :            :  *   A pointer to the stack structure.
     108                 :            :  */
     109                 :            : void
     110                 :            : rte_stack_std_init(struct rte_stack *s);
     111                 :            : 
     112                 :            : /**
     113                 :            :  * @internal Return the memory required for a standard stack.
     114                 :            :  *
     115                 :            :  * @param count
     116                 :            :  *   The size of the stack.
     117                 :            :  * @return
     118                 :            :  *   The bytes to allocate for a standard stack.
     119                 :            :  */
     120                 :            : ssize_t
     121                 :            : rte_stack_std_get_memsize(unsigned int count);
     122                 :            : 
     123                 :            : #endif /* _RTE_STACK_STD_H_ */

Generated by: LCOV version 1.14