Information Technology Reference
In-Depth Information
/*
*BBQ.cc--BlockingBoundedQueue.
*/
#include<assert.h>
#include<pthread.h>
#include"BBQ.h"
while(isEmpty()){
itemAdded.Wait(&lock);
}
assert(!isEmpty());
ret=items[firstFull];
nFull--;
firstFull=(firstFull+1)%MAX;
BBQ::BBQ()
{
nFull=0;
firstFull=0;
nextEmpty=0;
itemRemoved.Signal(&lock);
lock.Release();
returnret;
}
}
//Waituntilthereisroom
//theninsertanitem.
void
BBQ::insert(intitem)
{
lock.Acquire();
while(isFull()){
itemRemoved.Wait(&lock);
}
assert(!isFull());
items[nextEmpty]=item;
nFull++;
nextEmpty=(nextEmpty+1)%MAX;
itemAdded.Signal(&lock);
lock.Release();
return;
}
//Waituntilthereisanitem
//thenremoveanitem.
int
BBQ::remove(void)
{
intret;
lock.Acquire();
Figure5.10: BBQ.cc defines the implementation of our blocking bounded
queue.
Search WWH ::




Custom Search