summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5MF.c172
1 files changed, 92 insertions, 80 deletions
diff --git a/src/H5MF.c b/src/H5MF.c
index 6d44c69..4524517 100644
--- a/src/H5MF.c
+++ b/src/H5MF.c
@@ -21,25 +21,58 @@
*
* Purpose: File memory management functions.
*
- * Modifications:
- * Robb Matzke, 5 Aug 1997
- * Added calls to H5E.
- *
- * Robb Matzke, 8 Jun 1998
- * Implemented a very simple free list which is not persistent and which
- * is lossy.
- *
*-------------------------------------------------------------------------
*/
+
+/****************/
+/* Module Setup */
+/****************/
+
#define H5F_PACKAGE /*suppress error about including H5Fpkg */
-#include "H5private.h"
-#include "H5Eprivate.h"
-#include "H5Fpkg.h"
-#include "H5FDprivate.h"
-#include "H5MFprivate.h"
-#include "H5FDmulti.h" /*multiple files partitioned by mem usage */
+/***********/
+/* Headers */
+/***********/
+#include "H5private.h" /* Generic Functions */
+#include "H5Eprivate.h" /* Error handling */
+#include "H5Fpkg.h" /* File access */
+#include "H5MFprivate.h" /* File memory management */
+
+
+/****************/
+/* Local Macros */
+/****************/
+
+
+/******************/
+/* Local Typedefs */
+/******************/
+
+
+/********************/
+/* Package Typedefs */
+/********************/
+
+
+/********************/
+/* Local Prototypes */
+/********************/
+
+
+/*********************/
+/* Package Variables */
+/*********************/
+
+
+/*****************************/
+/* Library Private Variables */
+/*****************************/
+
+
+/*******************/
+/* Local Variables */
+/*******************/
/*-------------------------------------------------------------------------
@@ -51,16 +84,12 @@
* is being requested.
*
* Return: Success: The file address of new chunk.
- *
* Failure: HADDR_UNDEF
*
* Programmer: Robb Matzke
* matzke@llnl.gov
* Jul 11 1997
*
- * Modifications:
- * Robb Matzke, 1999-08-04
- * Modified to work with the virtual file layer.
*-------------------------------------------------------------------------
*/
haddr_t
@@ -68,33 +97,33 @@ H5MF_alloc(H5F_t *f, H5FD_mem_t type, hid_t dxpl_id, hsize_t size)
{
haddr_t ret_value;
- FUNC_ENTER_NOAPI(H5MF_alloc, HADDR_UNDEF);
+ FUNC_ENTER_NOAPI(H5MF_alloc, HADDR_UNDEF)
/* check arguments */
- assert(f);
- assert(size > 0);
+ HDassert(f);
+ HDassert(size > 0);
/* Fail if we don't have write access */
- if (0==(f->intent & H5F_ACC_RDWR))
- HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, HADDR_UNDEF, "file is read-only");
+ if(0 == (f->intent & H5F_ACC_RDWR))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, HADDR_UNDEF, "file is read-only")
/* Check that the file can address the new space */
- if( H5MF_alloc_overflow(f, size) )
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "not enough address space in file");
+ if(H5MF_alloc_overflow(f, size))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "not enough address space in file")
/* Allocate space from the virtual file layer */
- if (HADDR_UNDEF==(ret_value=H5FD_alloc(f->shared->lf, type, dxpl_id, size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "file allocation failed");
+ if(HADDR_UNDEF == (ret_value = H5FD_alloc(f->shared->lf, type, dxpl_id, size)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "file allocation failed")
/* Convert absolute file address to relative file address */
- assert(ret_value>=f->shared->base_addr);
+ HDassert(ret_value >= f->shared->base_addr);
/* Set return value */
ret_value -= f->shared->base_addr;
done:
- FUNC_LEAVE_NOAPI(ret_value);
-}
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5MF_alloc() */
/*-------------------------------------------------------------------------
@@ -109,44 +138,35 @@ done:
* matzke@llnl.gov
* Jul 17 1997
*
- * Modifications:
- * Robb Matzke, 1999-07-28
- * The ADDR argument is passed by value
- *
- * Robb Matzke, 1999-08-03
- * Modified to use the virtual file layer.
*-------------------------------------------------------------------------
*/
herr_t
H5MF_xfree(H5F_t *f, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, hsize_t size)
{
- herr_t ret_value=SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOFUNC(H5MF_xfree);
+ FUNC_ENTER_NOAPI_NOFUNC(H5MF_xfree)
/* check arguments */
- assert(f);
- if (!H5F_addr_defined(addr) || 0 == size)
+ HDassert(f);
+ if(!H5F_addr_defined(addr) || 0 == size)
HGOTO_DONE(SUCCEED);
- assert(addr!=0);
+ HDassert(addr != 0);
/* Convert relative address to absolute address */
addr += f->shared->base_addr;
/* Allow virtual file layer to free block */
- if (H5FD_free(f->shared->lf, type, dxpl_id, addr, size)<0) {
+ if(H5FD_free(f->shared->lf, type, dxpl_id, addr, size) < 0) {
#ifdef H5MF_DEBUG
- if (H5DEBUG(MF)) {
- fprintf(H5DEBUG(MF),
- "H5MF_free: lost %lu bytes of file storage\n",
- (unsigned long)size);
- }
+ if(H5DEBUG(MF))
+ fprintf(H5DEBUG(MF), "H5MF_free: lost %lu bytes of file storage\n", (unsigned long)size);
#endif
- }
+ } /* end if */
done:
- FUNC_LEAVE_NOAPI(ret_value);
-}
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5MF_xfree() */
/*-------------------------------------------------------------------------
@@ -169,19 +189,11 @@ done:
* circumstances the library may return the same address.
*
* Return: Success: The relative file address of the new block.
- *
* Failure: HADDR_UNDEF
*
* Programmer: Robb Matzke
* Thursday, April 16, 1998
*
- * Modifications:
- * Robb Matzke, 1999-07-28
- * The ORIG_ADDR is passed by value. The name of NEW_ADDR has
- * been changed to NEW_ADDR_P
- *
- * Robb Matzke, 1999-08-04
- * Modified to work with the virtual file layer.
*-------------------------------------------------------------------------
*/
haddr_t
@@ -190,31 +202,30 @@ H5MF_realloc(H5F_t *f, H5FD_mem_t type, hid_t dxpl_id, haddr_t old_addr, hsize_t
{
haddr_t ret_value;
- FUNC_ENTER_NOAPI(H5MF_realloc, HADDR_UNDEF);
+ FUNC_ENTER_NOAPI(H5MF_realloc, HADDR_UNDEF)
/* Convert old relative address to absolute address */
old_addr += f->shared->base_addr;
/* Check that the file can address the new space. */
/* In the worst case, this means adding new_size bytes to the end of the file. */
- if( H5MF_alloc_overflow(f, new_size) )
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "not enough address space in file");
+ if(H5MF_alloc_overflow(f, new_size))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "not enough address space in file")
/* Reallocate memory from the virtual file layer */
- ret_value = H5FD_realloc(f->shared->lf, type, dxpl_id, old_addr, old_size,
- new_size);
- if (HADDR_UNDEF==ret_value)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "unable to allocate new file memory");
+ ret_value = H5FD_realloc(f->shared->lf, type, dxpl_id, old_addr, old_size, new_size);
+ if(HADDR_UNDEF == ret_value)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "unable to allocate new file memory")
/* Convert return value to relative address */
- assert(ret_value>=f->shared->base_addr);
+ HDassert(ret_value >= f->shared->base_addr);
/* Set return value */
ret_value -= f->shared->base_addr;
done:
- FUNC_LEAVE_NOAPI(ret_value);
-}
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5MF_realloc() */
/*-------------------------------------------------------------------------
@@ -263,7 +274,7 @@ H5MF_alloc_overflow(H5F_t *f, hsize_t size)
* we shift by 64 bits all at once (<cough> Linux <cough>).
* Thus, we break one shift into several smaller shifts.
*/
- for(c=0; c < H5F_SIZEOF_ADDR(f); c += 2)
+ for(c = 0; c < H5F_SIZEOF_ADDR(f); c += 2)
space_needed = space_needed >> 16;
if(space_needed != 0)
@@ -272,7 +283,7 @@ H5MF_alloc_overflow(H5F_t *f, hsize_t size)
ret_value = FALSE;
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5MF_alloc_overflow() */
/*-------------------------------------------------------------------------
@@ -296,21 +307,21 @@ H5MF_can_extend(H5F_t *f, H5FD_mem_t type, haddr_t addr, hsize_t size, hsize_t e
{
htri_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5MF_can_extend, FAIL);
+ FUNC_ENTER_NOAPI(H5MF_can_extend, FAIL)
/* Convert old relative address to absolute address */
addr += H5F_BASE_ADDR(f);
/* Pass the request down to the virtual file layer */
- if((ret_value=H5FD_can_extend(f->shared->lf, type, addr, size, extra_requested))<0)
+ if((ret_value = H5FD_can_extend(f->shared->lf, type, addr, size, extra_requested)) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate new file memory");
/* Make sure there is enough addressable space to satisfy the request */
- if (ret_value == TRUE)
+ if(ret_value == TRUE)
ret_value = !H5MF_alloc_overflow(f, extra_requested);
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5MF_can_extend() */
@@ -335,19 +346,20 @@ H5MF_extend(H5F_t *f, H5FD_mem_t type, haddr_t addr, hsize_t size, hsize_t extra
{
herr_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5MF_extend, FAIL);
+ FUNC_ENTER_NOAPI(H5MF_extend, FAIL)
/* Make sure there is enough addressable space to satisfy the request */
- if ( H5MF_alloc_overflow(f, extra_requested) )
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate new file memory: out of address space");
+ if(H5MF_alloc_overflow(f, extra_requested))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate new file memory: out of address space")
/* Convert old relative address to absolute address */
addr += H5F_BASE_ADDR(f);
/* Pass the request down to the virtual file layer */
- if((ret_value=H5FD_extend(f->shared->lf, type, addr, size, extra_requested))<0)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate new file memory");
+ if((ret_value = H5FD_extend(f->shared->lf, type, addr, size, extra_requested)) < 0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate new file memory")
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5MF_extend() */
+