Skip to content

Commit f792e6c

Browse files
committed
py/scheduler: Convert mp_sched_full and mp_sched_num_pending to macros.
So they are guaranteed to be inlined within functions like mp_sched_schedule which may be located in a special memory region.
1 parent 0f83ef3 commit f792e6c

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

py/runtime.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ void mp_handle_pending_tail(mp_uint_t atomic_state);
7171
#if MICROPY_ENABLE_SCHEDULER
7272
void mp_sched_lock(void);
7373
void mp_sched_unlock(void);
74-
static inline unsigned int mp_sched_num_pending(void) {
75-
return MP_STATE_VM(sched_len);
76-
}
74+
#define mp_sched_num_pending() (MP_STATE_VM(sched_len))
7775
bool mp_sched_schedule(mp_obj_t function, mp_obj_t arg);
7876
#endif
7977

py/scheduler.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ void MICROPY_WRAP_MP_KEYBOARD_INTERRUPT(mp_keyboard_interrupt)(void) {
4545

4646
#define IDX_MASK(i) ((i) & (MICROPY_SCHEDULER_DEPTH - 1))
4747

48-
static inline bool mp_sched_full(void) {
48+
// This is a macro so it is guaranteed to be inlined in functions like
49+
// mp_sched_schedule that may be located in a special memory region.
50+
#define mp_sched_full() (mp_sched_num_pending() == MICROPY_SCHEDULER_DEPTH)
51+
52+
static inline bool mp_sched_empty(void) {
4953
MP_STATIC_ASSERT(MICROPY_SCHEDULER_DEPTH <= 255); // MICROPY_SCHEDULER_DEPTH must fit in 8 bits
5054
MP_STATIC_ASSERT((IDX_MASK(MICROPY_SCHEDULER_DEPTH) == 0)); // MICROPY_SCHEDULER_DEPTH must be a power of 2
5155

52-
return mp_sched_num_pending() == MICROPY_SCHEDULER_DEPTH;
53-
}
54-
55-
static inline bool mp_sched_empty(void) {
5656
return mp_sched_num_pending() == 0;
5757
}
5858

0 commit comments

Comments
 (0)