1: # include   "../ingres.h"
   2: # include   "../access.h"
   3: # include   "../aux.h"
   4: # include   "../lock.h"
   5: 
   6: /*
   7: **	UNIX read/write counters
   8: */
   9: 
  10: long    Accuread, Accuwrite;
  11: long    Accusread;
  12: 
  13: /* tTf flag 83	TTF	get_page() */
  14: 
  15: get_page(d1, tid)
  16: struct descriptor   *d1;
  17: struct tup_id       *tid;
  18: {
  19:     register int            i;
  20:     register struct descriptor  *d;
  21:     long                pageid;
  22:     register struct accbuf      *b;
  23:     struct accbuf           *b1;
  24:     int             lk;     /* lock condition*/
  25:     struct accbuf           *choose_buf();
  26: 
  27:     d = d1;
  28: #	ifdef xATR3
  29:     if (tTf(83, 0))
  30:     {
  31:         printf("GET_PAGE: %.14s,", d->relid);
  32:         dumptid(tid);
  33:     }
  34: #	endif
  35: 
  36:     pluck_page(tid, &pageid);
  37:     if ((b = choose_buf(d, pageid)) == NULL)
  38:         return (-1);
  39:     top_acc(b);
  40:     lk = Acclock && (d->relstat & S_CONCUR) && (d->relopn < 0);
  41:     if ((b->thispage != pageid) || (lk && !(b->bufstatus & BUF_LOCKED)))
  42:     {
  43:         if (i = pageflush(b))
  44:             return (i);
  45: #		ifdef xATR1
  46:         if (tTf(83, 1))
  47:         {
  48:             printf("GET_PAGE: rdg pg %s", locv(pageid));
  49:             printf(",relid %s\n", locv(d->reltid));
  50:         }
  51: #		endif
  52:         b->thispage = pageid;
  53:         if (lk)
  54:         {
  55:             b1 = Acc_head;
  56:             for (; b1 != 0; b1 = b1->modf)
  57:                 if (b1->bufstatus & BUF_LOCKED)
  58:                     pageflush(b1);  /*  */
  59:             if (setpgl(b) < 0)
  60:                 syserr("get-page: lk err");
  61:         }
  62: #		ifdef xATM
  63:         if (tTf(76, 1))
  64:             timtrace(17, &pageid, &d->reltid);
  65: #		endif
  66:         if ((lseek(d->relfp, pageid * PGSIZE, 0) < 0) ||
  67:             ((read(d->relfp, b, PGSIZE)) != PGSIZE))
  68:         {
  69:             resetacc(b);
  70:             return (acc_err(AMREAD_ERR));
  71:         }
  72:         Accuread++;
  73:         if (d->relstat & S_CATALOG)
  74:         {
  75:             Accusread++;
  76:         }
  77: #		ifdef xATM
  78:         if (tTf(76, 1))
  79:             timtrace(18, &pageid, &d->reltid);
  80: #		endif
  81:     }
  82:     return (0);
  83: }
  84: 
  85: /* tTf flag 84	TTF	pageflush() */
  86: 
  87: pageflush(buf)
  88: struct accbuf   *buf;
  89: {
  90:     register struct accbuf  *b;
  91:     register int        i, allbufs;
  92:     int         err;
  93: 
  94:     b = buf;
  95: #	ifdef xATR3
  96:     if (tTf(84, 0))
  97:         printf("PAGEFLUSH: (%u=%s)\n", b, locv(b->rel_tupid));
  98: #	endif
  99:     err = FALSE;
 100:     allbufs = FALSE;
 101:     if (b == 0)
 102:     {
 103:         b = Acc_buf;
 104:         allbufs = TRUE;
 105:     }
 106: 
 107:     do
 108:     {
 109:         if (b->bufstatus & BUF_DIRTY)
 110:         {
 111: #			ifdef xATR1
 112:             if (tTf(84, 1))
 113:             {
 114:                 printf("PAGEFLUSH: wr pg %s", locv(b->thispage));
 115:                 printf(",relid %s,stat %d\n", locv(b->rel_tupid), b->bufstatus);
 116:             }
 117: #			endif
 118: 
 119: #			ifdef xATM
 120:             if (tTf(76, 1))
 121:                 timtrace(19, &b->thispage, &b->rel_tupid);
 122: #			endif
 123: 
 124:             /* temp debug step */
 125:             if (b->mainpg > 32767)
 126:             {
 127:                 printf("rel %s:", locv(b->rel_tupid));
 128:                 printf("pg %s:", locv(b->thispage));
 129:                 syserr("pgflush mainpg %s", locv(b->mainpg));
 130:             }
 131:             b->bufstatus &= ~BUF_DIRTY;
 132:             if (lseek(b->filedesc, b->thispage * PGSIZE, 0) < 0 ||
 133:                 (write(b->filedesc, b, PGSIZE) != PGSIZE))
 134:             {
 135:                 resetacc(b);
 136:                 err = TRUE;
 137:             }
 138:             Accuwrite++;
 139: 
 140: #			ifdef xATM
 141:             if (tTf(76, 1))
 142:                 timtrace(20, &b->thispage, &b->rel_tupid);
 143: #			endif
 144:         }
 145:         if (Acclock && b->bufstatus & BUF_LOCKED)
 146:             unlpg(b);
 147: 
 148:     } while (allbufs && (b = b->modf) != NULL);
 149: 
 150:     if (err)
 151:         return (acc_err(AMWRITE_ERR));
 152: 
 153:     return (0);
 154: }
 155: 
 156: /*
 157: **	ACC_ERR -- set global error indicator "Accerror"
 158: */
 159: 
 160: /* tTf flag 85	TTF	acc_err() */
 161: 
 162: acc_err(errnum)
 163: int errnum;
 164: {
 165:     Accerror = errnum;
 166: #	ifdef xATR1
 167:     tTfp(85, 0, "ACC_ERR: %d\n", Accerror);
 168: #	endif
 169:     return (Accerror);
 170: }

Defined functions

Defined variables

Accusread defined in line 11; used 1 times
  • in line 75
Last modified: 1995-02-12
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1053
Valid CSS Valid XHTML 1.0 Strict