diff options
author | Mike McGreevy <mamcgree@hdfgroup.org> | 2010-09-10 16:15:57 (GMT) |
---|---|---|
committer | Mike McGreevy <mamcgree@hdfgroup.org> | 2010-09-10 16:15:57 (GMT) |
commit | 2d9a70085c38816df68a1b2cfce59c05853e3c4a (patch) | |
tree | 4fd2b91f1dcf8291ab6654caa8a68eef46aff824 /test | |
parent | a8646632e8f76b729c141d0570700bae2fa884e9 (diff) | |
download | hdf5-2d9a70085c38816df68a1b2cfce59c05853e3c4a.zip hdf5-2d9a70085c38816df68a1b2cfce59c05853e3c4a.tar.gz hdf5-2d9a70085c38816df68a1b2cfce59c05853e3c4a.tar.bz2 |
[svn-r19368] Purpose:
Add windows threads support to HDF5.
Description:
Added calls to the windows threads library to the H5TS layer, and wrapped
most calls to either pthreads or windows threads library with portable
H5TS-style defines. Modified tests to use portable function definitions
as well.
This can be configured via CMake with the HDF5_ENABLE_THREADSAFE
option, and should work on windows vista and later operating systems.
Tested:
h5committest, plus threadsafe with pthreads on jam and amani,
and tested on a Windows Vista VM with threadsafe using windows threads.
Diffstat (limited to 'test')
-rw-r--r-- | test/ttsafe.c | 13 | ||||
-rw-r--r-- | test/ttsafe.h | 2 | ||||
-rw-r--r-- | test/ttsafe_acreate.c | 10 | ||||
-rw-r--r-- | test/ttsafe_cancel.c | 2 | ||||
-rw-r--r-- | test/ttsafe_dcreate.c | 23 | ||||
-rw-r--r-- | test/ttsafe_error.c | 33 |
6 files changed, 39 insertions, 44 deletions
diff --git a/test/ttsafe.c b/test/ttsafe.c index 1fadd95..253470b 100644 --- a/test/ttsafe.c +++ b/test/ttsafe.c @@ -89,11 +89,14 @@ int main(int argc, char *argv[]) /* Initialize testing framework */ TestInit(argv[0], NULL, NULL); - /* Tests are generally arranged from least to most complexity... */ - AddTest("dcreate", tts_dcreate, cleanup_dcreate, "multi-dataset creation", NULL); - AddTest("error", tts_error, cleanup_error, "per-thread error stacks", NULL); - AddTest("cancel", tts_cancel, cleanup_cancel, "thread cancellation safety test", NULL); - AddTest("acreate", tts_acreate, cleanup_acreate, "multi-attribute creation", NULL); + /* Tests are generally arranged from least to most complexity... */ + AddTest("dcreate", tts_dcreate, cleanup_dcreate, "multi-dataset creation", NULL); + AddTest("error", tts_error, cleanup_error, "per-thread error stacks", NULL); +#ifdef H5_HAVE_PTHREAD_H + /* Thread cancellability only supported with pthreads ... */ + AddTest("cancel", tts_cancel, cleanup_cancel, "thread cancellation safety test", NULL); +#endif /* H5_HAVE_PTHREAD_H */ + AddTest("acreate", tts_acreate, cleanup_acreate, "multi-attribute creation", NULL); /* Display testing information */ TestInfo(argv[0]); diff --git a/test/ttsafe.h b/test/ttsafe.h index 482e1b2..b4826fc 100644 --- a/test/ttsafe.h +++ b/test/ttsafe.h @@ -33,7 +33,9 @@ #ifdef H5_HAVE_THREADSAFE /* Include pthread library for threadsafe tests */ +#ifdef H5_HAVE_PTHREAD_H #include <pthread.h> +#endif /* H5_HAVE_PTHREAD_H */ /* Prototypes for the support routines */ extern char* gen_name(int); diff --git a/test/ttsafe_acreate.c b/test/ttsafe_acreate.c index 0e2c7c8..0efd02c 100644 --- a/test/ttsafe_acreate.c +++ b/test/ttsafe_acreate.c @@ -68,8 +68,8 @@ typedef struct acreate_data_struct { void tts_acreate(void) { - /* Pthread declarations */ - pthread_t threads[NUM_THREADS]; + /* Thread declarations */ + H5TS_thread_t threads[NUM_THREADS]; /* HDF5 data declarations */ hid_t file, dataset; @@ -118,13 +118,11 @@ void tts_acreate(void) attrib_data->datatype = datatype; attrib_data->dataspace = dataspace; attrib_data->current_index = i; - ret = pthread_create(&threads[i], NULL, tts_acreate_thread, attrib_data); - assert(ret == 0); + threads[i] = H5TS_create_thread(tts_acreate_thread, NULL, attrib_data); } /* end for */ for(i = 0; i < NUM_THREADS; i++) { - ret = pthread_join(threads[i], NULL); - assert(ret == 0); + H5TS_wait_for_thread(threads[i]); } /* end for */ diff --git a/test/ttsafe_cancel.c b/test/ttsafe_cancel.c index 1cc2e8c..8264403 100644 --- a/test/ttsafe_cancel.c +++ b/test/ttsafe_cancel.c @@ -47,6 +47,7 @@ #include "ttsafe.h" #ifdef H5_HAVE_THREADSAFE +#ifndef H5_HAVE_WIN_THREADS #define FILENAME "ttsafe_cancel.h5" #define DATASETNAME "commonname" @@ -253,4 +254,5 @@ void cleanup_cancel(void) HDunlink(FILENAME); } +#endif /*H5_HAVE_WIN_THREADS*/ #endif /*H5_HAVE_THREADSAFE*/ diff --git a/test/ttsafe_dcreate.c b/test/ttsafe_dcreate.c index 35453ad..f83332d 100644 --- a/test/ttsafe_dcreate.c +++ b/test/ttsafe_dcreate.c @@ -88,21 +88,21 @@ thread_info thread_out[NUM_THREAD]; */ void tts_dcreate(void) { - /* Pthread definitions */ - pthread_t threads[NUM_THREAD]; + /* thread definitions */ + H5TS_thread_t threads[NUM_THREAD]; /* HDF5 data definitions */ hid_t file, dataset; int datavalue, i; - pthread_attr_t attribute; + H5TS_attr_t attribute; int ret; /* set pthread attribute to perform global scheduling */ - ret=pthread_attr_init(&attribute); - assert(ret==0); + H5TS_attr_init(&attribute); + + /* set thread scope to system */ #ifdef H5_HAVE_SYSTEM_SCOPE_THREADS - ret=pthread_attr_setscope(&attribute, PTHREAD_SCOPE_SYSTEM); - assert(ret==0); + H5TS_attr_setscope(&attribute, H5TS_SCOPE_SYSTEM); #endif /* H5_HAVE_SYSTEM_SCOPE_THREADS */ /* @@ -117,13 +117,11 @@ void tts_dcreate(void) thread_out[i].id = i; thread_out[i].file = file; thread_out[i].dsetname = dsetname[i]; - ret=pthread_create(&threads[i], NULL, tts_dcreate_creator, &thread_out[i]); - assert(ret==0); + threads[i] = H5TS_create_thread(tts_dcreate_creator, NULL, &thread_out[i]); } /* end for */ for(i = 0;i < NUM_THREAD; i++) { - ret = pthread_join(threads[i], NULL); - assert(ret == 0); + H5TS_wait_for_thread(threads[i]); } /* end for */ /* compare data to see if it is written correctly */ @@ -157,8 +155,7 @@ void tts_dcreate(void) assert(ret >= 0); /* Destroy the thread attribute */ - ret=pthread_attr_destroy(&attribute); - assert(ret==0); + H5TS_attr_destroy(&attribute); } void *tts_dcreate_creator(void *_thread_data) diff --git a/test/ttsafe_error.c b/test/ttsafe_error.c index b3d056f..f55afdc 100644 --- a/test/ttsafe_error.c +++ b/test/ttsafe_error.c @@ -71,12 +71,12 @@ err_num_t expected[8]; int error_flag = 0; int error_count = 0; -pthread_mutex_t error_mutex; +H5TS_mutex_simple_t error_mutex; void tts_error(void) { - pthread_t threads[NUM_THREAD]; - pthread_attr_t attribute; + H5TS_thread_t threads[NUM_THREAD]; + H5TS_attr_t attribute; hid_t dataset; int value, i; int ret; @@ -104,16 +104,15 @@ void tts_error(void) expected[6].min_num = H5E_EXISTS; /* set up mutex for global count of errors */ - ret=pthread_mutex_init(&error_mutex, NULL); - assert(ret==0); + H5TS_mutex_init(&error_mutex); /* make thread scheduling global */ - ret=pthread_attr_init(&attribute); - assert(ret==0); + H5TS_attr_init(&attribute); + + /* set thread scope to system */ #ifdef H5_HAVE_SYSTEM_SCOPE_THREADS - ret=pthread_attr_setscope(&attribute, PTHREAD_SCOPE_SYSTEM); - assert(ret==0); + H5TS_attr_setscope(&attribute, H5TS_SCOPE_SYSTEM); #endif /* H5_HAVE_SYSTEM_SCOPE_THREADS */ /* @@ -124,13 +123,11 @@ void tts_error(void) assert(error_file>=0); for (i = 0; i < NUM_THREAD; i++){ - ret=pthread_create(&threads[i], &attribute, tts_error_thread, NULL); - assert(ret==0); + threads[i] = H5TS_create_thread(tts_error_thread, &attribute, NULL); } for (i = 0; i < NUM_THREAD; i++){ - ret=pthread_join(threads[i],NULL); - assert(ret==0); + H5TS_wait_for_thread(threads[i]); } if (error_flag) @@ -153,9 +150,7 @@ void tts_error(void) ret=H5Fclose(error_file); assert(ret>=0); - /* Destroy the thread attribute */ - ret=pthread_attr_destroy(&attribute); - assert(ret==0); + H5TS_attr_destroy(&attribute); } static @@ -208,11 +203,9 @@ herr_t error_callback(hid_t estack_id, void *client_data) { int ret; - ret=pthread_mutex_lock(&error_mutex); - assert(ret==0); + H5TS_mutex_lock_simple(&error_mutex); error_count++; - ret=pthread_mutex_unlock(&error_mutex); - assert(ret==0); + H5TS_mutex_unlock_simple(&error_mutex); return H5Ewalk2(H5E_DEFAULT, H5E_WALK_DOWNWARD, walk_error_callback, client_data); } |