diff options
author | Cy Schubert <cy@FreeBSD.org> | 2014-12-20 22:52:39 +0000 |
---|---|---|
committer | Cy Schubert <cy@FreeBSD.org> | 2014-12-20 22:52:39 +0000 |
commit | b5e14a1344528861a7016aa2c6b0f2e9630d1526 (patch) | |
tree | f04bed14f7e8aed5c0e9d2f7785175c7951036d3 /lib/isc/heap.c | |
parent | 2b45e011ca352ce509bc83ae148230aeee0c7e0d (diff) |
Diffstat (limited to 'lib/isc/heap.c')
-rw-r--r-- | lib/isc/heap.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/isc/heap.c b/lib/isc/heap.c index 91d78c06d468..ebadd2fd807c 100644 --- a/lib/isc/heap.c +++ b/lib/isc/heap.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2007, 2010-2012 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1997-2001 Internet Software Consortium. * * Permission to use, copy, modify, and/or distribute this software for any @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: heap.c,v 1.37 2007/10/19 17:15:53 explorer Exp $ */ +/* $Id$ */ /*! \file * Heap implementation of priority queues adapted from the following: @@ -86,8 +86,9 @@ isc_heap_create(isc_mem_t *mctx, isc_heapcompare_t compare, if (heap == NULL) return (ISC_R_NOMEMORY); heap->magic = HEAP_MAGIC; - heap->mctx = mctx; heap->size = 0; + heap->mctx = NULL; + isc_mem_attach(mctx, &heap->mctx); if (size_increment == 0) heap->size_increment = SIZE_INCREMENT; else @@ -114,7 +115,7 @@ isc_heap_destroy(isc_heap_t **heapp) { isc_mem_put(heap->mctx, heap->array, heap->size * sizeof(void *)); heap->magic = 0; - isc_mem_put(heap->mctx, heap, sizeof(*heap)); + isc_mem_putanddetach(&heap->mctx, heap, sizeof(*heap)); *heapp = NULL; } @@ -186,15 +187,17 @@ sink_down(isc_heap_t *heap, unsigned int i, void *elt) { isc_result_t isc_heap_insert(isc_heap_t *heap, void *elt) { - unsigned int i; + unsigned int new_last; REQUIRE(VALID_HEAP(heap)); - i = ++heap->last; - if (heap->last >= heap->size && !resize(heap)) + new_last = heap->last + 1; + RUNTIME_CHECK(new_last > 0); /* overflow check */ + if (new_last >= heap->size && !resize(heap)) return (ISC_R_NOMEMORY); + heap->last = new_last; - float_up(heap, i, elt); + float_up(heap, new_last, elt); return (ISC_R_SUCCESS); } |