diff options
author | David Young <dyoung@hdfgroup.org> | 2020-04-16 21:08:15 (GMT) |
---|---|---|
committer | David Young <dyoung@hdfgroup.org> | 2020-04-16 21:08:15 (GMT) |
commit | 6f65412b76e64478d7a1089afec341f409203729 (patch) | |
tree | 69b0bd0aa923430bffae7ee6bdb12d8ffe092cdd | |
parent | 21f3fae46982195f88b37471896bb68668dff633 (diff) | |
download | hdf5-6f65412b76e64478d7a1089afec341f409203729.zip hdf5-6f65412b76e64478d7a1089afec341f409203729.tar.gz hdf5-6f65412b76e64478d7a1089afec341f409203729.tar.bz2 |
Extract a subroutine, H5F_vfd_swmr_process_eot_queue(), from the
end-of-tick processing macro. H5F_vfd_swmr_process_eot_queue() looks
for files due for end-of-tick processing and calls either the reader or
writer EOT routine.
Always call the reader/writer EOT routines with an actual H5F_t instead
of NULL.
-rw-r--r-- | src/H5Fvfd_swmr.c | 49 | ||||
-rw-r--r-- | src/H5private.h | 55 |
2 files changed, 58 insertions, 46 deletions
diff --git a/src/H5Fvfd_swmr.c b/src/H5Fvfd_swmr.c index 3c6df82..555deef 100644 --- a/src/H5Fvfd_swmr.c +++ b/src/H5Fvfd_swmr.c @@ -860,10 +860,6 @@ H5F_vfd_swmr_writer_end_of_tick(H5F_t *f) FUNC_ENTER_NOAPI(FAIL) - /* When called from FUNC ENTER/EXIT, get the first entry on the EOT queue */ - if(f == NULL) - f = TAILQ_FIRST(&eot_queue_g)->vfd_swmr_file; - HDassert(f); HDassert(f->shared); HDassert(f->shared->pb_ptr); @@ -1113,7 +1109,7 @@ done: *------------------------------------------------------------------------- */ herr_t -H5F_vfd_swmr_reader_end_of_tick(H5F_t *f) +H5F_vfd_swmr_reader_end_of_tick(H5F_t *f, bool entering_api) { uint64_t tmp_tick_num = 0; H5FD_vfd_swmr_idx_entry_t * tmp_mdf_idx; @@ -1129,10 +1125,6 @@ H5F_vfd_swmr_reader_end_of_tick(H5F_t *f) FUNC_ENTER_NOAPI(FAIL) - /* When called from FUNC ENTER/EXIT, get the first entry on the EOT queue */ - if(f == NULL) - f = TAILQ_FIRST(&eot_queue_g)->vfd_swmr_file; - HDassert(f); HDassert(f->shared); HDassert(f->shared->pb_ptr); @@ -1159,7 +1151,10 @@ H5F_vfd_swmr_reader_end_of_tick(H5F_t *f) "%s last tick %" PRIu64 " new tick %" PRIu64, __func__, f->shared->tick_num, tmp_tick_num); - assert(tmp_tick_num < + /* This is ok if we're entering the API, but it should + * not happen if we're exiting the API. + */ + assert(entering_api || tmp_tick_num < f->shared->tick_num + f->shared->vfd_swmr_config.max_lag); if ( tmp_tick_num != f->shared->tick_num ) { @@ -2026,3 +2021,37 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* H5F__vfd_swmr_writer__wait_a_tick() */ + +herr_t +H5F_vfd_swmr_process_eot_queue(bool entering_api) +{ + struct timespec now; + eot_queue_entry_t *first_head, *head; + herr_t ret_value = SUCCEED; + + FUNC_ENTER_NOAPI(FAIL) + + first_head = head = TAILQ_FIRST(&eot_queue_g); + + do { + H5F_t *f = head->vfd_swmr_file; + + if(HDclock_gettime(CLOCK_MONOTONIC, &now) < 0) { + HGOTO_ERROR(H5E_FUNC, H5E_CANTGET, FAIL, + "can't get time via clock_gettime"); + } + if(timespeccmp(&now, &head->end_of_tick, <)) + break; + if (f->shared->vfd_swmr_writer) { + if (H5F_vfd_swmr_writer_end_of_tick(f) < 0) + HGOTO_ERROR(H5E_FUNC, H5E_CANTSET, FAIL, + "end of tick error for VFD SWMR writer"); + } else if (H5F_vfd_swmr_reader_end_of_tick(f, entering_api) < 0) { + HGOTO_ERROR(H5E_FUNC, H5E_CANTSET, FAIL, + "end of tick error for VFD SWMR reader"); + } + } while ((head = TAILQ_FIRST(&eot_queue_g)) != NULL && head != first_head); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} diff --git a/src/H5private.h b/src/H5private.h index e40e5c1..a281c2b 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -2106,45 +2106,28 @@ H5_DLL herr_t H5CX_pop(void); #include "H5FDvfd_swmr_private.h" #include "H5time_private.h" /* for timespeccmp */ -#define VFD_SWMR_TEST_FOR_END_OF_TICK(entering, _swmr_reader_exit, err) \ - /* Initialize the library */ \ - /* TBD assert that the API lock is held. The API lock */ \ - /* synchronizes access to `vfd_swmr_api_entries_g` */ \ - if (!entering && --vfd_swmr_api_entries_g > 0) { \ - ; /* Do nothing: we are still in an API call. */ \ - } else if (entering && vfd_swmr_api_entries_g++ > 0) { \ - ; /* Do nothing: we are *re-*entering the API. */ \ - } else if(err_occurred) { \ - ; /* Do nothing: an error occurred. */ \ - } else if(TAILQ_FIRST(&eot_queue_g) != NULL) { \ - const bool swmr_reader_exit = _swmr_reader_exit; \ - struct timespec curr_time; \ - eot_queue_entry_t *init_eot_queue_head = TAILQ_FIRST(&eot_queue_g); \ - do { \ - if(HDclock_gettime(CLOCK_MONOTONIC, &curr_time) < 0) { \ - HGOTO_ERROR(H5E_FUNC, H5E_CANTGET, err, \ - "can't get time via clock_gettime") \ - } else if(timespeccmp(&curr_time, &end_of_tick_g, <)) { \ - break; \ - } else if (vfd_swmr_writer_g) { \ - if(H5F_vfd_swmr_writer_end_of_tick(NULL) < 0) \ - HGOTO_ERROR(H5E_FUNC, H5E_CANTSET, err, \ - "end of tick error for VFD SWMR writer") \ - } else if(!swmr_reader_exit) { \ - if(H5F_vfd_swmr_reader_end_of_tick(NULL) < 0) \ - HGOTO_ERROR(H5E_FUNC, H5E_CANTSET, err, \ - "end of tick error for VFD SWMR reader") \ - } else \ - break; \ - } while (TAILQ_FIRST(&eot_queue_g) != NULL && \ - TAILQ_FIRST(&eot_queue_g) != init_eot_queue_head); \ - } \ +#define VFD_SWMR_TEST_FOR_END_OF_TICK(entering, err) \ + do { \ + /* TBD assert that the API lock is held. The API lock */ \ + /* synchronizes access to `vfd_swmr_api_entries_g` */ \ + if (!entering && --vfd_swmr_api_entries_g > 0) { \ + ; /* Do nothing: we are still in an API call. */ \ + } else if (entering && vfd_swmr_api_entries_g++ > 0) { \ + ; /* Do nothing: we are *re-*entering the API. */ \ + } else if(err_occurred) { \ + ; /* Do nothing: an error occurred. */ \ + } else if(TAILQ_FIRST(&eot_queue_g) != NULL) { \ + if (H5F_vfd_swmr_process_eot_queue(entering) < 0) \ + HGOTO_ERROR(H5E_FUNC, H5E_CANTSET, err, \ + "error processing EOT queue") \ + } \ + } while (0) /* Use this macro for all "normal" API functions */ #define FUNC_ENTER_API(err) {{ \ FUNC_ENTER_API_COMMON \ FUNC_ENTER_API_INIT(err); \ - VFD_SWMR_TEST_FOR_END_OF_TICK(true, false, err); \ + VFD_SWMR_TEST_FOR_END_OF_TICK(true, err); \ /* Clear thread error stack entering public functions */ \ H5E_clear_stack(NULL); \ { @@ -2156,7 +2139,7 @@ H5_DLL herr_t H5CX_pop(void); #define FUNC_ENTER_API_NOCLEAR(err) {{ \ FUNC_ENTER_API_COMMON \ FUNC_ENTER_API_INIT(err); \ - VFD_SWMR_TEST_FOR_END_OF_TICK(true, false, err); \ + VFD_SWMR_TEST_FOR_END_OF_TICK(true, err); \ { /* @@ -2349,7 +2332,7 @@ H5_DLL herr_t H5CX_pop(void); H5TRACE_RETURN(ret_value); #define FUNC_LEAVE_API(ret_value) \ - VFD_SWMR_TEST_FOR_END_OF_TICK(false, !vfd_swmr_writer_g, ret_value); \ + VFD_SWMR_TEST_FOR_END_OF_TICK(false, ret_value); \ FUNC_LEAVE_API_COMMON(ret_value); \ (void)H5CX_pop(); \ H5_POP_FUNC \ |