qdf_delayed_work.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. /**
  20. * DOC: qdf_delayed_work.h
  21. * A simple, delayed work type for executing a callback after some delay.
  22. */
  23. #ifndef __QDF_DELAYED_WORK_H
  24. #define __QDF_DELAYED_WORK_H
  25. #include "i_qdf_delayed_work.h"
  26. #include "qdf_status.h"
  27. #include "qdf_types.h"
  28. typedef void (*qdf_delayed_work_cb)(void *context);
  29. /**
  30. * struct qdf_delayed_work - a deferred work type which executes a callback after
  31. * some delay
  32. * @dwork: OS-specific delayed work
  33. * @callback: the callback to be executed
  34. * @context: the context to pass to the callback
  35. */
  36. struct qdf_delayed_work {
  37. struct __qdf_opaque_delayed_work dwork;
  38. qdf_delayed_work_cb callback;
  39. void *context;
  40. };
  41. /**
  42. * qdf_delayed_work_create() - initialized a delayed work @dwork
  43. * @dwork: the delayed work to initialize
  44. * @callback: the callback to be executed
  45. * @context: the context to pass to the callback
  46. *
  47. * Return: QDF_STATUS
  48. */
  49. #define qdf_delayed_work_create(dwork, callback, context) \
  50. __qdf_delayed_work_create(dwork, callback, context, __func__, __LINE__)
  51. qdf_must_check QDF_STATUS
  52. __qdf_delayed_work_create(struct qdf_delayed_work *dwork,
  53. qdf_delayed_work_cb callback, void *context,
  54. const char *func, uint32_t line);
  55. /**
  56. * qdf_delayed_work_destroy() - deinitialize a delayed work @dwork
  57. * @dwork: the delayed work to de-initialize
  58. *
  59. * Return: None
  60. */
  61. #define qdf_delayed_work_destroy(dwork) \
  62. __qdf_delayed_work_destroy(dwork, __func__, __LINE__)
  63. void __qdf_delayed_work_destroy(struct qdf_delayed_work *dwork,
  64. const char *func, uint32_t line);
  65. /**
  66. * qdf_delayed_work_start() - schedule execution of @dwork callback
  67. * @dwork: the delayed work to start
  68. * @msec: the delay before execution in milliseconds
  69. *
  70. * Return: true if started successfully
  71. */
  72. #define qdf_delayed_work_start(dwork, msec) \
  73. __qdf_delayed_work_start(dwork, msec)
  74. bool __qdf_delayed_work_start(struct qdf_delayed_work *dwork, uint32_t msec);
  75. /**
  76. * qdf_delayed_work_stop_sync() - Synchronously stop execution of @dwork
  77. * @dwork: the delayed work to stop
  78. *
  79. * When this returns, @dwork is guaranteed to not be queued, and its callback
  80. * not executing.
  81. *
  82. * Return: true if @dwork was queued or running
  83. */
  84. #define qdf_delayed_work_stop_sync(dwork) \
  85. __qdf_delayed_work_stop_sync(dwork)
  86. bool __qdf_delayed_work_stop_sync(struct qdf_delayed_work *dwork);
  87. /**
  88. * qdf_delayed_work_stop() - Stop execution of @dwork
  89. * @dwork: the delayed work to stop
  90. *
  91. * Kill off a pending delayed_work
  92. *
  93. * Return: true if dwork was pending and canceled
  94. */
  95. #define qdf_delayed_work_stop(dwork) \
  96. __qdf_delayed_work_stop(dwork)
  97. bool __qdf_delayed_work_stop(struct qdf_delayed_work *dwork);
  98. #ifdef WLAN_DELAYED_WORK_DEBUG
  99. /**
  100. * qdf_delayed_work_check_for_leaks() - assert no delayed work leaks
  101. *
  102. * Return: None
  103. */
  104. void qdf_delayed_work_check_for_leaks(void);
  105. /**
  106. * qdf_delayed_work_feature_init() - global init logic for delayed work
  107. *
  108. * Return: None
  109. */
  110. void qdf_delayed_work_feature_init(void);
  111. /**
  112. * qdf_delayed_work_feature_deinit() - global de-init logic for delayed work
  113. *
  114. * Return: None
  115. */
  116. void qdf_delayed_work_feature_deinit(void);
  117. #else
  118. static inline void qdf_delayed_work_check_for_leaks(void) { }
  119. static inline void qdf_delayed_work_feature_init(void) { }
  120. static inline void qdf_delayed_work_feature_deinit(void) { }
  121. #endif /* WLAN_DELAYED_WORK_DEBUG */
  122. #endif /* __QDF_DELAYED_WORK_H */