LCOV - code coverage report
Current view: top level - common - adiag_list_def.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 20 20
Test Date: 2026-07-28 10:53:44 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #ifndef TRACE_LIST_DEF_H
      12              : #define TRACE_LIST_DEF_H
      13              : 
      14              : #include <stddef.h>
      15              : #include <stdbool.h>
      16              : 
      17              : #ifdef __cplusplus
      18              : extern "C" {
      19              : #endif
      20              : 
      21              : struct ListHead {
      22              :     struct ListHead *next;
      23              :     struct ListHead *prev;
      24              : };
      25              : 
      26              : #define INIT_LIST_HEAD(ptr) do { \
      27              :     (ptr)->next = (ptr); (ptr)->prev = (ptr); \
      28              : } while (0)
      29              : 
      30              : /**
      31              :  * @brief       Insert a new entry between two known consecutive entries.
      32              :  * @param [in]  item:    new entry to be added
      33              :  * @param [in]  prev:    previous entry to add it after
      34              :  * @param [in]  next:    next entry to add it before
      35              :  * @return      NA
      36              :  */
      37         4236 : static inline void ListAdd(struct ListHead *item, struct ListHead *prev, struct ListHead *next)
      38              : {
      39         4236 :     next->prev = item;
      40         4236 :     item->next = next;
      41         4236 :     item->prev = prev;
      42         4236 :     prev->next = item;
      43         4236 : }
      44              : 
      45              : /**
      46              :  * @brief       Insert a new entry after the specified head.
      47              :  * @param [in]  item:    new entry to be added
      48              :  * @param [in]  head:    list head to add it after
      49              :  * @return      NA
      50              :  */
      51              : static inline void ListAddAfterEntry(struct ListHead *item, struct ListHead *head)
      52              : {
      53              :     ListAdd(item, head, head->next);
      54              : }
      55              : 
      56              : /**
      57              :  * @brief       Insert a new entry before the specified head.
      58              :  * @param [in]  item:    new entry to be added
      59              :  * @param [in]  head:    list head to add it before
      60              :  * @return      NA
      61              :  */
      62         4236 : static inline void ListAddBeforeEntry(struct ListHead *item, struct ListHead *head)
      63              : {
      64         4236 :     ListAdd(item, head->prev, head);
      65         4236 : }
      66              : 
      67              : /*
      68              :  * @brief       Delete an existing entry between two known consecutive entries.
      69              :  * @param [in]  prev:    previous entry to delete it after
      70              :  * @param [in]  next:    next entry to delete it before
      71              :  * @return      NA
      72              :  */
      73         4218 : static inline void ListDel(struct ListHead *prev, struct ListHead *next)
      74              : {
      75         4218 :     next->prev = prev;
      76         4218 :     prev->next = next;
      77         4218 : }
      78              : 
      79              : /**
      80              :  * @brief       Delete an existing entry specified by entry.
      81              :  * @param [in]  entry:    entry to be deleted
      82              :  * @return      NA
      83              :  */
      84         4218 : static inline void ListDelEntry(struct ListHead *entry)
      85              : {
      86         4218 :     ListDel(entry->prev, entry->next);
      87         4218 :     entry->next = entry;
      88         4218 :     entry->prev = entry;
      89         4218 : }
      90              : 
      91              : /**
      92              :  * @brief       Check the head list empty or not specified by head.
      93              :  * @param [in]  head:    list head to be checked
      94              :  * @return      true or false
      95              :  */
      96        11038 : static inline bool ListEmpty(const struct ListHead *head)
      97              : {
      98        11038 :     return (const struct ListHead *)head->next == head;
      99              : }
     100              : 
     101              : #define LIST_ENTRY(ptr, type, member) \
     102              :     ((type *)((char *)(ptr) - offsetof(type, member)))
     103              : 
     104              : #define LIST_FIRST_ENTRY(ptr, type, member) \
     105              :     LIST_ENTRY((ptr)->next, type, member)
     106              : 
     107              : #define LIST_FOR_EACH(pos, head) \
     108              :     for ((pos) = (head)->next; ((pos) != NULL) && ((head) != (pos)); (pos) = (pos)->next)
     109              : 
     110              : #define LIST_FOR_EACH_ENTRY(pos, head, type, member) \
     111              :     for ((pos) = LIST_ENTRY((head)->next, type, member); \
     112              :         ((pos) != NULL) && (&(pos)->member != (head)); \
     113              :         (pos) = LIST_ENTRY((pos)->member.next, type, member))
     114              : 
     115              : #ifdef __cplusplus
     116              : }
     117              : #endif
     118              : 
     119              : #endif
        

Generated by: LCOV version 2.0-1