plan 9 kernel history: overview | file list | diff list

1992/1029/ss/scsibuf.c (diff list | history)

1992/1029/sys/src/9/ss/scsibuf.c:1,631993/0501/sys/src/9/ss/scsibuf.c:0 (short | long)
Deleted.
rsc Mon Mar 7 10:33:20 2005
1992/1029    
#include "u.h" 
#include "../port/lib.h" 
#include "mem.h" 
#include "dat.h" 
#include "fns.h" 
#include "../port/error.h" 
#include "io.h" 
                 
/* 
 * The following routines 
 *	scsibufreset, scsibuf, scsifree and scsialloc 
 * provide a pool of buffers used for scsi i/o. 
 * This is simplistic at best, and opportunities for 
 * deadlock abound. 
 */ 
#define Nbuf	2 
                 
struct { 
	Lock; 
	Scsibuf	*free; 
} scsibufalloc; 
                 
void 
scsibufreset(ulong datasize) 
{ 
	int i; 
                 
	for(i = 0; i < Nbuf; i++) 
		scsifree(scsialloc(datasize)); 
	lock(&scsibufalloc); 
	unlock(&scsibufalloc); 
} 
                 
/* 
 * get a scsi io buffer of DATASIZE size 
 */ 
Scsibuf * 
scsibuf(void) 
{ 
	Scsibuf *b; 
                 
	for(;;) { 
		lock(&scsibufalloc); 
		b = scsibufalloc.free; 
		if(b != 0) { 
			scsibufalloc.free = b->next; 
			unlock(&scsibufalloc); 
			return b; 
		} 
		unlock(&scsibufalloc); 
		resrcwait(0); 
	} 
	return 0;		/* not reached */ 
} 
                 
void 
scsifree(Scsibuf *b) 
{ 
	lock(&scsibufalloc); 
	b->next = scsibufalloc.free; 
	scsibufalloc.free = b; 
	unlock(&scsibufalloc); 
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)