Exemplo n.º 1
0
int bgtslt()
{
    int idx, i;

    idx = -1;
    /* any slots free? */
    for (i=0;i<ZMXBLK;i++) {
#if DEBUG >= 2
        printf("bgtslt: cntrl[%d].inmem = " ZINTFMT "\n",
               i,((btact->cntrl)+i)->inmem);
#endif
        if (((btact->cntrl)+i)->inmem < 0) {
            idx = i;
            break;
        }
    }
    if (idx < 0 ) {
        /* nope, need to free a memory block (least recently used)  */
        idx = bqhead();
    }
    if (idx < 0)
        bterr("BGTSLT",QNOMEM,NULL);
    else {
        /* flush block to disk if slot not empty */
        if (((btact->cntrl)+idx)->inmem >= 0)
            if (bwrblk(((btact->cntrl)+idx)->inmem) != 0)
                bterr("BGTSLT",QWRBLK,itostr(((btact->cntrl)+idx)->inmem));
    }
#if DEBUG >= 2
    printf("bgtslt: found idx of %d\n",idx);
#endif
    return(idx);
}
Exemplo n.º 2
0
/*
  btsync: sync memory blocks with B tree index file
    
  returns zero if no errors, error code otherwise
*/
int btsync()
{
    int i,ioerr;

    if (btact->idxunt != NULL) {
        /* write out all in-memory blocks */
        for (i=0;i<ZMXBLK;i++) {
            ioerr = bwrblk(((btact->cntrl)+i)->inmem);
            if (ioerr != 0) {
                bterr("BTSYNC",QWRBLK,itostr(((btact->cntrl)+i)->inmem));
                goto fin;
            }
        } 
        /* write super block if necessary */
        if (btact->cntxt->super.smod != 0) {
            if ( bwrsup() != 0) goto fin;
            btact->cntxt->super.smod = 0;
        }
    }

    /* force writes to disk */
    fflush(btact->idxunt);

    /* re-initialise control blocks to ensure blocks will be re-read
       from disk */
    initcntrl(btact);
    
fin:
    return(btgerr());
}