2
0
mirror of https://github.com/HDFGroup/hdf5.git synced 2025-03-19 16:50:46 +08:00

[svn-r27587] Added a new API call (H5is_library_threadsafe) to the library. This call can

be used to determine at runtime if the library was built with thread-safety.

Fixes HDFFV-9496

Tested on: h5committest
This commit is contained in:
Dana Robinson 2015-08-26 12:05:57 -05:00
parent 6635d4c003
commit 606c16e111
5 changed files with 81 additions and 25 deletions

@ -21,17 +21,17 @@
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5ACprivate.h" /* Metadata cache */
#include "H5Dprivate.h" /* Datasets */
#include "H5Eprivate.h" /* Error handling */
#include "H5FLprivate.h" /* Free lists */
#include "H5Lprivate.h" /* Links */
#include "H5private.h" /* Generic Functions */
#include "H5ACprivate.h" /* Metadata cache */
#include "H5Dprivate.h" /* Datasets */
#include "H5Eprivate.h" /* Error handling */
#include "H5FLprivate.h" /* Free lists */
#include "H5Lprivate.h" /* Links */
#include "H5MMprivate.h" /* Memory management */
#include "H5Pprivate.h" /* Property lists */
#include "H5Tprivate.h" /* Datatypes */
#include "H5Pprivate.h" /* Property lists */
#include "H5SLprivate.h" /* Skip lists */
#include "H5Tprivate.h" /* Datatypes */
#include "H5TSprivate.h" /* Thread safety */
/****************/
/* Local Macros */
@ -972,6 +972,36 @@ H5free_memory(void *mem)
} /* end H5free_memory() */
/*-------------------------------------------------------------------------
* Function: H5is_library_threadsafe
*
* Purpose: Checks to see if the library was built with thread-safety
* enabled.
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5is_library_threadsafe(hbool_t *is_ts)
{
herr_t ret_value = SUCCEED;
FUNC_ENTER_API_NOINIT
H5TRACE1("e", "*b", is_ts);
HDassert(is_ts);
#ifdef H5_HAVE_THREADSAFE
*is_ts = TRUE;
#else /* H5_HAVE_THREADSAFE */
*is_ts = FALSE;
#endif /* H5_HAVE_THREADSAFE */
FUNC_LEAVE_API(ret_value)
} /* end H5is_library_threadsafe() */
#if defined(H5_HAVE_THREADSAFE) && defined(H5_BUILT_AS_DYNAMIC_LIB) \
&& defined(H5_HAVE_WIN32_API) && defined(H5_HAVE_WIN_THREADS)

@ -331,6 +331,7 @@ H5_DLL herr_t H5get_libversion(unsigned *majnum, unsigned *minnum,
unsigned *relnum);
H5_DLL herr_t H5check_version(unsigned majnum, unsigned minnum,
unsigned relnum);
H5_DLL herr_t H5is_library_threadsafe(hbool_t *is_ts);
H5_DLL herr_t H5free_memory(void *mem);
H5_DLL void *H5allocate_memory(size_t size, hbool_t clear);
H5_DLL void *H5resize_memory(void *mem, size_t size);
@ -338,5 +339,6 @@ H5_DLL void *H5resize_memory(void *mem, size_t size);
#ifdef __cplusplus
}
#endif
#endif
#endif /* _H5public_H */

@ -40,13 +40,6 @@
/* ANY new test needs to have a prototype in ttsafe.h */
#include "ttsafe.h"
#ifndef H5_HAVE_THREADSAFE
int main(void)
{
printf("Test skipped because THREADSAFE not enabled\n");
return 0;
}
#else
#define MAX_NUM_NAME 1000
#define NAME_OFFSET 6 /* offset for "name<num>" */
@ -66,6 +59,30 @@ num_digits(int num)
return u;
}
/* Test the H5is_library_threadsafe() function */
void
tts_is_threadsafe(void)
{
hbool_t is_ts;
hbool_t should_be;
#ifdef H5_HAVE_THREADSAFE
is_ts = FALSE;
should_be = TRUE;
#else /* H5_HAVE_THREADSAFE */
is_ts = TRUE;
should_be = FALSE;
#endif /* H5_HAVE_THREADSAFE */
if(H5is_library_threadsafe(&is_ts) != SUCCEED)
TestErrPrintf("H5_is_library_threadsafe() call failed - test failed\n");
if(is_ts != should_be)
TestErrPrintf("Thread-safety value incorrect - test failed\n");
return;
}
/* Routine to generate attribute names for numeric values */
char *gen_name(int value)
{
@ -88,10 +105,13 @@ char *gen_name(int value)
int main(int argc, char *argv[])
{
/* Initialize testing framework */
TestInit(argv[0], NULL, NULL);
/* Tests are generally arranged from least to most complexity... */
AddTest("is_threadsafe", tts_is_threadsafe, NULL, "library threadsafe status", NULL);
#ifdef H5_HAVE_THREADSAFE
AddTest("dcreate", tts_dcreate, cleanup_dcreate, "multi-dataset creation", NULL);
AddTest("error", tts_error, cleanup_error, "per-thread error stacks", NULL);
#ifdef H5_HAVE_PTHREAD_H
@ -100,6 +120,12 @@ int main(int argc, char *argv[])
#endif /* H5_HAVE_PTHREAD_H */
AddTest("acreate", tts_acreate, cleanup_acreate, "multi-attribute creation", NULL);
#else /* H5_HAVE_THREADSAFE */
printf("Most thread-safety tests skipped because THREADSAFE not enabled\n");
#endif /* H5_HAVE_THREADSAFE */
/* Display testing information */
TestInfo(argv[0]);
@ -118,5 +144,6 @@ int main(int argc, char *argv[])
TestCleanup();
return GetTestNumErrs();
} /* end main() */
#endif /*H5_HAVE_THREADSAFE*/

@ -20,8 +20,6 @@
#ifndef TTSAFE_H
#define TTSAFE_H
#include <string.h>
/*
* Include required headers. This file tests internal library functions,
* so we include the private headers here.
@ -31,16 +29,13 @@
#include "H5Eprivate.h"
#include "testhdf5.h"
#ifdef H5_HAVE_THREADSAFE
/* Include pthread library for threadsafe tests */
#ifdef H5_HAVE_PTHREAD_H
#include <pthread.h>
#endif /* H5_HAVE_PTHREAD_H */
/* Prototypes for the support routines */
extern char* gen_name(int);
/* Prototypes for the test routines */
void tts_is_threadsafe(void);
#ifdef H5_HAVE_THREADSAFE
void tts_dcreate(void);
void tts_error(void);
void tts_cancel(void);
@ -54,3 +49,4 @@ void cleanup_acreate(void);
#endif /* H5_HAVE_THREADSAFE */
#endif /* TTSAFE_H */

@ -231,3 +231,4 @@ void cleanup_error(void)
}
#endif /*H5_HAVE_THREADSAFE*/