summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Wegner <swegner@hdfgroup.org>2008-06-06 19:11:46 (GMT)
committerScott Wegner <swegner@hdfgroup.org>2008-06-06 19:11:46 (GMT)
commit259d1afce9bca2f7dfada3bd396e7f804bb3c1a6 (patch)
treeb2c754200c341f52256a3b3c45924bf38d3c3769
parentba9abd20069ec92af1b25ff1a5ea9b88d84462b8 (diff)
downloadhdf5-259d1afce9bca2f7dfada3bd396e7f804bb3c1a6.zip
hdf5-259d1afce9bca2f7dfada3bd396e7f804bb3c1a6.tar.gz
hdf5-259d1afce9bca2f7dfada3bd396e7f804bb3c1a6.tar.bz2
[svn-r15165] Purpose: Create new HDpthread_self and HDpthread_self_ulong macros
Description: On Windows, the pthread_self function cannot be used to print the returned thread ID for debugging. Instead, we need a separate function, GetCurrentThreadId. To eliminate some Windows ifdef's in the code, we create two new function macros which can be used by all platforms. It is conditionally defined in H5win32defs.h, and globally in H5private.h. Tested: VS2005 w/ pthreads on WinXP kagiso w/ pthreads
-rw-r--r--src/H5CS.c2
-rw-r--r--src/H5Eint.c16
-rw-r--r--src/H5TS.c4
-rw-r--r--src/H5private.h9
-rw-r--r--src/H5win32defs.h6
-rw-r--r--test/h5test.c9
6 files changed, 21 insertions, 25 deletions
diff --git a/src/H5CS.c b/src/H5CS.c
index 6e485cc..dd80671 100644
--- a/src/H5CS.c
+++ b/src/H5CS.c
@@ -135,7 +135,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 %d.", (int)pthread_self());
+ HDfprintf (stream, "thread %lu.", HDpthread_self_ulong());
#else /* H5_HAVE_THREADSAFE */
HDfprintf (stream, "thread 0.");
#endif /* H5_HAVE_THREADSAFE */
diff --git a/src/H5Eint.c b/src/H5Eint.c
index 34290a4..e0fa482 100644
--- a/src/H5Eint.c
+++ b/src/H5Eint.c
@@ -275,13 +275,7 @@ H5E_walk1_cb(int n, H5E_error1_t *err_desc, void *client_data)
fprintf(stream, "thread 0");
} /* end block */
#elif defined(H5_HAVE_THREADSAFE)
-#ifdef _WIN32
- /* 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
+ fprintf(stream, "thread %lu", HDpthread_self_ulong());
#else
fprintf(stream, "thread 0");
#endif
@@ -397,13 +391,7 @@ H5E_walk2_cb(unsigned n, const H5E_error2_t *err_desc, void *client_data)
fprintf(stream, "thread 0");
} /* end block */
#elif defined(H5_HAVE_THREADSAFE)
-#ifdef _WIN32
- /* 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
+ fprintf(stream, "thread %lu", HDpthread_self_ulong());
#else
fprintf(stream, "thread 0");
#endif
diff --git a/src/H5TS.c b/src/H5TS.c
index a250067..5d38487 100644
--- a/src/H5TS.c
+++ b/src/H5TS.c
@@ -146,7 +146,7 @@ H5TS_mutex_lock(H5TS_mutex_t *mutex)
if (ret_value)
return ret_value;
- if(mutex->lock_count && pthread_equal(pthread_self(), mutex->owner_thread)) {
+ if(mutex->lock_count && pthread_equal(HDpthread_self(), mutex->owner_thread)) {
/* already owned by self - increment count */
mutex->lock_count++;
} else {
@@ -155,7 +155,7 @@ H5TS_mutex_lock(H5TS_mutex_t *mutex)
pthread_cond_wait(&mutex->cond_var, &mutex->atomic_lock);
/* After we've received the signal, take ownership of the mutex */
- mutex->owner_thread = pthread_self();
+ mutex->owner_thread = HDpthread_self();
mutex->lock_count = 1;
}
diff --git a/src/H5private.h b/src/H5private.h
index 4c8a6d6..97c53fb 100644
--- a/src/H5private.h
+++ b/src/H5private.h
@@ -1356,6 +1356,15 @@ extern char *strdup(const char *s);
#define HDstrdup(S) strdup(S)
#endif /* HDstrdup */
+#ifndef HDpthread_self
+ #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 */
+
#ifdef H5_HAVE_WINDOW_PATH
diff --git a/src/H5win32defs.h b/src/H5win32defs.h
index 484b73d..6ce8f77 100644
--- a/src/H5win32defs.h
+++ b/src/H5win32defs.h
@@ -52,5 +52,11 @@ typedef __int64 h5_stat_size_t;
#define HDvsnprintf(S,N,FMT,A) _vsnprintf(S,N,FMT,A)
#define HDwrite(F,M,Z) _write(F,M,Z)
+/* 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())
+
#endif /* _WIN32 */
diff --git a/test/h5test.c b/test/h5test.c
index e364d32..98508ff 100644
--- a/test/h5test.c
+++ b/test/h5test.c
@@ -667,14 +667,7 @@ h5_show_hostname(void)
printf("thread 0.");
}
#elif defined(H5_HAVE_THREADSAFE)
-#ifdef _WIN32
- /* 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
-
+ printf("thread %lu.", HDpthread_self_ulong());
#else
printf("thread 0.");
#endif