#include <string.h>
#include <errno.h>
#include <assert.h>
-#include <sys/time.h>
#include <mono/utils/mono-memory-model.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
#include "mono-mutex.h"
#ifndef HOST_WIN32
static int (*setpolicy_np) (pthread_mutexattr_t *, int);
if (!inited) {
- setpolicy_np = dlsym (RTLD_NEXT, "pthread_mutexattr_setpolicy_np");
+ setpolicy_np = (int (*) (pthread_mutexattr_t *, int)) dlsym (RTLD_NEXT, "pthread_mutexattr_setpolicy_np");
mono_atomic_store_release (&inited, TRUE);
}
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