summaryrefslogtreecommitdiffstats
path: root/test/ttsafe_cancel.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2004-01-10 01:41:13 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2004-01-10 01:41:13 (GMT)
commit987f5d5e4de41c02b682464fa8e94252553ed57c (patch)
tree2bf74eb88dee718490af7b7dda0e585b0d1b8a95 /test/ttsafe_cancel.c
parent12dca9ab3c362fc190feb330232bec4bd552df3c (diff)
downloadhdf5-987f5d5e4de41c02b682464fa8e94252553ed57c.zip
hdf5-987f5d5e4de41c02b682464fa8e94252553ed57c.tar.gz
hdf5-987f5d5e4de41c02b682464fa8e94252553ed57c.tar.bz2
[svn-r8048] Purpose:
Code cleanup & reorganization Description: Move further in the testing framework cleanup, eliminating all the global variables (moving them into testframe.c as static variables) from the testing framework code and moving it into the libh5test.a. Platforms tested: FreeBSD 4.9 (sleipnir) w & w/o thread-safety, c++ & parallel h5committested
Diffstat (limited to 'test/ttsafe_cancel.c')
-rw-r--r--test/ttsafe_cancel.c215
1 files changed, 101 insertions, 114 deletions
diff --git a/test/ttsafe_cancel.c b/test/ttsafe_cancel.c
index 4247f07..30e9bfb 100644
--- a/test/ttsafe_cancel.c
+++ b/test/ttsafe_cancel.c
@@ -40,7 +40,7 @@
*
* 19 May 2000, Bill Wendling
* Changed so that it creates its own HDF5 file and removes it at cleanup
- * time. Added num_errs flag.
+ * time.
*
********************************************************************/
#include "ttsafe.h"
@@ -68,117 +68,104 @@ pthread_cond_t cond;
void tts_cancel(void)
{
- pthread_attr_t attribute;
- hid_t dataset;
- int buffer;
+ pthread_attr_t attribute;
+ hid_t dataset;
+ int buffer;
- /* make thread scheduling global */
- pthread_attr_init(&attribute);
+ /* make thread scheduling global */
+ pthread_attr_init(&attribute);
#ifdef H5_HAVE_SYSTEM_SCOPE_THREADS
- pthread_attr_setscope(&attribute, PTHREAD_SCOPE_SYSTEM);
+ pthread_attr_setscope(&attribute, PTHREAD_SCOPE_SYSTEM);
#endif /* H5_HAVE_SYSTEM_SCOPE_THREADS */
- /*
- * Create a hdf5 file using H5F_ACC_TRUNC access, default file
- * creation plist and default file access plist
- */
- cancel_file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- pthread_create(&childthread, &attribute, tts_cancel_thread, NULL);
- tts_cancel_barrier();
- pthread_cancel(childthread);
-
- dataset = H5Dopen(cancel_file, DATASETNAME);
- H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
- &buffer);
-
- if (buffer != 11) {
- fprintf(stderr,
- "operation unsuccessful with value at %d instead of 11\n",
- buffer);
- num_errs++;
- }
-
- H5Dclose(dataset);
- H5Fclose(cancel_file);
-
- /* Destroy the thread attribute */
- pthread_attr_destroy(&attribute);
+ /*
+ * Create a hdf5 file using H5F_ACC_TRUNC access, default file
+ * creation plist and default file access plist
+ */
+ cancel_file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ pthread_create(&childthread, &attribute, tts_cancel_thread, NULL);
+ tts_cancel_barrier();
+ pthread_cancel(childthread);
+
+ dataset = H5Dopen(cancel_file, DATASETNAME);
+ H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &buffer);
+
+ if (buffer != 11)
+ TestErrPrintf("operation unsuccessful with value at %d instead of 11\n", buffer);
+
+ H5Dclose(dataset);
+ H5Fclose(cancel_file);
+
+ /* Destroy the thread attribute */
+ pthread_attr_destroy(&attribute);
}
void *tts_cancel_thread(void UNUSED *arg)
{
- int datavalue;
- int *buffer;
- hid_t dataspace, datatype, dataset;
- hsize_t dimsf[1]; /* dataset dimensions */
- cancel_cleanup_t *cleanup_structure;
-
- /* define dataspace for dataset */
- dimsf[0] = 1;
- dataspace = H5Screate_simple(1,dimsf,NULL);
-
- /* define datatype for the data using native little endian integers */
- datatype = H5Tcopy(H5T_NATIVE_INT);
- H5Tset_order(datatype, H5T_ORDER_LE);
-
- /* create a new dataset within the file */
- dataset = H5Dcreate(cancel_file, DATASETNAME, datatype, dataspace,
- H5P_DEFAULT);
-
- /* If thread is cancelled, make cleanup call */
- cleanup_structure = (cancel_cleanup_t*)malloc(sizeof(cancel_cleanup_t));
- cleanup_structure->dataset = dataset;
- cleanup_structure->datatype = datatype;
- cleanup_structure->dataspace = dataspace;
- pthread_cleanup_push(cancellation_cleanup, cleanup_structure);
-
- datavalue = 1;
- H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
- &datavalue);
-
- buffer = malloc(sizeof(int));
- H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
- buffer);
- H5Diterate(buffer, H5T_NATIVE_INT, dataspace, tts_cancel_callback,
- &dataset);
-
- sleep(3);
-
- datavalue = 100;
- H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
- &datavalue);
- H5Dclose(dataset);
- H5Tclose(datatype);
- H5Sclose(dataspace);
-
- /*
- * Required by pthreads. The argument 0 pops the stack but does not
- * execute the cleanup routine.
- */
- pthread_cleanup_pop(0);
- return NULL;
+ int datavalue;
+ int *buffer;
+ hid_t dataspace, datatype, dataset;
+ hsize_t dimsf[1]; /* dataset dimensions */
+ cancel_cleanup_t *cleanup_structure;
+
+ /* define dataspace for dataset */
+ dimsf[0] = 1;
+ dataspace = H5Screate_simple(1,dimsf,NULL);
+
+ /* define datatype for the data using native little endian integers */
+ datatype = H5Tcopy(H5T_NATIVE_INT);
+ H5Tset_order(datatype, H5T_ORDER_LE);
+
+ /* create a new dataset within the file */
+ dataset = H5Dcreate(cancel_file, DATASETNAME, datatype, dataspace, H5P_DEFAULT);
+
+ /* If thread is cancelled, make cleanup call */
+ cleanup_structure = (cancel_cleanup_t*)malloc(sizeof(cancel_cleanup_t));
+ cleanup_structure->dataset = dataset;
+ cleanup_structure->datatype = datatype;
+ cleanup_structure->dataspace = dataspace;
+ pthread_cleanup_push(cancellation_cleanup, cleanup_structure);
+
+ datavalue = 1;
+ H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &datavalue);
+
+ buffer = malloc(sizeof(int));
+ H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buffer);
+ H5Diterate(buffer, H5T_NATIVE_INT, dataspace, tts_cancel_callback, &dataset);
+
+ sleep(3);
+
+ datavalue = 100;
+ H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &datavalue);
+ H5Dclose(dataset);
+ H5Tclose(datatype);
+ H5Sclose(dataspace);
+
+ /*
+ * Required by pthreads. The argument 0 pops the stack but does not
+ * execute the cleanup routine.
+ */
+ pthread_cleanup_pop(0);
+ return NULL;
}
herr_t tts_cancel_callback(void *elem, hid_t UNUSED type_id, hsize_t UNUSED ndim,
hssize_t UNUSED *point, void *operator_data)
{
- int value = *(int *)elem;
- hid_t dataset = *(hid_t *)operator_data;
-
- tts_cancel_barrier();
- sleep(3);
-
- if (value != 1) {
- fprintf(stderr, "Error! Element value should be 1 and not %d\n",
- value);
- num_errs++;
- return -1;
- }
-
- value += 10;
- H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
- &value);
- return 0;
+ int value = *(int *)elem;
+ hid_t dataset = *(hid_t *)operator_data;
+
+ tts_cancel_barrier();
+ sleep(3);
+
+ if (value != 1) {
+ TestErrPrintf("Error! Element value should be 1 and not %d\n", value);
+ return -1;
+ }
+
+ value += 10;
+ H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &value);
+ return 0;
}
/*
@@ -187,13 +174,13 @@ herr_t tts_cancel_callback(void *elem, hid_t UNUSED type_id, hsize_t UNUSED ndim
*/
void cancellation_cleanup(void *arg)
{
- cancel_cleanup_t *cleanup_structure = (cancel_cleanup_t *)arg;
- H5Dclose(cleanup_structure->dataset);
- H5Tclose(cleanup_structure->datatype);
- H5Sclose(cleanup_structure->dataspace);
+ cancel_cleanup_t *cleanup_structure = (cancel_cleanup_t *)arg;
+ H5Dclose(cleanup_structure->dataset);
+ H5Tclose(cleanup_structure->datatype);
+ H5Sclose(cleanup_structure->dataspace);
- /* retained for debugging */
- /* print_func("cancellation noted, cleaning up ... \n"); */
+ /* retained for debugging */
+ /* print_func("cancellation noted, cleaning up ... \n"); */
}
/*
@@ -202,18 +189,18 @@ void cancellation_cleanup(void *arg)
*/
void tts_cancel_barrier(void)
{
- static int count = 2;
+ static int count = 2;
- pthread_mutex_lock(&mutex);
+ pthread_mutex_lock(&mutex);
- if (count != 1) {
- count--;
- pthread_cond_wait(&cond, &mutex);
- } else {
- pthread_cond_signal(&cond);
- }
+ if (count != 1) {
+ count--;
+ pthread_cond_wait(&cond, &mutex);
+ } else {
+ pthread_cond_signal(&cond);
+ }
- pthread_mutex_unlock(&mutex);
+ pthread_mutex_unlock(&mutex);
}
void cleanup_cancel(void)