Skip to content

Commit 7071959

Browse files
committed
supervisor: tick: Rewrite without atomics
1 parent 568636d commit 7071959

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

supervisor/shared/tick.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include <stdatomic.h>
28-
2927
#include "supervisor/shared/tick.h"
3028
#include "supervisor/filesystem.h"
3129
#include "supervisor/shared/autoreload.h"
3230

33-
static atomic_bool tick_up;
3431
static volatile uint64_t ticks_ms;
32+
static volatile uint32_t background_ticks_ms32;
3533

3634
#if CIRCUITPY_GAMEPAD
3735
#include "shared-module/gamepad/__init__.h"
@@ -47,8 +45,6 @@ void supervisor_tick(void) {
4745

4846
ticks_ms ++;
4947

50-
atomic_store(&tick_up, true);
51-
5248
#if CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS > 0
5349
filesystem_tick();
5450
#endif
@@ -82,7 +78,14 @@ uint32_t supervisor_ticks_ms32() {
8278
extern void run_background_tasks(void);
8379

8480
void supervisor_run_background_tasks_if_tick() {
85-
if (atomic_exchange(&tick_up, false)) {
86-
run_background_tasks();
81+
uint32_t now32 = ticks_ms;
82+
83+
if (now32 == background_ticks_ms32) {
84+
return;
8785
}
86+
background_ticks_ms32 = now32;
87+
88+
run_background_tasks();
89+
}
90+
8891
}

supervisor/shared/tick.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#define __INCLUDED_SUPERVISOR_TICK_H
2929

3030
#include <stdint.h>
31-
#include <stdatomic.h>
3231

3332
extern void supervisor_tick(void);
3433
extern uint32_t supervisor_ticks_ms32(void);

0 commit comments

Comments
 (0)