Skip to content

Commit

Permalink
More code duplication reduction (#2930)
Browse files Browse the repository at this point in the history
* Add failure value where it's missing from 1+ macros.  Clean up
whitespace / continuation characters ('\').  Made hash-table macros generic
for use in both the package header and test header.  Remove duplicated
copy & pasted macros (by hoisting difference into #ifdef'd macro).
Updated and re-flowed comments to read better.

Also clean up a few compiler warnings in production builds.

Signed-off-by: Quincey Koziol <[email protected]>

* Committing clang-format changes

* Remove unused variable warning in H5C.c (#2844)

* Remove trailing /* NDEBUG */ comment from #endif's

* Committing clang-format changes

---------

Signed-off-by: Quincey Koziol <[email protected]>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
qkoziol and github-actions[bot] authored May 9, 2023
1 parent 80cf406 commit 1a89fa2
Show file tree
Hide file tree
Showing 5 changed files with 1,536 additions and 2,247 deletions.
58 changes: 31 additions & 27 deletions src/H5C.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static herr_t H5C__verify_len_eoa(H5F_t *f, const H5C_class_t *type, haddr_t add
#ifndef NDEBUG
static void H5C__assert_flush_dep_nocycle(const H5C_cache_entry_t *entry,
const H5C_cache_entry_t *base_entry);
#endif /* NDEBUG */
#endif

/*********************/
/* Package Variables */
Expand Down Expand Up @@ -410,7 +410,7 @@ H5C_create(size_t max_cache_size, size_t min_clean_size, int max_type_id,

#ifndef NDEBUG
cache_ptr->get_entry_ptr_from_addr_counter = 0;
#endif /* NDEBUG */
#endif

/* Set return value */
ret_value = cache_ptr;
Expand Down Expand Up @@ -454,9 +454,9 @@ void
H5C_def_auto_resize_rpt_fcn(H5C_t *cache_ptr,
#ifndef NDEBUG
int32_t version,
#else /* NDEBUG */
#else
int32_t H5_ATTR_UNUSED version,
#endif /* NDEBUG */
#endif
double hit_rate, enum H5C_resize_status status, size_t old_max_cache_size,
size_t new_max_cache_size, size_t old_min_clean_size, size_t new_min_clean_size)
{
Expand Down Expand Up @@ -732,7 +732,7 @@ H5C_dest(H5F_t *f)
#endif /* H5C_DO_SANITY_CHECKS */

cache_ptr->magic = 0;
#endif /* NDEBUG */
#endif

cache_ptr = H5FL_FREE(H5C_t, cache_ptr);

Expand Down Expand Up @@ -1216,7 +1216,7 @@ H5C_insert_entry(H5F_t *f, const H5C_class_t *type, haddr_t addr, void *thing, u
entry_ptr->prefetched_dirty = FALSE;
#ifndef NDEBUG /* debugging field */
entry_ptr->serialization_count = 0;
#endif /* NDEBUG */
#endif

/* initialize tag list fields */
entry_ptr->tl_next = NULL;
Expand Down Expand Up @@ -1500,7 +1500,7 @@ H5C_mark_entry_clean(void *_thing)
if (was_dirty)
H5C__UPDATE_INDEX_FOR_ENTRY_CLEAN(cache_ptr, entry_ptr, FAIL)
if (entry_ptr->in_slist)
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, FALSE)
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, FALSE, FAIL)

/* Update stats for entry being marked clean */
H5C__UPDATE_STATS_FOR_CLEAR(cache_ptr, entry_ptr)
Expand Down Expand Up @@ -1703,7 +1703,7 @@ H5C_move_entry(H5C_t *cache_ptr, const H5C_class_t *type, haddr_t old_addr, hadd

if (entry_ptr->in_slist) {
HDassert(cache_ptr->slist_ptr);
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, FALSE)
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, FALSE, FAIL)
} /* end if */
} /* end if */

Expand Down Expand Up @@ -2747,7 +2747,7 @@ H5C_set_slist_enabled(H5C_t *cache_ptr, hbool_t slist_enabled, hbool_t clear_sli
node_ptr = H5SL_first(cache_ptr->slist_ptr);
while (node_ptr != NULL) {
entry_ptr = (H5C_cache_entry_t *)H5SL_item(node_ptr);
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, FALSE);
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, FALSE, FAIL)
node_ptr = H5SL_first(cache_ptr->slist_ptr);
}
}
Expand Down Expand Up @@ -3435,8 +3435,8 @@ H5C_create_flush_dependency(void *parent_thing, void *child_thing)

for (u = 0; u < child_entry->flush_dep_nparents; u++)
HDassert(child_entry->flush_dep_parent[u] != parent_entry);
} /* end block */
#endif /* NDEBUG */
} /* end block */
#endif

/* More sanity checks */
if (child_entry == parent_entry)
Expand Down Expand Up @@ -3529,7 +3529,7 @@ H5C_create_flush_dependency(void *parent_thing, void *child_thing)
HDassert(child_entry->flush_dep_parent_nalloc > 0);
#ifndef NDEBUG
H5C__assert_flush_dep_nocycle(parent_entry, child_entry);
#endif /* NDEBUG */
#endif

done:
FUNC_LEAVE_NOAPI(ret_value)
Expand Down Expand Up @@ -4859,7 +4859,7 @@ H5C__flush_invalidate_cache(H5F_t *f, unsigned flags)
HDassert(cache_ptr->pl_size == 0);
HDassert(cache_ptr->LRU_list_len == 0);
HDassert(cache_ptr->LRU_list_size == 0);
#endif /* NDEBUG */
#endif

done:
FUNC_LEAVE_NOAPI(ret_value)
Expand Down Expand Up @@ -5884,7 +5884,7 @@ H5C__flush_single_entry(H5F_t *f, H5C_cache_entry_t *entry_ptr, unsigned flags)
H5C__DELETE_FROM_INDEX(cache_ptr, entry_ptr, FAIL)

if (entry_ptr->in_slist && del_from_slist_on_destroy)
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, during_flush)
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, during_flush, FAIL)

#ifdef H5_HAVE_PARALLEL
/* Check for collective read access flag */
Expand Down Expand Up @@ -5916,7 +5916,7 @@ H5C__flush_single_entry(H5F_t *f, H5C_cache_entry_t *entry_ptr, unsigned flags)
* Hence no differentiation between them.
*/
H5C__UPDATE_RP_FOR_FLUSH(cache_ptr, entry_ptr, FAIL)
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, during_flush)
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, during_flush, FAIL)

/* mark the entry as clean and update the index for
* entry clean. Also, call the clear callback
Expand Down Expand Up @@ -6005,7 +6005,7 @@ H5C__flush_single_entry(H5F_t *f, H5C_cache_entry_t *entry_ptr, unsigned flags)
entry_ptr->type->image_len((void *)entry_ptr, &curr_len);
HDassert(curr_len == entry_ptr->size);
}
#endif /* NDEBUG */
#endif

/* If the file space free size callback is defined, use
* it to get the size of the block of file space to free.
Expand Down Expand Up @@ -6508,7 +6508,7 @@ H5C__load_entry(H5F_t *f,
entry->prefetched_dirty = FALSE;
#ifndef NDEBUG /* debugging field */
entry->serialization_count = 0;
#endif /* NDEBUG */
#endif

/* initialize tag list fields */
entry->tl_next = NULL;
Expand Down Expand Up @@ -6579,8 +6579,10 @@ H5C__make_space_in_cache(H5F_t *f, size_t space_needed, hbool_t write_permitted)
H5C_cache_entry_t *entry_ptr;
H5C_cache_entry_t *prev_ptr;
H5C_cache_entry_t *next_ptr;
uint32_t num_corked_entries = 0;
herr_t ret_value = SUCCEED; /* Return value */
#ifndef NDEBUG
uint32_t num_corked_entries = 0;
#endif
herr_t ret_value = SUCCEED; /* Return value */

FUNC_ENTER_PACKAGE

Expand Down Expand Up @@ -6628,8 +6630,10 @@ H5C__make_space_in_cache(H5F_t *f, size_t space_needed, hbool_t write_permitted)

if (entry_ptr->is_dirty && (entry_ptr->tag_info && entry_ptr->tag_info->corked)) {
/* Skip "dirty" corked entries. */
num_corked_entries = num_corked_entries + 1;
didnt_flush_entry = TRUE;
#ifndef NDEBUG
++num_corked_entries;
#endif
didnt_flush_entry = TRUE;
}
else if ((entry_ptr->type->id != H5AC_EPOCH_MARKER_ID) && !entry_ptr->flush_in_progress &&
!entry_ptr->prefetched_dirty) {
Expand Down Expand Up @@ -7475,7 +7479,7 @@ H5C__assert_flush_dep_nocycle(const H5C_cache_entry_t *entry, const H5C_cache_en

FUNC_LEAVE_NOAPI_VOID
} /* H5C__assert_flush_dep_nocycle() */
#endif /* NDEBUG */
#endif

/*-------------------------------------------------------------------------
* Function: H5C__serialize_cache
Expand Down Expand Up @@ -7587,7 +7591,7 @@ H5C__serialize_cache(H5F_t *f)
scan_ptr = scan_ptr->il_next;
} /* end while */
} /* end block */
#endif /* NDEBUG */
#endif

/* set cache_ptr->serialization_in_progress to TRUE, and back
* to FALSE at the end of the function. Must maintain this flag
Expand Down Expand Up @@ -7653,7 +7657,7 @@ H5C__serialize_cache(H5F_t *f)
scan_ptr = scan_ptr->il_next;
} /* end while */
} /* end block */
#endif /* NDEBUG */
#endif

done:
cache_ptr->serialization_in_progress = FALSE;
Expand Down Expand Up @@ -7830,7 +7834,7 @@ H5C__serialize_ring(H5F_t *f, H5C_ring_t ring)
#ifndef NDEBUG
/* Increment serialization counter (to detect multiple serializations) */
entry_ptr->serialization_count++;
#endif /* NDEBUG */
#endif
} /* end if */
} /* end if */

Expand Down Expand Up @@ -7899,7 +7903,7 @@ H5C__serialize_ring(H5F_t *f, H5C_ring_t ring)
#ifndef NDEBUG
/* Increment serialization counter (to detect multiple serializations) */
entry_ptr->serialization_count++;
#endif /* NDEBUG */
#endif
} /* end if */
} /* end if */
else {
Expand Down Expand Up @@ -8119,7 +8123,7 @@ H5C__generate_image(H5F_t *f, H5C_t *cache_ptr, H5C_cache_entry_t *entry_ptr)
if (entry_ptr->addr == old_addr) {
/* Delete the entry from the hash table and the slist */
H5C__DELETE_FROM_INDEX(cache_ptr, entry_ptr, FAIL);
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, FALSE);
H5C__REMOVE_ENTRY_FROM_SLIST(cache_ptr, entry_ptr, FALSE, FAIL)

/* Update the entry for its new address */
entry_ptr->addr = new_addr;
Expand Down
Loading

0 comments on commit 1a89fa2

Please sign in to comment.