@@ -87,6 +87,8 @@ static dq_queue_t g_notifier_free;
87
87
88
88
static dq_queue_t g_notifier_pending ;
89
89
90
+ static spinlock_t g_work_notifier_lock ;
91
+
90
92
/****************************************************************************
91
93
* Private Functions
92
94
****************************************************************************/
@@ -166,17 +168,21 @@ static void work_notifier_worker(FAR void *arg)
166
168
167
169
/* Disable interrupts very briefly. */
168
170
169
- flags = enter_critical_section ( );
171
+ flags = spin_lock_irqsave ( & g_work_notifier_lock );
170
172
171
173
/* Remove the notification from the pending list */
172
174
173
- dq_rem (& notifier -> entry , & g_notifier_pending );
175
+ notifier = work_notifier_find (notifier -> key );
176
+ if (notifier != NULL )
177
+ {
178
+ dq_rem (& notifier -> entry , & g_notifier_pending );
174
179
175
- /* Put the notification to the free list */
180
+ /* Put the notification to the free list */
176
181
177
- dq_addlast (& notifier -> entry , & g_notifier_free );
182
+ dq_addlast (& notifier -> entry , & g_notifier_free );
183
+ }
178
184
179
- leave_critical_section ( flags );
185
+ spin_unlock_irqrestore ( & g_work_notifier_lock , flags );
180
186
}
181
187
182
188
/****************************************************************************
@@ -213,14 +219,14 @@ int work_notifier_setup(FAR struct work_notifier_s *info)
213
219
214
220
/* Disable interrupts very briefly. */
215
221
216
- flags = enter_critical_section ( );
222
+ flags = spin_lock_irqsave ( & g_work_notifier_lock );
217
223
218
224
/* Try to get the entry from the free list */
219
225
220
226
notifier = (FAR struct work_notifier_entry_s * )
221
227
dq_remfirst (& g_notifier_free );
222
228
223
- leave_critical_section ( flags );
229
+ spin_unlock_irqrestore ( & g_work_notifier_lock , flags );
224
230
225
231
if (notifier == NULL )
226
232
{
@@ -245,7 +251,7 @@ int work_notifier_setup(FAR struct work_notifier_s *info)
245
251
246
252
/* Disable interrupts very briefly. */
247
253
248
- flags = enter_critical_section ( );
254
+ flags = spin_lock_irqsave ( & g_work_notifier_lock );
249
255
250
256
/* Generate a unique key for this notification */
251
257
@@ -262,7 +268,7 @@ int work_notifier_setup(FAR struct work_notifier_s *info)
262
268
dq_addlast (& notifier -> entry , & g_notifier_pending );
263
269
ret = notifier -> key ;
264
270
265
- leave_critical_section ( flags );
271
+ spin_unlock_irqrestore ( & g_work_notifier_lock , flags );
266
272
}
267
273
268
274
return ret ;
@@ -293,7 +299,7 @@ void work_notifier_teardown(int key)
293
299
294
300
/* Disable interrupts very briefly. */
295
301
296
- flags = enter_critical_section ( );
302
+ flags = spin_lock_irqsave ( & g_work_notifier_lock );
297
303
298
304
/* Find the entry matching this key in the g_notifier_pending list. We
299
305
* assume that there is only one.
@@ -304,19 +310,18 @@ void work_notifier_teardown(int key)
304
310
{
305
311
/* Cancel the work, this may be waiting */
306
312
307
- if (work_cancel_sync (notifier -> info .qid , & notifier -> work ) != 1 )
308
- {
309
- /* Remove the notification from the pending list */
313
+ work_cancel (notifier -> info .qid , & notifier -> work );
310
314
311
- dq_rem ( & notifier -> entry , & g_notifier_pending );
315
+ /* Remove the notification from the pending list */
312
316
313
- /* Put the notification to the free list */
317
+ dq_rem ( & notifier -> entry , & g_notifier_pending );
314
318
315
- dq_addlast (& notifier -> entry , & g_notifier_free );
316
- }
319
+ /* Put the notification to the free list */
320
+
321
+ dq_addlast (& notifier -> entry , & g_notifier_free );
317
322
}
318
323
319
- leave_critical_section ( flags );
324
+ spin_unlock_irqrestore ( & g_work_notifier_lock , flags );
320
325
}
321
326
322
327
/****************************************************************************
@@ -352,7 +357,7 @@ void work_notifier_signal(enum work_evtype_e evtype,
352
357
* the notifications have been sent.
353
358
*/
354
359
355
- flags = enter_critical_section ( );
360
+ flags = spin_lock_irqsave ( & g_work_notifier_lock );
356
361
sched_lock ();
357
362
358
363
/* Process the notification at the head of the pending list until the
@@ -397,7 +402,7 @@ void work_notifier_signal(enum work_evtype_e evtype,
397
402
}
398
403
399
404
sched_unlock ();
400
- leave_critical_section ( flags );
405
+ spin_unlock_irqrestore ( & g_work_notifier_lock , flags );
401
406
}
402
407
403
408
#endif /* CONFIG_WQUEUE_NOTIFIER */
0 commit comments