xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_delayed_work.h (revision dd4dc88b837a295134aa9869114a2efee0f4894b)
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 /**
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 bool qdf_delayed_work_start(struct qdf_delayed_work *dwork, uint32_t msec);
82 
83 /**
84  * qdf_delayed_work_stop_sync() - Synchronously stop execution of @dwork
85  * @dwork: the delayed work to stop
86  *
87  * When this returns, @dwork is guaranteed to not be queued, and its callback
88  * not executing.
89  *
90  * Return: true if @dwork was queued or running
91  */
92 bool qdf_delayed_work_stop_sync(struct qdf_delayed_work *dwork);
93 
94 #ifdef WLAN_DELAYED_WORK_DEBUG
95 /**
96  * qdf_delayed_work_check_for_leaks() - assert no delayed work leaks
97  *
98  * Return: None
99  */
100 void qdf_delayed_work_check_for_leaks(void);
101 
102 /**
103  * qdf_delayed_work_feature_init() - global init logic for delayed work
104  *
105  * Return: None
106  */
107 void qdf_delayed_work_feature_init(void);
108 
109 /**
110  * qdf_delayed_work_feature_deinit() - global de-init logic for delayed work
111  *
112  * Return: None
113  */
114 void qdf_delayed_work_feature_deinit(void);
115 #else
116 static inline void qdf_delayed_work_check_for_leaks(void) { }
117 static inline void qdf_delayed_work_feature_init(void) { }
118 static inline void qdf_delayed_work_feature_deinit(void) { }
119 #endif /* WLAN_DELAYED_WORK_DEBUG */
120 
121 #endif /* __QDF_DELAYED_WORK_H */
122 
123