void ABuffer::PopPacket() { HEnterSection(lock); while (pktList.size()==0) { HWaitSignal(notEmpty, lock); } pktList.pop_front(); HLeaveSection(lock); HSendSignal(notFull); SendBufferEvents(); }
// Get packet p from the front of the pktList. Wait for nonEmpty // if the buffer is empty. APacket ABuffer::GetPacket() { HEnterSection(lock); while (pktList.size()==0) { HWaitSignal(notEmpty, lock); } APacket p = pktList.front(); pktList.pop_front(); HLeaveSection(lock); HSendSignal(notFull); return p; }
void SimpleSignal(void) { HThread t; int status; t3_lock = HCreateLock("t3_lock"); t3_signal = HCreateSignal("t3_signal"); t = HCreateThread("t3wait",10,HPRIO_NORM,test3,(void *)0); printf(" press key to send signal\n"); getchar(); HSendSignal(t3_signal); HJoinThread(t,&status); }
// Push packet p onto the end of the pktList. Wait for nonFull // if the buffer is full void ABuffer::PutPacket(APacket p) { assert(filter == AnyPacket || p.GetKind() == filter); HEnterSection(lock); while (bsize!=0 && int(pktList.size())>= bsize) { HWaitSignal(notFull, lock); } pktList.push_back(p); HLeaveSection(lock); HSendSignal(notEmpty); SendBufferEvents(); }
void bput(char c) { HPauseThread(pdel); printf("<%c",c); fflush(stdout); HEnterSection(lock); while (used>=bsize) { printf("!"); HWaitSignal(notfull,lock); } buf[inx] = c; inx++; used++; if (inx == bsize) inx = 0; HSendSignal(notempty); HLeaveSection(lock); printf(">"); fflush(stdout); }
char bget() { int c; HPauseThread(cdel); printf("{"); fflush(stdout); HEnterSection(lock); while (used==0) { printf("?"); HWaitSignal(notempty,lock); } c = buf[outx]; outx++; --used; if (outx == bsize) outx = 0; HSendSignal(notfull); HLeaveSection(lock); printf("%c}",c); fflush(stdout); return c; }
// Push packet p onto the end of the pktList. Wait for nonFull // if the buffer is full void ABuffer::PutPacket(APacket p) { assert(filter == AnyPacket || p.GetKind() == filter); for (ABufferListenerList::iterator l = listenerList.begin(); l != listenerList.end(); l++) { ABufferListener *listener = *l; listener->ABufferReceivedPacket(*this, p); } HEnterSection(lock); while (bsize!=0 && int(pktList.size())>= bsize) { HWaitSignal(notFull, lock); } pktList.push_back(p); HLeaveSection(lock); HSendSignal(notEmpty); SendBufferEvents(); }