Skip to content

Commit bccb09b

Browse files
committed
Revert ticks implementation for unix build.
1 parent 6b7ad72 commit bccb09b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

extmod/moduasyncio.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
#include "py/pairheap.h"
3030
#include "py/mphal.h"
3131

32-
// Unix build does not have shared-bindings/supervisor/__init__.h
33-
extern mp_obj_t supervisor_ticks_ms(void);
32+
#ifndef __unix__
33+
#include "shared-bindings/supervisor/__init__.h"
34+
#endif
3435

3536
#if MICROPY_PY_UASYNCIO
3637

@@ -66,6 +67,19 @@ STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, si
6667
/******************************************************************************/
6768
// Ticks for task ordering in pairing heap
6869

70+
#ifdef __unix__
71+
STATIC mp_obj_t ticks(void) {
72+
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1));
73+
}
74+
75+
STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) {
76+
mp_uint_t t0 = MP_OBJ_SMALL_INT_VALUE(t0_in);
77+
mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_in);
78+
mp_int_t diff = ((t1 - t0 + MICROPY_PY_UTIME_TICKS_PERIOD / 2) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1))
79+
- MICROPY_PY_UTIME_TICKS_PERIOD / 2;
80+
return diff;
81+
}
82+
#else
6983
#define _TICKS_PERIOD (1lu << 29)
7084
#define _TICKS_MAX (_TICKS_PERIOD - 1)
7185
#define _TICKS_HALFPERIOD (_TICKS_PERIOD >> 1)
@@ -78,6 +92,7 @@ STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) {
7892
mp_int_t diff = ((t1 - t0 + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD;
7993
return diff;
8094
}
95+
#endif
8196

8297
STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) {
8398
mp_obj_task_t *t1 = (mp_obj_task_t *)n1;

0 commit comments

Comments
 (0)