2006-04-16 05:11:42 +08:00
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
|
* All rights reserved. *
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
|
|
|
|
* the files COPYING and Copyright.html. COPYING can be found at the root *
|
|
|
|
|
* of the source code distribution tree; Copyright.html can be found at the *
|
|
|
|
|
* root level of an installed copy of the electronic HDF5 document set and *
|
|
|
|
|
* is linked from the top-level documents page. It can also be found at *
|
|
|
|
|
* http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
|
|
|
|
|
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
|
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* Created: H5HFhdr.c
|
|
|
|
|
* Apr 10 2006
|
|
|
|
|
* Quincey Koziol <koziol@ncsa.uiuc.edu>
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Heap header routines for fractal heaps.
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/****************/
|
|
|
|
|
/* Module Setup */
|
|
|
|
|
/****************/
|
|
|
|
|
|
|
|
|
|
#define H5HF_PACKAGE /*suppress error about including H5HFpkg */
|
|
|
|
|
|
|
|
|
|
/***********/
|
|
|
|
|
/* Headers */
|
|
|
|
|
/***********/
|
|
|
|
|
#include "H5private.h" /* Generic Functions */
|
|
|
|
|
#include "H5Eprivate.h" /* Error handling */
|
|
|
|
|
#include "H5HFpkg.h" /* Fractal heaps */
|
|
|
|
|
#include "H5Vprivate.h" /* Vectors and arrays */
|
|
|
|
|
|
|
|
|
|
/****************/
|
|
|
|
|
/* Local Macros */
|
|
|
|
|
/****************/
|
|
|
|
|
|
|
|
|
|
/* Limit on the size of the max. direct block size */
|
|
|
|
|
/* (This is limited to 32-bits currently, because I think it's unlikely to
|
|
|
|
|
* need to be larger, the 32-bit limit for H5V_log2_of2(n), and
|
|
|
|
|
* some offsets/sizes are encoded with a maxiumum of 32-bits - QAK)
|
|
|
|
|
*/
|
2006-05-15 12:35:53 +08:00
|
|
|
|
#define H5HF_MAX_DIRECT_SIZE_LIMIT ((hsize_t)2 * 1024 * 1024 * 1024)
|
|
|
|
|
|
|
|
|
|
/* Limit on the width of the doubling table */
|
|
|
|
|
/* (This is limited to 16-bits currently, because I think it's unlikely to
|
|
|
|
|
* need to be larger, and its encoded with a maxiumum of 16-bits - QAK)
|
|
|
|
|
*/
|
|
|
|
|
#define H5HF_WIDTH_LIMIT (64 * 1024)
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
/******************/
|
|
|
|
|
/* Local Typedefs */
|
|
|
|
|
/******************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************/
|
|
|
|
|
/* Package Typedefs */
|
|
|
|
|
/********************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************/
|
|
|
|
|
/* Local Prototypes */
|
|
|
|
|
/********************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************/
|
|
|
|
|
/* Package Variables */
|
|
|
|
|
/*********************/
|
|
|
|
|
|
2006-05-15 12:35:53 +08:00
|
|
|
|
/* Declare a free list to manage the H5HF_hdr_t struct */
|
|
|
|
|
H5FL_DEFINE(H5HF_hdr_t);
|
|
|
|
|
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
/*****************************/
|
|
|
|
|
/* Library Private Variables */
|
|
|
|
|
/*****************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*******************/
|
|
|
|
|
/* Local Variables */
|
|
|
|
|
/*******************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5HF_hdr_alloc
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Allocate shared fractal heap header
|
|
|
|
|
*
|
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* koziol@ncsa.uiuc.edu
|
|
|
|
|
* Mar 21 2006
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2006-04-30 21:32:41 +08:00
|
|
|
|
H5HF_hdr_t *
|
2006-04-16 05:11:42 +08:00
|
|
|
|
H5HF_hdr_alloc(H5F_t *f)
|
|
|
|
|
{
|
2006-04-30 21:32:41 +08:00
|
|
|
|
H5HF_hdr_t *hdr = NULL; /* Shared fractal heap header */
|
|
|
|
|
H5HF_hdr_t *ret_value = NULL; /* Return value */
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
FUNC_ENTER_NOAPI_NOINIT(H5HF_hdr_alloc)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check arguments.
|
|
|
|
|
*/
|
|
|
|
|
HDassert(f);
|
|
|
|
|
|
|
|
|
|
/* Allocate space for the shared information */
|
2006-04-30 21:32:41 +08:00
|
|
|
|
if(NULL == (hdr = H5FL_CALLOC(H5HF_hdr_t)))
|
2006-04-16 05:11:42 +08:00
|
|
|
|
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for fractal heap shared header")
|
|
|
|
|
|
|
|
|
|
/* Set the internal parameters for the heap */
|
2006-04-30 21:32:41 +08:00
|
|
|
|
hdr->f = f;
|
|
|
|
|
hdr->sizeof_size = H5F_SIZEOF_SIZE(f);
|
|
|
|
|
hdr->sizeof_addr = H5F_SIZEOF_ADDR(f);
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
/* Set the return value */
|
2006-04-30 21:32:41 +08:00
|
|
|
|
ret_value = hdr;
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
if(!ret_value)
|
2006-04-30 21:32:41 +08:00
|
|
|
|
if(hdr)
|
|
|
|
|
(void)H5HF_cache_hdr_dest(f, hdr);
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
|
|
|
|
} /* end H5HF_hdr_alloc() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5HF_hdr_free_space
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Compute direct block free space, for indirect blocks of
|
|
|
|
|
* different sizes.
|
|
|
|
|
*
|
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* koziol@ncsa.uiuc.edu
|
|
|
|
|
* Mar 21 2006
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static hsize_t
|
2006-04-30 21:32:41 +08:00
|
|
|
|
H5HF_hdr_compute_free_space(H5HF_hdr_t *hdr, hsize_t iblock_size)
|
2006-04-16 05:11:42 +08:00
|
|
|
|
{
|
|
|
|
|
hsize_t acc_heap_size; /* Accumumated heap space */
|
|
|
|
|
hsize_t acc_dblock_free; /* Accumumated direct block free space */
|
|
|
|
|
unsigned curr_row; /* Current row in block */
|
|
|
|
|
hsize_t ret_value; /* Return value */
|
|
|
|
|
|
|
|
|
|
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5HF_hdr_compute_free_space)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check arguments.
|
|
|
|
|
*/
|
|
|
|
|
HDassert(hdr);
|
|
|
|
|
HDassert(iblock_size > hdr->man_dtable.cparam.max_direct_size);
|
|
|
|
|
|
|
|
|
|
/* Set the free space in direct blocks */
|
|
|
|
|
acc_heap_size = 0;
|
|
|
|
|
acc_dblock_free = 0;
|
|
|
|
|
curr_row = 0;
|
|
|
|
|
while(acc_heap_size < iblock_size) {
|
|
|
|
|
acc_heap_size += hdr->man_dtable.row_block_size[curr_row] *
|
|
|
|
|
hdr->man_dtable.cparam.width;
|
|
|
|
|
acc_dblock_free += hdr->man_dtable.row_dblock_free[curr_row] *
|
|
|
|
|
hdr->man_dtable.cparam.width;
|
|
|
|
|
curr_row++;
|
|
|
|
|
} /* end while */
|
|
|
|
|
|
|
|
|
|
/* Set return value */
|
|
|
|
|
ret_value = acc_dblock_free;
|
|
|
|
|
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
|
|
|
|
} /* end H5HF_hdr_compute_free_space() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5HF_hdr_finish_init
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Finish initializing info in shared heap header
|
|
|
|
|
*
|
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* koziol@ncsa.uiuc.edu
|
|
|
|
|
* Mar 21 2006
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
herr_t
|
2006-04-30 21:32:41 +08:00
|
|
|
|
H5HF_hdr_finish_init(H5HF_hdr_t *hdr)
|
2006-04-16 05:11:42 +08:00
|
|
|
|
{
|
2006-05-15 12:35:53 +08:00
|
|
|
|
unsigned u; /* Local index variable */
|
2006-04-16 05:11:42 +08:00
|
|
|
|
herr_t ret_value = SUCCEED; /* Return value */
|
|
|
|
|
|
|
|
|
|
FUNC_ENTER_NOAPI_NOINIT(H5HF_hdr_finish_init)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check arguments.
|
|
|
|
|
*/
|
|
|
|
|
HDassert(hdr);
|
|
|
|
|
|
|
|
|
|
/* Compute/cache some values */
|
|
|
|
|
hdr->heap_off_size = H5HF_SIZEOF_OFFSET_BITS(hdr->man_dtable.cparam.max_index);
|
|
|
|
|
if(H5HF_dtable_init(&hdr->man_dtable) < 0)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't initialize doubling table info")
|
|
|
|
|
|
|
|
|
|
/* Set the size of heap IDs */
|
2006-05-23 00:43:45 +08:00
|
|
|
|
hdr->heap_len_size = MIN(hdr->man_dtable.max_dir_blk_off_size,
|
|
|
|
|
((H5V_log2_gen((hsize_t)hdr->standalone_size) + 7) / 8));
|
|
|
|
|
hdr->id_len = hdr->heap_off_size + hdr->heap_len_size;
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
/* Set the free space in direct blocks */
|
|
|
|
|
for(u = 0; u < hdr->man_dtable.max_root_rows; u++) {
|
|
|
|
|
if(u < hdr->man_dtable.max_direct_rows)
|
|
|
|
|
hdr->man_dtable.row_dblock_free[u] = hdr->man_dtable.row_block_size[u] -
|
2006-05-15 12:35:53 +08:00
|
|
|
|
H5HF_MAN_ABS_DIRECT_OVERHEAD(hdr);
|
2006-04-16 05:11:42 +08:00
|
|
|
|
else
|
|
|
|
|
hdr->man_dtable.row_dblock_free[u] = H5HF_hdr_compute_free_space(hdr, hdr->man_dtable.row_block_size[u]);
|
|
|
|
|
#ifdef QAK
|
|
|
|
|
HDfprintf(stderr, "%s: row_block_size[%Zu] = %Hu\n", FUNC, u, hdr->man_dtable.row_block_size[u]);
|
|
|
|
|
HDfprintf(stderr, "%s: row_block_off[%Zu] = %Hu\n", FUNC, u, hdr->man_dtable.row_block_off[u]);
|
|
|
|
|
HDfprintf(stderr, "%s: row_dblock_free[%Zu] = %Hu\n", FUNC, u, hdr->man_dtable.row_dblock_free[u]);
|
|
|
|
|
#endif /* QAK */
|
|
|
|
|
} /* end for */
|
|
|
|
|
|
2006-04-30 21:32:41 +08:00
|
|
|
|
/* Initialize the block iterator for searching for free space */
|
|
|
|
|
if(H5HF_man_iter_init(&hdr->next_block) < 0)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't initialize space search block iterator")
|
|
|
|
|
|
2006-04-16 05:11:42 +08:00
|
|
|
|
done:
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
|
|
|
|
} /* end H5HF_hdr_finish_init() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5HF_hdr_init
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Initialize shared fractal heap header for new heap
|
|
|
|
|
*
|
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* koziol@ncsa.uiuc.edu
|
|
|
|
|
* Mar 21 2006
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
herr_t
|
2006-04-30 21:32:41 +08:00
|
|
|
|
H5HF_hdr_init(H5HF_hdr_t *hdr, haddr_t fh_addr, H5HF_create_t *cparam)
|
2006-04-16 05:11:42 +08:00
|
|
|
|
{
|
|
|
|
|
herr_t ret_value = SUCCEED; /* Return value */
|
|
|
|
|
|
|
|
|
|
FUNC_ENTER_NOAPI_NOINIT(H5HF_hdr_init)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check arguments.
|
|
|
|
|
*/
|
2006-04-30 21:32:41 +08:00
|
|
|
|
HDassert(hdr);
|
2006-04-16 05:11:42 +08:00
|
|
|
|
HDassert(cparam);
|
|
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
/* Check for valid parameters */
|
2006-05-15 12:35:53 +08:00
|
|
|
|
if(cparam->managed.width == 0)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "width must be greater than zero")
|
|
|
|
|
if(cparam->managed.width > H5HF_WIDTH_LIMIT)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "width too large")
|
|
|
|
|
if(!POWER_OF_TWO(cparam->managed.width))
|
2006-04-16 05:11:42 +08:00
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "width not power of two")
|
2006-05-15 12:35:53 +08:00
|
|
|
|
if(cparam->managed.start_block_size == 0)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "starting block size must be greater than zero")
|
|
|
|
|
if(!POWER_OF_TWO(cparam->managed.start_block_size))
|
2006-04-16 05:11:42 +08:00
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "starting block size not power of two")
|
2006-05-15 12:35:53 +08:00
|
|
|
|
if(cparam->managed.max_direct_size == 0)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "max. direct block size must be greater than zero")
|
|
|
|
|
if(cparam->managed.max_direct_size > H5HF_MAX_DIRECT_SIZE_LIMIT)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "max. direct block size too large")
|
|
|
|
|
if(!POWER_OF_TWO(cparam->managed.max_direct_size))
|
2006-04-16 05:11:42 +08:00
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "max. direct block size not power of two")
|
|
|
|
|
if(cparam->managed.max_direct_size < cparam->standalone_size)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "max. direct block size not large enough to hold all managed blocks")
|
2006-05-15 12:35:53 +08:00
|
|
|
|
if(cparam->managed.max_index == 0)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "max. heap size must be greater than zero")
|
|
|
|
|
if(cparam->managed.max_index > (8 * hdr->sizeof_size))
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, FAIL, "max. heap size too large for file")
|
2006-04-16 05:11:42 +08:00
|
|
|
|
#endif /* NDEBUG */
|
|
|
|
|
|
|
|
|
|
/* Set the creation parameters for the heap */
|
2006-04-30 21:32:41 +08:00
|
|
|
|
hdr->heap_addr = fh_addr;
|
|
|
|
|
hdr->addrmap = cparam->addrmap;
|
|
|
|
|
hdr->standalone_size = cparam->standalone_size;
|
|
|
|
|
HDmemcpy(&(hdr->man_dtable.cparam), &(cparam->managed), sizeof(H5HF_dtable_cparam_t));
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
2006-05-15 12:35:53 +08:00
|
|
|
|
/* Set root table address to indicate that the heap is empty currently */
|
2006-04-30 21:32:41 +08:00
|
|
|
|
hdr->man_dtable.table_addr = HADDR_UNDEF;
|
|
|
|
|
|
2006-05-15 12:35:53 +08:00
|
|
|
|
/* Set free list header address to indicate that the heap is empty currently */
|
|
|
|
|
hdr->fs_addr = HADDR_UNDEF;
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
/* Note that the shared info is dirty (it's not written to the file yet) */
|
2006-04-30 21:32:41 +08:00
|
|
|
|
hdr->dirty = TRUE;
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
/* Make shared heap info reference counted */
|
2006-04-30 21:32:41 +08:00
|
|
|
|
if(H5HF_hdr_finish_init(hdr) < 0)
|
2006-04-16 05:11:42 +08:00
|
|
|
|
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't create ref-count wrapper for shared fractal heap header")
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
if(ret_value < 0)
|
2006-04-30 21:32:41 +08:00
|
|
|
|
if(hdr)
|
|
|
|
|
(void)H5HF_cache_hdr_dest(NULL, hdr);
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
|
|
|
|
} /* end H5HF_hdr_init() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5HF_hdr_incr
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Increment reference count on shared heap header
|
|
|
|
|
*
|
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* koziol@ncsa.uiuc.edu
|
|
|
|
|
* Mar 27 2006
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
herr_t
|
2006-04-30 21:32:41 +08:00
|
|
|
|
H5HF_hdr_incr(H5HF_hdr_t *hdr)
|
2006-04-16 05:11:42 +08:00
|
|
|
|
{
|
2006-04-30 21:32:41 +08:00
|
|
|
|
herr_t ret_value = SUCCEED; /* Return value */
|
|
|
|
|
|
|
|
|
|
FUNC_ENTER_NOAPI_NOINIT(H5HF_hdr_incr)
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
|
HDassert(hdr);
|
|
|
|
|
|
|
|
|
|
/* XXX: When "un-evictable" feature is finished, mark the header as
|
|
|
|
|
* unevictable on the first block to share it. - QAK
|
|
|
|
|
*/
|
2006-04-30 21:32:41 +08:00
|
|
|
|
/* Mark header as un-evictable when a block is depending on it */
|
|
|
|
|
if(hdr->rc == 0)
|
|
|
|
|
if(H5AC_pin_protected_entry(hdr->f, hdr) < 0)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_CANTPIN, FAIL, "unable to pin fractal heap header")
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
/* Increment reference count on shared header */
|
|
|
|
|
hdr->rc++;
|
|
|
|
|
|
2006-04-30 21:32:41 +08:00
|
|
|
|
done:
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
2006-04-16 05:11:42 +08:00
|
|
|
|
} /* end H5HF_hdr_incr() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5HF_hdr_decr
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Decrement reference count on shared heap header
|
|
|
|
|
*
|
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* koziol@ncsa.uiuc.edu
|
|
|
|
|
* Mar 27 2006
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
herr_t
|
2006-04-30 21:32:41 +08:00
|
|
|
|
H5HF_hdr_decr(H5HF_hdr_t *hdr)
|
2006-04-16 05:11:42 +08:00
|
|
|
|
{
|
2006-04-30 21:32:41 +08:00
|
|
|
|
herr_t ret_value = SUCCEED; /* Return value */
|
|
|
|
|
|
|
|
|
|
FUNC_ENTER_NOAPI_NOINIT(H5HF_hdr_decr)
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
|
HDassert(hdr);
|
|
|
|
|
|
|
|
|
|
/* Decrement reference count on shared header */
|
|
|
|
|
hdr->rc--;
|
|
|
|
|
|
2006-04-30 21:32:41 +08:00
|
|
|
|
/* Mark header as evictable again when no child blocks depend on it */
|
|
|
|
|
if(hdr->rc == 0)
|
|
|
|
|
if(H5AC_unpin_entry(hdr->f, hdr) < 0)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_CANTUNPIN, FAIL, "unable to unpin fractal heap header")
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
2006-04-30 21:32:41 +08:00
|
|
|
|
done:
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
2006-04-16 05:11:42 +08:00
|
|
|
|
} /* end H5HF_hdr_decr() */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5HF_hdr_dirty
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Mark heap header as dirty
|
|
|
|
|
*
|
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* koziol@ncsa.uiuc.edu
|
|
|
|
|
* Mar 27 2006
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
herr_t
|
2006-04-30 21:32:41 +08:00
|
|
|
|
H5HF_hdr_dirty(H5HF_hdr_t *hdr)
|
2006-04-16 05:11:42 +08:00
|
|
|
|
{
|
|
|
|
|
herr_t ret_value = SUCCEED; /* Return value */
|
|
|
|
|
|
|
|
|
|
FUNC_ENTER_NOAPI_NOINIT(H5HF_hdr_dirty)
|
|
|
|
|
#ifdef QAK
|
|
|
|
|
HDfprintf(stderr, "%s: Marking heap header as dirty\n", FUNC);
|
|
|
|
|
#endif /* QAK */
|
|
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
|
HDassert(hdr);
|
|
|
|
|
|
2006-04-30 21:32:41 +08:00
|
|
|
|
/* Mark header as dirty in cache */
|
|
|
|
|
if(H5AC_mark_pinned_entry_dirty(hdr->f, hdr, FALSE, 0) < 0)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_CANTMARKDIRTY, FAIL, "unable to mark fractal heap header as dirty")
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
/* Set the dirty flags for the heap header */
|
|
|
|
|
hdr->dirty = TRUE;
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
|
|
|
|
} /* end H5HF_hdr_dirty() */
|
|
|
|
|
|
2006-05-15 12:35:53 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5HF_hdr_adj_free
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Adjust the free space for a heap
|
|
|
|
|
*
|
|
|
|
|
* Return: SUCCEED/FAIL
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* koziol@ncsa.uiuc.edu
|
|
|
|
|
* May 9 2006
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
herr_t
|
|
|
|
|
H5HF_hdr_adj_free(H5HF_hdr_t *hdr, ssize_t amt)
|
|
|
|
|
{
|
|
|
|
|
herr_t ret_value = SUCCEED; /* Return value */
|
|
|
|
|
|
|
|
|
|
FUNC_ENTER_NOAPI_NOINIT(H5HF_hdr_adj_free)
|
|
|
|
|
#ifdef QAK
|
|
|
|
|
HDfprintf(stderr, "%s: amt = %Zd\n", FUNC, amt);
|
|
|
|
|
#endif /* QAK */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check arguments.
|
|
|
|
|
*/
|
|
|
|
|
HDassert(hdr);
|
|
|
|
|
|
|
|
|
|
/* Update heap header */
|
|
|
|
|
HDassert(amt > 0 || hdr->total_man_free >= (hsize_t)-amt);
|
|
|
|
|
hdr->total_man_free += amt;
|
|
|
|
|
#ifdef QAK
|
|
|
|
|
HDfprintf(stderr, "%s: hdr->total_man_free = %Hu\n", FUNC, hdr->total_man_free);
|
|
|
|
|
#endif /* QAK */
|
|
|
|
|
|
|
|
|
|
/* Mark heap header as modified */
|
|
|
|
|
if(H5HF_hdr_dirty(hdr) < 0)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, FAIL, "can't mark heap header as dirty")
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
|
|
|
|
} /* end H5HF_hdr_adj_free() */
|
|
|
|
|
|
2006-04-16 05:11:42 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5HF_hdr_extend_heap
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Extend heap to cover more space
|
|
|
|
|
*
|
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* koziol@ncsa.uiuc.edu
|
|
|
|
|
* Apr 10 2006
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
herr_t
|
2006-04-30 21:32:41 +08:00
|
|
|
|
H5HF_hdr_extend_heap(H5HF_hdr_t *hdr, hsize_t new_size, hsize_t extra_free)
|
2006-04-16 05:11:42 +08:00
|
|
|
|
{
|
|
|
|
|
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5HF_hdr_extend_heap)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check arguments.
|
|
|
|
|
*/
|
|
|
|
|
HDassert(hdr);
|
|
|
|
|
HDassert(new_size >= hdr->total_size);
|
|
|
|
|
|
|
|
|
|
/* Set the total space in heap */
|
|
|
|
|
hdr->total_size = new_size;
|
|
|
|
|
hdr->man_size = new_size;
|
|
|
|
|
|
|
|
|
|
/* Increment the free space in direct blocks */
|
|
|
|
|
hdr->total_man_free += extra_free;
|
|
|
|
|
|
|
|
|
|
FUNC_LEAVE_NOAPI(SUCCEED)
|
|
|
|
|
} /* end H5HF_hdr_extend_heap() */
|
|
|
|
|
|
2006-04-30 21:32:41 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5HF_hdr_inc_alloc
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Increase allocated size of heap
|
|
|
|
|
*
|
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* koziol@ncsa.uiuc.edu
|
|
|
|
|
* Apr 24 2006
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
herr_t
|
|
|
|
|
H5HF_hdr_inc_alloc(H5HF_hdr_t *hdr, hsize_t new_alloc_size, unsigned nentries)
|
|
|
|
|
{
|
|
|
|
|
herr_t ret_value = SUCCEED; /* Return value */
|
|
|
|
|
|
|
|
|
|
FUNC_ENTER_NOAPI_NOINIT(H5HF_hdr_inc_alloc)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check arguments.
|
|
|
|
|
*/
|
|
|
|
|
HDassert(hdr);
|
|
|
|
|
HDassert(new_alloc_size >= hdr->man_alloc_size);
|
|
|
|
|
|
|
|
|
|
/* Advance the iterator for the current location with in the indirect block */
|
|
|
|
|
if(hdr->next_block.curr)
|
|
|
|
|
if(H5HF_man_iter_next(hdr, &hdr->next_block, nentries) < 0)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_CANTNEXT, FAIL, "unable to advance current block iterator location")
|
|
|
|
|
|
|
|
|
|
/* Update the "allocated" size within the heap */
|
|
|
|
|
hdr->man_alloc_size = new_alloc_size;
|
|
|
|
|
#ifdef QAK
|
|
|
|
|
HDfprintf(stderr, "%s: hdr->man_alloc_size = %Hu\n", FUNC, hdr->man_alloc_size);
|
|
|
|
|
#endif /* QAK */
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
|
|
|
|
} /* end H5HF_hdr_inc_alloc() */
|
|
|
|
|
|
2006-05-23 00:43:45 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: H5HF_hdr_empty
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Reset heap header to 'empty heap' state
|
|
|
|
|
*
|
|
|
|
|
* Return: Non-negative on success/Negative on failure
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Quincey Koziol
|
|
|
|
|
* koziol@ncsa.uiuc.edu
|
|
|
|
|
* May 17 2006
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
herr_t
|
|
|
|
|
H5HF_hdr_empty(H5HF_hdr_t *hdr)
|
|
|
|
|
{
|
|
|
|
|
herr_t ret_value = SUCCEED; /* Return value */
|
|
|
|
|
|
|
|
|
|
FUNC_ENTER_NOAPI_NOINIT(H5HF_hdr_empty)
|
|
|
|
|
#ifdef QAK
|
|
|
|
|
HDfprintf(stderr, "%s: Reseting heap header to empty\n", FUNC);
|
|
|
|
|
#endif /* QAK */
|
|
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
|
HDassert(hdr);
|
|
|
|
|
|
|
|
|
|
/* Reset root pointer information */
|
|
|
|
|
hdr->man_dtable.curr_root_rows = 0;
|
|
|
|
|
hdr->man_dtable.table_addr = HADDR_UNDEF;
|
|
|
|
|
|
|
|
|
|
/* Shrink heap size */
|
|
|
|
|
hdr->total_size = hdr->std_size;
|
|
|
|
|
hdr->man_size = 0;
|
|
|
|
|
|
|
|
|
|
/* Reset the free space in direct blocks */
|
|
|
|
|
hdr->total_man_free = 0;
|
|
|
|
|
|
|
|
|
|
/* Mark heap header as modified */
|
|
|
|
|
if(H5HF_hdr_dirty(hdr) < 0)
|
|
|
|
|
HGOTO_ERROR(H5E_HEAP, H5E_CANTDIRTY, FAIL, "can't mark header as dirty")
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
FUNC_LEAVE_NOAPI(ret_value)
|
|
|
|
|
} /* end H5HF_hdr_empty() */
|
|
|
|
|
|