Esempio n. 1
0
Boolean ABuffer::IsEmpty()
{
  HEnterSection(lock);
  Boolean ans = (pktList.size()==0)?TRUE:FALSE;
  HLeaveSection(lock);
  return ans;
}
Esempio n. 2
0
int ABuffer::NumPackets()
{
  HEnterSection(lock);
  int np = pktList.size();
  HLeaveSection(lock);
  return np;
}
Esempio n. 3
0
Boolean ABuffer::IsFull()
{
  HEnterSection(lock);
  if (bsize==0) return FALSE;
  Boolean ans = (int(pktList.size())>=bsize)?TRUE:FALSE;
  HLeaveSection(lock);
  return ans;
}
Esempio n. 4
0
// open this gram for editing
void AGram::OpenEdit()
{
   HEnterSection(lock);
   if (isOpen){
      HRError(10761,"Attempting to open an already open grammar %s",rname.c_str());
      throw ATK_Error(10761);
   }
   isOpen = TRUE;
}
Esempio n. 5
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;
}
Esempio n. 6
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;
}
Esempio n. 7
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;
}
Esempio n. 8
0
void ABuffer::PopPacket()
{
  HEnterSection(lock);
  while (pktList.size()==0) {
    HWaitSignal(notEmpty, lock);
  }
  pktList.pop_front();
  HLeaveSection(lock);
  HSendSignal(notFull);
  SendBufferEvents();
}
Esempio n. 9
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;
}
Esempio n. 10
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();
}
Esempio n. 11
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);
}
Esempio n. 12
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;
}
Esempio n. 13
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();
}
Esempio n. 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;
}