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