Dump-like file system backup for Unix, built on Venti.
This commit is contained in:
parent
0c98da8bf8
commit
004aa293f3
27 changed files with 4437 additions and 0 deletions
64
src/cmd/vbackup/queue.c
Normal file
64
src/cmd/vbackup/queue.c
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#include <u.h>
|
||||
#include <libc.h>
|
||||
#include <thread.h>
|
||||
#include <venti.h>
|
||||
#include <diskfs.h>
|
||||
#include "queue.h"
|
||||
|
||||
Queue*
|
||||
qalloc(void)
|
||||
{
|
||||
Queue *q;
|
||||
|
||||
q = vtmallocz(sizeof(Queue));
|
||||
q->r.l = &q->lk;
|
||||
return q;
|
||||
}
|
||||
|
||||
Block*
|
||||
qread(Queue *q, u32int *pbno)
|
||||
{
|
||||
Block *db;
|
||||
u32int bno;
|
||||
|
||||
qlock(&q->lk);
|
||||
while(q->nel == 0 && !q->closed)
|
||||
rsleep(&q->r);
|
||||
if(q->nel == 0 && q->closed){
|
||||
qunlock(&q->lk);
|
||||
return nil;
|
||||
}
|
||||
db = q->el[q->ri].db;
|
||||
bno = q->el[q->ri].bno;
|
||||
if(++q->ri == MAXQ)
|
||||
q->ri = 0;
|
||||
if(q->nel-- == MAXQ/2)
|
||||
rwakeup(&q->r);
|
||||
qunlock(&q->lk);
|
||||
*pbno = bno;
|
||||
return db;
|
||||
}
|
||||
|
||||
void
|
||||
qwrite(Queue *q, Block *db, u32int bno)
|
||||
{
|
||||
qlock(&q->lk);
|
||||
while(q->nel == MAXQ)
|
||||
rsleep(&q->r);
|
||||
q->el[q->wi].db = db;
|
||||
q->el[q->wi].bno = bno;
|
||||
if(++q->wi == MAXQ)
|
||||
q->wi = 0;
|
||||
if(q->nel++ == MAXQ/2)
|
||||
rwakeup(&q->r);
|
||||
qunlock(&q->lk);
|
||||
}
|
||||
|
||||
void
|
||||
qclose(Queue *q)
|
||||
{
|
||||
qlock(&q->lk);
|
||||
q->closed = 1;
|
||||
rwakeup(&q->r);
|
||||
qunlock(&q->lk);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue