wolfevent.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* wolfevent.h
  2. *
  3. * Copyright (C) 2006-2022 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifndef _WOLF_EVENT_H_
  22. #define _WOLF_EVENT_H_
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. #ifndef SINGLE_THREADED
  27. #include <wolfssl/wolfcrypt/wc_port.h>
  28. #endif
  29. typedef struct WOLF_EVENT WOLF_EVENT;
  30. typedef unsigned short WOLF_EVENT_FLAG;
  31. typedef enum WOLF_EVENT_TYPE {
  32. WOLF_EVENT_TYPE_NONE,
  33. #ifdef WOLFSSL_ASYNC_CRYPT
  34. WOLF_EVENT_TYPE_ASYNC_WOLFSSL, /* context is WOLFSSL* */
  35. WOLF_EVENT_TYPE_ASYNC_WOLFCRYPT, /* context is WC_ASYNC_DEV */
  36. WOLF_EVENT_TYPE_ASYNC_FIRST = WOLF_EVENT_TYPE_ASYNC_WOLFSSL,
  37. WOLF_EVENT_TYPE_ASYNC_LAST = WOLF_EVENT_TYPE_ASYNC_WOLFCRYPT,
  38. #endif /* WOLFSSL_ASYNC_CRYPT */
  39. } WOLF_EVENT_TYPE;
  40. typedef enum WOLF_EVENT_STATE {
  41. WOLF_EVENT_STATE_READY,
  42. WOLF_EVENT_STATE_PENDING,
  43. WOLF_EVENT_STATE_DONE,
  44. } WOLF_EVENT_STATE;
  45. struct WOLF_EVENT {
  46. /* double linked list */
  47. WOLF_EVENT* next;
  48. WOLF_EVENT* prev;
  49. void* context;
  50. union {
  51. void* ptr;
  52. #ifdef WOLFSSL_ASYNC_CRYPT
  53. struct WC_ASYNC_DEV* async;
  54. #endif
  55. } dev;
  56. #ifdef HAVE_CAVIUM
  57. word64 reqId;
  58. #ifdef WOLFSSL_NITROX_DEBUG
  59. word32 pendCount;
  60. #endif
  61. #endif
  62. #ifndef WC_NO_ASYNC_THREADING
  63. pthread_t threadId;
  64. #endif
  65. int ret; /* Async return code */
  66. unsigned int flags;
  67. WOLF_EVENT_TYPE type;
  68. WOLF_EVENT_STATE state;
  69. };
  70. enum WOLF_POLL_FLAGS {
  71. WOLF_POLL_FLAG_CHECK_HW = 0x01,
  72. };
  73. typedef struct {
  74. WOLF_EVENT* head; /* head of queue */
  75. WOLF_EVENT* tail; /* tail of queue */
  76. #ifndef SINGLE_THREADED
  77. wolfSSL_Mutex lock; /* queue lock */
  78. #endif
  79. int count;
  80. } WOLF_EVENT_QUEUE;
  81. #ifdef HAVE_WOLF_EVENT
  82. /* Event */
  83. WOLFSSL_API int wolfEvent_Init(WOLF_EVENT* event, WOLF_EVENT_TYPE type, void* context);
  84. WOLFSSL_API int wolfEvent_Poll(WOLF_EVENT* event, WOLF_EVENT_FLAG flags);
  85. /* Event Queue */
  86. WOLFSSL_API int wolfEventQueue_Init(WOLF_EVENT_QUEUE* queue);
  87. WOLFSSL_API int wolfEventQueue_Push(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event);
  88. WOLFSSL_API int wolfEventQueue_Pop(WOLF_EVENT_QUEUE* queue, WOLF_EVENT** event);
  89. WOLFSSL_API int wolfEventQueue_Poll(WOLF_EVENT_QUEUE* queue, void* context_filter,
  90. WOLF_EVENT** events, int maxEvents, WOLF_EVENT_FLAG flags, int* eventCount);
  91. WOLFSSL_API int wolfEventQueue_Count(WOLF_EVENT_QUEUE* queue);
  92. WOLFSSL_API void wolfEventQueue_Free(WOLF_EVENT_QUEUE* queue);
  93. /* the queue mutex must be locked prior to calling these */
  94. WOLFSSL_API int wolfEventQueue_Add(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event);
  95. WOLFSSL_API int wolfEventQueue_Remove(WOLF_EVENT_QUEUE* queue, WOLF_EVENT* event);
  96. #endif /* HAVE_WOLF_EVENT */
  97. #ifdef __cplusplus
  98. } /* extern "C" */
  99. #endif
  100. #endif /* _WOLF_EVENT_H_ */