mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-07 11:58:41 +03:00
reduce type casts in atomic operations
This commit is contained in:
parent
0f14f431c5
commit
e3b16fe4ef
9 changed files with 93 additions and 92 deletions
22
src/stats.c
22
src/stats.c
|
@ -26,13 +26,13 @@ static void mi_stat_update(mi_stat_count_t* stat, int64_t amount) {
|
|||
if (mi_is_in_main(stat))
|
||||
{
|
||||
// add atomically (for abandoned pages)
|
||||
mi_atomic_add64(&stat->current,amount);
|
||||
mi_atomic_addi64(&stat->current,amount);
|
||||
if (stat->current > stat->peak) stat->peak = stat->current; // racing.. it's ok
|
||||
if (amount > 0) {
|
||||
mi_atomic_add64(&stat->allocated,amount);
|
||||
mi_atomic_addi64(&stat->allocated,amount);
|
||||
}
|
||||
else {
|
||||
mi_atomic_add64(&stat->freed, -amount);
|
||||
mi_atomic_addi64(&stat->freed, -amount);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -50,8 +50,8 @@ static void mi_stat_update(mi_stat_count_t* stat, int64_t amount) {
|
|||
|
||||
void _mi_stat_counter_increase(mi_stat_counter_t* stat, size_t amount) {
|
||||
if (mi_is_in_main(stat)) {
|
||||
mi_atomic_add64( &stat->count, 1 );
|
||||
mi_atomic_add64( &stat->total, (int64_t)amount );
|
||||
mi_atomic_addi64( &stat->count, 1 );
|
||||
mi_atomic_addi64( &stat->total, (int64_t)amount );
|
||||
}
|
||||
else {
|
||||
stat->count++;
|
||||
|
@ -70,17 +70,17 @@ void _mi_stat_decrease(mi_stat_count_t* stat, size_t amount) {
|
|||
// must be thread safe as it is called from stats_merge
|
||||
static void mi_stat_add(mi_stat_count_t* stat, const mi_stat_count_t* src, int64_t unit) {
|
||||
if (stat==src) return;
|
||||
mi_atomic_add64( &stat->allocated, src->allocated * unit);
|
||||
mi_atomic_add64( &stat->current, src->current * unit);
|
||||
mi_atomic_add64( &stat->freed, src->freed * unit);
|
||||
mi_atomic_addi64( &stat->allocated, src->allocated * unit);
|
||||
mi_atomic_addi64( &stat->current, src->current * unit);
|
||||
mi_atomic_addi64( &stat->freed, src->freed * unit);
|
||||
// peak scores do not work across threads..
|
||||
mi_atomic_add64( &stat->peak, src->peak * unit);
|
||||
mi_atomic_addi64( &stat->peak, src->peak * unit);
|
||||
}
|
||||
|
||||
static void mi_stat_counter_add(mi_stat_counter_t* stat, const mi_stat_counter_t* src, int64_t unit) {
|
||||
if (stat==src) return;
|
||||
mi_atomic_add64( &stat->total, src->total * unit);
|
||||
mi_atomic_add64( &stat->count, src->count * unit);
|
||||
mi_atomic_addi64( &stat->total, src->total * unit);
|
||||
mi_atomic_addi64( &stat->count, src->count * unit);
|
||||
}
|
||||
|
||||
// must be thread safe as it is called from stats_merge
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue