qdf_periodic_work.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (c) 2019 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /**
  19. * DOC: qdf_periodic_work.h
  20. * A simple, periodic work type for repeatedly executing a callback with a
  21. * certain frequency.
  22. */
  23. #ifndef __QDF_PERIODIC_WORK_H
  24. #define __QDF_PERIODIC_WORK_H
  25. #include "i_qdf_periodic_work.h"
  26. #include "qdf_status.h"
  27. #include "qdf_types.h"
  28. typedef void (*qdf_periodic_work_cb)(void *context);
  29. /**
  30. * struct qdf_periodic_work - a defered work type which executes a callback
  31. * periodically until stopped
  32. * @dwork: OS-specific delayed work
  33. * @callback: the callback to be executed periodically
  34. * @context: the context to pass to the callback
  35. * @msec: the delay between executions in milliseconds
  36. */
  37. struct qdf_periodic_work {
  38. struct __qdf_opaque_delayed_work dwork;
  39. qdf_periodic_work_cb callback;
  40. void *context;
  41. uint32_t msec;
  42. };
  43. /**
  44. * qdf_periodic_work_create() - initialized a periodic work @pwork
  45. * @pwork: the periodic work to initialize
  46. * @callback: the callback to be executed periodically
  47. * @context: the context to pass to the callback
  48. *
  49. * Return: QDF_STATUS
  50. */
  51. #define qdf_periodic_work_create(pwork, callback, context) \
  52. __qdf_periodic_work_create(pwork, callback, context, __func__, __LINE__)
  53. qdf_must_check QDF_STATUS
  54. __qdf_periodic_work_create(struct qdf_periodic_work *pwork,
  55. qdf_periodic_work_cb callback, void *context,
  56. const char *func, uint32_t line);
  57. /**
  58. * qdf_periodic_work_destroy() - deinitialize a periodic work @pwork
  59. * @pwork: the periodic work to de-initialize
  60. *
  61. * Return: None
  62. */
  63. #define qdf_periodic_work_destroy(pwork) \
  64. __qdf_periodic_work_destroy(pwork, __func__, __LINE__)
  65. void __qdf_periodic_work_destroy(struct qdf_periodic_work *pwork,
  66. const char *func, uint32_t line);
  67. /**
  68. * qdf_periodic_work_start() - begin periodic execution of @pwork callback
  69. * @pwork: the periodic work to start
  70. * @msec: the delay between executions in milliseconds
  71. *
  72. * Return: true if started successfully
  73. */
  74. bool qdf_periodic_work_start(struct qdf_periodic_work *pwork, uint32_t msec);
  75. /**
  76. * qdf_periodic_work_stop_async() - Asynchronously stop execution of @pwork
  77. * @pwork: the periodic work to stop
  78. *
  79. * When this returns, @pwork is guaranteed to not be queued, *but* its callback
  80. * may still be executing.
  81. *
  82. * This is safe to call from the @pwork callback.
  83. *
  84. * Return: true if @pwork was previously started
  85. */
  86. bool qdf_periodic_work_stop_async(struct qdf_periodic_work *pwork);
  87. /**
  88. * qdf_periodic_work_stop_sync() - Synchronously stop execution of @pwork
  89. * @pwork: the periodic work to stop
  90. *
  91. * When this returns, @pwork is guaranteed to not be queued, and its callback
  92. * not executing.
  93. *
  94. * This will deadlock if called from the @pwork callback.
  95. *
  96. * Return: true if @pwork was previously started
  97. */
  98. bool qdf_periodic_work_stop_sync(struct qdf_periodic_work *pwork);
  99. #ifdef WLAN_PERIODIC_WORK_DEBUG
  100. /**
  101. * qdf_periodic_work_check_for_leaks() - assert no periodic work leaks
  102. *
  103. * Return: None
  104. */
  105. void qdf_periodic_work_check_for_leaks(void);
  106. /**
  107. * qdf_periodic_work_feature_init() - global init logic for periodic work
  108. *
  109. * Return: None
  110. */
  111. void qdf_periodic_work_feature_init(void);
  112. /**
  113. * qdf_periodic_work_feature_deinit() - global de-init logic for periodic work
  114. *
  115. * Return: None
  116. */
  117. void qdf_periodic_work_feature_deinit(void);
  118. #else
  119. static inline void qdf_periodic_work_check_for_leaks(void) { }
  120. static inline void qdf_periodic_work_feature_init(void) { }
  121. static inline void qdf_periodic_work_feature_deinit(void) { }
  122. #endif /* WLAN_PERIODIC_WORK_DEBUG */
  123. #endif /* __QDF_PERIODIC_WORK_H */