summaryrefslogtreecommitdiffstats
path: root/test/ttsafe_cancel.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
commitb2d661b508a7fc7a2592c13bc6bdc175551f075d (patch)
tree13baeb0d83a7c2a4c6299993c182b1227c2f6114 /test/ttsafe_cancel.c
parent29ab58b58dce556639ea3154e262895773a8a8df (diff)
downloadhdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.zip
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.gz
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.bz2
Clang-format of source files
Diffstat (limited to 'test/ttsafe_cancel.c')
-rw-r--r--test/ttsafe_cancel.c117
1 files changed, 58 insertions, 59 deletions
diff --git a/test/ttsafe_cancel.c b/test/ttsafe_cancel.c
index f6bcd0d..1e40c58 100644
--- a/test/ttsafe_cancel.c
+++ b/test/ttsafe_cancel.c
@@ -36,92 +36,91 @@
#ifdef H5_HAVE_THREADSAFE
#ifndef H5_HAVE_WIN_THREADS
-#define FILENAME "ttsafe_cancel.h5"
-#define DATASETNAME "commonname"
+#define FILENAME "ttsafe_cancel.h5"
+#define DATASETNAME "commonname"
-void *tts_cancel_thread(void *);
-void tts_cancel_barrier(void);
-herr_t tts_cancel_callback(void *, hid_t, unsigned , const hsize_t *, void *);
-void cancellation_cleanup(void *);
+void * tts_cancel_thread(void *);
+void tts_cancel_barrier(void);
+herr_t tts_cancel_callback(void *, hid_t, unsigned, const hsize_t *, void *);
+void cancellation_cleanup(void *);
hid_t cancel_file;
typedef struct cleanup_struct {
- hid_t dataset;
- hid_t datatype;
- hid_t dataspace;
+ hid_t dataset;
+ hid_t datatype;
+ hid_t dataspace;
} cancel_cleanup_t;
-pthread_t childthread;
+pthread_t childthread;
pthread_mutex_t mutex;
-pthread_cond_t cond;
+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;
int H5_ATTR_NDEBUG_UNUSED ret;
/* make thread scheduling global */
- ret=pthread_attr_init(&attribute);
- assert(ret==0);
+ ret = pthread_attr_init(&attribute);
+ assert(ret == 0);
#ifdef H5_HAVE_SYSTEM_SCOPE_THREADS
- ret=pthread_attr_setscope(&attribute, PTHREAD_SCOPE_SYSTEM);
- assert(ret==0);
+ ret = pthread_attr_setscope(&attribute, PTHREAD_SCOPE_SYSTEM);
+ assert(ret == 0);
#endif /* H5_HAVE_SYSTEM_SCOPE_THREADS */
-
/* Initialize mutex & condition variables */
- ret=pthread_mutex_init(&mutex,NULL);
- assert(ret==0);
- ret=pthread_cond_init(&cond,NULL);
- assert(ret==0);
+ ret = pthread_mutex_init(&mutex, NULL);
+ assert(ret == 0);
+ ret = pthread_cond_init(&cond, NULL);
+ assert(ret == 0);
/*
* 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);
- assert(cancel_file>=0);
- ret=pthread_create(&childthread, &attribute, tts_cancel_thread, NULL);
- assert(ret==0);
+ assert(cancel_file >= 0);
+ ret = pthread_create(&childthread, &attribute, tts_cancel_thread, NULL);
+ assert(ret == 0);
tts_cancel_barrier();
- ret=pthread_cancel(childthread);
- assert(ret==0);
+ ret = pthread_cancel(childthread);
+ assert(ret == 0);
dataset = H5Dopen2(cancel_file, DATASETNAME, H5P_DEFAULT);
- assert(dataset>=0);
- ret=H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &buffer);
- assert(ret>=0);
+ assert(dataset >= 0);
+ ret = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &buffer);
+ assert(ret >= 0);
if (buffer != 11)
TestErrPrintf("operation unsuccessful with value at %d instead of 11\n", buffer);
- ret=H5Dclose(dataset);
- assert(ret>=0);
- ret=H5Fclose(cancel_file);
- assert(ret>=0);
+ ret = H5Dclose(dataset);
+ assert(ret >= 0);
+ ret = H5Fclose(cancel_file);
+ assert(ret >= 0);
/* Destroy the thread attribute */
- ret=pthread_attr_destroy(&attribute);
- assert(ret==0);
+ ret = pthread_attr_destroy(&attribute);
+ assert(ret == 0);
} /* end tts_cancel() */
void *
tts_cancel_thread(void H5_ATTR_UNUSED *arg)
{
- hid_t dataspace = H5I_INVALID_HID;
- hid_t datatype = H5I_INVALID_HID;
- hid_t dataset = H5I_INVALID_HID;
- int datavalue;
- int buffer;
- hsize_t dimsf[1]; /* dataset dimensions */
+ hid_t dataspace = H5I_INVALID_HID;
+ hid_t datatype = H5I_INVALID_HID;
+ hid_t dataset = H5I_INVALID_HID;
+ int datavalue;
+ int buffer;
+ hsize_t dimsf[1]; /* dataset dimensions */
cancel_cleanup_t *cleanup_structure;
- herr_t status;
+ herr_t status;
/* define dataspace for dataset */
- dimsf[0] = 1;
+ dimsf[0] = 1;
dataspace = H5Screate_simple(1, dimsf, NULL);
CHECK(dataspace, H5I_INVALID_HID, "H5Screate_simple");
@@ -132,19 +131,19 @@ tts_cancel_thread(void H5_ATTR_UNUSED *arg)
CHECK(status, FAIL, "H5Tset_order");
/* create a new dataset within the file */
- dataset = H5Dcreate2(cancel_file, DATASETNAME, datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ dataset =
+ H5Dcreate2(cancel_file, DATASETNAME, datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK(dataset, H5I_INVALID_HID, "H5Dcreate2");
/* If thread is cancelled, make cleanup call */
- cleanup_structure = (cancel_cleanup_t*)HDmalloc(sizeof(cancel_cleanup_t));
- cleanup_structure->dataset = dataset;
- cleanup_structure->datatype = datatype;
+ cleanup_structure = (cancel_cleanup_t *)HDmalloc(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;
- status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &datavalue);
+ status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &datavalue);
CHECK(status, FAIL, "H5Dwrite");
status = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &buffer);
@@ -155,7 +154,7 @@ tts_cancel_thread(void H5_ATTR_UNUSED *arg)
HDsleep(3);
datavalue = 100;
- status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &datavalue);
+ status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &datavalue);
CHECK(status, FAIL, "H5Dwrite");
status = H5Dclose(dataset);
@@ -176,10 +175,10 @@ tts_cancel_thread(void H5_ATTR_UNUSED *arg)
herr_t
tts_cancel_callback(void *elem, hid_t H5_ATTR_UNUSED type_id, unsigned H5_ATTR_UNUSED ndim,
- const hsize_t H5_ATTR_UNUSED *point, void *operator_data)
+ const hsize_t H5_ATTR_UNUSED *point, void *operator_data)
{
- hid_t dataset = *(hid_t *)operator_data;
- int value = *(int *)elem;
+ hid_t dataset = *(hid_t *)operator_data;
+ int value = *(int *)elem;
herr_t status;
tts_cancel_barrier();
@@ -205,7 +204,7 @@ void
cancellation_cleanup(void *arg)
{
cancel_cleanup_t *cleanup_structure = (cancel_cleanup_t *)arg;
- herr_t status;
+ herr_t status;
status = H5Dclose(cleanup_structure->dataset);
CHECK(status, FAIL, "H5Dclose");
@@ -226,7 +225,7 @@ void
tts_cancel_barrier(void)
{
static int count = 2;
- int status;
+ int status;
status = pthread_mutex_lock(&mutex);
VERIFY(status, 0, "pthread_mutex_lock");
@@ -245,11 +244,11 @@ tts_cancel_barrier(void)
VERIFY(status, 0, "pthread_mutex_unlock");
} /* end tts_cancel_barrier() */
-void cleanup_cancel(void)
+void
+cleanup_cancel(void)
{
HDunlink(FILENAME);
}
#endif /*H5_HAVE_WIN_THREADS*/
#endif /*H5_HAVE_THREADSAFE*/
-