lib_iqueue.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*!
  2. @file lib_iqueue.h
  3. @brief <brief description here>
  4. @t.odo -
  5. ---------------------------------------------------------------------------
  6. MIT License
  7. Copyright (c) 2018 Io. D (Devcoons)
  8. Permission is hereby granted, free of charge, to any person obtaining a copy
  9. of this software and associated documentation files (the "Software"), to deal
  10. in the Software without restriction, including without limitation the rights
  11. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. copies of the Software, and to permit persons to whom the Software is
  13. furnished to do so, subject to the following conditions:
  14. The above copyright notice and this permission notice shall be included in all
  15. copies or substantial portions of the Software.
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. SOFTWARE.
  23. */
  24. /******************************************************************************
  25. * Preprocessor Definitions & Macros
  26. ******************************************************************************/
  27. #ifndef LIBRARIES_INC_LIB_IQUEUE_H_
  28. #define LIBRARIES_INC_LIB_IQUEUE_H_
  29. /******************************************************************************
  30. * Includes
  31. ******************************************************************************/
  32. #include <inttypes.h>
  33. #include <string.h>
  34. /******************************************************************************
  35. * Enumerations, structures & Variables
  36. ******************************************************************************/
  37. #if !defined(ENUM_I_STATUS)
  38. #define ENUM_I_STATUS
  39. typedef enum
  40. {
  41. I_OK = 0x00,
  42. I_INVALID = 0x01,
  43. I_EXISTS = 0x02,
  44. I_NOTEXISTS = 0x03,
  45. I_FAILED = 0x04,
  46. I_EXPIRED = 0x05,
  47. I_UNKNOWN = 0x06,
  48. I_INPROGRESS = 0x07,
  49. I_IDLE = 0x08,
  50. I_FULL = 0x09,
  51. I_EMPTY = 0x0A,
  52. I_YES = 0x0B,
  53. I_NO = 0x0C,
  54. I_SKIP = 0x0D,
  55. I_DEBUG_01 = 0xE0,
  56. I_DEBUG_02 = 0xE1,
  57. I_DEBUG_03 = 0xE2,
  58. I_DEBUG_04 = 0xE3,
  59. I_DEBUG_05 = 0xE4,
  60. I_DEBUG_06 = 0xE5,
  61. I_DEBUG_07 = 0xE6,
  62. I_DEBUG_08 = 0xE7,
  63. I_DEBUG_09 = 0xE8,
  64. I_DEBUG_10 = 0xE9,
  65. I_DEBUG_11 = 0xEA,
  66. I_DEBUG_12 = 0xEB,
  67. I_DEBUG_13 = 0xEC,
  68. I_DEBUG_14 = 0xED,
  69. I_DEBUG_15 = 0xEE,
  70. I_DEBUG_16 = 0xEF,
  71. I_MEMUNALIGNED = 0xFD,
  72. I_NOTIMPLEMENTED = 0xFE,
  73. I_ERROR = 0xFF
  74. }i_status;
  75. #endif
  76. typedef struct
  77. {
  78. volatile void * storage;
  79. volatile uintptr_t first;
  80. volatile uintptr_t next;
  81. volatile size_t element_size;
  82. volatile uint32_t max_elements;
  83. }
  84. iqueue_t;
  85. /******************************************************************************
  86. * Declaration | Public Functions
  87. ******************************************************************************/
  88. i_status iqueue_init (iqueue_t * _queue, int _max_elements, size_t _element_size, void * _storage);
  89. i_status iqueue_enqueue(iqueue_t * _queue, void * _element);
  90. i_status iqueue_dequeue(iqueue_t * _queue, void * _element);
  91. i_status iqueue_size (iqueue_t * _queue, uint32_t * _size);
  92. i_status iqueue_advance_next(iqueue_t * _queue);
  93. volatile void* iqueue_get_next_enqueue(iqueue_t * _queue);
  94. void* iqueue_dequeue_fast(iqueue_t * _queue);
  95. /******************************************************************************
  96. * EOF - NO CODE AFTER THIS LINE
  97. ******************************************************************************/
  98. #endif