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