From 5f9d95b9363aaf7a8d18e82888dec426ade4fe99 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 15 Jun 2018 01:57:54 +0300 Subject: [PATCH] Use atomic allocation for leafs in reverse_test (gctest) * tests/test.c [NO_CONS_ATOMIC_LEAF] (small_cons_leaf): Redirect to small_cons. * tests/test.c [!NO_CONS_ATOMIC_LEAF] (small_cons_leaf): Define function (which uses GC_MALLOC_ATOMIC). * tests/test.c (small_cons_uncollectable, uncollectable_ints): Replace small_cons(INT_TO_SEXPR(low),nil) to small_cons_leaf(low). --- tests/test.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/test.c b/tests/test.c index 435af8c..a3c1b46 100644 --- a/tests/test.c +++ b/tests/test.c @@ -381,6 +381,21 @@ sexpr small_cons (sexpr x, sexpr y) return(r); } +#ifdef NO_CONS_ATOMIC_LEAF +# define small_cons_leaf(x) small_cons(INT_TO_SEXPR(x), nil) +#else + sexpr small_cons_leaf(int x) + { + sexpr r = (sexpr)GC_MALLOC_ATOMIC(sizeof(struct SEXPR)); + + CHECK_OUT_OF_MEMORY(r); + AO_fetch_and_add1(&atomic_count); + r -> sexpr_car = INT_TO_SEXPR(x); + r -> sexpr_cdr = nil; + return r; + } +#endif + sexpr small_cons_uncollectable (sexpr x, sexpr y) { sexpr r = (sexpr)GC_MALLOC_UNCOLLECTABLE(sizeof(struct SEXPR)); @@ -435,7 +450,7 @@ sexpr ints(int low, int up) if (low > up) { return(nil); } else { - return(small_cons(small_cons(INT_TO_SEXPR(low), nil), ints(low+1, up))); + return small_cons(small_cons_leaf(low), ints(low + 1, up)); } } @@ -472,7 +487,7 @@ sexpr uncollectable_ints(int low, int up) if (low > up) { return(nil); } else { - return(small_cons_uncollectable(small_cons(INT_TO_SEXPR(low), nil), + return(small_cons_uncollectable(small_cons_leaf(low), uncollectable_ints(low+1, up))); } } -- 2.7.4