summaryrefslogtreecommitdiffstats
path: root/src/H5Fcwfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Fcwfs.c')
-rw-r--r--src/H5Fcwfs.c132
1 files changed, 61 insertions, 71 deletions
diff --git a/src/H5Fcwfs.c b/src/H5Fcwfs.c
index 2b368d5..729108d 100644
--- a/src/H5Fcwfs.c
+++ b/src/H5Fcwfs.c
@@ -33,19 +33,17 @@
/* Module Setup */
/****************/
-#include "H5Fmodule.h" /* This source code file is part of the H5F module */
-
+#include "H5Fmodule.h" /* This source code file is part of the H5F module */
/***********/
/* Headers */
/***********/
-#include "H5private.h" /* Generic Functions */
-#include "H5Eprivate.h" /* Error handling */
-#include "H5Fpkg.h" /* File access */
-#include "H5HGprivate.h" /* Global heaps */
-#include "H5MFprivate.h" /* File memory management */
-#include "H5MMprivate.h" /* Memory management */
-
+#include "H5private.h" /* Generic Functions */
+#include "H5Eprivate.h" /* Error handling */
+#include "H5Fpkg.h" /* File access */
+#include "H5HGprivate.h" /* Global heaps */
+#include "H5MFprivate.h" /* File memory management */
+#include "H5MMprivate.h" /* Memory management */
/****************/
/* Local Macros */
@@ -55,40 +53,32 @@
* Maximum length of the CWFS list, the list of remembered collections that
* have free space.
*/
-#define H5F_NCWFS 16
-
+#define H5F_NCWFS 16
/******************/
/* Local Typedefs */
/******************/
-
/********************/
/* Package Typedefs */
/********************/
-
/********************/
/* Local Prototypes */
/********************/
-
/*********************/
/* Package Variables */
/*********************/
-
/*****************************/
/* Library Private Variables */
/*****************************/
-
/*******************/
/* Local Variables */
/*******************/
-
-
/*-------------------------------------------------------------------------
* Function: H5F_cwfs_add
*
@@ -105,7 +95,7 @@
herr_t
H5F_cwfs_add(H5F_t *f, H5HG_heap_t *heap)
{
- herr_t ret_value = SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
@@ -119,23 +109,25 @@ H5F_cwfs_add(H5F_t *f, H5HG_heap_t *heap)
* necessary to make room. We remove the right-most entry that has less
* free space than this heap.
*/
- if(NULL == f->shared->cwfs) {
- if(NULL == (f->shared->cwfs = (H5HG_heap_t **)H5MM_malloc(H5F_NCWFS * sizeof(H5HG_heap_t *))))
- HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "can't allocate CWFS for file")
- f->shared->cwfs[0] = heap;
- f->shared->ncwfs = 1;
- } else if(H5F_NCWFS == f->shared->ncwfs) {
- int i; /* Local index variable */
-
- for(i = H5F_NCWFS - 1; i >= 0; --i)
- if(H5HG_FREE_SIZE(f->shared->cwfs[i]) < H5HG_FREE_SIZE(heap)) {
+ if (NULL == f->shared->cwfs) {
+ if (NULL == (f->shared->cwfs = (H5HG_heap_t **)H5MM_malloc(H5F_NCWFS * sizeof(H5HG_heap_t *))))
+ HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "can't allocate CWFS for file")
+ f->shared->cwfs[0] = heap;
+ f->shared->ncwfs = 1;
+ }
+ else if (H5F_NCWFS == f->shared->ncwfs) {
+ int i; /* Local index variable */
+
+ for (i = H5F_NCWFS - 1; i >= 0; --i)
+ if (H5HG_FREE_SIZE(f->shared->cwfs[i]) < H5HG_FREE_SIZE(heap)) {
HDmemmove(f->shared->cwfs + 1, f->shared->cwfs, (size_t)i * sizeof(H5HG_heap_t *));
f->shared->cwfs[0] = heap;
break;
} /* end if */
- } else {
+ }
+ else {
HDmemmove(f->shared->cwfs + 1, f->shared->cwfs, f->shared->ncwfs * sizeof(H5HG_heap_t *));
- f->shared->cwfs[0] = heap;
+ f->shared->cwfs[0] = heap;
f->shared->ncwfs += 1;
} /* end else */
@@ -143,7 +135,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5F_cwfs_add() */
-
/*-------------------------------------------------------------------------
* Function: H5F_cwfs_find_free_heap
*
@@ -161,9 +152,9 @@ done:
herr_t
H5F_cwfs_find_free_heap(H5F_t *f, size_t need, haddr_t *addr)
{
- unsigned cwfsno; /* Local index for iterating over collections */
- hbool_t found = FALSE; /* Flag to indicate a heap with enough space was found */
- herr_t ret_value = SUCCEED; /* Return value */
+ unsigned cwfsno; /* Local index for iterating over collections */
+ hbool_t found = FALSE; /* Flag to indicate a heap with enough space was found */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
@@ -188,59 +179,60 @@ H5F_cwfs_find_free_heap(H5F_t *f, size_t need, haddr_t *addr)
*
* JRM - 5/24/04
*/
- for(cwfsno = 0; cwfsno < f->shared->ncwfs; cwfsno++)
- if(H5HG_FREE_SIZE(f->shared->cwfs[cwfsno]) >= need) {
- *addr = H5HG_ADDR(f->shared->cwfs[cwfsno]);
+ for (cwfsno = 0; cwfsno < f->shared->ncwfs; cwfsno++)
+ if (H5HG_FREE_SIZE(f->shared->cwfs[cwfsno]) >= need) {
+ *addr = H5HG_ADDR(f->shared->cwfs[cwfsno]);
found = TRUE;
- break;
- } /* end if */
+ break;
+ } /* end if */
/*
* If we didn't find any collection with enough free space the check if
* we can extend any of the collections to make enough room.
*/
- if(!found) {
+ 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 -= H5HG_FREE_SIZE(f->shared->cwfs[cwfsno]);
new_need = MAX(H5HG_SIZE(f->shared->cwfs[cwfsno]), new_need);
- if((H5HG_SIZE(f->shared->cwfs[cwfsno]) + new_need) <= H5HG_MAXSIZE) {
- htri_t was_extended; /* Whether the heap was extended */
+ if ((H5HG_SIZE(f->shared->cwfs[cwfsno]) + new_need) <= H5HG_MAXSIZE) {
+ htri_t was_extended; /* Whether the heap was extended */
- was_extended = H5MF_try_extend(f, H5FD_MEM_GHEAP, H5HG_ADDR(f->shared->cwfs[cwfsno]), (hsize_t)H5HG_SIZE(f->shared->cwfs[cwfsno]), (hsize_t)new_need);
- if(was_extended < 0)
+ was_extended =
+ H5MF_try_extend(f, H5FD_MEM_GHEAP, H5HG_ADDR(f->shared->cwfs[cwfsno]),
+ (hsize_t)H5HG_SIZE(f->shared->cwfs[cwfsno]), (hsize_t)new_need);
+ if (was_extended < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTEXTEND, FAIL, "error trying to extend heap")
- else if(was_extended == TRUE) {
- if(H5HG_extend(f, H5HG_ADDR(f->shared->cwfs[cwfsno]), new_need) < 0)
+ else if (was_extended == TRUE) {
+ if (H5HG_extend(f, H5HG_ADDR(f->shared->cwfs[cwfsno]), new_need) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTRESIZE, FAIL, "unable to extend global heap collection")
*addr = H5HG_ADDR(f->shared->cwfs[cwfsno]);
found = TRUE;
break;
} /* end if */
- } /* end if */
- } /* end for */
- } /* end if */
+ } /* end if */
+ } /* end for */
+ } /* end if */
- if(found) {
+ if (found) {
/* Move the collection forward in the CWFS list, if it's not
* already at the front
*/
- if(cwfsno > 0) {
+ if (cwfsno > 0) {
H5HG_heap_t *tmp = f->shared->cwfs[cwfsno];
- f->shared->cwfs[cwfsno] = f->shared->cwfs[cwfsno - 1];
+ f->shared->cwfs[cwfsno] = f->shared->cwfs[cwfsno - 1];
f->shared->cwfs[cwfsno - 1] = tmp;
} /* end if */
- } /* end if */
+ } /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5F_cwfs_find_free_heap() */
-
/*-------------------------------------------------------------------------
* Function: H5F_cwfs_advance_heap
*
@@ -257,8 +249,8 @@ done:
herr_t
H5F_cwfs_advance_heap(H5F_t *f, H5HG_heap_t *heap, hbool_t add_heap)
{
- unsigned u; /* Local index variable */
- herr_t ret_value = SUCCEED; /* Return value */
+ unsigned u; /* Local index variable */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
@@ -267,16 +259,16 @@ H5F_cwfs_advance_heap(H5F_t *f, H5HG_heap_t *heap, hbool_t add_heap)
HDassert(f->shared);
HDassert(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];
+ 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(add_heap && u >= f->shared->ncwfs) {
- f->shared->ncwfs = MIN(f->shared->ncwfs + 1, H5F_NCWFS);
+ if (add_heap && u >= f->shared->ncwfs) {
+ f->shared->ncwfs = MIN(f->shared->ncwfs + 1, H5F_NCWFS);
f->shared->cwfs[f->shared->ncwfs - 1] = heap;
} /* end if */
@@ -284,7 +276,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5F_cwfs_advance_heap() */
-
/*-------------------------------------------------------------------------
* Function: H5F_cwfs_remove_heap
*
@@ -301,8 +292,8 @@ done:
herr_t
H5F_cwfs_remove_heap(H5F_shared_t *shared, H5HG_heap_t *heap)
{
- unsigned u; /* Local index variable */
- herr_t ret_value = SUCCEED; /* Return value */
+ unsigned u; /* Local index variable */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
@@ -311,15 +302,14 @@ H5F_cwfs_remove_heap(H5F_shared_t *shared, H5HG_heap_t *heap)
HDassert(heap);
/* Remove the heap from the CWFS list */
- for(u = 0; u < shared->ncwfs; u++) {
- if(shared->cwfs[u] == heap) {
+ for (u = 0; u < shared->ncwfs; u++) {
+ if (shared->cwfs[u] == heap) {
shared->ncwfs -= 1;
HDmemmove(shared->cwfs + u, shared->cwfs + u + 1, (shared->ncwfs - u) * sizeof(H5HG_heap_t *));
break;
} /* end if */
- } /* end for */
+ } /* end for */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5F_cwfs_remove_heap() */
-