@@ -302,6 +302,7 @@ struct ErtsHLTimerService_ {
302
302
ErtsHLTimer * next_timeout ;
303
303
ErtsYieldingTimeoutState yield ;
304
304
ErtsTWheelTimer service_timer ;
305
+ Uint btm_count ;
305
306
};
306
307
307
308
static ERTS_INLINE int
@@ -635,6 +636,7 @@ erts_create_timer_service(void)
635
636
srv -> btm_tree = NULL ;
636
637
srv -> next_timeout = NULL ;
637
638
srv -> yield = init_yield ;
639
+ srv -> btm_count = 0 ;
638
640
erts_twheel_init_timer (& srv -> service_timer );
639
641
640
642
init_canceled_queue (& srv -> canceled_queue );
@@ -707,6 +709,21 @@ port_timeout_common(Port *port, void *tmr)
707
709
return 0 ;
708
710
}
709
711
712
+ static ERTS_INLINE void
713
+ insert_btm (ErtsBifTimer * tmr , ErtsHLTimerService * srv )
714
+ {
715
+ btm_rbt_insert (& srv -> btm_tree , tmr );
716
+ ++ srv -> btm_count ;
717
+ }
718
+
719
+ static ERTS_INLINE void
720
+ remove_btm (ErtsBifTimer * tmr , ErtsHLTimerService * srv )
721
+ {
722
+ btm_rbt_delete (& srv -> btm_tree , tmr );
723
+ -- srv -> btm_count ;
724
+ tmr -> btm .tree .parent = ERTS_HLT_PFIELD_NOT_IN_TABLE ;
725
+ }
726
+
710
727
static ERTS_INLINE erts_aint_t
711
728
init_btm_specifics (ErtsSchedulerData * esdp ,
712
729
ErtsBifTimer * tmr , Eterm msg ,
@@ -732,7 +749,7 @@ init_btm_specifics(ErtsSchedulerData *esdp,
732
749
733
750
tmr -> btm .proc_tree .parent = ERTS_HLT_PFIELD_NOT_IN_TABLE ;
734
751
735
- btm_rbt_insert ( & esdp -> timer_service -> btm_tree , tmr );
752
+ insert_btm ( tmr , esdp -> timer_service );
736
753
737
754
erts_atomic32_init_nob (& tmr -> btm .state , ERTS_TMR_STATE_ACTIVE );
738
755
return refc ; /* refc from magic binary... */
@@ -1142,8 +1159,7 @@ bif_timer_timeout(ErtsHLTimerService *srv,
1142
1159
}
1143
1160
1144
1161
if (tmr -> btm .tree .parent != ERTS_HLT_PFIELD_NOT_IN_TABLE ) {
1145
- btm_rbt_delete (& srv -> btm_tree , tmr );
1146
- tmr -> btm .tree .parent = ERTS_HLT_PFIELD_NOT_IN_TABLE ;
1162
+ remove_btm (tmr , srv );
1147
1163
}
1148
1164
1149
1165
}
@@ -1470,8 +1486,7 @@ cleanup_sched_local_canceled_timer(ErtsSchedulerData *esdp,
1470
1486
if (roflgs & ERTS_TMR_ROFLG_BIF_TMR ) {
1471
1487
ErtsBifTimer * btm = (ErtsBifTimer * ) tmr ;
1472
1488
if (btm -> btm .tree .parent != ERTS_HLT_PFIELD_NOT_IN_TABLE ) {
1473
- btm_rbt_delete (& esdp -> timer_service -> btm_tree , btm );
1474
- btm -> btm .tree .parent = ERTS_HLT_PFIELD_NOT_IN_TABLE ;
1489
+ remove_btm (btm , esdp -> timer_service );
1475
1490
}
1476
1491
}
1477
1492
@@ -1779,8 +1794,7 @@ setup_bif_timer(Process *c_p, int twheel, ErtsMonotonicTime timeout_pos,
1779
1794
ERTS_P2P_FLG_INC_REFC );
1780
1795
if (!proc ) {
1781
1796
if (tmr -> btm .tree .parent != ERTS_HLT_PFIELD_NOT_IN_TABLE ) {
1782
- btm_rbt_delete (& esdp -> timer_service -> btm_tree , tmr );
1783
- tmr -> btm .tree .parent = ERTS_HLT_PFIELD_NOT_IN_TABLE ;
1797
+ remove_btm (tmr , esdp -> timer_service );
1784
1798
}
1785
1799
if (tmr -> btm .bp )
1786
1800
free_message_buffer (tmr -> btm .bp );
@@ -1884,8 +1898,7 @@ access_btm(ErtsBifTimer *tmr, Uint32 sid, ErtsSchedulerData *esdp, int cancel)
1884
1898
}
1885
1899
else {
1886
1900
if (tmr -> btm .tree .parent != ERTS_HLT_PFIELD_NOT_IN_TABLE ) {
1887
- btm_rbt_delete (& esdp -> timer_service -> btm_tree , tmr );
1888
- tmr -> btm .tree .parent = ERTS_HLT_PFIELD_NOT_IN_TABLE ;
1901
+ remove_btm (tmr , esdp -> timer_service );
1889
1902
}
1890
1903
if (is_hlt ) {
1891
1904
if (cncl_res > 0 )
@@ -2361,8 +2374,7 @@ exit_cancel_bif_timer(ErtsBifTimer *tmr, void *vesdp, Sint reds)
2361
2374
}
2362
2375
2363
2376
if (tmr -> btm .tree .parent != ERTS_HLT_PFIELD_NOT_IN_TABLE ) {
2364
- btm_rbt_delete (& esdp -> timer_service -> btm_tree , tmr );
2365
- tmr -> btm .tree .parent = ERTS_HLT_PFIELD_NOT_IN_TABLE ;
2377
+ remove_btm (tmr , esdp -> timer_service );
2366
2378
}
2367
2379
if (is_hlt )
2368
2380
hlt_delete_timer (esdp , & tmr -> type .hlt );
@@ -2898,6 +2910,12 @@ erts_read_port_timer(Port *c_prt)
2898
2910
return get_time_left (NULL , timeout_pos );
2899
2911
}
2900
2912
2913
+ Uint
2914
+ erts_bif_timer_count_in_timer_service (ErtsHLTimerService * service )
2915
+ {
2916
+ return service -> btm_count ;
2917
+ }
2918
+
2901
2919
/*
2902
2920
* Debug stuff...
2903
2921
*/
0 commit comments