summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2004-11-29 21:01:24 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2004-11-29 21:01:24 (GMT)
commitd5b0db14a939d07aa220216b1698c9ddc9cc7430 (patch)
tree05528092819fe67012dba14723595703309e092c
parent3eea418b507d9a561606c658eba5c6b0158f520d (diff)
downloadhdf5-d5b0db14a939d07aa220216b1698c9ddc9cc7430.zip
hdf5-d5b0db14a939d07aa220216b1698c9ddc9cc7430.tar.gz
hdf5-d5b0db14a939d07aa220216b1698c9ddc9cc7430.tar.bz2
[svn-r9599] Purpose:
New internal feature Description: Add a "release" routine to the skip lists, which releases all the nodes in the skip list, but keeps the skip list active. Platforms tested: FreeBSD 4.10 (sleipnir) Linux 2.4 (verbena) Too minor to require h5committest
-rw-r--r--src/H5C.c10
-rw-r--r--src/H5SL.c65
-rw-r--r--src/H5SLprivate.h1
-rw-r--r--test/tskiplist.c22
4 files changed, 82 insertions, 16 deletions
diff --git a/src/H5C.c b/src/H5C.c
index 0d58339..394ddde 100644
--- a/src/H5C.c
+++ b/src/H5C.c
@@ -2490,15 +2490,9 @@ H5C_flush_cache(H5F_t * f,
if(cache_ptr->slist_ptr) {
- /* XXX: Replace this with call to H5SL_free() when its implemented... */
- H5SL_close(cache_ptr->slist_ptr);
+ /* Release all nodes from skip list, but keep list active */
+ H5SL_release(cache_ptr->slist_ptr);
- /* XXX: ...and remove this call */
- if ( (cache_ptr->slist_ptr = H5SL_create(H5SL_TYPE_HADDR,0.5,16))
- == NULL ) {
-
- HGOTO_ERROR(H5E_CACHE, H5E_CANTCREATE, FAIL, "can't create skip list.")
- }
}
cache_ptr->slist_len = 0;
cache_ptr->slist_size = 0;
diff --git a/src/H5SL.c b/src/H5SL.c
index c238a63..36ff763 100644
--- a/src/H5SL.c
+++ b/src/H5SL.c
@@ -678,6 +678,59 @@ H5SL_item(H5SL_node_t *slist_node)
/*--------------------------------------------------------------------------
NAME
+ H5SL_release
+ PURPOSE
+ Release all nodes from a skip list
+ USAGE
+ herr_t H5SL_release(slist)
+ H5SL_t *slist; IN/OUT: Pointer to skip list to release nodes
+
+ RETURNS
+ Returns non-negative on success, negative on failure.
+ DESCRIPTION
+ Release all the nodes in a skip list. Any objects left in the skip list
+ nodes are not deallocated.
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+herr_t
+H5SL_release(H5SL_t *slist)
+{
+ H5SL_node_t *node, *next_node; /* Pointers to skip list nodes */
+ size_t u; /* Local index variable */
+
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SL_release);
+
+ /* Check args */
+ assert(slist);
+
+ /* Check internal consistency */
+ /* (Pre-condition) */
+
+ /* Free skip list nodes */
+ node=slist->header->forward[0];
+ while(node!=NULL) {
+ next_node=node->forward[0];
+ H5MM_xfree(node);
+ node=next_node;
+ } /* end while */
+
+ /* Reset the header pointers */
+ for(u=0; u<slist->max_level; u++)
+ slist->header->forward[u]=NULL;
+
+ /* Reset the dynamic internal fields */
+ slist->curr_level=-1;
+ slist->nobjs=0;
+
+ FUNC_LEAVE_NOAPI(SUCCEED);
+} /* end H5SL_release() */
+
+
+/*--------------------------------------------------------------------------
+ NAME
H5SL_close
PURPOSE
Close a skip list, deallocating it.
@@ -698,8 +751,6 @@ H5SL_item(H5SL_node_t *slist_node)
herr_t
H5SL_close(H5SL_t *slist)
{
- H5SL_node_t *node, *next_node; /* Pointers to skip list nodes */
-
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5SL_close);
/* Check args */
@@ -709,12 +760,10 @@ H5SL_close(H5SL_t *slist)
/* (Pre-condition) */
/* Free skip list nodes */
- node=slist->header;
- while(node!=NULL) {
- next_node=node->forward[0];
- H5MM_xfree(node);
- node=next_node;
- } /* end while */
+ H5SL_release(slist); /* always succeeds */
+
+ /* Release header node */
+ H5MM_xfree(slist->header);
/* Free skip list object */
H5FL_FREE(H5SL_t,slist);
diff --git a/src/H5SLprivate.h b/src/H5SLprivate.h
index 94e2b4d..e6f64d8 100644
--- a/src/H5SLprivate.h
+++ b/src/H5SLprivate.h
@@ -60,6 +60,7 @@ H5_DLL void *H5SL_search(H5SL_t *slist, void *key);
H5_DLL H5SL_node_t *H5SL_first(H5SL_t *slist);
H5_DLL H5SL_node_t *H5SL_next(H5SL_node_t *slist_node);
H5_DLL void *H5SL_item(H5SL_node_t *slist_node);
+H5_DLL herr_t H5SL_release(H5SL_t *slist);
H5_DLL herr_t H5SL_close(H5SL_t *slist);
#endif /* _H5HPprivate_H */
diff --git a/test/tskiplist.c b/test/tskiplist.c
index cf88daf..dfd73a9 100644
--- a/test/tskiplist.c
+++ b/test/tskiplist.c
@@ -235,6 +235,28 @@ test_skiplist_insert_many(void)
VERIFY(*found_item,rand_num[u],"H5SL_search");
} /* end for */
+ /* Release all the items from the list */
+ ret=H5SL_release(slist);
+ CHECK(ret, FAIL, "H5SL_release");
+
+ /* Check that the skip list has no elements */
+ num=H5SL_count(slist);
+ VERIFY(num, 0, "H5SL_count");
+
+ /* Insert many objects into the skip list */
+ for(u=0; u<NUM_ELEMS; u++) {
+ ret=H5SL_insert(slist,&rand_num[u],&rand_num[u]);
+ CHECK(ret, FAIL, "H5SL_insert");
+ } /* end for */
+
+ /* Check that the skip list has correct # of elements */
+ num=H5SL_count(slist);
+ VERIFY(num, NUM_ELEMS, "H5SL_count");
+
+ /* Release all the items from the list */
+ ret=H5SL_release(slist);
+ CHECK(ret, FAIL, "H5SL_release");
+
/* Close the skip list */
ret=H5SL_close(slist);
CHECK(ret, FAIL, "H5SL_close");