summaryrefslogtreecommitdiffstats
path: root/src/mercury/src/util/mercury_thread_condition.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mercury/src/util/mercury_thread_condition.c')
-rw-r--r--src/mercury/src/util/mercury_thread_condition.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/mercury/src/util/mercury_thread_condition.c b/src/mercury/src/util/mercury_thread_condition.c
new file mode 100644
index 0000000..35133ea
--- /dev/null
+++ b/src/mercury/src/util/mercury_thread_condition.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2013-2020 Argonne National Laboratory, Department of Energy,
+ * UChicago Argonne, LLC and The HDF Group.
+ * All rights reserved.
+ *
+ * The full copyright notice, including terms governing use, modification,
+ * and redistribution, is contained in the COPYING file that can be
+ * found at the root of the source code distribution tree.
+ */
+
+#include "mercury_thread_condition.h"
+
+/*---------------------------------------------------------------------------*/
+int
+hg_thread_cond_init(hg_thread_cond_t *cond)
+{
+#ifdef _WIN32
+ InitializeConditionVariable(cond);
+#else
+ pthread_condattr_t attr;
+
+ pthread_condattr_init(&attr);
+#if defined(HG_UTIL_HAS_PTHREAD_CONDATTR_SETCLOCK) && defined(HG_UTIL_HAS_CLOCK_MONOTONIC_COARSE)
+ /* Must set clock ID if using different clock
+ * (CLOCK_MONOTONIC_COARSE not supported here) */
+ pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
+#endif
+ if (pthread_cond_init(cond, &attr))
+ return HG_UTIL_FAIL;
+ pthread_condattr_destroy(&attr);
+#endif
+
+ return HG_UTIL_SUCCESS;
+}
+
+/*---------------------------------------------------------------------------*/
+int
+hg_thread_cond_destroy(hg_thread_cond_t *cond)
+{
+#ifndef _WIN32
+ if (pthread_cond_destroy(cond))
+ return HG_UTIL_FAIL;
+#endif
+
+ return HG_UTIL_SUCCESS;
+}