diff options
author | David Young <dyoung@hdfgroup.org> | 2019-12-10 16:52:58 (GMT) |
---|---|---|
committer | David Young <dyoung@hdfgroup.org> | 2019-12-10 16:52:58 (GMT) |
commit | fed174988dc6eb9125adcf33b946be042d68cf1c (patch) | |
tree | 6a44d35cb945a2d1eda92f7598b26f725213eaf4 /src | |
parent | 38902de4932939e701f01219f4bff6d70b3953a7 (diff) | |
download | hdf5-fed174988dc6eb9125adcf33b946be042d68cf1c.zip hdf5-fed174988dc6eb9125adcf33b946be042d68cf1c.tar.gz hdf5-fed174988dc6eb9125adcf33b946be042d68cf1c.tar.bz2 |
Shorten the type name `H5F_vfd_swmr_eot_queue_entry_t` to `eot_queue_entry_t`:
people have to read and type this stuff!
Use TAILQ_* macros instead of an unnecessary custom implementation of
doubly-linked lists.
Diffstat (limited to 'src')
-rw-r--r-- | src/H5FDvfd_swmr_private.h | 32 | ||||
-rw-r--r-- | src/H5Fvfd_swmr.c | 92 | ||||
-rw-r--r-- | src/H5private.h | 8 |
3 files changed, 46 insertions, 86 deletions
diff --git a/src/H5FDvfd_swmr_private.h b/src/H5FDvfd_swmr_private.h index c12239c..5351b07 100644 --- a/src/H5FDvfd_swmr_private.h +++ b/src/H5FDvfd_swmr_private.h @@ -12,13 +12,15 @@ #ifndef _H5FDvfd_swmr_private_H #define _H5FDvfd_swmr_private_H +#include "bsdqueue.h" /* for TAILQ_* */ + /* Forward declaration */ struct H5F_t; struct H5F_shared_t; struct H5FD_vfd_swmr_idx_entry_t; /* - * struct H5F_vfd_eot_queue_entry_t + * struct eot_queue_entry_t * * This is the structure for an entry on the end-of-tick queue (EOT queue) of files * opened in either VFD SWMR write or VFD SWMR read mode. This queue is maintained @@ -27,7 +29,7 @@ struct H5FD_vfd_swmr_idx_entry_t; * of tick has arrived for the specified file, and to initiate end of tick processing * if it has. * - * The fields of H5F_vfd_eot_queue_entry_t are discussed below: + * The fields of eot_queue_entry_t are discussed below: * * vfd_swmr_file: Pointer to the instance of H5F_file_t containing the shared * fields of the associated file that has been opened in VFD SWMR mode @@ -41,31 +43,27 @@ struct H5FD_vfd_swmr_idx_entry_t; * * end_of_tick: Expiration time of the current tick of the target file. * - * next: Pointer to the next element in the end of tick queue, or NULL if there - * is no next entry. Note that if next is not NULL, next->end_of_tick - * must be greater than or equal to end_of_tick. - * - * prev: Pointer to the previous element in the end of tick queue, or NULL if - * there is no previous entry. Note that if prev is not NULL, - * prev->end_of_tick must be less than or equal to end_of_tick. - * + * link: Forward and backward linkage between the next element and the previous + * element (or the queue head). Note that if there is a following entry, + * `next`, then `next->end_of_tick` must be greater than or equal to + * `end_of_tick`. */ -typedef struct H5F_vfd_swmr_eot_queue_entry_t { +typedef struct eot_queue_entry { hbool_t vfd_swmr_writer; uint64_t tick_num; struct timespec end_of_tick; struct H5F_t *vfd_swmr_file; /* NOTE: for the time being use H5F_t instead H5F_file_t */ - struct H5F_vfd_swmr_eot_queue_entry_t *next; - struct H5F_vfd_swmr_eot_queue_entry_t *prev; -} H5F_vfd_swmr_eot_queue_entry_t; + TAILQ_ENTRY(eot_queue_entry) link; +} eot_queue_entry_t; extern unsigned int vfd_swmr_api_entries_g; extern hbool_t vfd_swmr_writer_g; extern struct timespec end_of_tick_g; -/* The head and tail pointers of the EOT queue */ -extern H5F_vfd_swmr_eot_queue_entry_t *vfd_swmr_eot_queue_head_g; -extern H5F_vfd_swmr_eot_queue_entry_t *vfd_swmr_eot_queue_tail_g; +/* The head of the EOT queue */ +typedef TAILQ_HEAD(eot_queue, eot_queue_entry) eot_queue_t; + +extern eot_queue_t eot_queue_g; /***************************************/ /* Library-private Function Prototypes */ diff --git a/src/H5Fvfd_swmr.c b/src/H5Fvfd_swmr.c index 78f0dd6..f7ab9fd 100644 --- a/src/H5Fvfd_swmr.c +++ b/src/H5Fvfd_swmr.c @@ -76,20 +76,6 @@ entry_ptr->prev = NULL; \ } /* H5F__LL_REMOVE() */ -/* Append an entry to the doubly linked list */ -#define H5F__LL_APPEND(entry_ptr, head_ptr, tail_ptr) \ -{ \ - if((head_ptr) == NULL ) { \ - (head_ptr) = (entry_ptr); \ - (tail_ptr) = (entry_ptr); \ - } \ - else { \ - (tail_ptr)->next = (entry_ptr); \ - (entry_ptr)->prev = (tail_ptr); \ - (tail_ptr) = (entry_ptr); \ - } \ -} /* H5F__LL_APPEND() */ - /* Prepend an entry to the doubly linked list */ #define H5F__LL_PREPEND(entry_ptr, head_ptr, tail_ptr) \ { \ @@ -103,27 +89,6 @@ } \ } /* H5F__LL_PREPEND() */ -/* Insert an entry after the predecessor entry "prec_ptr" on the EOT queue */ -#define H5F_EOT_INSERT_AFTER(entry_ptr, prec_ptr, head_ptr, tail_ptr) \ -{ \ - /* The list is empty or has no predecessor -- prepend */ \ - if(prec_ptr == NULL) \ - H5F__LL_PREPEND(entry_ptr, head_ptr, tail_ptr) \ - \ - /* The predecessor entry is at head of list -- append */ \ - else if(prec_ptr->prev == NULL) \ - H5F__LL_APPEND(entry_ptr, head_ptr, tail_ptr) \ - \ - /* The predecessor entry is in the body of list -- insert after it */ \ - else \ - { \ - entry_ptr->prev = prec_ptr; \ - entry_ptr->next = prec_ptr->next; \ - prec_ptr->next->prev = entry_ptr; \ - prec_ptr->next = entry_ptr; \ - } \ -} /* H5F_EOT_INSERT_AFTER() */ - /********************/ /* Local Prototypes */ /********************/ @@ -154,11 +119,10 @@ unsigned int vfd_swmr_api_entries_g = 0;/* Times the library was entered * transitions. */ /* - * The head and tail of the end of tick queue (EOT queue) for files opened in either + * The head of the end of tick queue (EOT queue) for files opened in either * VFD SWMR write or VFD SWMR read mode */ -H5F_vfd_swmr_eot_queue_entry_t *vfd_swmr_eot_queue_head_g = NULL; -H5F_vfd_swmr_eot_queue_entry_t *vfd_swmr_eot_queue_tail_g = NULL; +eot_queue_t eot_queue_g = TAILQ_HEAD_INITIALIZER(eot_queue_g); /*******************/ /* Local Variables */ @@ -167,8 +131,8 @@ H5F_vfd_swmr_eot_queue_entry_t *vfd_swmr_eot_queue_tail_g = NULL; /* Declare a free list to manage the H5F_vfd_swmr_dl_entry_t struct */ H5FL_DEFINE(H5F_vfd_swmr_dl_entry_t); -/* Declare a free list to manage the H5F_vfd_swmr_eot_queue_entry_t struct */ -H5FL_DEFINE(H5F_vfd_swmr_eot_queue_entry_t); +/* Declare a free list to manage the eot_queue_entry_t struct */ +H5FL_DEFINE(eot_queue_entry_t); /*------------------------------------------------------------------------- @@ -839,7 +803,7 @@ H5F_vfd_swmr_writer_end_of_tick(H5F_t *f) /* When called from FUNC ENTER/EXIT, get the first entry on the EOT queue */ if(f == NULL) - f = vfd_swmr_eot_queue_head_g->vfd_swmr_file; + f = TAILQ_FIRST(&eot_queue_g)->vfd_swmr_file; HDassert(f); HDassert(f->shared); @@ -1116,7 +1080,7 @@ H5F_vfd_swmr_reader_end_of_tick(H5F_t *f) /* When called from FUNC ENTER/EXIT, get the first entry on the EOT queue */ if(f == NULL) - f = vfd_swmr_eot_queue_head_g->vfd_swmr_file; + f = TAILQ_FIRST(&eot_queue_g)->vfd_swmr_file; HDassert(f); HDassert(f->shared); @@ -1421,26 +1385,25 @@ done: herr_t H5F_vfd_swmr_remove_entry_eot(H5F_t *f) { - H5F_vfd_swmr_eot_queue_entry_t *curr; + eot_queue_entry_t *curr; FUNC_ENTER_NOAPI_NOINIT_NOERR /* Free the entry on the EOT queue that corresponds to f */ - for (curr = vfd_swmr_eot_queue_head_g; curr != NULL; curr = curr->next) { + TAILQ_FOREACH(curr, &eot_queue_g, link) { if (curr->vfd_swmr_file == f) break; } if (curr != NULL) { - H5F__LL_REMOVE(curr, vfd_swmr_eot_queue_head_g, - vfd_swmr_eot_queue_tail_g) - curr = H5FL_FREE(H5F_vfd_swmr_eot_queue_entry_t, curr); + TAILQ_REMOVE(&eot_queue_g, curr, link); + curr = H5FL_FREE(eot_queue_entry_t, curr); } - if(vfd_swmr_eot_queue_head_g) { - vfd_swmr_writer_g = vfd_swmr_eot_queue_head_g->vfd_swmr_writer; - end_of_tick_g = vfd_swmr_eot_queue_head_g->end_of_tick; + if(!TAILQ_EMPTY(&eot_queue_g)) { + vfd_swmr_writer_g = TAILQ_FIRST(&eot_queue_g)->vfd_swmr_writer; + end_of_tick_g = TAILQ_FIRST(&eot_queue_g)->end_of_tick; } else vfd_swmr_writer_g = FALSE; @@ -1464,14 +1427,14 @@ H5F_vfd_swmr_remove_entry_eot(H5F_t *f) herr_t H5F_vfd_swmr_insert_entry_eot(H5F_t *f) { - H5F_vfd_swmr_eot_queue_entry_t *entry_ptr; /* An entry on the EOT end of tick queue */ - H5F_vfd_swmr_eot_queue_entry_t *prec_ptr; /* The predecessor entry on the EOT end of tick queue */ + eot_queue_entry_t *entry_ptr; /* An entry on the EOT end of tick queue */ + eot_queue_entry_t *prec_ptr; /* The predecessor entry on the EOT end of tick queue */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) /* Allocate an entry to be inserted onto the EOT queue */ - if (NULL == (entry_ptr = H5FL_CALLOC(H5F_vfd_swmr_eot_queue_entry_t))) + if (NULL == (entry_ptr = H5FL_CALLOC(eot_queue_entry_t))) HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "unable to allocate the end of tick queue entry") /* Initialize the entry */ @@ -1479,24 +1442,23 @@ H5F_vfd_swmr_insert_entry_eot(H5F_t *f) entry_ptr->tick_num = f->shared->tick_num; entry_ptr->end_of_tick = f->shared->end_of_tick; entry_ptr->vfd_swmr_file = f; - entry_ptr->next = NULL; - entry_ptr->prev = NULL; /* Found the position to insert the entry on the EOT queue */ - for (prec_ptr = vfd_swmr_eot_queue_tail_g; - prec_ptr != NULL; - prec_ptr = prec_ptr->prev) { + TAILQ_FOREACH_REVERSE(prec_ptr, &eot_queue_g, eot_queue, link) { if (timespeccmp(&prec_ptr->end_of_tick, &entry_ptr->end_of_tick, <=)) break; } /* Insert the entry onto the EOT queue */ - H5F_EOT_INSERT_AFTER(entry_ptr, prec_ptr, vfd_swmr_eot_queue_head_g, vfd_swmr_eot_queue_tail_g); + if (prec_ptr != NULL) + TAILQ_INSERT_AFTER(&eot_queue_g, prec_ptr, entry_ptr, link); + else + TAILQ_INSERT_HEAD(&eot_queue_g, entry_ptr, link); /* Set up globals accordinly */ - if(vfd_swmr_eot_queue_head_g) { - vfd_swmr_writer_g = vfd_swmr_eot_queue_head_g->vfd_swmr_writer; - end_of_tick_g = vfd_swmr_eot_queue_head_g->end_of_tick; + if(!TAILQ_EMPTY(&eot_queue_g)) { + vfd_swmr_writer_g = TAILQ_FIRST(&eot_queue_g)->vfd_swmr_writer; + end_of_tick_g = TAILQ_FIRST(&eot_queue_g)->end_of_tick; } else vfd_swmr_writer_g = FALSE; @@ -1523,13 +1485,13 @@ herr_t H5F_dump_eot_queue(void) { int i; - H5F_vfd_swmr_eot_queue_entry_t *curr; + eot_queue_entry_t *curr; FUNC_ENTER_NOAPI_NOINIT_NOERR - for (i = 0, curr = vfd_swmr_eot_queue_head_g; + for (curr = TAILQ_FIRST(&eot_queue_g), i = 0; curr != NULL; - curr = curr->next, i++) { + curr = TAILQ_NEXT(curr, link), i++) { HDfprintf(stderr, "%d: %s tick_num %" PRIu64 ", end_of_tick %jd.%09ld, vfd_swmr_file %p\n", i, curr->vfd_swmr_writer ? "writer" : "not writer", diff --git a/src/H5private.h b/src/H5private.h index cbdccce..e40e5c1 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -2116,10 +2116,10 @@ H5_DLL herr_t H5CX_pop(void); ; /* Do nothing: we are *re-*entering the API. */ \ } else if(err_occurred) { \ ; /* Do nothing: an error occurred. */ \ - } else if(vfd_swmr_eot_queue_head_g != NULL) { \ + } else if(TAILQ_FIRST(&eot_queue_g) != NULL) { \ const bool swmr_reader_exit = _swmr_reader_exit; \ struct timespec curr_time; \ - struct H5F_vfd_swmr_eot_queue_entry_t *init_eot_queue_head = vfd_swmr_eot_queue_head_g; \ + 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, \ @@ -2136,8 +2136,8 @@ H5_DLL herr_t H5CX_pop(void); "end of tick error for VFD SWMR reader") \ } else \ break; \ - } while ((vfd_swmr_eot_queue_head_g != NULL) && \ - (vfd_swmr_eot_queue_head_g != init_eot_queue_head)); \ + } while (TAILQ_FIRST(&eot_queue_g) != NULL && \ + TAILQ_FIRST(&eot_queue_g) != init_eot_queue_head); \ } \ /* Use this macro for all "normal" API functions */ |