bidirect_list.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /****************************************************************************
  2. *
  3. * The MIT License (MIT)
  4. *
  5. * Copyright (c) 2014 - 2021 VERISILICON
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. *****************************************************************************
  26. *
  27. * The GPL License (GPL)
  28. *
  29. * Copyright (C) 2014 - 2021 VERISILICON
  30. *
  31. * This program is free software; you can redistribute it and/or
  32. * modify it under the terms of the GNU General Public License
  33. * as published by the Free Software Foundation; either version 2
  34. * of the License, or (at your option) any later version.
  35. *
  36. * This program is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. * GNU General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU General Public License
  42. * along with this program; if not, write to the Free Software Foundation,
  43. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  44. *
  45. *****************************************************************************
  46. *
  47. * Note: This software is released under dual MIT and GPL licenses. A
  48. * recipient may use this file under the terms of either the MIT license or
  49. * GPL License. If you wish to use only one license not the other, you can
  50. * indicate your decision by deleting one of the above license notices in your
  51. * version of this file.
  52. *
  53. *****************************************************************************/
  54. #ifndef _BIDIRECT_LIST_H_
  55. #define _BIDIRECT_LIST_H_
  56. #ifdef __FREERTOS__
  57. #include "dev_common_freertos.h" /* needed for the _IOW etc stuff used later */
  58. #elif defined(__linux__)
  59. #include <linux/ioctl.h> /* needed for the _IOW etc stuff used later */
  60. #else //For other os
  61. //TODO...
  62. #endif
  63. /*
  64. * Macros to help debugging
  65. */
  66. #undef PDEBUG /* undef it, just in case */
  67. #ifdef BIDIRECTION_LIST_DEBUG
  68. # ifdef __KERNEL__
  69. /* This one if debugging is on, and kernel space */
  70. # define PDEBUG(fmt, args...) printk( KERN_INFO "hmp4e: " fmt, ## args)
  71. # else
  72. /* This one for user space */
  73. # define PDEBUG(fmt, args...) printf(__FILE__ ":%d: " fmt, __LINE__ , ## args)
  74. # endif
  75. #else
  76. # define PDEBUG(fmt, args...) /* not debugging: nothing */
  77. #endif
  78. /***********************************************************************************************************************************************\
  79. * <Typedefs>
  80. \**********************************************************************************************************************************************/
  81. typedef struct bi_list_node{
  82. void* data;
  83. struct bi_list_node* next;
  84. struct bi_list_node* previous;
  85. }bi_list_node;
  86. typedef struct bi_list{
  87. bi_list_node* head;
  88. bi_list_node* tail;
  89. }bi_list;
  90. void init_bi_list(bi_list* list);
  91. bi_list_node* bi_list_create_node(void);
  92. void bi_list_free_node(bi_list_node* node);
  93. void bi_list_insert_node_tail(bi_list* list,bi_list_node* current_node);
  94. void bi_list_insert_node_before(bi_list* list,bi_list_node* base_node,bi_list_node* new_node);
  95. void bi_list_remove_node(bi_list* list,bi_list_node* current_node);
  96. #endif /* !_BIDIRECT_LIST_H_ */