Annotation of lucent/sys/src/9/gnot/scsibuf.c, revision 1.1.1.1

1.1       root        1: #include "u.h"
                      2: #include "../port/lib.h"
                      3: #include "mem.h"
                      4: #include "dat.h"
                      5: #include "fns.h"
                      6: #include "../port/error.h"
                      7: #include "io.h"
                      8: 
                      9: /*
                     10:  * The following routines
                     11:  *     scsibufreset, scsibuf, scsifree and scsialloc
                     12:  * provide a pool of buffers used for scsi i/o.
                     13:  * This is simplistic at best, and opportunities for
                     14:  * deadlock abound.
                     15:  */
                     16: #define Nbuf   1
                     17: 
                     18: struct {
                     19:        Lock;
                     20:        Scsibuf *free;
                     21: } scsibufalloc;
                     22: 
                     23: void
                     24: scsibufreset(ulong datasize)
                     25: {
                     26:        int i;
                     27: 
                     28:        for(i = 0; i < Nbuf; i++)
                     29:                scsifree(scsialloc(datasize));
                     30:        lock(&scsibufalloc);
                     31:        unlock(&scsibufalloc);
                     32: }
                     33: 
                     34: /*
                     35:  * get a scsi io buffer of DATASIZE size
                     36:  */
                     37: Scsibuf *
                     38: scsibuf(void)
                     39: {
                     40:        Scsibuf *b;
                     41: 
                     42:        for(;;) {
                     43:                lock(&scsibufalloc);
                     44:                b = scsibufalloc.free;
                     45:                if(b != 0) {
                     46:                        scsibufalloc.free = b->next;
                     47:                        unlock(&scsibufalloc);
                     48:                        return b;
                     49:                }
                     50:                unlock(&scsibufalloc);
                     51:                resrcwait(0);
                     52:        }
                     53:        return 0;               /* not reached */
                     54: }
                     55: 
                     56: void
                     57: scsifree(Scsibuf *b)
                     58: {
                     59:        lock(&scsibufalloc);
                     60:        b->next = scsibufalloc.free;
                     61:        scsibufalloc.free = b;
                     62:        unlock(&scsibufalloc);
                     63: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.