File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414#include "supervisor/shared/tick.h"
1515#include "shared-bindings/microcontroller/__init__.h"
1616
17- static volatile background_callback_t * volatile callback_head = NULL ;
18- static volatile background_callback_t * volatile callback_tail = NULL ;
19- ;
17+ static volatile background_callback_t * volatile callback_head , * volatile callback_tail ;
2018
2119#ifndef CALLBACK_CRITICAL_BEGIN
2220#define CALLBACK_CRITICAL_BEGIN (common_hal_mcu_disable_interrupts())
@@ -30,26 +28,15 @@ MP_WEAK void PLACE_IN_ITCM(port_wake_main_task)(void) {
3028
3129void PLACE_IN_ITCM (background_callback_add_core )(background_callback_t * cb ) {
3230 CALLBACK_CRITICAL_BEGIN ;
33- // next_callback_on_list is volatile only to match callback_head declaration.
34- volatile background_callback_t * next_callback_on_list = callback_head ;
35- // Add cb only if it is not already on the callback list.
36- while (next_callback_on_list ) {
37- if (cb == next_callback_on_list ) {
38- // Already on the list. Don't add.
39- CALLBACK_CRITICAL_END ;
40- return ;
41- }
42- next_callback_on_list = next_callback_on_list -> next ;
31+ if (cb -> prev || callback_head == cb ) {
32+ CALLBACK_CRITICAL_END ;
33+ return ;
4334 }
44-
45- // Add the cb to the end of the list.
4635 cb -> next = 0 ;
4736 cb -> prev = (background_callback_t * )callback_tail ;
4837 if (callback_tail ) {
4938 callback_tail -> next = cb ;
5039 }
51-
52- // If the callback list was empty, record that cb is the first item.
5340 if (!callback_head ) {
5441 callback_head = cb ;
5542 }
You can’t perform that action at this time.
0 commit comments