summaryrefslogtreecommitdiff
path: root/tests/memory.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-05-23 16:12:32 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-05-23 16:12:32 +0000
commit2107bfbc19c3ea9b60adf575eb528e4e236ca8fe (patch)
treeac02996fbc0d823e5535bf88e3a01ee8f9bfd8cd /tests/memory.c
parent3eb219a24f100bcd97e77c3be9a0b59f1ed211a2 (diff)
downloadmpfr-2107bfbc19c3ea9b60adf575eb528e4e236ca8fe.tar.gz
Added shared cache support (from a patch by Patrick PĂ©lissier).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@10327 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/memory.c')
-rw-r--r--tests/memory.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/memory.c b/tests/memory.c
index 87e2063f4..64038e522 100644
--- a/tests/memory.c
+++ b/tests/memory.c
@@ -42,6 +42,7 @@ struct header {
static struct header *tests_memory_list;
static size_t tests_total_size = 0;
+MPFR_LOCK_DECL(mpfr_lock_memory)
static void *
mpfr_default_allocate (size_t size)
@@ -121,6 +122,8 @@ tests_allocate (size_t size)
{
struct header *h;
+ MPFR_LOCK_WRITE(mpfr_lock_memory);
+
if (size == 0)
{
printf ("tests_allocate(): attempt to allocate 0 bytes\n");
@@ -135,6 +138,9 @@ tests_allocate (size_t size)
h->size = size;
h->ptr = mpfr_default_allocate (size);
+
+ MPFR_UNLOCK_WRITE(mpfr_lock_memory);
+
return h->ptr;
}
@@ -143,6 +149,8 @@ tests_reallocate (void *ptr, size_t old_size, size_t new_size)
{
struct header **hp, *h;
+ MPFR_LOCK_WRITE(mpfr_lock_memory);
+
if (new_size == 0)
{
printf ("tests_reallocate(): attempt to reallocate 0x%lX to 0 bytes\n",
@@ -173,6 +181,9 @@ tests_reallocate (void *ptr, size_t old_size, size_t new_size)
h->size = new_size;
h->ptr = mpfr_default_reallocate (ptr, old_size, new_size);
+
+ MPFR_UNLOCK_WRITE(mpfr_lock_memory);
+
return h->ptr;
}
@@ -204,8 +215,13 @@ tests_free_nosize (void *ptr)
void
tests_free (void *ptr, size_t size)
{
- struct header **hp = tests_free_find (ptr);
- struct header *h = *hp;
+ struct header **hp;
+ struct header *h;
+
+ MPFR_LOCK_WRITE(mpfr_lock_memory);
+
+ hp = tests_free_find (ptr);
+ h = *hp;
if (h->size != size)
{
@@ -218,6 +234,8 @@ tests_free (void *ptr, size_t size)
tests_total_size -= size;
tests_free_nosize (ptr);
+
+ MPFR_UNLOCK_WRITE(mpfr_lock_memory);
}
void