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