With this commit all functions declared in libc.h have been renamed with the "jehanne_" prefix. This is done for several reason: - it removes conflicts during symbol resolution when linking standard C libraries like newlib or musl - it allows programs depending on a standard C library to directly link to a library depending on our non standard libc (eg libsec). To ease transiction two files are provided: - sys/include/lib9.h that can be included instead of <libc.h> to use the old names (via a simple set of macros) - sys/src/lib/c/lib9.c that can be compiled with a program where the macro provided by lib9.h are too dumb (see for example rc or grep). In the kernel port/lib.h has been modified accordingly and some of the functions it directly provides has been renamed too (eg malloc in qmalloc.c and print in devcons.c).
		
			
				
	
	
		
			71 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include <u.h>
 | 
						|
#include <lib9.h>
 | 
						|
 | 
						|
int nring = 32;
 | 
						|
int niter = 1024;
 | 
						|
int debug = 0;
 | 
						|
char data[8192];
 | 
						|
int i;
 | 
						|
int id;
 | 
						|
int intr = 0;
 | 
						|
 | 
						|
void
 | 
						|
handler(void *v, char *s)
 | 
						|
{
 | 
						|
	print("%d: %d iterations\n", id, i);
 | 
						|
	if (intr++ < 16)
 | 
						|
		noted(NCONT);
 | 
						|
	exits("too many interrupts");
 | 
						|
}
 | 
						|
 | 
						|
void
 | 
						|
main(int argc, char *argv[])
 | 
						|
{
 | 
						|
	int pid;
 | 
						|
 | 
						|
	if (notify(handler)){
 | 
						|
		sysfatal("notify: %r");
 | 
						|
	}
 | 
						|
 | 
						|
	if (argc > 1)
 | 
						|
		nring = strtoull(argv[1], 0, 0);
 | 
						|
 | 
						|
	if (argc > 2)
 | 
						|
		niter = strtoull(argv[2], 0, 0);
 | 
						|
	debug = argc > 3;
 | 
						|
 | 
						|
	fprint(2, "Running with %d pipes %d times\n", nring, niter);
 | 
						|
	int *pfd = malloc(sizeof(int)* nring * 2);
 | 
						|
 | 
						|
	if (pfd == nil)
 | 
						|
		sysfatal(smprint("alloc %d pipes: %r", nring*2));
 | 
						|
 | 
						|
	for(i = 0; i < nring; i++)
 | 
						|
		if (pipe(&pfd[i*2]) < 0)
 | 
						|
			sysfatal(smprint("create pipe pair %d of %d: %r", i, nring));
 | 
						|
 | 
						|
	for(i = 0; debug && i < nring; i++ ) fprint(2, "pfd[%d,%d]\n", pfd[i*2],pfd[i*2+1]);
 | 
						|
	for(i = 0, id = 0; i < nring-1; i++, id++) {
 | 
						|
		pid = fork();
 | 
						|
		if (pid == 0)
 | 
						|
			break;
 | 
						|
		if (pid < 0)
 | 
						|
			sysfatal("fork");
 | 
						|
	}
 | 
						|
 | 
						|
	if (debug) fprint(2, "Forked. pid %d\n", getpid());
 | 
						|
	for(i = 0; debug && i < nring; i++ ) fprint(2, "pfd[%d,%d]\n", pfd[i*2],pfd[i*2+1]);
 | 
						|
	for(i = 0; i < niter; i++) {
 | 
						|
		if (debug) fprint(2, "%d: write %d\n", id, pfd[(id%nring)*2+1]);
 | 
						|
		int amt = write(pfd[(id%nring)*2+1], data, sizeof(data));
 | 
						|
		if (amt < sizeof(data))
 | 
						|
			sysfatal(smprint("%d: write only got %d of %d: %r", id, amt, sizeof(data)));
 | 
						|
		if (debug) print("%d: read %d\n", id, pfd[(id%nring)*2]);
 | 
						|
		amt = read(pfd[(id%nring)*2], data, sizeof(data));
 | 
						|
		if (amt < sizeof(data))
 | 
						|
			sysfatal(smprint("%d: read only got %d of %d: %r", id, amt, sizeof(data)));
 | 
						|
	}
 | 
						|
	print("PASS\n");
 | 
						|
	exits("PASS");
 | 
						|
}
 |