diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2016-01-15 12:48:06 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2016-01-15 12:48:06 +0300 |
commit | 283e7fded73a8428f94fa0e0baa24e5ed2a1f78b (patch) | |
tree | 0b21acceb21996b1c552fa15adc6f95aa5581a9c /mallocx.c | |
parent | be76fecc24a410f26ac33fb363cfb90a1ace6fca (diff) | |
download | bdwgc-283e7fded73a8428f94fa0e0baa24e5ed2a1f78b.tar.gz |
GC_malloc_[atomic_]uncollectable generalization
* include/gc_mark.h (GC_generic_malloc_uncollectable): New public
function declaration.
* malloc.c (GC_generic_malloc_uncollectable): New function
(imlementation mostly copied from GC_malloc_uncollectable).
* malloc.c (GC_malloc_uncollectable, GC_malloc_atomic_uncollectable,
calloc): Use GC_malloc_atomic_uncollectable.
* mallocx.c (GC_generic_or_special_malloc): Likewise.
* mallocx.c (GC_malloc_atomic_uncollectable): Move to malloc.c.
Diffstat (limited to 'mallocx.c')
-rw-r--r-- | mallocx.c | 56 |
1 files changed, 1 insertions, 55 deletions
@@ -69,11 +69,10 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_or_special_malloc(size_t lb, case NORMAL: return GC_malloc(lb); case UNCOLLECTABLE: - return GC_malloc_uncollectable(lb); # ifdef GC_ATOMIC_UNCOLLECTABLE case AUNCOLLECTABLE: - return GC_malloc_atomic_uncollectable(lb); # endif + return GC_generic_malloc_uncollectable(lb, knd); default: return GC_generic_malloc(lb, knd); } @@ -515,59 +514,6 @@ GC_API int GC_CALL GC_posix_memalign(void **memptr, size_t align, size_t lb) return 0; } -#ifdef GC_ATOMIC_UNCOLLECTABLE - /* Allocate lb bytes of pointer-free, untraced, uncollectible data */ - /* This is normally roughly equivalent to the system malloc. */ - /* But it may be useful if malloc is redefined. */ - GC_API GC_ATTR_MALLOC void * GC_CALL - GC_malloc_atomic_uncollectable(size_t lb) - { - void *op; - size_t lg; - DCL_LOCK_STATE; - - if (SMALL_OBJ(lb)) { - GC_DBG_COLLECT_AT_MALLOC(lb); - if (EXTRA_BYTES != 0 && lb != 0) lb--; - /* We don't need the extra byte, since this won't be */ - /* collected anyway. */ - lg = GC_size_map[lb]; - LOCK(); - op = GC_freelists[AUNCOLLECTABLE][lg]; - if (EXPECT(op != 0, TRUE)) { - GC_freelists[AUNCOLLECTABLE][lg] = obj_link(op); - obj_link(op) = 0; - GC_bytes_allocd += GRANULES_TO_BYTES(lg); - /* Mark bit was already set while object was on free list. */ - GC_non_gc_bytes += GRANULES_TO_BYTES(lg); - UNLOCK(); - } else { - UNLOCK(); - op = (ptr_t)GC_generic_malloc(lb, AUNCOLLECTABLE); - } - GC_ASSERT(0 == op || GC_is_marked(op)); - return((void *) op); - } else { - hdr * hhdr; - - op = (ptr_t)GC_generic_malloc(lb, AUNCOLLECTABLE); - if (0 == op) return(0); - - GC_ASSERT(((word)op & (HBLKSIZE - 1)) == 0); - hhdr = HDR(op); - - LOCK(); - set_mark_bit_from_hdr(hhdr, 0); /* Only object. */ -# ifndef THREADS - GC_ASSERT(hhdr -> hb_n_marks == 0); -# endif - hhdr -> hb_n_marks = 1; - UNLOCK(); - return((void *) op); - } - } -#endif /* GC_ATOMIC_UNCOLLECTABLE */ - /* provide a version of strdup() that uses the collector to allocate the copy of the string */ GC_API GC_ATTR_MALLOC char * GC_CALL GC_strdup(const char *s) |