summaryrefslogtreecommitdiff
path: root/benchmarks/hbench/patches/patch-al
blob: 3b2f968af90ecb42accf889a839ccb3fe4fd92aa (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
# $NetBSD: patch-al,v 1.3 2005/03/03 08:53:06 garbled Exp $
--- src/bw_pipe.c.orig	1997-06-26 17:34:33.000000000 -0700
+++ src/bw_pipe.c	2005-03-03 01:31:48.000000000 -0700
@@ -134,7 +134,7 @@
 	}
 
 	/* Amount to transfer */
-	todo = XFERUNIT * num_iter;
+	todo = XFERUNIT * num_iter + bufsize;
 	
 	/* Allocate buffer */
 	buf = (char *) malloc(bufsize);
@@ -147,6 +147,8 @@
 	/* Spawn off a writer, then time the read */
 	switch (fork()) {
 	case 0:			/* writer */
+		close(pipes[0]);
+
 		while ((done < todo) &&
 		       ((n = write(pipes[1], buf, bufsize)) > 0))
 			done += n;
@@ -159,8 +161,13 @@
 		/*NOTREACHED*/
 		
 	default:		/* reader */
+		close(pipes[1]);
+
 		/* wait for writer */
-		sleep(1);
+		while ((done < bufsize) &&
+			((n = read(pipes[0], buf, bufsize - done)) > 0))
+			done += n;
+
 		
 		start();	/* start timing */
 		while ((done < todo) &&
@@ -168,6 +175,7 @@
 			done += n;
 		*t = stop();	/* stop timing */
 
+		close(pipes[0]);
 		wait(&termstat); /* wait for writer to exit */
 	}