#include <assert.h>
#include <mono/utils/mono-memory-model.h>
-#ifndef HOST_WIN32
+#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
return mono_mutex_init (mutex);
#endif
}
+
+#ifndef HOST_WIN32
+int
+mono_cond_timedwait_ms (mono_cond_t *cond, mono_mutex_t *mutex, int timeout_ms)
+{
+ struct timeval tv;
+ struct timespec ts;
+ gint64 usecs;
+ int res;
+
+ /* ms = 10^-3, us = 10^-6, ns = 10^-9 */
+
+ gettimeofday (&tv, NULL);
+ tv.tv_sec += timeout_ms / 1000;
+ usecs = tv.tv_usec + ((timeout_ms % 1000) * 1000);
+ if (usecs >= 1000000) {
+ usecs -= 1000000;
+ tv.tv_sec ++;
+ }
+ ts.tv_sec = tv.tv_sec;
+ ts.tv_nsec = usecs * 1000;
+
+ res = pthread_cond_timedwait (cond, mutex, &ts);
+ g_assert (res != EINVAL);
+ return res;
+}
+
+#endif
#define mono_cond_broadcast(cond) pthread_cond_broadcast (cond)
#define mono_cond_destroy(cond)
+/*
+ * This should be used instead of mono_cond_timedwait, since that function is not implemented on windows.
+ */
+int mono_cond_timedwait_ms (mono_cond_t *cond, mono_mutex_t *mutex, int timeout_ms);
+
/* This is a function so it can be passed to pthread_cleanup_push -
* that is a macro and giving it a macro as a parameter breaks.
*/
}
static inline int
-mono_cond_timedwait (mono_cond_t *cond, mono_mutex_t *mutex, DWORD timeout)
+mono_cond_wait (mono_cond_t *cond, mono_mutex_t *mutex)
{
- BOOL res;
-
- // FIXME: This needs to take a struct timespec
- g_assert_not_reached ();
+ int res;
- res = SleepConditionVariableCS (cond, mutex, timeout);
+ res = SleepConditionVariableCS (cond, mutex, INFINITE);
if (res)
/* Success */
return 0;
}
static inline int
-mono_cond_wait (mono_cond_t *cond, mono_mutex_t *mutex)
+mono_cond_timedwait (mono_cond_t *cond, mono_mutex_t *mutex, struct timespec *timeout)
{
- return mono_cond_timedwait (cond, mutex, INFINITE);
+ // FIXME:
+ g_assert_not_reached ();
+ return 0;
}
static inline int
{
}
+static inline int
+mono_cond_timedwait_ms (mono_cond_t *cond, mono_mutex_t *mutex, int timeout_ms)
+{
+ int res;
+
+ res = SleepConditionVariableCS (cond, mutex, timeout_ms);
+ if (res)
+ /* Success */
+ return 0;
+ else
+ return 1;
+}
+
#endif
int mono_mutex_init_suspend_safe (mono_mutex_t *mutex);