git.haldean.org expel / 65d5979
add a gc-free mode Haldean Brown 6 years ago
2 changed file(s) with 25 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
2121
2222 #include <stdio.h>
2323 #define gc_out stderr
24 #define XL_GC_NOPAGES 1
2425
2526 #include <inttypes.h>
2627 #include <stdbool.h>
250251 no_ignore xl_error
251252 xl_value_new(struct xl_value **v)
252253 {
254 #if !XL_GC_NOPAGES
253255 struct xl_alloc_page *p;
254256 size_t i;
255257 bool pages_full;
258 #endif
256259
257260 #ifndef XL_RECKLESS
258261 if (unlikely(gc_stats == NULL))
259262 return xl_raise(ERR_NOT_STARTED, "gc not started");
260263 #endif
261264
265 #if XL_GC_NOPAGES
266 *v = calloc(1, sizeof(struct xl_value));
267 if (*v == NULL)
268 return xl_raise(ERR_NO_MEMORY, "new value");
269 (*v)->tag = TAG_VALUE;
270 (*v)->refcount = 1;
271 return OK;
272 #else
262273 pages_full = true;
263274 p = page_tail;
264275 while (p != NULL)
316327 gc_stats->n_val_allocs++;
317328 #endif
318329 return OK;
330 #endif
319331 }
320332
321333 /* Takes a reference to the given tree. */
404416 _release_value(struct xl_value *v)
405417 {
406418 xl_error err;
419 #if !XL_GC_NOPAGES
407420 struct xl_alloc_page *p;
421 #endif
408422
409423 if (unlikely(v->refcount == 0))
410424 return xl_raise(ERR_REFCOUNT_UNDERFLOW, "release");
419433
420434 if (v->refcount == 0)
421435 {
436 if (v->tag & (TAG_LEFT_NODE | TAG_LEFT_GRAPH))
437 err = xl_release(v->left.any);
438 if (err == OK && (v->tag & (TAG_RIGHT_NODE | TAG_RIGHT_GRAPH)))
439 err = xl_release(v->right.any);
440
441 #if XL_GC_NOPAGES
442 free(v);
443 #else
422444 p = v->alloc_page;
423445 p->open_values[p->n_open_values] = v;
424446 p->n_open_values++;
430452 / sizeof(struct xl_value),
431453 ((uintptr_t) p) & 0xFFFF);
432454 #endif
433
434 if (v->tag & (TAG_LEFT_NODE | TAG_LEFT_GRAPH))
435 err = xl_release(v->left.any);
436 if (err == OK && (v->tag & (TAG_RIGHT_NODE | TAG_RIGHT_GRAPH)))
437 err = xl_release(v->right.any);
455 #endif
456
438457 }
439458
440459 if (unlikely(err == OK && gc_stats->releases_until_gc == 0))
8585 assert(xl_env_overwrite(&env, &uris[i], v, t) == OK);
8686 }
8787
88 assert(xl_release(t) == OK);
8889 assert(v.tree->refcount == N_TEST_URIS + 1);
8990 assert(xl_env_free(&env) == OK);
9091 assert(v.tree->refcount == 1);