#include "mempool.h"
#include "mempool-internals.h"
+#include "utils/unlocked.h"
/*
* MonoMemPool is for fast allocation of memory. We free
} d;
};
-static long total_bytes_allocated = 0;
+static gint64 total_bytes_allocated = 0;
/**
* mono_mempool_new:
pool->pos = (guint8*)pool + SIZEOF_MEM_POOL; // Start after header
pool->end = (guint8*)pool + initial_size; // End at end of allocated space
pool->d.allocated = pool->size = initial_size;
- total_bytes_allocated += initial_size;
+ UnlockedAdd64 (&total_bytes_allocated, initial_size);
return pool;
}
{
MonoMemPool *p, *n;
- total_bytes_allocated -= pool->d.allocated;
+ UnlockedSubtract64 (&total_bytes_allocated, pool->d.allocated);
p = pool;
while (p) {
np->size = new_size;
pool->next = np;
pool->d.allocated += new_size;
- total_bytes_allocated += new_size;
+ UnlockedAdd64 (&total_bytes_allocated, new_size);
rval = (guint8*)np + SIZEOF_MEM_POOL;
} else {
pool->pos = (guint8*)np + SIZEOF_MEM_POOL;
pool->end = (guint8*)np + new_size;
pool->d.allocated += new_size;
- total_bytes_allocated += new_size;
+ UnlockedAdd64 (&total_bytes_allocated, new_size);
rval = pool->pos;
pool->pos += size;
long
mono_mempool_get_bytes_allocated (void)
{
- return total_bytes_allocated;
+ return UnlockedRead64 (&total_bytes_allocated);
}