Beispiel #1
0
Boolean ABuffer::IsEmpty()
{
  HEnterSection(lock);
  Boolean ans = (pktList.size()==0)?TRUE:FALSE;
  HLeaveSection(lock);
  return ans;
}
Beispiel #2
0
int ABuffer::NumPackets()
{
  HEnterSection(lock);
  int np = pktList.size();
  HLeaveSection(lock);
  return np;
}
Beispiel #3
0
Boolean ABuffer::IsFull()
{
  HEnterSection(lock);
  if (bsize==0) return FALSE;
  Boolean ans = (int(pktList.size())>=bsize)?TRUE:FALSE;
  HLeaveSection(lock);
  return ans;
}
Beispiel #4
0
// 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;
}
Beispiel #5
0
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;
}
Beispiel #6
0
// Peek at kind of first item in buffer
PacketKind  ABuffer::GetFirstKind()
{
  PacketKind pk = AnyPacket;
  HEnterSection(lock);
  if (pktList.size()>0){
    APacket p = pktList.front();
    pk = p.GetKind();
  }
  HLeaveSection(lock);
  return pk;
}
Beispiel #7
0
void ABuffer::PopPacket()
{
  HEnterSection(lock);
  while (pktList.size()==0) {
    HWaitSignal(notEmpty, lock);
  }
  pktList.pop_front();
  HLeaveSection(lock);
  HSendSignal(notFull);
  SendBufferEvents();
}
Beispiel #8
0
// 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;
}
Beispiel #9
0
// 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();
}
Beispiel #10
0
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);
}
Beispiel #11
0
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;
}
Beispiel #12
0
// 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();
}
Beispiel #13
0
// close gram to allow use by recogniser
void AGram::CloseEdit()
{
   if (!isOpen){
      HRError(10762,"Attempting to close an already closed grammar %s",rname.c_str());
      throw ATK_Error(10762);
   }
   for (SubNIterator si=subs.begin(); si!=subs.end(); ++si){
      // ensure that grammar is valid
      if (int n = (*si)->IsBroken(TRUE)){
         HRError(10731,"Attempting to close invalid grammar %s(%d)",rname.c_str(),n);
         throw ATK_Error(10731);
      }
      // ensure that entry node is the first in every nodelist
      (*si)->CheckNodeOrder();
   }
   ++version;  // ensure that ARMan rebuilds the network
   isOpen = FALSE;
   HLeaveSection(lock);
}
Beispiel #14
0
TASKTYPE TASKMOD test2(void * hp)
{
	int i; float x;
	HPriority p;
	FILE *f;

	p = (HPriority)hp;
	if (t2_lockon) HEnterSection(t2_lock);
	x = t2_sum;                        /* Load shared variable */
	f = fopen("Readme.txt","r");       /* waste a bit of time on i/o */
	if (f==NULL)
		printf("Cant open ../HThreadTest.c\n");
	else {
		while ((i=fgetc(f)) != '\n') putchar(i);
		printf("\n"); fflush(stdout);
		fclose(f);
	}
	x = x + t2_inc;
	t2_sum = x;                   /* update shared variable */
	if (t2_lockon)   HLeaveSection(t2_lock);
	HExitThread(0);
	return 0;
}