From d83709c4e6d274ea83b2b0e865d776c244727a38 Mon Sep 17 00:00:00 2001 From: Scott Wegner Date: Mon, 2 Jun 2008 15:39:52 -0500 Subject: [svn-r15128] Purpose: Make Windows threadsafe debug message more useful Description: On Linux-like systems, we can get the ID of the current thread through a pthread_self. However on Windows, the return cannot be cast as a threadID, so we simply couldn't get the ID. Previously we simply gave up and printed a message that we couldn't get an ID. Instead, though, we can use the Windows-specific call to GetCurrentThreadId(), which achieves the same goal. This way we can provide better debug output with threadsafe features. Tested: VS2005 on WinXP VS.NET on WinXP (other platforms not tested because change is within _WIN32 ifdef) --- src/H5Eint.c | 8 ++++++-- test/h5test.c | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/H5Eint.c b/src/H5Eint.c index 66fba91..34290a4 100644 --- a/src/H5Eint.c +++ b/src/H5Eint.c @@ -276,7 +276,9 @@ H5E_walk1_cb(int n, H5E_error1_t *err_desc, void *client_data) } /* end block */ #elif defined(H5_HAVE_THREADSAFE) #ifdef _WIN32 - fprintf(stream, "some thread: no way to know the thread number from pthread on windows"); + /* use GetCurrentThreadId because pthread_self return cannot be cast */ + /* as an unsigned long on Windows */ + fprintf(stream, "thread %lu", (unsigned long)GetCurrentThreadId()); #else fprintf(stream, "thread %lu", (unsigned long)pthread_self()); #endif @@ -396,7 +398,9 @@ H5E_walk2_cb(unsigned n, const H5E_error2_t *err_desc, void *client_data) } /* end block */ #elif defined(H5_HAVE_THREADSAFE) #ifdef _WIN32 - fprintf(stream, "some thread: no way to know the thread number from pthread on windows"); + /* use GetCurrentThreadId because pthread_self return cannot be cast */ + /* as an unsigned long on Windows */ + fprintf(stream, "thread %lu", (unsigned long)GetCurrentThreadId()); #else fprintf(stream, "thread %lu", (unsigned long)pthread_self()); #endif diff --git a/test/h5test.c b/test/h5test.c index 6445ce6..e364d32 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -668,7 +668,9 @@ h5_show_hostname(void) } #elif defined(H5_HAVE_THREADSAFE) #ifdef _WIN32 - printf("some thread: no way to know the thread number from pthread on windows."); + /* use GetCurrentThreadId because pthread_self return cannot be cast */ + /* as an int on Windows */ + fprintf("thread %d.", (int)GetCurrentThreadId()); #else printf("thread %d.", (int)pthread_self()); #endif -- cgit v0.12