summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5Fpkg.h2
-rw-r--r--src/H5HG.c79
-rw-r--r--src/H5HGcache.c42
-rw-r--r--src/H5HGdbg.c14
-rw-r--r--src/H5HGpkg.h6
5 files changed, 88 insertions, 55 deletions
diff --git a/src/H5Fpkg.h b/src/H5Fpkg.h
index fd6da0d..01ecf17 100644
--- a/src/H5Fpkg.h
+++ b/src/H5Fpkg.h
@@ -225,7 +225,7 @@ typedef struct H5F_file_t {
unsigned gc_ref; /* Garbage-collect references? */
hbool_t latest_format; /* Always use the latest format? */
hbool_t store_msg_crt_idx; /* Store creation index for object header messages? */
- int ncwfs; /* Num entries on cwfs list */
+ unsigned ncwfs; /* Num entries on cwfs list */
struct H5HG_heap_t **cwfs; /* Global heap cache */
struct H5G_t *root_grp; /* Open root group */
H5FO_t *open_objs; /* Open objects in file */
diff --git a/src/H5HG.c b/src/H5HG.c
index f1edb71..4fb22c9 100644
--- a/src/H5HG.c
+++ b/src/H5HG.c
@@ -164,6 +164,7 @@ H5HG_create(H5F_t *f, hid_t dxpl_id, size_t size)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "memory allocation failed")
heap->addr = addr;
heap->size = size;
+ heap->shared = f->shared;
if(NULL == (heap->chunk = H5FL_BLK_MALLOC(gheap_chunk, size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "memory allocation failed")
@@ -222,7 +223,7 @@ HDmemset(heap->chunk, 0, size);
HDmemmove(f->shared->cwfs + 1, f->shared->cwfs,
MIN(f->shared->ncwfs, H5HG_NCWFS - 1) * sizeof(H5HG_heap_t *));
f->shared->cwfs[0] = heap;
- f->shared->ncwfs = MIN(H5HG_NCWFS, f->shared->ncwfs+1);
+ f->shared->ncwfs = MIN(H5HG_NCWFS, f->shared->ncwfs + 1);
} /* end else */
/* Add the heap to the cache */
@@ -242,7 +243,7 @@ done:
/* Check if the heap object was allocated */
if(heap)
/* Destroy the heap object */
- if(H5HG_dest(f, heap) < 0)
+ if(H5HG_free(heap) < 0)
HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, HADDR_UNDEF, "unable to destroy global heap collection")
} /* end if */
} /* end if */
@@ -485,7 +486,7 @@ herr_t
H5HG_insert(H5F_t *f, hid_t dxpl_id, size_t size, void *obj, H5HG_t *hobj/*out*/)
{
size_t need; /*total space needed for object */
- int cwfsno;
+ unsigned cwfsno;
size_t idx;
haddr_t addr = HADDR_UNDEF;
H5HG_heap_t *heap = NULL;
@@ -544,7 +545,7 @@ H5HG_insert(H5F_t *f, hid_t dxpl_id, size_t size, void *obj, H5HG_t *hobj/*out*/
if(!found) {
size_t new_need;
- for (cwfsno=0; cwfsno<f->shared->ncwfs; cwfsno++) {
+ for(cwfsno = 0; cwfsno < f->shared->ncwfs; cwfsno++) {
new_need = need;
new_need -= f->shared->cwfs[cwfsno]->obj[0].size;
new_need = MAX(f->shared->cwfs[cwfsno]->size, new_need);
@@ -575,7 +576,6 @@ H5HG_insert(H5F_t *f, hid_t dxpl_id, size_t size, void *obj, H5HG_t *hobj/*out*/
if(!H5F_addr_defined(addr))
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "unable to allocate a global heap collection")
- cwfsno = 0;
} /* end if */
else {
/* Move the collection forward in the CWFS list, if it's not
@@ -671,13 +671,13 @@ H5HG_read(H5F_t *f, hid_t dxpl_id, H5HG_t *hobj, void *object/*out*/,
* with the H5AC_protect(), but it won't hurt to do it twice.
*/
if(heap->obj[0].begin) {
- int i;
+ unsigned u; /* Local index variable */
- for(i = 0; i < f->shared->ncwfs; i++)
- if(f->shared->cwfs[i] == heap) {
- if(i) {
- f->shared->cwfs[i] = f->shared->cwfs[i - 1];
- f->shared->cwfs[i - 1] = heap;
+ for(u = 0; u < f->shared->ncwfs; u++)
+ if(f->shared->cwfs[u] == heap) {
+ if(u) {
+ f->shared->cwfs[u] = f->shared->cwfs[u - 1];
+ f->shared->cwfs[u - 1] = heap;
} /* end if */
break;
} /* end if */
@@ -691,7 +691,7 @@ H5HG_read(H5F_t *f, hid_t dxpl_id, H5HG_t *hobj, void *object/*out*/,
ret_value = object;
done:
- if(heap && H5AC_unprotect(f, dxpl_id, H5AC_GHEAP, hobj->addr, heap, H5AC__NO_FLAGS_SET)<0)
+ if(heap && H5AC_unprotect(f, dxpl_id, H5AC_GHEAP, hobj->addr, heap, H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_HEAP, H5E_PROTECT, NULL, "unable to release object header")
if(NULL == ret_value && NULL == orig_object && object)
@@ -838,22 +838,20 @@ H5HG_remove (H5F_t *f, hid_t dxpl_id, H5HG_t *hobj)
flags |= H5AC__DELETED_FLAG | H5AC__FREE_FILE_SPACE_FLAG; /* Indicate that the object was deleted, for the unprotect call */
} /* end if */
else {
- int i; /* Local index variable */
-
/*
* If the heap is in the CWFS list then advance it one position. The
* H5AC_protect() might have done that too, but that's okay. If the
* heap isn't on the CWFS list then add it to the end.
*/
- for(i = 0; i < f->shared->ncwfs; i++)
- if(f->shared->cwfs[i] == heap) {
- if(i) {
- f->shared->cwfs[i] = f->shared->cwfs[i - 1];
- f->shared->cwfs[i - 1] = heap;
+ for(u = 0; u < f->shared->ncwfs; u++)
+ if(f->shared->cwfs[u] == heap) {
+ if(u) {
+ f->shared->cwfs[u] = f->shared->cwfs[u - 1];
+ f->shared->cwfs[u - 1] = heap;
} /* end if */
break;
} /* end if */
- if(i >= f->shared->ncwfs) {
+ if(u >= f->shared->ncwfs) {
f->shared->ncwfs = MIN(f->shared->ncwfs + 1, H5HG_NCWFS);
f->shared->cwfs[f->shared->ncwfs - 1] = heap;
} /* end if */
@@ -866,3 +864,44 @@ done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5HG_remove() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5HG_free
+ *
+ * Purpose: Destroys a global heap collection in memory
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Quincey Koziol
+ * Wednesday, January 15, 2003
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5HG_free(H5HG_heap_t *heap)
+{
+ unsigned u; /* Local index variable */
+
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5HG_free)
+
+ /* Check arguments */
+ HDassert(heap);
+
+ /* Remove the heap from the CWFS list */
+ for(u = 0; u < heap->shared->ncwfs; u++) {
+ if(heap->shared->cwfs[u] == heap) {
+ heap->shared->ncwfs -= 1;
+ HDmemmove(heap->shared->cwfs + u, heap->shared->cwfs + u + 1, (heap->shared->ncwfs - u) * sizeof(H5HG_heap_t *));
+ break;
+ } /* end if */
+ } /* end for */
+
+ if(heap->chunk)
+ heap->chunk = H5FL_BLK_FREE(gheap_chunk, heap->chunk);
+ if(heap->obj)
+ heap->obj = H5FL_SEQ_FREE(H5HG_obj_t, heap->obj);
+ heap = H5FL_FREE(H5HG_heap_t, heap);
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* H5HG_free() */
+
diff --git a/src/H5HGcache.c b/src/H5HGcache.c
index b7a701a..79a1526 100644
--- a/src/H5HGcache.c
+++ b/src/H5HGcache.c
@@ -67,6 +67,7 @@ static H5HG_heap_t *H5HG_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void
void *udata2);
static herr_t H5HG_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr,
H5HG_heap_t *heap, unsigned UNUSED * flags_ptr);
+static herr_t H5HG_dest(H5F_t *f, H5HG_heap_t *heap);
static herr_t H5HG_clear(H5F_t *f, H5HG_heap_t *heap, hbool_t destroy);
static herr_t H5HG_size(const H5F_t *f, const H5HG_heap_t *heap, size_t *size_ptr);
@@ -117,12 +118,12 @@ H5HG_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1,
void UNUSED * udata2)
{
H5HG_heap_t *heap = NULL;
- uint8_t *p = NULL;
+ uint8_t *p;
size_t nalloc, need;
size_t max_idx = 0; /* The maximum index seen */
H5HG_heap_t *ret_value = NULL; /* Return value */
- FUNC_ENTER_NOAPI(H5HG_load, NULL)
+ FUNC_ENTER_NOAPI_NOINIT(H5HG_load)
/* check arguments */
HDassert(f);
@@ -134,15 +135,17 @@ H5HG_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1,
if(NULL == (heap = H5FL_CALLOC(H5HG_heap_t)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
heap->addr = addr;
+ heap->shared = f->shared;
if(NULL == (heap->chunk = H5FL_BLK_MALLOC(gheap_chunk, (size_t)H5HG_MINSIZE)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
if(H5F_block_read(f, H5FD_MEM_GHEAP, addr, (size_t)H5HG_MINSIZE, dxpl_id, heap->chunk) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_READERROR, NULL, "unable to read global heap collection")
+ p = heap->chunk;
/* Magic number */
- if(HDmemcmp(heap->chunk, H5HG_MAGIC, (size_t)H5_SIZEOF_MAGIC))
+ if(HDmemcmp(p, H5HG_MAGIC, (size_t)H5_SIZEOF_MAGIC))
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, NULL, "bad global heap collection signature")
- p = heap->chunk + H5_SIZEOF_MAGIC;
+ p += H5_SIZEOF_MAGIC;
/* Version */
if(H5HG_VERSION != *p++)
@@ -186,7 +189,7 @@ H5HG_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1,
* assume that it's free space.
*/
HDassert(NULL == heap->obj[0].begin);
- heap->obj[0].size = (heap->chunk + heap->size) - p;
+ heap->obj[0].size = ((const uint8_t *)heap->chunk + heap->size) - p;
heap->obj[0].begin = p;
p += heap->obj[0].size;
} /* end if */
@@ -215,7 +218,7 @@ H5HG_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1,
/* Update heap information */
heap->nalloc = new_alloc;
heap->obj = new_obj;
- HDassert(heap->nalloc>heap->nused);
+ HDassert(heap->nalloc > heap->nused);
} /* end if */
UINT16DECODE(p, heap->obj[idx].nrefs);
@@ -259,8 +262,7 @@ H5HG_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1,
* free space than this heap.
*/
if(!f->shared->cwfs) {
- f->shared->cwfs = (H5HG_heap_t **)H5MM_malloc(H5HG_NCWFS * sizeof(H5HG_heap_t *));
- if(NULL == f->shared->cwfs)
+ if(NULL == (f->shared->cwfs = (H5HG_heap_t **)H5MM_malloc(H5HG_NCWFS * sizeof(H5HG_heap_t *))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
f->shared->ncwfs = 1;
f->shared->cwfs[0] = heap;
@@ -283,7 +285,7 @@ H5HG_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * udata1,
done:
if(!ret_value && heap)
- if(H5HG_dest(f, heap) < 0)
+ if(H5HG_free(heap) < 0)
HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, NULL, "unable to destroy global heap collection")
FUNC_LEAVE_NOAPI(ret_value)
@@ -308,7 +310,7 @@ H5HG_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5HG_heap_t *
{
herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5HG_flush, FAIL)
+ FUNC_ENTER_NOAPI_NOINIT(H5HG_flush)
/* Check arguments */
HDassert(f);
@@ -343,10 +345,9 @@ done:
*
*-------------------------------------------------------------------------
*/
-herr_t
+static herr_t
H5HG_dest(H5F_t *f, H5HG_heap_t *heap)
{
- int i; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5HG_dest)
@@ -368,20 +369,9 @@ H5HG_dest(H5F_t *f, H5HG_heap_t *heap)
HGOTO_ERROR(H5E_BTREE, H5E_CANTFREE, FAIL, "unable to free global heap")
} /* end if */
- /* Remove heap from NCWFS array, if it's present */
- for(i = 0; i < f->shared->ncwfs; i++)
- if(f->shared->cwfs[i] == heap) {
- f->shared->ncwfs -= 1;
- HDmemmove(f->shared->cwfs + i, f->shared->cwfs + i + 1, (f->shared->ncwfs - i) * sizeof(H5HG_heap_t *));
- break;
- } /* end if */
-
- /* Release resources */
- if(heap->chunk)
- heap->chunk = H5FL_BLK_FREE(gheap_chunk, heap->chunk);
- if(heap->obj)
- heap->obj = H5FL_SEQ_FREE(H5HG_obj_t, heap->obj);
- heap = H5FL_FREE(H5HG_heap_t, heap);
+ /* Destroy global heap collection */
+ if(H5HG_free(heap) < 0)
+ HGOTO_ERROR(H5E_HEAP, H5E_CANTFREE, FAIL, "unable to destroy global heap collection")
done:
FUNC_LEAVE_NOAPI(ret_value)
diff --git a/src/H5HGdbg.c b/src/H5HGdbg.c
index bda9832..07de139 100644
--- a/src/H5HGdbg.c
+++ b/src/H5HGdbg.c
@@ -67,13 +67,13 @@ H5HG_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent,
FUNC_ENTER_NOAPI(H5HG_debug, FAIL);
/* check arguments */
- assert(f);
- assert(H5F_addr_defined (addr));
- assert(stream);
- assert(indent >= 0);
- assert(fwidth >= 0);
+ HDassert(f);
+ HDassert(H5F_addr_defined (addr));
+ HDassert(stream);
+ HDassert(indent >= 0);
+ HDassert(fwidth >= 0);
- if (NULL == (h = (H5HG_heap_t *)H5AC_protect(f, dxpl_id, H5AC_GHEAP, addr, NULL, NULL, H5AC_READ)))
+ if(NULL == (h = (H5HG_heap_t *)H5AC_protect(f, dxpl_id, H5AC_GHEAP, addr, NULL, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load global heap collection");
fprintf(stream, "%*sGlobal Heap Collection...\n", indent, "");
@@ -135,7 +135,7 @@ H5HG_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent,
}
done:
- if (h && H5AC_unprotect(f, dxpl_id, H5AC_GHEAP, addr, h, H5AC__NO_FLAGS_SET) != SUCCEED)
+ if (h && H5AC_unprotect(f, dxpl_id, H5AC_GHEAP, addr, h, H5AC__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release object header");
FUNC_LEAVE_NOAPI(ret_value);
diff --git a/src/H5HGpkg.h b/src/H5HGpkg.h
index 96be009..7ce18c9 100644
--- a/src/H5HGpkg.h
+++ b/src/H5HGpkg.h
@@ -128,6 +128,9 @@ typedef struct H5HG_obj_t {
uint8_t *begin; /*ptr to object into heap->chunk*/
} H5HG_obj_t;
+/* Forward declarations for fields */
+struct H5F_file_t;
+
struct H5HG_heap_t {
H5AC_info_t cache_info; /* Information for H5AC cache functions, _must_ be */
/* first field in structure */
@@ -139,13 +142,14 @@ struct H5HG_heap_t {
/* If this value is >65535 then all indices */
/* have been used at some time and the */
/* correct new index should be searched for */
+ struct H5F_file_t *shared; /* shared file */
H5HG_obj_t *obj; /*array of object descriptions */
};
/******************************/
/* Package Private Prototypes */
/******************************/
-H5_DLL herr_t H5HG_dest(H5F_t *f, H5HG_heap_t *heap);
+H5_DLL herr_t H5HG_free(H5HG_heap_t *heap);
#endif /* _H5HGpkg_H */