@@ -480,9 +480,20 @@ void *gc_alloc(mp_uint_t n_bytes, bool has_finaliser) {
480
480
end_block = i ;
481
481
start_block = i - n_free + 1 ;
482
482
483
- // mark first block as used head
484
483
#if MICROPY_REENTRANT_GC
485
484
mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION ();
485
+ #endif
486
+
487
+ // Set last free ATB index to block after last block we found, for start of
488
+ // next scan. To reduce fragmentation, we only do this if there are no free
489
+ // blocks before this one. Also, whenever we free or shink a block we must
490
+ // check if this index needs adjusting (see gc_realloc and gc_free).
491
+ if ((i + 1 ) / BLOCKS_PER_ATB < gc_last_free_atb_index ) {
492
+ gc_last_free_atb_index = (i + 1 ) / BLOCKS_PER_ATB ;
493
+ }
494
+
495
+ // mark first block as used head
496
+ #if MICROPY_REENTRANT_GC
486
497
if (ATB_GET_KIND (start_block ) == AT_FREE ) {
487
498
// TODO might need to make MARK
488
499
ATB_FREE_TO_HEAD (start_block );
@@ -518,14 +529,6 @@ void *gc_alloc(mp_uint_t n_bytes, bool has_finaliser) {
518
529
#endif
519
530
}
520
531
521
- // Set last free ATB index to block after last block we found, for start of
522
- // next scan. To reduce fragmentation, we only do this if there are no free
523
- // blocks before this one. Also, whenever we free or shink a block we must
524
- // check if this index needs adjusting (see gc_realloc and gc_free).
525
- if ((i + 1 ) / BLOCKS_PER_ATB < gc_last_free_atb_index ) {
526
- gc_last_free_atb_index = (i + 1 ) / BLOCKS_PER_ATB ;
527
- }
528
-
529
532
#if MICROPY_REENTRANT_GC
530
533
MICROPY_END_ATOMIC_SECTION (atomic_state );
531
534
#endif
0 commit comments