Skip to content

Commit

Permalink
Move atomic type specification into macros
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Nov 18, 2024
1 parent 83f7cb4 commit 3f05a46
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 82 deletions.
34 changes: 2 additions & 32 deletions src/H5VLdyn_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ static void H5VL__release_dyn_op(H5VL_dyn_op_t *dyn_op);
/*******************/

/* The current optional operation values */
#ifdef H5_HAVE_MULTITHREAD
/* Initialize in H5VL_init_opt_operation_table() */
static _Atomic(int) H5VL_opt_vals_g[H5VL_SUBCLS_TOKEN + 1];
#else
static int H5VL_opt_vals_g[H5VL_SUBCLS_TOKEN + 1] =
static H5_ATOMIC_SPECIFIER(int) H5VL_opt_vals_g[H5VL_SUBCLS_TOKEN + 1] =
{
H5VL_RESERVED_NATIVE_OPTIONAL, /* H5VL_SUBCLS_NONE */
H5VL_RESERVED_NATIVE_OPTIONAL, /* H5VL_SUBCLS_INFO */
Expand All @@ -87,14 +83,9 @@ static int H5VL_opt_vals_g[H5VL_SUBCLS_TOKEN + 1] =
H5VL_RESERVED_NATIVE_OPTIONAL, /* H5VL_SUBCLS_BLOB */
H5VL_RESERVED_NATIVE_OPTIONAL /* H5VL_SUBCLS_TOKEN */
};
#endif

/* The current optional operations' info */
#ifdef H5_HAVE_MULTITHREAD
static _Atomic(H5SL_t *) H5VL_opt_ops_g[H5VL_SUBCLS_TOKEN + 1] =
#else
static H5SL_t *H5VL_opt_ops_g[H5VL_SUBCLS_TOKEN + 1] =
#endif
static H5_ATOMIC_SPECIFIER(H5SL_t *) H5VL_opt_ops_g[H5VL_SUBCLS_TOKEN + 1] =
{
NULL, /* H5VL_SUBCLS_NONE */
NULL, /* H5VL_SUBCLS_INFO */
Expand Down Expand Up @@ -189,27 +180,6 @@ H5VL__term_opt_operation(void)
FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5VL__term_opt_operation() */

#ifdef H5_HAVE_MULTITHREAD
/*---------------------------------------------------------------------------
* Function: H5VL__init_opt_operation_table
*
* Purpose: Initialize the atomic optional operation table for VOL objects.
*
*---------------------------------------------------------------------------
*/
void
H5VL__init_opt_operation_table(void) {
size_t subcls = 0; /* Index over the elements of operation array */

FUNC_ENTER_PACKAGE_NOERR

/* Iterate over the VOL subclasses */
for (subcls = 0; subcls < NELMTS(H5VL_opt_vals_g); subcls++)
atomic_init(&H5VL_opt_vals_g[subcls], H5VL_RESERVED_NATIVE_OPTIONAL);

FUNC_LEAVE_NOAPI_VOID
} /* H5VL__init_opt_operation_table() */
#endif
/*---------------------------------------------------------------------------
* Function: H5VL__register_opt_operation
*
Expand Down
10 changes: 1 addition & 9 deletions src/H5VLint.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@

/* Object wrapping context info */
typedef struct H5VL_wrap_ctx_t {
#ifdef H5_HAVE_MULTITHREAD
_Atomic unsigned rc;
#else
unsigned rc; /* Ref. count for the # of times the context was set / reset */
#endif
H5_ATOMIC(unsigned) rc; /* Ref. count for the # of times the context was set / reset */
H5VL_t *connector; /* VOL connector for "outermost" class to start wrap */
void *obj_wrap_ctx; /* "wrap context" for outermost connector */
} H5VL_wrap_ctx_t;
Expand Down Expand Up @@ -239,10 +235,6 @@ H5VL_init_phase2(void)
if (H5VL__set_def_conn() < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "unable to set default VOL connector");

#ifdef H5_HAVE_MULTITHREAD
/* Initialize the atomic dynamic optional operation table */
H5VL__init_opt_operation_table();
#endif
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_init_phase2() */
Expand Down
14 changes: 5 additions & 9 deletions src/H5VLpassthru.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
#include <stdlib.h>
#include <string.h>

/* TODO: H5_HAVE_MULTITHREAD seems not to be exposed to this module, always import */
#include <stdatomic.h>

/* Public HDF5 file */
#include "hdf5.h"

#ifdef H5_HAVE_MULTITHREAD
#include <stdatomic.h>
#endif

/* This connector's header */
#include "H5VLpassthru.h"

Expand Down Expand Up @@ -368,12 +369,7 @@ static const H5VL_class_t H5VL_pass_through_g = {
};

/* The connector identification number, initialized at runtime */
#ifdef H5_HAVE_MULTITHREAD
static _Atomic(hid_t) H5VL_PASSTHRU_ID_g = ATOMIC_VAR_INIT(H5I_INVALID_HID);
#else
static hid_t H5VL_PASSTHRU_ID_g = H5I_INVALID_HID;
#endif

static H5_ATOMIC_SPECIFIER(hid_t) H5VL_PASSTHRU_ID_g = H5_ATOMIC_VAR_INIT(H5I_INVALID_HID);
/*-------------------------------------------------------------------------
* Function: H5VL__pass_through_new_obj
*
Expand Down
12 changes: 2 additions & 10 deletions src/H5VLprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,15 @@
/* Internal struct to track VOL connector information for objects */
typedef struct H5VL_t {
const H5VL_class_t *cls; /* Pointer to connector class struct */
#ifdef H5_HAVE_MULTITHREAD
_Atomic int64_t nrefs; /* Number of references by objects using this struct */
#else
int64_t nrefs; /* Number of references by objects using this struct */
#endif
H5_ATOMIC(int64_t) nrefs; /* Number of references by objects using this struct */
hid_t id; /* Identifier for the VOL connector */
} H5VL_t;

/* Internal vol object structure returned to the API */
typedef struct H5VL_object_t {
void *data; /* Pointer to connector-managed data for this object */
H5VL_t *connector; /* Pointer to VOL connector struct */
#ifdef H5_HAVE_MULTITHREAD
_Atomic size_t rc; /* Reference count */
#else
size_t rc; /* Reference count */
#endif
H5_ATOMIC(size_t) rc; /* Reference count */

} H5VL_object_t;

Expand Down
15 changes: 15 additions & 0 deletions src/H5public.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,21 @@ typedef void (*H5_atclose_func_t)(void *ctx);
extern "C" {
#endif

/**
* Macros that paper over differences between single-threaded and
* multi-threaded builds of the library.
*/
#ifdef H5_HAVE_MULTITHREAD
#define H5_ATOMIC(type) _Atomic type
#define H5_ATOMIC_SPECIFIER(type) _Atomic(type)
#define H5_ATOMIC_VAR_INIT(value) ATOMIC_VAR_INIT(value)
#else
#define H5_ATOMIC(type) type
#define H5_ATOMIC_SPECIFIER(type) type
#define H5_ATOMIC_VAR_INIT(value) value
#endif


/* Functions in H5.c */
/**
* \ingroup H5
Expand Down
15 changes: 4 additions & 11 deletions test/h5test.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,10 @@ const char *LIBVER_NAMES[] = {"earliest", /* H5F_LIBVER_EARLIEST = 0 */
static H5E_auto2_t err_func = NULL;

/* Global variables for testing */
#ifdef H5_HAVE_MULTITHREAD
_Atomic size_t n_tests_run_g = 0;
_Atomic size_t n_tests_passed_g = 0;
_Atomic size_t n_tests_failed_g = 0;
_Atomic size_t n_tests_skipped_g = 0;
#else
size_t n_tests_run_g = 0;
size_t n_tests_passed_g = 0;
size_t n_tests_failed_g = 0;
size_t n_tests_skipped_g = 0;
#endif /* H5_HAVE_MULTITHREAD */
H5_ATOMIC(size_t) n_tests_run_g = 0;
H5_ATOMIC(size_t) n_tests_passed_g = 0;
H5_ATOMIC(size_t) n_tests_failed_g = 0;
H5_ATOMIC(size_t) n_tests_skipped_g = 0;

/* Value of currently registered optional dynamic VOL operation */
int reg_opt_curr_op_val = 0;
Expand Down
15 changes: 4 additions & 11 deletions test/h5test.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,17 +413,10 @@ H5TEST_DLL char *getenv_all(MPI_Comm comm, int root, const char *name);
/* Extern global variables */
H5TEST_DLLVAR int TestVerbosity;
/* Global variables for testing */
#ifdef H5_HAVE_MULTITHREAD
H5TEST_DLLVAR _Atomic size_t n_tests_run_g;
H5TEST_DLLVAR _Atomic size_t n_tests_passed_g;
H5TEST_DLLVAR _Atomic size_t n_tests_failed_g;
H5TEST_DLLVAR _Atomic size_t n_tests_skipped_g;
#else
H5TEST_DLLVAR size_t n_tests_run_g;
H5TEST_DLLVAR size_t n_tests_passed_g;
H5TEST_DLLVAR size_t n_tests_failed_g;
H5TEST_DLLVAR size_t n_tests_skipped_g;
#endif
H5TEST_DLLVAR H5_ATOMIC(size_t) n_tests_run_g;
H5TEST_DLLVAR H5_ATOMIC(size_t) n_tests_passed_g;
H5TEST_DLLVAR H5_ATOMIC(size_t) n_tests_failed_g;
H5TEST_DLLVAR H5_ATOMIC(size_t) n_tests_skipped_g;

H5TEST_DLLVAR uint64_t vol_cap_flags_g;

Expand Down

0 comments on commit 3f05a46

Please sign in to comment.