qdf_delayed_work.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c) 2019-2020 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_delayed_work.h
  20. * A simple, delayed work type for executing a callback after some delay.
  21. */
  22. #ifndef __QDF_DELAYED_WORK_H
  23. #define __QDF_DELAYED_WORK_H
  24. #include "i_qdf_delayed_work.h"
  25. #include "qdf_status.h"
  26. #include "qdf_types.h"
  27. typedef void (*qdf_delayed_work_cb)(void *context);
  28. /**
  29. * struct qdf_delayed_work - a defered work type which executes a callback after
  30. * some delay
  31. * @dwork: OS-specific delayed work
  32. * @callback: the callback to be executed
  33. * @context: the context to pass to the callback
  34. */
  35. struct qdf_delayed_work {
  36. struct __qdf_opaque_delayed_work dwork;
  37. qdf_delayed_work_cb callback;
  38. void *context;
  39. };
  40. /**
  41. * qdf_delayed_work_create() - initialized a delayed work @dwork
  42. * @dwork: the delayed work to initialize
  43. * @callback: the callback to be executed
  44. * @context: the context to pass to the callback
  45. *
  46. * Return: QDF_STATUS
  47. */
  48. #define qdf_delayed_work_create(dwork, callback, context) \
  49. __qdf_delayed_work_create(dwork, callback, context, __func__, __LINE__)
  50. qdf_must_check QDF_STATUS
  51. __qdf_delayed_work_create(struct qdf_delayed_work *dwork,
  52. qdf_delayed_work_cb callback, void *context,
  53. const char *func, uint32_t line);
  54. /**
  55. * qdf_delayed_work_destroy() - deinitialize a delayed work @dwork
  56. * @dwork: the delayed work to de-initialize
  57. *
  58. * Return: None
  59. */
  60. #define qdf_delayed_work_destroy(dwork) \
  61. __qdf_delayed_work_destroy(dwork, __func__, __LINE__)
  62. void __qdf_delayed_work_destroy(struct qdf_delayed_work *dwork,
  63. const char *func, uint32_t line);
  64. /**
  65. * qdf_delayed_work_start() - schedule execution of @dwork callback
  66. * @dwork: the delayed work to start
  67. * @msec: the delay before execution in milliseconds
  68. *
  69. * Return: true if started successfully
  70. */
  71. #define qdf_delayed_work_start(dwork, msec) \
  72. __qdf_delayed_work_start(dwork, msec)
  73. bool __qdf_delayed_work_start(struct qdf_delayed_work *dwork, uint32_t msec);
  74. /**
  75. * qdf_delayed_work_stop_sync() - Synchronously stop execution of @dwork
  76. * @dwork: the delayed work to stop
  77. *
  78. * When this returns, @dwork is guaranteed to not be queued, and its callback
  79. * not executing.
  80. *
  81. * Return: true if @dwork was queued or running
  82. */
  83. #define qdf_delayed_work_stop_sync(dwork) \
  84. __qdf_delayed_work_stop_sync(dwork)
  85. bool __qdf_delayed_work_stop_sync(struct qdf_delayed_work *dwork);
  86. /**
  87. * qdf_delayed_work_stop() - Stop execution of @dwork
  88. * @dwork: the delayed work to stop
  89. *
  90. * Kill off a pending delayed_work
  91. *
  92. * Return: true if dwork was pending and canceled
  93. */
  94. #define qdf_delayed_work_stop(dwork) \
  95. __qdf_delayed_work_stop(dwork)
  96. bool __qdf_delayed_work_stop(struct qdf_delayed_work *dwork);
  97. #ifdef WLAN_DELAYED_WORK_DEBUG
  98. /**
  99. * qdf_delayed_work_check_for_leaks() - assert no delayed work leaks
  100. *
  101. * Return: None
  102. */
  103. void qdf_delayed_work_check_for_leaks(void);
  104. /**
  105. * qdf_delayed_work_feature_init() - global init logic for delayed work
  106. *
  107. * Return: None
  108. */
  109. void qdf_delayed_work_feature_init(void);
  110. /**
  111. * qdf_delayed_work_feature_deinit() - global de-init logic for delayed work
  112. *
  113. * Return: None
  114. */
  115. void qdf_delayed_work_feature_deinit(void);
  116. #else
  117. static inline void qdf_delayed_work_check_for_leaks(void) { }
  118. static inline void qdf_delayed_work_feature_init(void) { }
  119. static inline void qdf_delayed_work_feature_deinit(void) { }
  120. #endif /* WLAN_DELAYED_WORK_DEBUG */
  121. #endif /* __QDF_DELAYED_WORK_H */