// Copy packet from the front of the pktList. Wait for nonEmpty // if the buffer is empty. Leave the packet where it is. APacket ABuffer::PeekPacket() { HEnterSection(lock); while (pktList.size()==0) { HWaitSignal(notEmpty, lock); } APacket p = pktList.front(); HLeaveSection(lock); return p; }
TASKTYPE TASKMOD test3(void * hp) { HEnterSection(t3_lock); printf("Test 3 - waiting for Signal\n"); fflush(stdout); HWaitSignal(t3_signal,t3_lock); printf("Test 3 - Signal Received\n"); fflush(stdout); HLeaveSection(t3_lock); HExitThread(0); return 0; }
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; }
// 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(); }