summaryrefslogtreecommitdiff
path: root/lang/mono2/patches/patch-ah
blob: 40fd3e111c09f9890259ca78355cba8fc1f4f5bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
$NetBSD: patch-ah,v 1.1 2013/06/17 12:43:28 wiz Exp $
--- mono/utils/mono-semaphore.c.orig	2011-01-04 19:39:55.000000000 +0200
+++ mono/utils/mono-semaphore.c	2011-01-08 18:52:28.000000000 +0200
@@ -22,7 +22,7 @@
 #  ifdef USE_MACH_SEMA
 #    define TIMESPEC mach_timespec_t
 #    define WAIT_BLOCK(a,b) semaphore_timedwait (*(a), *(b))
-#  elif defined(__OpenBSD__)
+#  elif (defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__))
 #    define TIMESPEC struct timespec
 #    define WAIT_BLOCK(a) sem_trywait(a)
 #  else
@@ -34,12 +34,13 @@
 int
 mono_sem_timedwait (MonoSemType *sem, guint32 timeout_ms, gboolean alertable)
 {
+#if (defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
+	uint32_t timeout = timeout_ms;
+#else
 	TIMESPEC ts, copy;
 	struct timeval t;
-	int res = 0;
-#if defined(__OpenBSD__)
-	int timeout;
 #endif
+	int res = 0;
 
 #ifndef USE_MACH_SEMA
 	if (timeout_ms == 0)
@@ -48,6 +49,19 @@
 	if (timeout_ms == (guint32) 0xFFFFFFFF)
 		return mono_sem_wait (sem, alertable);
 
+#if (defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
+	if (timeout < 50)
+		timeout += 50;
+	do {
+		if ((res = WAIT_BLOCK(sem)) == 0)
+			break;
+		usleep(50000);
+		timeout -= 50;
+		if (alertable)  /* XXX: Not on EINTR */
+			return -1;
+	} while (timeout > 50);
+#else
+
 #ifdef USE_MACH_SEMA
 	memset (&t, 0, sizeof (TIMESPEC));
 #else
@@ -59,19 +73,6 @@
 		ts.tv_nsec -= NSEC_PER_SEC;
 		ts.tv_sec++;
 	}
-#if defined(__OpenBSD__)
-	timeout = ts.tv_sec;
-	while (timeout) {
-		if ((res = WAIT_BLOCK (sem)) == 0)
-			return res;
-
-		if (alertable)
-			return -1;
-
-		usleep (ts.tv_nsec / 1000);
-		timeout--;
-	}
-#else
 	copy = ts;
 	while ((res = WAIT_BLOCK (sem, &ts)) == -1 && errno == EINTR) {
 		struct timeval current;