#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:
/**
* mono_mempool_new_size:
- * @initial_size: the amount of memory to initially reserve for the memory pool.
- *
- * Returns: a new memory pool with a specific initial memory reservation.
+ * \param initial_size the amount of memory to initially reserve for the memory pool.
+ * \returns a new memory pool with a specific initial memory reservation.
*/
MonoMemPool *
mono_mempool_new_size (int initial_size)
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;
}
/**
* mono_mempool_destroy:
- * @pool: the memory pool to destroy
+ * \param pool the memory pool to destroy
*
* Free all memory associated with this pool.
*/
{
MonoMemPool *p, *n;
- total_bytes_allocated -= pool->d.allocated;
+ UnlockedSubtract64 (&total_bytes_allocated, pool->d.allocated);
p = pool;
while (p) {
/**
* mono_mempool_invalidate:
- * @pool: the memory pool to invalidate
+ * \param pool the memory pool to invalidate
*
* Fill the memory associated with this pool to 0x2a (42). Useful for debugging.
*/
/**
* mono_mempool_stats:
- * @pool: the momory pool we need stats for
+ * \param pool the memory pool we need stats for
*
* Print a few stats about the mempool:
* - Total memory allocated (malloced) by mem pool
#endif
/**
- * mono_mempool_alloc:
+ * get_next_size:
* @pool: the memory pool to use
* @size: size of the memory entity we are trying to allocate
*
/**
* mono_mempool_alloc:
- * @pool: the memory pool to use
- * @size: size of the memory block
+ * \param pool the memory pool to use
+ * \param size size of the memory block
*
- * Allocates a new block of memory in @pool.
+ * Allocates a new block of memory in \p pool .
*
- * Returns: the address of a newly allocated memory block.
+ * \returns the address of a newly allocated memory block.
*/
gpointer
mono_mempool_alloc (MonoMemPool *pool, guint size)
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;
/**
* mono_mempool_alloc0:
*
- * same as mono_mempool_alloc, but fills memory with zero.
+ * same as \c mono_mempool_alloc, but fills memory with zero.
*/
gpointer
mono_mempool_alloc0 (MonoMemPool *pool, guint size)
/**
* mono_mempool_contains_addr:
*
- * Determines whenever ADDR is inside the memory used by the mempool.
+ * Determines whether \p addr is inside the memory used by the mempool.
*/
gboolean
mono_mempool_contains_addr (MonoMemPool *pool,
long
mono_mempool_get_bytes_allocated (void)
{
- return total_bytes_allocated;
+ return UnlockedRead64 (&total_bytes_allocated);
}