From 986c7451a03aa8d54ce3b57ffd2e394665d360cc Mon Sep 17 00:00:00 2001 From: David Young Date: Mon, 3 Feb 2020 11:59:14 -0600 Subject: Replace pthread_self_ulong() with H5TS_thread_id(). The POSIX Threads implementation ought to be portable to any system that has POSIX Threads. On Windows, I use the same API call as before. --- src/H5CS.c | 6 +- src/H5Eint.c | 8 +-- src/H5TS.c | 119 +++++++++++++++++++++++++++++++++++++++ src/H5TSprivate.h | 3 +- src/H5private.h | 5 -- src/H5win32defs.h | 4 -- test/Makefile.am | 2 +- test/h5test.c | 4 +- test/thread_id.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 288 insertions(+), 25 deletions(-) create mode 100644 test/thread_id.c diff --git a/src/H5CS.c b/src/H5CS.c index 0a3dcce..f429d98 100644 --- a/src/H5CS.c +++ b/src/H5CS.c @@ -145,11 +145,7 @@ H5CS_print_stack(const H5CS_t *fstack, FILE *stream) HDfprintf(stream, "HDF5-DIAG: Function stack from %s ", H5_lib_vers_info_g); /* try show the process or thread id in multiple processes cases*/ -#ifdef H5_HAVE_THREADSAFE - HDfprintf(stream, "thread %lu.", HDpthread_self_ulong()); -#else /* H5_HAVE_THREADSAFE */ - HDfprintf(stream, "thread 0."); -#endif /* H5_HAVE_THREADSAFE */ + HDfprintf(stream, "thread %lu.", H5TS_thread_id()); if(fstack && fstack->nused>0) HDfprintf(stream, " Back trace follows."); HDfputc('\n', stream); diff --git a/src/H5Eint.c b/src/H5Eint.c index acd5b28..1cca2eb 100644 --- a/src/H5Eint.c +++ b/src/H5Eint.c @@ -259,10 +259,8 @@ H5E__walk1_cb(int n, H5E_error1_t *err_desc, void *client_data) else HDfprintf(stream, "thread 0"); } /* end block */ -#elif defined(H5_HAVE_THREADSAFE) - HDfprintf(stream, "thread %lu", (unsigned long)HDpthread_self_ulong()); #else - HDfprintf(stream, "thread 0"); + HDfprintf(stream, "thread %lu", H5TS_thread_id()); #endif HDfprintf(stream, ":\n"); } /* end if */ @@ -391,10 +389,8 @@ H5E__walk2_cb(unsigned n, const H5E_error2_t *err_desc, void *client_data) else HDfprintf(stream, "thread 0"); } /* end block */ -#elif defined(H5_HAVE_THREADSAFE) - HDfprintf(stream, "thread %lu", (unsigned long)HDpthread_self_ulong()); #else - HDfprintf(stream, "thread 0"); + HDfprintf(stream, "thread %lu", H5TS_thread_id()); #endif HDfprintf(stream, ":\n"); } /* end if */ diff --git a/src/H5TS.c b/src/H5TS.c index 10e14d5..aa60eba 100644 --- a/src/H5TS.c +++ b/src/H5TS.c @@ -37,6 +37,31 @@ H5TS_key_t H5TS_funcstk_key_g; H5TS_key_t H5TS_apictx_key_g; H5TS_key_t H5TS_cancel_key_g; +#ifndef H5_HAVE_WIN_THREADS + +/* An h5_tid_t is a record of a thread identifier that is + * available for reuse. + */ +struct _tid; +typedef struct _tid h5_tid_t; + +struct _tid { + h5_tid_t *next; + unsigned long id; +}; + +/* Pointer to first free thread ID record or NULL. */ +static h5_tid_t *tid_next_free = NULL; +static unsigned long tid_next_id = 0; + +/* Mutual exclusion for access to tid_next_free and tid_next_id. */ +static pthread_mutex_t tid_mtx; + +/* Key for thread-local storage of the thread ID. */ +static H5TS_key_t tid_key; + +#endif /* H5_HAVE_WIN_THREADS */ + /*-------------------------------------------------------------------------- * NAME @@ -68,6 +93,89 @@ H5TS_key_destructor(void *key_val) #ifndef H5_HAVE_WIN_THREADS +/* When a thread shuts down, put its ID record on the free list. */ +static void +tid_destructor(void *_v) +{ + h5_tid_t *tid = _v; + + if (tid == NULL) + return; + + /* XXX I can use mutexes in destructors, right? */ + /* TBD use an atomic CAS */ + pthread_mutex_lock(&tid_mtx); + tid->next = tid_next_free; + tid_next_free = tid; + pthread_mutex_unlock(&tid_mtx); +} + +/* Initialize for integer thread identifiers. */ +static void +tid_init(void) +{ + pthread_mutex_init(&tid_mtx, NULL); + pthread_key_create(&tid_key, tid_destructor); +} + +/* Return an integer identifier, ID, for the current thread satisfies the + * following properties: + * + * 1 1 <= ID <= ULONG_MAX + * 2 The ID is constant over the thread's lifetime. + * 3 No two threads share an ID during their lifetimes. + * 4 A thread's ID is available for reuse as soon as it is joined. + * + * ID 0 is reserved. H5TS_thread_id() returns 0 if the library was not built + * with thread safety or if an error prevents it from assigning an ID. + */ +unsigned long +H5TS_thread_id(void) +{ + h5_tid_t *tid = pthread_getspecific(tid_key); + h5_tid_t proto_tid; + + /* An ID is already assigned. */ + if (tid != NULL) + return tid->id; + + /* An ID is *not* already assigned: reuse an ID that's on the + * free list, or else generate a new ID. + * + * Allocating memory while holding a mutex is bad form, so + * point `tid` at `proto_tid` if we need to allocate some + * memory. + */ + pthread_mutex_lock(&tid_mtx); + if ((tid = tid_next_free) != NULL) + tid_next_free = tid->next; + else if (tid_next_id != ULONG_MAX) { + tid = &proto_tid; + tid->id = ++tid_next_id; + } + pthread_mutex_unlock(&tid_mtx); + + /* If a prototype ID record was established, copy it to the heap. */ + if (tid == &proto_tid) { + if ((tid = HDmalloc(sizeof(*tid))) != NULL) + *tid = proto_tid; + } + + if (tid == NULL) + return 0; + + /* Finish initializing the ID record and set a thread-local pointer + * to it. + */ + tid->next = NULL; + if (pthread_setspecific(tid_key, tid) != 0) { + tid_destructor(tid); + return 0; + } + + return tid->id; +} + /*-------------------------------------------------------------------------- * NAME * H5TS_pthread_first_thread_init @@ -104,6 +212,9 @@ H5TS_pthread_first_thread_init(void) pthread_cond_init(&H5_g.init_lock.cond_var, NULL); H5_g.init_lock.lock_count = 0; + /* Initialize integer thread identifiers. */ + tid_init(); + /* initialize key for thread-specific error stacks */ pthread_key_create(&H5TS_errstk_key_g, H5TS_key_destructor); @@ -528,5 +639,13 @@ H5TS_create_thread(void *(*func)(void *), H5TS_attr_t *attr, void *udata) } /* H5TS_create_thread */ +#else /* H5_HAVE_THREADSAFE */ + +unsigned long +H5TS_thread_id(void) +{ + return 0; +} + #endif /* H5_HAVE_THREADSAFE */ diff --git a/src/H5TSprivate.h b/src/H5TSprivate.h index 9e093a6..76cf8f1 100644 --- a/src/H5TSprivate.h +++ b/src/H5TSprivate.h @@ -68,7 +68,7 @@ H5_DLL void H5TS_win32_process_exit(void); H5_DLL herr_t H5TS_win32_thread_enter(void); H5_DLL herr_t H5TS_win32_thread_exit(void); - +#define H5TS_thread_id() ((unsigned long)GetCurrentThreadId()) #else /* H5_HAVE_WIN_THREADS */ @@ -102,6 +102,7 @@ typedef pthread_once_t H5TS_once_t; #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) +H5_DLL unsigned long H5TS_thread_id(void); #endif /* H5_HAVE_WIN_THREADS */ diff --git a/src/H5private.h b/src/H5private.h index 41cef16..f0f3687 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1549,11 +1549,6 @@ extern char *strdup(const char *s); #define HDpthread_self() pthread_self() #endif /* HDpthread_self */ -/* Use this version of pthread_self for printing the thread ID */ -#ifndef HDpthread_self_ulong - #define HDpthread_self_ulong() ((unsigned long)pthread_self()) -#endif /* HDpthread_self_ulong */ - /* Macro for "stringizing" an integer in the C preprocessor (use H5_TOSTRING) */ /* (use H5_TOSTRING, H5_STRINGIZE is just part of the implementation) */ #define H5_STRINGIZE(x) #x diff --git a/src/H5win32defs.h b/src/H5win32defs.h index 0a0bd37..00df56d 100644 --- a/src/H5win32defs.h +++ b/src/H5win32defs.h @@ -163,10 +163,6 @@ extern "C" { /* Non-POSIX functions */ -/* Don't use actual pthread_self on Windows because the return - * type cannot be cast as a ulong like other systems. */ -#define HDpthread_self_ulong() ((unsigned long)GetCurrentThreadId()) - #ifndef H5_HAVE_MINGW #define HDftruncate(F,L) _chsize_s(F,L) #define HDfseek(F,O,W) _fseeki64(F,O,W) diff --git a/test/Makefile.am b/test/Makefile.am index 57080aa..dd0a579 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -63,7 +63,7 @@ TEST_PROG= testhdf5 \ flush1 flush2 app_ref enum set_extent ttsafe enc_dec_plist \ enc_dec_plist_cross_platform getname vfd ros3 s3comms hdfs ntypes \ dangle dtransform reserved cross_read freespace mf vds file_image \ - unregister cache_logging cork swmr vol + unregister cache_logging cork swmr thread_id vol # List programs to be built when testing here. # error_test and err_compat are built at the same time as the other tests, but executed by testerror.sh. diff --git a/test/h5test.c b/test/h5test.c index 78d0077..53a4fdb 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -1172,10 +1172,8 @@ h5_show_hostname(void) else HDprintf("thread 0."); } -#elif defined(H5_HAVE_THREADSAFE) - HDprintf("thread %lu.", HDpthread_self_ulong()); #else - HDprintf("thread 0."); + HDprintf("thread %lu.", H5TS_thread_id()); #endif #ifdef H5_HAVE_WIN32_API diff --git a/test/thread_id.c b/test/thread_id.c new file mode 100644 index 0000000..711a21b --- /dev/null +++ b/test/thread_id.c @@ -0,0 +1,162 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* Check that a thread ID returned by H5TS_thread_id() possesses the + * following properties: + * + * 1 ID >= 1. + * 2 The ID is constant over the thread's lifetime. + * 3 No two threads share an ID during their lifetimes. + * 4 A thread's ID is available for reuse as soon as it is joined. + */ +#include + +/* + * Include required headers. This file tests internal library functions, + * so we include the private headers here. + */ +#include "testhdf5.h" + +#define threads_failure(_call, _result) do { \ + errx(EXIT_FAILURE, "%s.%d: " #_call ": %s", __func__, \ + __LINE__, strerror(_result)); \ +} while (false) + +#if defined(H5_HAVE_THREADSAFE) && !defined(H5_HAVE_WIN_THREADS) + +#define NTHREADS 5 + +static volatile bool failed = false; +static pthread_barrier_t barrier; +static bool used[NTHREADS]; +static pthread_mutex_t used_lock; + +static void +atomic_printf(const char *fmt, ...) +{ + char buf[80]; + va_list ap; + ssize_t nprinted, nwritten; + + va_start(ap, fmt); + nprinted = vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + + if (nprinted == -1) + err(EXIT_FAILURE, "%s.%d: vsnprintf", __func__, __LINE__); + else if (nprinted >= (ssize_t)sizeof(buf)) + errx(EXIT_FAILURE, "%s.%d: vsnprintf overflowed", __func__, __LINE__); + + nwritten = write(STDOUT_FILENO, buf, (size_t)nprinted); + if (nwritten < nprinted) { + errx(EXIT_FAILURE, "%s.%d: write error or short write", + __func__, __LINE__); + } +} + +/* Each thread runs this routine. The routine fetches the current + * thread's ID, makes sure that it is in the expected range, makes + * sure that in this round of testing, no two threads shared the + * same ID, + */ +static void * +thread_main(void H5_ATTR_UNUSED *arg) +{ + unsigned long ntid, tid; + + tid = H5TS_thread_id(); + + if (tid < 1 || NTHREADS < tid) { + atomic_printf("unexpected tid %lu FAIL\n", tid); + goto pre_barrier_error; + } + pthread_mutex_lock(&used_lock); + if (used[tid - 1]) { + atomic_printf("reused tid %lu FAIL\n", tid); + pthread_mutex_unlock(&used_lock); + goto pre_barrier_error; + } + used[tid - 1] = true; + pthread_mutex_unlock(&used_lock); + + atomic_printf("tid %lu in [1, %d] PASS\n", tid, NTHREADS); + pthread_barrier_wait(&barrier); + + ntid = H5TS_thread_id(); + if (ntid != tid) { + atomic_printf("tid changed from %lu to %lu FAIL\n", tid, ntid); + failed = true; + } + return NULL; +pre_barrier_error: + pthread_barrier_wait(&barrier); + failed = true; + return NULL; +} + +int +main(void) +{ + int i, rc, times; + pthread_t threads[NTHREADS]; + + /* Run H5open() to initialize the library's thread-ID freelist, + * mutex, etc. + */ + if (H5open() != SUCCEED) + errx(EXIT_FAILURE, "%s.%d: H5open failed", __func__, __LINE__); + + if ((rc = pthread_mutex_init(&used_lock, NULL)) == -1) + threads_failure(pthread_mutex_init, rc); + + if ((rc = pthread_barrier_init(&barrier, NULL, NTHREADS)) != 0) + threads_failure(pthread_barrier_init, rc); + + /* Start the test threads and join them twice to make sure that + * the thread IDs are recycled in the second round. + */ + for (times = 0; times < 2; times++) { + + for (i = 0; i < NTHREADS; i++) + used[i] = false; // access synchronized by thread create/join + + for (i = 0; i < NTHREADS; i++) { + rc = pthread_create(&threads[i], NULL, thread_main, NULL); + if (rc != 0) + threads_failure(pthread_create, rc); + } + + for (i = 0; i < NTHREADS; i++) { + rc = pthread_join(threads[i], NULL); + if (rc != 0) + threads_failure(pthread_join, rc); + } + + for (i = 0; i < NTHREADS; i++) { + if (!used[i]) // access synchronized by thread create/join + errx(EXIT_FAILURE, "thread ID %d did not run.", i + 1); + } + } + if ((rc = pthread_barrier_destroy(&barrier)) != 0) + threads_failure(pthread_barrier_destroy, rc); + return failed ? EXIT_FAILURE : EXIT_SUCCESS; +} + +#else /*H5_HAVE_THREADSAFE && !H5_HAVE_WIN_THREADS*/ +int +main(void) +{ + errx(EXIT_FAILURE, "not implemented in this configuration."); +} + +#endif /*H5_HAVE_THREADSAFE && !H5_HAVE_WIN_THREADS*/ + -- cgit v0.12 From 65600cbd7229340d7f5ab86dd20b35ae2dabd1ad Mon Sep 17 00:00:00 2001 From: David Young Date: Mon, 3 Feb 2020 12:59:52 -0600 Subject: Add thread_id.c to the MANIFEST and the CMakeLists.txt per Allen's request. --- MANIFEST | 1 + test/CMakeLists.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/MANIFEST b/MANIFEST index c6a7b31..b33c845 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1183,6 +1183,7 @@ ./test/th5s.c ./test/th5s.h5 ./test/theap.c +./test/thread_id.c ./test/tid.c ./test/titerate.c ./test/tlayouto.h5 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 77f9191..a2fb31d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -287,6 +287,7 @@ set (H5_TESTS cache_logging cork swmr + thread_id vol ) -- cgit v0.12 From a20b68b25796d94f1159156acf97322326565c93 Mon Sep 17 00:00:00 2001 From: David Young Date: Mon, 3 Feb 2020 16:23:06 -0600 Subject: Change thread IDs to uint64_t from unsigned long, per Quincey's suggestion. Fix a typo in the H5TS_thread_init() comment and reword some ID properties. --- src/H5CS.c | 2 +- src/H5Eint.c | 4 ++-- src/H5TS.c | 16 ++++++++-------- src/H5TSprivate.h | 4 ++-- test/h5test.c | 2 +- test/thread_id.c | 11 ++++++----- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/H5CS.c b/src/H5CS.c index f429d98..3fccce4 100644 --- a/src/H5CS.c +++ b/src/H5CS.c @@ -145,7 +145,7 @@ H5CS_print_stack(const H5CS_t *fstack, FILE *stream) HDfprintf(stream, "HDF5-DIAG: Function stack from %s ", H5_lib_vers_info_g); /* try show the process or thread id in multiple processes cases*/ - HDfprintf(stream, "thread %lu.", H5TS_thread_id()); + HDfprintf(stream, "thread %" PRIu64 ".", H5TS_thread_id()); if(fstack && fstack->nused>0) HDfprintf(stream, " Back trace follows."); HDfputc('\n', stream); diff --git a/src/H5Eint.c b/src/H5Eint.c index 1cca2eb..ce6675e 100644 --- a/src/H5Eint.c +++ b/src/H5Eint.c @@ -260,7 +260,7 @@ H5E__walk1_cb(int n, H5E_error1_t *err_desc, void *client_data) HDfprintf(stream, "thread 0"); } /* end block */ #else - HDfprintf(stream, "thread %lu", H5TS_thread_id()); + HDfprintf(stream, "thread %" PRIu64, H5TS_thread_id()); #endif HDfprintf(stream, ":\n"); } /* end if */ @@ -390,7 +390,7 @@ H5E__walk2_cb(unsigned n, const H5E_error2_t *err_desc, void *client_data) HDfprintf(stream, "thread 0"); } /* end block */ #else - HDfprintf(stream, "thread %lu", H5TS_thread_id()); + HDfprintf(stream, "thread %" PRIu64, H5TS_thread_id()); #endif HDfprintf(stream, ":\n"); } /* end if */ diff --git a/src/H5TS.c b/src/H5TS.c index aa60eba..7a801e2 100644 --- a/src/H5TS.c +++ b/src/H5TS.c @@ -47,12 +47,12 @@ typedef struct _tid h5_tid_t; struct _tid { h5_tid_t *next; - unsigned long id; + uint64_t id; }; /* Pointer to first free thread ID record or NULL. */ static h5_tid_t *tid_next_free = NULL; -static unsigned long tid_next_id = 0; +static uint64_t tid_next_id = 0; /* Mutual exclusion for access to tid_next_free and tid_next_id. */ static pthread_mutex_t tid_mtx; @@ -118,18 +118,18 @@ tid_init(void) pthread_key_create(&tid_key, tid_destructor); } -/* Return an integer identifier, ID, for the current thread satisfies the +/* Return an integer identifier, ID, for the current thread satisfying the * following properties: * - * 1 1 <= ID <= ULONG_MAX - * 2 The ID is constant over the thread's lifetime. + * 1 1 <= ID <= UINT64_MAX + * 2 ID is constant over the thread's lifetime. * 3 No two threads share an ID during their lifetimes. * 4 A thread's ID is available for reuse as soon as it is joined. * * ID 0 is reserved. H5TS_thread_id() returns 0 if the library was not built * with thread safety or if an error prevents it from assigning an ID. */ -unsigned long +uint64_t H5TS_thread_id(void) { h5_tid_t *tid = pthread_getspecific(tid_key); @@ -149,7 +149,7 @@ H5TS_thread_id(void) pthread_mutex_lock(&tid_mtx); if ((tid = tid_next_free) != NULL) tid_next_free = tid->next; - else if (tid_next_id != ULONG_MAX) { + else if (tid_next_id != UINT64_MAX) { tid = &proto_tid; tid->id = ++tid_next_id; } @@ -641,7 +641,7 @@ H5TS_create_thread(void *(*func)(void *), H5TS_attr_t *attr, void *udata) #else /* H5_HAVE_THREADSAFE */ -unsigned long +uint64_t H5TS_thread_id(void) { return 0; diff --git a/src/H5TSprivate.h b/src/H5TSprivate.h index 76cf8f1..f22ed52 100644 --- a/src/H5TSprivate.h +++ b/src/H5TSprivate.h @@ -68,7 +68,7 @@ H5_DLL void H5TS_win32_process_exit(void); H5_DLL herr_t H5TS_win32_thread_enter(void); H5_DLL herr_t H5TS_win32_thread_exit(void); -#define H5TS_thread_id() ((unsigned long)GetCurrentThreadId()) +#define H5TS_thread_id() ((uint64_t)GetCurrentThreadId()) #else /* H5_HAVE_WIN_THREADS */ @@ -102,7 +102,7 @@ typedef pthread_once_t H5TS_once_t; #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) -H5_DLL unsigned long H5TS_thread_id(void); +H5_DLL uint64_t H5TS_thread_id(void); #endif /* H5_HAVE_WIN_THREADS */ diff --git a/test/h5test.c b/test/h5test.c index 53a4fdb..03731c6 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -1173,7 +1173,7 @@ h5_show_hostname(void) HDprintf("thread 0."); } #else - HDprintf("thread %lu.", H5TS_thread_id()); + HDprintf("thread %" PRIu64 ".", H5TS_thread_id()); #endif #ifdef H5_HAVE_WIN32_API diff --git a/test/thread_id.c b/test/thread_id.c index 711a21b..75ffe17 100644 --- a/test/thread_id.c +++ b/test/thread_id.c @@ -71,29 +71,30 @@ atomic_printf(const char *fmt, ...) static void * thread_main(void H5_ATTR_UNUSED *arg) { - unsigned long ntid, tid; + uint64_t ntid, tid; tid = H5TS_thread_id(); if (tid < 1 || NTHREADS < tid) { - atomic_printf("unexpected tid %lu FAIL\n", tid); + atomic_printf("unexpected tid %" PRIu64 " FAIL\n", tid); goto pre_barrier_error; } pthread_mutex_lock(&used_lock); if (used[tid - 1]) { - atomic_printf("reused tid %lu FAIL\n", tid); + atomic_printf("reused tid %" PRIu64 " FAIL\n", tid); pthread_mutex_unlock(&used_lock); goto pre_barrier_error; } used[tid - 1] = true; pthread_mutex_unlock(&used_lock); - atomic_printf("tid %lu in [1, %d] PASS\n", tid, NTHREADS); + atomic_printf("tid %" PRIu64 " in [1, %d] PASS\n", tid, NTHREADS); pthread_barrier_wait(&barrier); ntid = H5TS_thread_id(); if (ntid != tid) { - atomic_printf("tid changed from %lu to %lu FAIL\n", tid, ntid); + atomic_printf("tid changed from %" PRIu64 " to %" PRIu64 " FAIL\n", + tid, ntid); failed = true; } return NULL; -- cgit v0.12 From cefacee21b5ad569e2394b32793648e1b80f3d6b Mon Sep 17 00:00:00 2001 From: David Young Date: Mon, 3 Feb 2020 16:33:28 -0600 Subject: src/H5Eint.c: #include H5TSprivate.h for H5TS_thread_id() definitions. test/thread_id.c: move threads_failure() inside #ifdefs. --- src/H5Eint.c | 1 + test/thread_id.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/H5Eint.c b/src/H5Eint.c index ce6675e..2aedc17 100644 --- a/src/H5Eint.c +++ b/src/H5Eint.c @@ -37,6 +37,7 @@ #include "H5Epkg.h" /* Error handling */ #include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ +#include "H5TSprivate.h" /* Thread stuff */ /****************/ diff --git a/test/thread_id.c b/test/thread_id.c index 75ffe17..8f6e2d5 100644 --- a/test/thread_id.c +++ b/test/thread_id.c @@ -26,13 +26,13 @@ */ #include "testhdf5.h" +#if defined(H5_HAVE_THREADSAFE) && !defined(H5_HAVE_WIN_THREADS) + #define threads_failure(_call, _result) do { \ errx(EXIT_FAILURE, "%s.%d: " #_call ": %s", __func__, \ __LINE__, strerror(_result)); \ } while (false) -#if defined(H5_HAVE_THREADSAFE) && !defined(H5_HAVE_WIN_THREADS) - #define NTHREADS 5 static volatile bool failed = false; -- cgit v0.12