Skip to content

Commit 5c113f7

Browse files
Fix-Pointjerpelea
authored andcommitted
timers/oneshot: Remove all private callback.
This commit removed all private callback and handle it on the upperhalf of oneshot. Signed-off-by: ouyangxiangzhen <[email protected]>
1 parent f70ec73 commit 5c113f7

File tree

32 files changed

+144
-606
lines changed

32 files changed

+144
-606
lines changed

arch/arm/src/armv7-a/arm_timer.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ struct arm_timer_lowerhalf_s
6363
{
6464
struct oneshot_lowerhalf_s lh; /* Lower half operations */
6565
uint32_t freq; /* Timer working clock frequency(Hz) */
66-
oneshot_callback_t callback; /* Current user interrupt callback */
67-
void *arg; /* Argument passed to upper half callback */
6866

6967
/* which cpu timer is running, -1 indicate timer stoppd */
7068

@@ -180,9 +178,6 @@ static int arm_timer_start(struct oneshot_lowerhalf_s *lower_,
180178

181179
flags = up_irq_save();
182180

183-
lower->callback = callback;
184-
lower->arg = arg;
185-
186181
lower->running = this_cpu();
187182

188183
count = sec_to_count(ts->tv_sec, lower->freq) +
@@ -206,8 +201,6 @@ static int arm_timer_cancel(struct oneshot_lowerhalf_s *lower_,
206201

207202
flags = up_irq_save();
208203

209-
lower->callback = NULL;
210-
lower->arg = NULL;
211204
lower->running = -1;
212205

213206
arm_timer_phy_set_irq_mask(true);
@@ -234,23 +227,14 @@ static int arm_timer_current(struct oneshot_lowerhalf_s *lower_,
234227
static int arm_timer_interrupt(int irq, void *context, void *arg)
235228
{
236229
struct arm_timer_lowerhalf_s *lower = arg;
237-
oneshot_callback_t callback;
238-
void *cbarg;
239230

240231
DEBUGASSERT(lower != NULL);
241232

242233
arm_timer_phy_set_irq_mask(true);
243234

244-
if (lower->callback != NULL && lower->running == this_cpu())
235+
if (lower->running == this_cpu())
245236
{
246-
callback = lower->callback;
247-
cbarg = lower->arg;
248-
lower->callback = NULL;
249-
lower->arg = NULL;
250-
251-
/* Then perform the callback */
252-
253-
callback(&lower->lh, cbarg);
237+
oneshot_process_callback(&lower->lh);
254238
}
255239

256240
return 0;

arch/arm/src/armv7-r/arm_timer.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ struct arm_timer_lowerhalf_s
6262
{
6363
struct oneshot_lowerhalf_s lh; /* Lower half operations */
6464
uint32_t freq; /* Timer working clock frequency(Hz) */
65-
oneshot_callback_t callback; /* Current user interrupt callback */
66-
void *arg; /* Argument passed to upper half callback */
6765

6866
/* which cpu timer is running, -1 indicate timer stoppd */
6967

@@ -173,9 +171,6 @@ static int arm_timer_start(struct oneshot_lowerhalf_s *lower_,
173171

174172
flags = up_irq_save();
175173

176-
lower->callback = callback;
177-
lower->arg = arg;
178-
179174
lower->running = this_cpu();
180175

181176
count = sec_to_count(ts->tv_sec, arm_timer_get_freq()) +
@@ -199,8 +194,6 @@ static int arm_timer_cancel(struct oneshot_lowerhalf_s *lower_,
199194

200195
flags = up_irq_save();
201196

202-
lower->callback = NULL;
203-
lower->arg = NULL;
204197
lower->running = -1;
205198

206199
arm_timer_phy_set_irq_mask(true);
@@ -225,23 +218,13 @@ static int arm_timer_current(struct oneshot_lowerhalf_s *lower_,
225218
static int arm_timer_interrupt(int irq, void *context, void *arg)
226219
{
227220
struct arm_timer_lowerhalf_s *lower = arg;
228-
oneshot_callback_t callback;
229-
void *cbarg;
230-
231221
DEBUGASSERT(lower != NULL);
232222

233223
arm_timer_phy_set_irq_mask(true);
234224

235-
if (lower->callback != NULL && lower->running == this_cpu())
225+
if (lower->running == this_cpu())
236226
{
237-
callback = lower->callback;
238-
cbarg = lower->arg;
239-
lower->callback = NULL;
240-
lower->arg = NULL;
241-
242-
/* Then perform the callback */
243-
244-
callback(&lower->lh, cbarg);
227+
oneshot_process_callback(&lower->lh);
245228
}
246229

247230
return 0;

arch/arm/src/armv8-r/arm_timer.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ struct arm_oneshot_lowerhalf_s
8080

8181
/* Private lower half data follows */
8282

83-
void *arg; /* Argument that is passed to the handler */
8483
uint32_t frequency; /* Frequency */
85-
oneshot_callback_t callback; /* Internal handler that receives callback */
8684
};
8785

8886
/****************************************************************************
@@ -146,12 +144,9 @@ static int arm_arch_timer_compare_isr(int irq, void *regs, void *arg)
146144

147145
arm_timer_phy_set_irq_mask(true);
148146

149-
if (priv->callback)
150-
{
151-
/* Then perform the callback */
147+
/* Then perform the callback */
152148

153-
priv->callback(&priv->lh, priv->arg);
154-
}
149+
oneshot_process_callback(&priv->lh);
155150

156151
return OK;
157152
}
@@ -258,11 +253,6 @@ static int arm_start(struct oneshot_lowerhalf_s *lower,
258253

259254
DEBUGASSERT(priv && callback && ts);
260255

261-
/* Save the new handler and its argument */
262-
263-
priv->callback = callback;
264-
priv->arg = arg;
265-
266256
/* Set the timeout */
267257

268258
count = arm_timer_phy_count();

arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ struct sam_oneshot_lowerhalf_s
5858
/* Private lower half data follows */
5959

6060
struct sam_oneshot_s oneshot; /* SAM-specific oneshot state */
61-
oneshot_callback_t callback; /* internal handler that receives callback */
62-
void *arg; /* Argument that is passed to the handler */
6361
};
6462

6563
/****************************************************************************
@@ -112,30 +110,14 @@ static void sam_oneshot_handler(void *arg)
112110
{
113111
struct sam_oneshot_lowerhalf_s *priv =
114112
(struct sam_oneshot_lowerhalf_s *)arg;
115-
oneshot_callback_t callback;
116-
void *cbarg;
117113

118114
DEBUGASSERT(priv != NULL);
119115

120116
/* Perhaps the callback was nullified in a race condition with
121117
* sam_cancel?
122118
*/
123119

124-
if (priv->callback)
125-
{
126-
/* Sample and nullify BEFORE executing callback (in case the callback
127-
* restarts the oneshot).
128-
*/
129-
130-
callback = priv->callback;
131-
cbarg = priv->arg;
132-
priv->callback = NULL;
133-
priv->arg = NULL;
134-
135-
/* Then perform the callback */
136-
137-
callback(&priv->lh, cbarg);
138-
}
120+
oneshot_process_callback(&priv->lh);
139121
}
140122

141123
/****************************************************************************
@@ -211,11 +193,9 @@ static int sam_start(struct oneshot_lowerhalf_s *lower,
211193

212194
/* Save the callback information and start the timer */
213195

214-
flags = enter_critical_section();
215-
priv->callback = callback;
216-
priv->arg = arg;
217-
ret = sam_oneshot_start(&priv->oneshot, NULL,
218-
sam_oneshot_handler, priv, ts);
196+
flags = enter_critical_section();
197+
ret = sam_oneshot_start(&priv->oneshot, NULL,
198+
sam_oneshot_handler, priv, ts);
219199
leave_critical_section(flags);
220200

221201
if (ret < 0)
@@ -262,10 +242,8 @@ static int sam_cancel(struct oneshot_lowerhalf_s *lower,
262242

263243
/* Cancel the timer */
264244

265-
flags = enter_critical_section();
266-
ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts);
267-
priv->callback = NULL;
268-
priv->arg = NULL;
245+
flags = enter_critical_section();
246+
ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts);
269247
leave_critical_section(flags);
270248

271249
if (ret < 0)

arch/arm/src/sama5/sam_oneshot_lowerhalf.c

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ struct sam_oneshot_lowerhalf_s
6060
/* Private lower half data follows */
6161

6262
struct sam_oneshot_s oneshot; /* SAM-specific oneshot state */
63-
oneshot_callback_t callback; /* internal handler that receives callback */
64-
void *arg; /* Argument that is passed to the handler */
6563
};
6664

6765
/****************************************************************************
@@ -114,30 +112,14 @@ static void sam_oneshot_handler(void *arg)
114112
{
115113
struct sam_oneshot_lowerhalf_s *priv =
116114
(struct sam_oneshot_lowerhalf_s *)arg;
117-
oneshot_callback_t callback;
118-
void *cbarg;
119115

120116
DEBUGASSERT(priv != NULL);
121117

122118
/* Perhaps the callback was nullified in a race condition with
123119
* sam_cancel?
124120
*/
125121

126-
if (priv->callback)
127-
{
128-
/* Sample and nullify BEFORE executing callback (in case the callback
129-
* restarts the oneshot).
130-
*/
131-
132-
callback = priv->callback;
133-
cbarg = priv->arg;
134-
priv->callback = NULL;
135-
priv->arg = NULL;
136-
137-
/* Then perform the callback */
138-
139-
callback(&priv->lh, cbarg);
140-
}
122+
oneshot_process_callback(&priv->lh);
141123
}
142124

143125
/****************************************************************************
@@ -213,11 +195,9 @@ static int sam_start(struct oneshot_lowerhalf_s *lower,
213195

214196
/* Save the callback information and start the timer */
215197

216-
flags = enter_critical_section();
217-
priv->callback = callback;
218-
priv->arg = arg;
219-
ret = sam_oneshot_start(&priv->oneshot, NULL,
220-
sam_oneshot_handler, priv, ts);
198+
flags = enter_critical_section();
199+
ret = sam_oneshot_start(&priv->oneshot, NULL,
200+
sam_oneshot_handler, priv, ts);
221201
leave_critical_section(flags);
222202

223203
if (ret < 0)
@@ -264,10 +244,8 @@ static int sam_cancel(struct oneshot_lowerhalf_s *lower,
264244

265245
/* Cancel the timer */
266246

267-
flags = enter_critical_section();
268-
ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts);
269-
priv->callback = NULL;
270-
priv->arg = NULL;
247+
flags = enter_critical_section();
248+
ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts);
271249
leave_critical_section(flags);
272250

273251
if (ret < 0)

arch/arm/src/samd5e5/sam_oneshot_lowerhalf.c

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ struct sam_oneshot_lowerhalf_s
5858
/* Private lower half data follows */
5959

6060
struct sam_oneshot_s oneshot; /* SAM-specific oneshot state */
61-
oneshot_callback_t callback; /* internal handler that receives callback */
62-
void *arg; /* Argument that is passed to the handler */
6361
};
6462

6563
/****************************************************************************
@@ -112,30 +110,14 @@ static void sam_oneshot_handler(void *arg)
112110
{
113111
struct sam_oneshot_lowerhalf_s *priv =
114112
(struct sam_oneshot_lowerhalf_s *)arg;
115-
oneshot_callback_t callback;
116-
void *cbarg;
117113

118114
DEBUGASSERT(priv != NULL);
119115

120116
/* Perhaps the callback was nullified in a race condition with
121117
* sam_cancel?
122118
*/
123119

124-
if (priv->callback)
125-
{
126-
/* Sample and nullify BEFORE executing callback (in case the callback
127-
* restarts the oneshot).
128-
*/
129-
130-
callback = priv->callback;
131-
cbarg = priv->arg;
132-
priv->callback = NULL;
133-
priv->arg = NULL;
134-
135-
/* Then perform the callback */
136-
137-
callback(&priv->lh, cbarg);
138-
}
120+
oneshot_process_callback(&priv->lh);
139121
}
140122

141123
/****************************************************************************
@@ -211,11 +193,9 @@ static int sam_start(struct oneshot_lowerhalf_s *lower,
211193

212194
/* Save the callback information and start the timer */
213195

214-
flags = enter_critical_section();
215-
priv->callback = callback;
216-
priv->arg = arg;
217-
ret = sam_oneshot_start(&priv->oneshot, NULL,
218-
sam_oneshot_handler, priv, ts);
196+
flags = enter_critical_section();
197+
ret = sam_oneshot_start(&priv->oneshot, NULL,
198+
sam_oneshot_handler, priv, ts);
219199
leave_critical_section(flags);
220200

221201
if (ret < 0)
@@ -262,10 +242,8 @@ static int sam_cancel(struct oneshot_lowerhalf_s *lower,
262242

263243
/* Cancel the timer */
264244

265-
flags = enter_critical_section();
266-
ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts);
267-
priv->callback = NULL;
268-
priv->arg = NULL;
245+
flags = enter_critical_section();
246+
ret = sam_oneshot_cancel(&priv->oneshot, NULL, ts);
269247
leave_critical_section(flags);
270248

271249
if (ret < 0)

0 commit comments

Comments
 (0)