Skip to content

Commit

Permalink
Merge pull request HDFGroup#14 from mattjala/errstk_compatibility
Browse files Browse the repository at this point in the history
Use library thread routines in error stack test
  • Loading branch information
mattjala authored Nov 25, 2024
2 parents 877fc64 + 9d72bc4 commit 3e445e1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/H5TSprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ typedef pthread_once_t H5TS_once_t;
#define H5TS_attr_setscope(attr_ptr, scope) pthread_attr_setscope(attr_ptr, scope)
#define H5TS_attr_destroy(attr_ptr) pthread_attr_destroy(attr_ptr)
#define H5TS_wait_for_thread(thread) pthread_join(thread, NULL)
#define H5TS_wait_for_thread_ret(thread, ret) pthread_join(thread, ret)
#define H5TS_mutex_init(mutex) pthread_mutex_init(mutex, NULL)
#define H5TS_mutex_lock_simple(mutex) pthread_mutex_lock(mutex)
#define H5TS_mutex_unlock_simple(mutex) pthread_mutex_unlock(mutex)
Expand Down
7 changes: 5 additions & 2 deletions test/ttsafe.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,15 @@ main(int argc, char *argv[])

/* Tests are generally arranged from least to most complexity... */
AddTest("is_threadsafe", tts_is_threadsafe, NULL, "library threadsafe status", NULL, 0);

#if defined(H5_HAVE_THREADSAFE) || defined(H5_HAVE_MULTITHREAD)
AddTest("errstk", tts_errstk, NULL, "error stack cleanup", NULL, 0);
#endif

#ifdef H5_HAVE_THREADSAFE
AddTest("dcreate", tts_dcreate, cleanup_dcreate, "multi-dataset creation", NULL, 0);
AddTest("error", tts_error, cleanup_error, "per-thread error stacks", NULL, 0);
#ifdef H5_HAVE_PTHREAD_H
/* TBD - Later library versions add H5TS wrapper routines for compatibility with windows threads too */
AddTest("tts_errstk", tts_errstk, NULL, "per-thread error stack cleanup", NULL, 0);
/* Thread cancellability only supported with pthreads ... */
AddTest("cancel", tts_cancel, cleanup_cancel, "thread cancellation safety test", NULL, 0);
#endif /* H5_HAVE_PTHREAD_H */
Expand Down
6 changes: 5 additions & 1 deletion test/ttsafe.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ extern char *gen_name(int);

/* Prototypes for the test routines */
void tts_is_threadsafe(void);

#if defined H5_HAVE_THREADSAFE || defined H5_HAVE_MULTITHREAD
void tts_errstk(void);
#endif

#ifdef H5_HAVE_THREADSAFE
void tts_dcreate(void);
void tts_error(void);
void tts_cancel(void);
void tts_acreate(void);
void tts_attr_vlen(void);
void tts_errstk(void);

/* Prototypes for the cleanup routines */
void cleanup_dcreate(void);
Expand Down
17 changes: 7 additions & 10 deletions test/ttsafe_error_stacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "ttsafe.h"

/* TBD - Later library versions add H5TS wrapper routines for compatibility with windows threads too */
#ifdef H5_HAVE_PTHREAD_H
#if defined(H5_HAVE_THREADSAFE) || defined(H5_HAVE_MULTITHREAD)

#define ERR_CLS_NAME "Custom error class"
#define ERR_CLS_LIB_NAME "example_lib"
Expand Down Expand Up @@ -88,17 +87,15 @@ tts_errstk(void)
/* Open library */
H5open();

status = pthread_create(&threads[0], NULL, generate_hdf5_error, NULL);
CHECK(status, FAIL, "H5TS_thread_create");
threads[0] = H5TS_create_thread(generate_hdf5_error, NULL, NULL);

status = pthread_join(threads[0], NULL);
CHECK(status, FAIL, "H5TS_thread_join");
status = H5TS_wait_for_thread(threads[0]);
CHECK(status, FAIL, "H5TS_wait_for_thread");

status = pthread_create(&threads[1], NULL, generate_user_error, NULL);
CHECK(status, FAIL, "H5TS_thread_create");
threads[1] = H5TS_create_thread(generate_hdf5_error, NULL, NULL);

status = pthread_join(threads[1], (void *)&err_cls_id);
CHECK(status, FAIL, "H5TS_thread_join");
status = H5TS_wait_for_thread_ret(threads[1], (void *)&err_cls_id);
CHECK(status, FAIL, "H5TS_wait_for_thread");

if (err_cls_id <= 0) {
TestErrPrintf("Failed to set up user error\n");
Expand Down

0 comments on commit 3e445e1

Please sign in to comment.