summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5HL.c17
-rw-r--r--src/H5HLcache.c28
-rw-r--r--src/H5HLpkg.h6
3 files changed, 22 insertions, 29 deletions
diff --git a/src/H5HL.c b/src/H5HL.c
index d806308..e37eb9f 100644
--- a/src/H5HL.c
+++ b/src/H5HL.c
@@ -153,9 +153,12 @@ H5HL_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, haddr_t *addr_p/*out*/)
heap->freelist->offset = 0;
heap->freelist->size = size_hint;
heap->freelist->prev = heap->freelist->next = NULL;
+ heap->free_block = 0;
} /* end if */
- else
+ else {
heap->freelist = NULL;
+ heap->free_block = H5HL_FREE_NULL;
+ } /* end else */
/* Allocate the heap prefix */
if(NULL == (prfx = H5HL_prfx_new(heap)))
@@ -459,8 +462,6 @@ H5HL_protect(H5F_t *f, hid_t dxpl_id, haddr_t addr, H5AC_protect_t rw)
prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f);
prfx_udata.prfx_addr = addr;
prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f);
- prfx_udata.loaded = FALSE;
- prfx_udata.free_block = H5HL_FREE_NULL;
/* Protect the local heap prefix */
if(NULL == (prfx = (H5HL_prfx_t *)H5AC_protect(f, dxpl_id, H5AC_LHEAP_PRFX, addr, &prfx_udata, rw)))
@@ -482,8 +483,6 @@ H5HL_protect(H5F_t *f, hid_t dxpl_id, haddr_t addr, H5AC_protect_t rw)
/* Construct the user data for protect callback */
dblk_udata.heap = heap;
- dblk_udata.free_block = prfx_udata.loaded ? prfx_udata.free_block :
- (heap->freelist ? heap->freelist->offset : H5HL_FREE_NULL);
dblk_udata.loaded = FALSE;
/* Protect the local heap data block */
@@ -1076,8 +1075,6 @@ H5HL_delete(H5F_t *f, hid_t dxpl_id, haddr_t addr)
prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f);
prfx_udata.prfx_addr = addr;
prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f);
- prfx_udata.loaded = FALSE;
- prfx_udata.free_block = H5HL_FREE_NULL;
/* Protect the local heap prefix */
if(NULL == (prfx = (H5HL_prfx_t *)H5AC_protect(f, dxpl_id, H5AC_LHEAP_PRFX, addr, &prfx_udata, H5AC_WRITE)))
@@ -1092,8 +1089,6 @@ H5HL_delete(H5F_t *f, hid_t dxpl_id, haddr_t addr)
/* Construct the user data for protect callback */
dblk_udata.heap = heap;
- dblk_udata.free_block = prfx_udata.loaded ? prfx_udata.free_block :
- (heap->freelist ? heap->freelist->offset : H5HL_FREE_NULL);
dblk_udata.loaded = FALSE;
/* Protect the local heap data block */
@@ -1156,8 +1151,6 @@ H5HL_get_size(H5F_t *f, hid_t dxpl_id, haddr_t addr, size_t *size)
prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f);
prfx_udata.prfx_addr = addr;
prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f);
- prfx_udata.loaded = FALSE;
- prfx_udata.free_block = H5HL_FREE_NULL;
/* Protect the local heap prefix */
if(NULL == (prfx = (H5HL_prfx_t *)H5AC_protect(f, dxpl_id, H5AC_LHEAP_PRFX, addr, &prfx_udata, H5AC_READ)))
@@ -1210,8 +1203,6 @@ H5HL_heapsize(H5F_t *f, hid_t dxpl_id, haddr_t addr, hsize_t *heap_size)
prfx_udata.sizeof_addr = H5F_SIZEOF_ADDR(f);
prfx_udata.prfx_addr = addr;
prfx_udata.sizeof_prfx = H5HL_SIZEOF_HDR(f);
- prfx_udata.loaded = FALSE;
- prfx_udata.free_block = H5HL_FREE_NULL;
/* Protect the local heap prefix */
if(NULL == (prfx = (H5HL_prfx_t *)H5AC_protect(f, dxpl_id, H5AC_LHEAP_PRFX, addr, &prfx_udata, H5AC_READ)))
diff --git a/src/H5HLcache.c b/src/H5HLcache.c
index 56d9919..daf1d87 100644
--- a/src/H5HLcache.c
+++ b/src/H5HLcache.c
@@ -134,9 +134,10 @@ const H5AC_class_t H5AC_LHEAP_DBLK[1] = {{
*-------------------------------------------------------------------------
*/
static herr_t
-H5HL_fl_deserialize(H5HL_t *heap, hsize_t free_block)
+H5HL_fl_deserialize(H5HL_t *heap)
{
H5HL_free_t *fl = NULL, *tail = NULL; /* Heap free block nodes */
+ hsize_t free_block; /* Offset of free block */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5HL_fl_deserialize)
@@ -146,6 +147,7 @@ H5HL_fl_deserialize(H5HL_t *heap, hsize_t free_block)
HDassert(!heap->freelist);
/* Build free list */
+ free_block = heap->free_block;
while(H5HL_FREE_NULL != free_block) {
const uint8_t *p; /* Pointer into image buffer */
@@ -310,8 +312,8 @@ H5HL_prefix_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)
H5F_DECODE_LENGTH_LEN(p, heap->dblk_size, udata->sizeof_size);
/* Free list head */
- H5F_DECODE_LENGTH_LEN(p, udata->free_block, udata->sizeof_size);
- if(udata->free_block != H5HL_FREE_NULL && udata->free_block >= heap->dblk_size)
+ H5F_DECODE_LENGTH_LEN(p, heap->free_block, udata->sizeof_size);
+ if(heap->free_block != H5HL_FREE_NULL && heap->free_block >= heap->dblk_size)
HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, NULL, "bad heap free list")
/* Heap data address */
@@ -345,7 +347,7 @@ H5HL_prefix_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)
} /* end else */
/* Build free list */
- if(H5HL_fl_deserialize(heap, udata->free_block) < 0)
+ if(H5HL_fl_deserialize(heap) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, NULL, "can't initialize free list")
} /* end if */
else
@@ -353,9 +355,6 @@ H5HL_prefix_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)
heap->single_cache_obj = FALSE;
} /* end if */
- /* Set flag to indicate prefix from loaded from file */
- udata->loaded = TRUE;
-
/* Set return value */
ret_value = prfx;
@@ -408,7 +407,6 @@ H5HL_prefix_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr,
if(prfx->cache_info.is_dirty) {
H5HL_t *heap = prfx->heap; /* Pointer to the local heap */
- H5HL_free_t *fl = heap->freelist; /* Pointer to heap's free list */
uint8_t *buf; /* Pointer to heap buffer */
size_t buf_size; /* Size of buffer for encoding & writing heap info */
uint8_t *p; /* Pointer into raw data buffer */
@@ -426,6 +424,9 @@ H5HL_prefix_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr,
if(NULL == (buf = (uint8_t *)H5WB_actual(wb, buf_size)))
HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "can't get actual buffer")
+ /* Update the free block value from the free list */
+ heap->free_block = heap->freelist ? heap->freelist->offset : H5HL_FREE_NULL;
+
/* Serialize the heap prefix */
p = buf;
HDmemcpy(p, H5HL_MAGIC, (size_t)H5_SIZEOF_MAGIC);
@@ -435,18 +436,18 @@ H5HL_prefix_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr,
*p++ = 0; /*reserved*/
*p++ = 0; /*reserved*/
H5F_ENCODE_LENGTH_LEN(p, heap->dblk_size, heap->sizeof_size);
- H5F_ENCODE_LENGTH_LEN(p, fl ? fl->offset : H5HL_FREE_NULL, heap->sizeof_size);
+ H5F_ENCODE_LENGTH_LEN(p, heap->free_block, heap->sizeof_size);
H5F_addr_encode_len(heap->sizeof_addr, &p, heap->dblk_addr);
/* Check if the local heap is a single object in cache */
if(heap->single_cache_obj) {
- if((p - buf) < heap->prfx_size) {
+ if((size_t)(p - buf) < heap->prfx_size) {
size_t gap; /* Size of gap between prefix and data block */
/* Set p to the start of the data block. This is necessary because
* there may be a gap between the used portion of the prefix and the
* data block due to alignment constraints. */
- gap = heap->prfx_size - (p - buf);
+ gap = heap->prfx_size - (size_t)(p - buf);
HDmemset(p, 0, gap);
p += gap;
} /* end if */
@@ -654,7 +655,7 @@ H5HL_datablock_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *_udata)
HGOTO_ERROR(H5E_HEAP, H5E_READERROR, NULL, "unable to read local heap data block")
/* Build free list */
- if(H5HL_fl_deserialize(udata->heap, udata->free_block) < 0)
+ if(H5HL_fl_deserialize(udata->heap) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, NULL, "can't initialize free list")
} /* end if */
@@ -707,6 +708,9 @@ H5HL_datablock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr,
if(dblk->cache_info.is_dirty) {
H5HL_t *heap = dblk->heap; /* Pointer to the local heap */
+ /* Update the free block value from the free list */
+ heap->free_block = heap->freelist ? heap->freelist->offset : H5HL_FREE_NULL;
+
/* Serialize the free list into the heap data's image */
H5HL_fl_serialize(heap);
diff --git a/src/H5HLpkg.h b/src/H5HLpkg.h
index b7e0ece..bf9be2c 100644
--- a/src/H5HLpkg.h
+++ b/src/H5HLpkg.h
@@ -90,18 +90,19 @@ struct H5HL_t {
size_t sizeof_size; /* Size of file sizes */
size_t sizeof_addr; /* Size of file addresses */
hbool_t single_cache_obj; /* Indicate if the heap is a single object in the cache */
+ H5HL_free_t *freelist; /*the free list */
/* Prefix-specific fields */
H5HL_prfx_t *prfx; /* The prefix object for the heap */
haddr_t prfx_addr; /* address of heap prefix */
size_t prfx_size; /* size of heap prefix */
+ hsize_t free_block; /* Address of first free block */
/* Data block-specific fields */
H5HL_dblk_t *dblk; /* The data block object for the heap */
haddr_t dblk_addr; /* address of data block */
size_t dblk_size; /* size of heap data block on disk and in mem */
uint8_t *dblk_image; /* The data block image */
- H5HL_free_t *freelist; /*the free list */
};
/* Struct for heap data block */
@@ -127,15 +128,12 @@ typedef struct H5HL_cache_prfx_ud_t {
size_t sizeof_prfx; /* Size of heap prefix */
/* Upwards */
- hbool_t loaded; /* Whether prefix was loaded from file */
- hsize_t free_block; /* First free block in heap */
} H5HL_cache_prfx_ud_t;
/* Callback information for loading local heap data block from disk */
typedef struct H5HL_cache_dblk_ud_t {
/* Downwards */
H5HL_t *heap; /* Local heap */
- hsize_t free_block; /* First free block in heap */
/* Upwards */
hbool_t loaded; /* Whether data block was loaded from file */