diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2006-12-13 03:19:43 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2006-12-13 03:19:43 (GMT) |
commit | d694a6897c3304decbe520692207df11bbdfe39e (patch) | |
tree | 9eda87dc1f79fa1122a91cf3d15ae913b7b0da08 | |
parent | bcc000dd8a37ab792ba2fc3b9b45ff83c94edfa1 (diff) | |
download | hdf5-d694a6897c3304decbe520692207df11bbdfe39e.zip hdf5-d694a6897c3304decbe520692207df11bbdfe39e.tar.gz hdf5-d694a6897c3304decbe520692207df11bbdfe39e.tar.bz2 |
[svn-r13058] Description:
Clean up some shared message operations and other minor tweaks, in the
process of trying to solve the messy way that shared object header messages
are implemented in general (not James' work - which is fine :-)
Tested on:
Mac OS X/32 10.4.8 (amazon)
FreeBSD/32 4.11 (sleipnir)
AIX/32 5.? (copper)
-rw-r--r-- | src/H5Adense.c | 8 | ||||
-rw-r--r-- | src/H5Oattr.c | 70 | ||||
-rw-r--r-- | src/H5Odtype.c | 16 | ||||
-rw-r--r-- | src/H5Ofill.c | 10 | ||||
-rw-r--r-- | src/H5Opline.c | 10 | ||||
-rw-r--r-- | src/H5Oprivate.h | 2 | ||||
-rw-r--r-- | src/H5Osdspace.c | 12 | ||||
-rw-r--r-- | src/H5Oshared.c | 35 |
8 files changed, 74 insertions, 89 deletions
diff --git a/src/H5Adense.c b/src/H5Adense.c index e2a3d76..3258019 100644 --- a/src/H5Adense.c +++ b/src/H5Adense.c @@ -66,8 +66,8 @@ #define H5A_CORDER_BT2_MERGE_PERC 40 #define H5A_CORDER_BT2_SPLIT_PERC 100 -/* Size of stack buffer for serialized messages */ -#define H5A_MESG_BUF_SIZE 128 +/* Size of stack buffer for serialized attributes */ +#define H5A_ATTR_BUF_SIZE 128 /******************/ @@ -620,7 +620,7 @@ H5A_dense_insert(H5F_t *f, hid_t dxpl_id, const H5O_t *oh, unsigned mesg_flags, H5HF_t *shared_fheap = NULL; /* Fractal heap handle for shared header messages */ uint8_t id[H5A_DENSE_FHEAP_ID_LEN]; /* Heap ID of attribute to insert */ H5O_shared_t sh_mesg; /* Shared object header message */ - uint8_t attr_buf[H5A_MESG_BUF_SIZE]; /* Buffer for serializing message */ + uint8_t attr_buf[H5A_ATTR_BUF_SIZE]; /* Buffer for serializing message */ void *attr_ptr = NULL; /* Pointer to serialized message */ htri_t attr_sharable; /* Flag indicating attributes are sharable */ herr_t ret_value = SUCCEED; /* Return value */ @@ -812,7 +812,7 @@ H5A_dense_write(H5F_t *f, hid_t dxpl_id, const H5O_t *oh, const H5A_t *attr) H5HF_t *shared_fheap = NULL; /* Fractal heap handle for shared header messages */ H5HF_t *fheap = NULL; /* Fractal heap handle */ size_t attr_size; /* Size of serialized attribute in the heap */ - uint8_t attr_buf[H5A_MESG_BUF_SIZE]; /* Buffer for serializing attribute */ + uint8_t attr_buf[H5A_ATTR_BUF_SIZE]; /* Buffer for serializing attribute */ void *attr_ptr = NULL; /* Pointer to serialized attribute */ htri_t attr_sharable; /* Flag indicating attributes are sharable */ herr_t ret_value = SUCCEED; /* Return value */ diff --git a/src/H5Oattr.c b/src/H5Oattr.c index 59a684e..bc2b81f 100644 --- a/src/H5Oattr.c +++ b/src/H5Oattr.c @@ -650,8 +650,6 @@ herr_t H5O_attr_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link) { const H5A_t *attr = (const H5A_t *) _mesg; - htri_t tri_ret; - H5O_shared_t sh_mesg; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_attr_delete) @@ -660,33 +658,37 @@ H5O_attr_delete(H5F_t *f, hid_t dxpl_id, const void *_mesg, hbool_t adj_link) HDassert(f); HDassert(attr); - /* Remove both the datatype and dataspace from the SOHM heap if they're - * shared there. - */ - if((tri_ret = H5O_msg_is_shared(H5O_DTYPE_ID, attr->dt)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't tell if datatype is shared") - if(tri_ret > 0) - { - if(H5O_msg_get_share(H5O_DTYPE_ID, attr->dt, &sh_mesg) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't get shared message from datatype") - if(H5SM_try_delete(f, H5AC_dxpl_id, H5O_DTYPE_ID, &sh_mesg) < 0) - HGOTO_ERROR(H5E_SOHM, H5E_CANTREMOVE, FAIL, "can't remove datatype from SOHM heap") - } /* end if */ - - if((tri_ret = H5O_msg_is_shared(H5O_SDSPACE_ID, attr->ds)) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't tell if dataspace is shared") - if(tri_ret > 0) - { - if(H5O_msg_get_share(H5O_SDSPACE_ID, attr->ds, &sh_mesg) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't get shared message from dataspace") - if(H5SM_try_delete(f, H5AC_dxpl_id, H5O_SDSPACE_ID, &sh_mesg) < 0) - HGOTO_ERROR(H5E_OHDR, H5E_SOHM, FAIL, "can't remove dataspace from SOHM heap") - } /* end if */ - - /* Check whether datatype is shared */ - if(H5T_committed(attr->dt)) { - /* Decrement the reference count on the shared datatype, if requested */ - if(adj_link) + /* Check if we are adjusting link count on components in the file */ + if(adj_link) { + htri_t tri_ret; + H5O_shared_t sh_mesg; + + /* Remove both the datatype and dataspace from the SOHM heap if they're + * shared there. + */ + if((tri_ret = H5O_msg_is_shared(H5O_DTYPE_ID, attr->dt)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't tell if datatype is shared") + if(tri_ret > 0) + { + if(H5O_msg_get_share(H5O_DTYPE_ID, attr->dt, &sh_mesg) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't get shared message from datatype") + if(H5SM_try_delete(f, H5AC_dxpl_id, H5O_DTYPE_ID, &sh_mesg) < 0) + HGOTO_ERROR(H5E_SOHM, H5E_CANTREMOVE, FAIL, "can't remove datatype from SOHM heap") + } /* end if */ + + if((tri_ret = H5O_msg_is_shared(H5O_SDSPACE_ID, attr->ds)) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't tell if dataspace is shared") + if(tri_ret > 0) + { + if(H5O_msg_get_share(H5O_SDSPACE_ID, attr->ds, &sh_mesg) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "can't get shared message from dataspace") + if(H5SM_try_delete(f, H5AC_dxpl_id, H5O_SDSPACE_ID, &sh_mesg) < 0) + HGOTO_ERROR(H5E_OHDR, H5E_SOHM, FAIL, "can't remove dataspace from SOHM heap") + } /* end if */ + + /* Check whether datatype is shared */ + if(H5T_committed(attr->dt)) + /* Decrement the reference count on the shared datatype */ if(H5T_link(attr->dt, -1, dxpl_id) < 0) HGOTO_ERROR(H5E_OHDR, H5E_LINKCOUNT, FAIL, "unable to adjust shared datatype link count") } /* end if */ @@ -1117,7 +1119,6 @@ static htri_t H5O_attr_is_shared(const void *_mesg) { const H5A_t *mesg = (const H5A_t *)_mesg; - htri_t ret_value; FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_attr_is_shared) @@ -1127,13 +1128,8 @@ H5O_attr_is_shared(const void *_mesg) * library read a "committed attribute" if we ever create one in * the future. */ - if(mesg->sh_loc.flags & (H5O_COMMITTED_FLAG | H5O_SHARED_IN_HEAP_FLAG)) - ret_value = TRUE; - else - ret_value = FALSE; - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_attr_is_shared */ + FUNC_LEAVE_NOAPI(H5O_IS_SHARED(mesg->sh_loc.flags)) +} /* end H5O_attr_is_shared() */ /*-------------------------------------------------------------------------- diff --git a/src/H5Odtype.c b/src/H5Odtype.c index f42120f..73f8686 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -1359,22 +1359,16 @@ H5O_dtype_set_share(void *_mesg/*in,out*/, const H5O_shared_t *sh) *------------------------------------------------------------------------- */ static htri_t -H5O_dtype_is_shared (const void *_mesg) +H5O_dtype_is_shared(const void *_mesg) { - const H5T_t *dt = (const H5T_t *)_mesg; - htri_t ret_value; + const H5T_t *mesg = (const H5T_t *)_mesg; FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_dtype_is_shared) - HDassert(dt); - - if(dt->sh_loc.flags & (H5O_COMMITTED_FLAG | H5O_SHARED_IN_HEAP_FLAG)) - ret_value = TRUE; - else - ret_value = FALSE; + HDassert(mesg); - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_dtype_is_shared */ + FUNC_LEAVE_NOAPI(H5O_IS_SHARED(mesg->sh_loc.flags)) +} /* end H5O_dtype_is_shared() */ /*------------------------------------------------------------------------- diff --git a/src/H5Ofill.c b/src/H5Ofill.c index 213df3f..2c6158b 100644 --- a/src/H5Ofill.c +++ b/src/H5Ofill.c @@ -747,7 +747,6 @@ static htri_t H5O_fill_new_is_shared(const void *_mesg) { const H5O_fill_new_t *mesg = (const H5O_fill_new_t *)_mesg; - htri_t ret_value; FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_fill_new_is_shared) @@ -757,13 +756,8 @@ H5O_fill_new_is_shared(const void *_mesg) * library read a "committed fill value" if we ever create one in * the future. */ - if(mesg->sh_loc.flags & (H5O_COMMITTED_FLAG | H5O_SHARED_IN_HEAP_FLAG)) - ret_value = TRUE; - else - ret_value = FALSE; - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_fill_new_is_shared */ + FUNC_LEAVE_NOAPI(H5O_IS_SHARED(mesg->sh_loc.flags)) +} /* end H5O_fill_new_is_shared() */ /*------------------------------------------------------------------------- diff --git a/src/H5Opline.c b/src/H5Opline.c index 5756aab..ccbddd0 100644 --- a/src/H5Opline.c +++ b/src/H5Opline.c @@ -675,7 +675,6 @@ static htri_t H5O_pline_is_shared(const void *_mesg) { const H5O_pline_t *mesg = (const H5O_pline_t *)_mesg; - htri_t ret_value; FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_pline_is_shared) @@ -685,13 +684,8 @@ H5O_pline_is_shared(const void *_mesg) * library read a "committed I/O pipeline" if we ever create one in * the future. */ - if(mesg->sh_loc.flags & (H5O_COMMITTED_FLAG | H5O_SHARED_IN_HEAP_FLAG)) - ret_value = TRUE; - else - ret_value = FALSE; - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_pline_is_shared */ + FUNC_LEAVE_NOAPI(H5O_IS_SHARED(mesg->sh_loc.flags)) +} /* end H5O_pline_is_shared() */ /*------------------------------------------------------------------------- diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index 5e84ff6..cd68ae5 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -139,6 +139,8 @@ typedef struct H5O_copy_t { #define H5O_SHARED_IN_HEAP_FLAG 0x01 #define H5O_COMMITTED_FLAG 0x02 +#define H5O_IS_SHARED(F) (((F) & (H5O_SHARED_IN_HEAP_FLAG | H5O_COMMITTED_FLAG)) ? TRUE : FALSE) + /* * Shared object message. * This needs to go first because other messages can be shared and diff --git a/src/H5Osdspace.c b/src/H5Osdspace.c index d691ca5..9b4c473 100644 --- a/src/H5Osdspace.c +++ b/src/H5Osdspace.c @@ -523,10 +523,9 @@ H5O_sdspace_set_share(void *_mesg/*in,out*/, const H5O_shared_t *sh) *------------------------------------------------------------------------- */ static htri_t -H5O_sdspace_is_shared (const void *_mesg) +H5O_sdspace_is_shared(const void *_mesg) { const H5S_extent_t *mesg = (const H5S_extent_t *)_mesg; - htri_t ret_value; FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_sdspace_is_shared) @@ -536,13 +535,8 @@ H5O_sdspace_is_shared (const void *_mesg) * library read a "committed dataspace" if we ever create one in * the future. */ - if(mesg->sh_loc.flags & (H5O_COMMITTED_FLAG | H5O_SHARED_IN_HEAP_FLAG)) - ret_value = TRUE; - else - ret_value = FALSE; - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5O_sdspace_is_shared */ + FUNC_LEAVE_NOAPI(H5O_IS_SHARED(mesg->sh_loc.flags)) +} /* end H5O_sdspace_is_shared() */ /*------------------------------------------------------------------------- diff --git a/src/H5Oshared.c b/src/H5Oshared.c index 07e5489..963e8f4 100644 --- a/src/H5Oshared.c +++ b/src/H5Oshared.c @@ -32,6 +32,7 @@ #include "H5private.h" /* Generic Functions */ #include "H5Eprivate.h" /* Error handling */ #include "H5Fpkg.h" /* File access */ +#include "H5FLprivate.h" /* Free lists */ #include "H5Gprivate.h" /* Groups */ #include "H5HFprivate.h" /* Fractal heap */ #include "H5MMprivate.h" /* Memory management */ @@ -83,6 +84,12 @@ const H5O_msg_class_t H5O_MSG_SHARED[1] = {{ #define H5O_SHARED_VERSION_3 3 #define H5O_SHARED_VERSION H5O_SHARED_VERSION_3 +/* Size of stack buffer for serialized messages */ +#define H5O_MESG_BUF_SIZE 128 + +/* Declare a free list to manage the serialized message information */ +H5FL_BLK_DEFINE(ser_mesg); + /*------------------------------------------------------------------------- * Function: H5O_shared_read @@ -108,7 +115,8 @@ H5O_shared_read(H5F_t *f, hid_t dxpl_id, const H5O_shared_t *shared, const H5O_msg_class_t *type, void *mesg) { H5HF_t *fheap = NULL; - unsigned char *buf = NULL; /* Pointer to raw message in heap */ + uint8_t mesg_buf[H5O_MESG_BUF_SIZE]; /* Buffer for deserializing messages */ + uint8_t *buf = NULL; /* Pointer to raw message in heap */ void *native_mesg = NULL; /* Used for messages shared in heap */ void *ret_value = NULL; /* Return value */ @@ -132,23 +140,27 @@ H5O_shared_read(H5F_t *f, hid_t dxpl_id, const H5O_shared_t *shared, /* Retrieve the fractal heap address for shared messages */ if((fheap_addr = H5SM_get_fheap_addr(f, type->id, dxpl_id)) == HADDR_UNDEF) - HGOTO_ERROR(H5E_SOHM, H5E_CANTGET, NULL, "can't get fheap address for shared messages") + HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, NULL, "can't get fheap address for shared messages") /* Open the fractal heap */ if(NULL == (fheap = H5HF_open(f, dxpl_id, fheap_addr))) - HGOTO_ERROR(H5E_HEAP, H5E_CANTOPENOBJ, NULL, "unable to open fractal heap") + HGOTO_ERROR(H5E_OHDR, H5E_CANTOPENOBJ, NULL, "unable to open fractal heap") /* Get the size of the message in the heap */ if(H5HF_get_obj_len(fheap, dxpl_id, &(shared->u.heap_id), &buf_size) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, NULL, "can't get message size from fractal heap.") + HGOTO_ERROR(H5E_OHDR, H5E_CANTGET, NULL, "can't get message size from fractal heap.") - /* Allocate buffer */ - if(NULL == (buf = H5MM_malloc(buf_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") + /* Allocate space for serialized message, if necessary */ + if(buf_size > sizeof(mesg_buf)) { + if(NULL == (buf = H5FL_BLK_MALLOC(ser_mesg, buf_size))) + HGOTO_ERROR(H5E_OHDR, H5E_NOSPACE, NULL, "memory allocation failed") + } /* end if */ + else + buf = mesg_buf; /* Retrieve the message from the heap */ if(H5HF_read(fheap, dxpl_id, &(shared->u.heap_id), buf) < 0) - HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, NULL, "can't read message from fractal heap.") + HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "can't read message from fractal heap.") /* Decode the message */ if(NULL == (native_mesg = H5O_msg_decode(f, dxpl_id, type->id, buf))) @@ -171,12 +183,11 @@ H5O_shared_read(H5F_t *f, hid_t dxpl_id, const H5O_shared_t *shared, HGOTO_ERROR(H5E_OHDR, H5E_CANTINIT, NULL, "unable to set sharing information") done: - if(buf) - H5MM_xfree(buf); - + /* Release resources */ + if(buf && buf != mesg_buf) + H5FL_BLK_FREE(ser_mesg, buf); if(native_mesg) H5O_msg_free(type->id, native_mesg); - if(fheap && H5HF_close(fheap, dxpl_id) < 0) HDONE_ERROR(H5E_HEAP, H5E_CANTFREE, NULL, "can't close fractal heap") |