| 25 | } |
| 26 | |
| 27 | static void mi_stat_update(mi_stat_count_t* stat, int64_t amount) { |
| 28 | if (amount == 0) return; |
| 29 | if (mi_is_in_main(stat)) |
| 30 | { |
| 31 | // add atomically (for abandoned pages) |
| 32 | int64_t current = mi_atomic_addi64_relaxed(&stat->current, amount); |
| 33 | mi_atomic_maxi64_relaxed(&stat->peak, current + amount); |
| 34 | if (amount > 0) { |
| 35 | mi_atomic_addi64_relaxed(&stat->allocated,amount); |
| 36 | } |
| 37 | else { |
| 38 | mi_atomic_addi64_relaxed(&stat->freed, -amount); |
| 39 | } |
| 40 | } |
| 41 | else { |
| 42 | // add thread local |
| 43 | stat->current += amount; |
| 44 | if (stat->current > stat->peak) stat->peak = stat->current; |
| 45 | if (amount > 0) { |
| 46 | stat->allocated += amount; |
| 47 | } |
| 48 | else { |
| 49 | stat->freed += -amount; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | void _mi_stat_counter_increase(mi_stat_counter_t* stat, size_t amount) { |
| 55 | if (mi_is_in_main(stat)) { |
no test coverage detected