Beispiel #1
0
/*****************************************************************************
 Function   : VOS_ShowFidsQueueInfo
 Description: print used msg's useage info
 Input      : void
 Return     : void
 Other      : only for designer
 *****************************************************************************/
VOS_VOID VOS_ShowFidsQueueInfo(VOS_UINT32 Para0, VOS_UINT32 Para1,
                                VOS_UINT32 Para2, VOS_UINT32 Para3 )
{
    VOS_UINT32              i;
    VOS_UINT32              *pulMsgAddr;
    VOS_UINT32              ulCount;

    for( i=VOS_FID_DOPRAEND; i<VOS_FID_BUTT; i++ )
    {
        Print2("# FID %d %s queue info.\r\n", i, vos_FidCtrlBlk[i].Name);

        ulCount = 0;

        pulMsgAddr = (VOS_UINT32 *)VOS_OutMsg(vos_FidCtrlBlk[i].Qid );

        while ( VOS_NULL_PTR != pulMsgAddr )
        {
            ulCount++;

            if ( ulCount > VOS_FID_QUEUE_LENGTH )
            {
                LogPrint("# VOS_ShowFidsQueueInfo error.\r\n");
            }

            Print4("# Msg :S pid %08X R Pid %08X Length %08X Name %08X.\r\n",
                    *(pulMsgAddr + 1), *(pulMsgAddr + 3),
                    *(pulMsgAddr + 4), *(pulMsgAddr + 5));

            pulMsgAddr = (VOS_UINT32 *)VOS_OutMsg(vos_FidCtrlBlk[i].Qid );
        }
    }

    return;
}
Beispiel #2
0
void testfunc()
{

#if 1

	int myID;
	myID=threadID;
	threadID=threadID+1;


	Print("START --------------------- testfunc \n");

	Print2("THREAD %d TRYING TO ACQUIRE LOCK %d \n",myID,lockNumber1);
	Acquire(lockNumber1);
	Print2("THREAD %d ACQUIRED LOCK %d \n",myID,lockNumber1);

	Print2("Thread : %d is waiting on lockId : %d \n",myID,lockNumber1);
	Wait(cvNumber1,lockNumber1);

	Print1("Thread %d Coming Out of Wait\n",myID);

	Print2("THREAD %d RELEASING LOCK %d\n",myID,lockNumber1);
	Release(lockNumber1);
	Print2("THREAD %d RELEASED LOCK %d\n",myID,lockNumber1);

	Print1("THREAD %d is done !!!!!!!!!!!!!!!!!! \n",myID);

#endif
	Print("END -----------------------------------  testfunc \n");

	/*
	Exit(0);
	*/

	Yield();
	Yield();
	Yield();
	Yield();
	Yield();
	Yield();
	Yield();
	Yield();
	Yield();
	Exit(0);


}
Beispiel #3
0
void testfunc1()
{
#if 1
	int myID;
	myID=threadID;
	threadID=threadID+1;

	Print("START --------------------- testfunc1 \n");

	Print2("THREAD %d TRYING TO ACQUIRE LOCK %d \n",myID,lockNumber1);
	Acquire(lockNumber1);
	Print2("THREAD %d ACQUIRED LOCK %d \n",myID,lockNumber1);

	Print2("Thread : %d to send Signal on LOCK %d \n",myID,lockNumber1);
	Signal(cvNumber1,lockNumber1);

	Print2("THREAD %d RELEASING LOCK %d\n",myID,lockNumber1);
	Release(lockNumber1);
	Print2("THREAD %d RELEASED LOCK %d\n",myID,lockNumber1);

	Print1("THREAD %d is done !!!!!!!!!!!!!!!!!! \n",myID);

#endif

	Print("END -----------------------------------  testfunc1 \n");

	Yield();
	Yield();
	Yield();
	Yield();
	Yield();
	Yield();
	Yield();
	Yield();
	Yield();

	/*
	Exit(0);
	 */

	Exit(0);
}
Beispiel #4
0
/*****************************************************************************
 Function   : VOS_GetTidFromPid
 Description: Get Tid From Pid
 Input      : Pid
 Return     :
 Other      : only for designer
 *****************************************************************************/
VOS_UINT32 VOS_GetTCBFromPid(VOS_UINT32 ulPid)
{
    VOS_UINT32         ulFid;

    if((ulPid < VOS_PID_DOPRAEND)||(ulPid >= VOS_PID_BUTT))
    {
        Print1("VOS_GetTCBFromPid: Wrong Pid %d\r\n", ulPid);

        return VOS_NULL;
    }

    ulFid = (VOS_UINT32)(vos_PidRecords[ulPid-VOS_PID_DOPRAEND].Fid);

    if ((ulFid < (VOS_UINT32)VOS_FID_DOPRAEND) || (ulFid >= (VOS_UINT32)VOS_FID_BUTT))
    {
        Print2("VOS_GetTCBFromPid Wrong PID %d. FID %d\r\n", (VOS_INT)ulPid, (VOS_INT)ulFid);

        return VOS_NULL;
    }

    return (VOS_UINT32)VOS_GetTCBFromTID(vos_FidCtrlBlk[ulFid].Tid);

}
Beispiel #5
0
/*****************************************************************************
 Function   : VOS_FidCtrlBlkInit
 Description: Init the control block of FID
 Input      : VOS_VOID
 Return     : VOS_OK on success or errno on failure.
 Other      :
 *****************************************************************************/
VOS_UINT32 VOS_FidCtrlBlkInit(VOS_VOID)
{
    VOS_UINT32               i,j;
    VOS_UINT32               ulTotalStackSize = 0;
    VOS_FID_CONTROL_BLOCK    *pFidCtrlBlk = vos_FidCtrlBlk;
    FID_Static_Table_Type    *pFidStaticTable;

    for(i=0; i<VOS_FID_BUTT; i++)
    {
        pFidCtrlBlk->Fid = i;

        pFidCtrlBlk->InitFunc = FidInitFuncDefault;
        pFidCtrlBlk->Priority = vos_FidTaskRealPriority[VOS_PRIORITY_BASE];
        pFidCtrlBlk->StackSize  = TASK_STACK_SIZE;
        pFidCtrlBlk->MaxMsgNumber = VOS_FID_QUEUE_LENGTH;

        pFidCtrlBlk++;
    }

    for(i=VOS_FID_DOPRAEND; i<VOS_FID_BUTT; i++)
    {
        pFidCtrlBlk = &vos_FidCtrlBlk[i];
        pFidStaticTable = &g_aFidStaticTable[i];

        if(pFidStaticTable->ulFID != (VOS_FID)i)
        {
            Print2("# Fid Init Fid invalid ulFID %ld I %ld",
                pFidStaticTable->ulFID, i );

            return(VOS_ERR);
        }

        pFidCtrlBlk->InitFunc = pFidStaticTable->pfnInitFun;

        if( 0 != pFidStaticTable->usStackSize )
        {
            pFidCtrlBlk->StackSize = pFidStaticTable->usStackSize;
        }

        ulTotalStackSize += pFidCtrlBlk->StackSize;

        if( 0 != pFidStaticTable->usMsgNumber)
        {
            pFidCtrlBlk->MaxMsgNumber = pFidStaticTable->usMsgNumber;
        }

        for(j=0; j<(VOS_PID_BUTT - VOS_PID_DOPRAEND); j++)
        {
            if( vos_PidRecords[j].Fid == i )
            {
                pFidCtrlBlk->PidsBelong[j] = VOS_ID_PID_BELONG_TO_FID;
            }
            else
            {
                pFidCtrlBlk->PidsBelong[j] = VOS_ID_PID_NOT_BELONG_TO_FID;
            }
        }
    }

    /* Added for checking stack */
    if ( VOS_TASK_STACK_SIZE < ulTotalStackSize )
    {
        Print1("# Fid Init stack too small %ld.\r\n", ulTotalStackSize);

        return(VOS_ERR);
    }

    return(VOS_OK);
}
void Waiter()
{
  int MyWaiterID=0;
  int NoOfCustServed=0;
	int i=0;
	int j=0;
	int k=0;
	Acquire(WaiterCountLock);
	MyWaiterID = WaiterCount++;
	Release(WaiterCountLock);
  /*Print1("Created %d Waiter\n", MyWaiterID);*/
   while(1)
     {
        /*Check if there are customers seated and thier food is ready
       Looping myself */
       Acquire(GrabedFoodLock);
       /*See for which customers food is grabed	 */
			 for(i=0;i<MAX_SIZE;i++)
			 {
				if(NoOfCustServed>0)
				{
					NoOfCustServed=0;
					break;
				}
				for(j=0;j<MAX_SIZE;j++)
				{
					if(GrabedFood[i][j]==1)
					{
						if(NoOfCustServed>0)
						{
							break;
						}
						
						Acquire(TableAllotedCustLock);
						for(k=0;k<MAX_SIZE;k++)		/* see if that customer is seated */
						{
							if(TableAllotedCustList[k]==j)
							{
								Acquire(NeedWaitersLock[j]);				/*Customer is ready to be served*/
								Signal(NeedWaitersCV[j],NeedWaitersLock[j]);
								Release(NeedWaitersLock[j]);
								Print3("Waiter [%d] got token number [%d] for Customer [%d]\n",MyWaiterID,j,j);
								Print2("Waiter [%d] validates the token number for Customer [%d]\n",MyWaiterID,j);
								Print2("Waiter [%d] serves food to Customer [%d]\n",MyWaiterID,j);
								TableAllotedCustList[k]=-1;
								/*Print2("TableAllotedCustList[%d]=%d\n",k,TableAllotedCustList[k]);*/
								GrabedFood[i][j]=-1;
								NoOfCustServed++;
								Acquire(TotalTablesUpdateLock);
								TotalTables++;
								Release(TotalTablesUpdateLock);
								break;
							}
						}
						Release(TableAllotedCustLock);
					}
				}
				if(NoOfCustServed>0)
				{
					NoOfCustServed=0;
					break;
				}
			}
			i=j=k=0;
			Release(GrabedFoodLock);
			for( i=0; i<20;i++)
			{
					/*currentThread->Yield();*/
			}

		/* There are no customers waiting, Waiters go on break */
			Acquire(WaitersQLock);
			Print1("Waiter[%d] going on break\n", MyWaiterID);
			Acquire(SleepingWaiterCountLock);
			SleepingWaiterCount++;
			Release(SleepingWaiterCountLock);
			Wait(WaitersCV,WaitersQLock);
			Acquire(SleepingWaiterCountLock);
			SleepingWaiterCount--;
			Release(SleepingWaiterCountLock);
			Release(WaitersQLock);
			Acquire(AliveCustCountLock);
			/*Print1("AliveCustCount%d\n",AliveCustCount);*/
			if(AliveCustCount==0)
			{
				/*Print1("Waiter %d is exiting\n",MyWaiterID);*/
				Release(AliveCustCountLock);
				Exit(1);
			}
			else
			{
				Print1(" Waiter[%d] returned from break\n", MyWaiterID);
				Release(AliveCustCountLock);
			}
     }/*end of while()*/
} /*end of waiter()	*/
void OrderTaker()
{
  int MyCustID = -1;
  int CustFoodIsReady =-1;
  int Poped_CID = -1;
  int Poped_OT = -1;
	int i=0;
	int myOTId=0;
	
  Acquire(OTCountLock);
	myOTId = OTcount++;
	Release(OTCountLock);
	/*Print1("Created %d OT\n", myOTId);*/
  while(1)
   {
		Acquire(AliveCustCountLock);
		if(AliveCustCount==0)
		{
			Acquire(ActiveOTCountLock);
			ActiveOTCount--;
			Release(ActiveOTCountLock);
			Release(AliveCustCountLock);
			Exit(1);
		}
		else
			Release(AliveCustCountLock);
    Acquire(custLineLock);
    /*Are there any waiting customers?*/
    if(custLineLength > 0)
      {
        Signal(custWaitingCV,custLineLock);
        custLineLength--;
        Release(custLineLock);
        Acquire(OTStatusUpdateLock);
        OrderTakerStatus[myOTId]=WAITING;
        Release(OTStatusUpdateLock);
      }
    /*Is there any food to bag?*/
	else
	{
	  Release(custLineLock);
	  Acquire(EatInCustWaitingForFoodLock);
	  for(i=0;i<MAX_SIZE;i++)
	  {
			if(EatInCustWaitingForFood[i]==1)
			{
				EatInCustWaitingForFood[i]=0;
				MyCustID=i;
				break;
			}
	  }
		i=0;
	 
	/*For (each) this customer, check if his order is ready for each type of food*/
	if(MyCustID!=-1)
		{
			CustFoodIsReady = IsCustomerFoodReady (MyCustID);
			 /* if CustFoodIsReady = 1, Food is ready and can be grabed*/
			 if (CustFoodIsReady==1)
				{
				 Acquire(GrabedFoodLock);
				 GrabedFood[myOTId][MyCustID]=1;/* 1 means food is grabed and 0 means otherwise*/
				 Release(GrabedFoodLock);
				 Print2("OrderTaker[%d] packed the food for Customer[%d]\n",myOTId, MyCustID);
				 MyCustID=-1;
				 Release(EatInCustWaitingForFoodLock);
				}
			 else
				{
				 /*list of customers to whom token should be handled but shouldnt grab the food*/
				 /*this Q is as good as saying who gave token number to whom when they wanna wait*/
				  EatInCustWaitingForFood[MyCustID]=1;
				  Print1("OrderTaker[%d] gives token number to Customer[%d]\n", MyCustID);
					MyCustID=-1;
					Release(EatInCustWaitingForFoodLock);
				}
		}
	
	 else
		{
			Release(EatInCustWaitingForFoodLock);
			Acquire(ToGoCustWaitingForFoodLock);
			i=0;
			for(i=0;i<MAX_SIZE;i++)
			{
				if(ToGoCustWaitingForFood[i]==1)
				{
					ToGoCustWaitingForFood[i]=0;
					MyCustID=i;
					break;
				}
			}
			i=0;
			
			if(MyCustID!=-1)
			{
				CustFoodIsReady = IsCustomerFoodReady (MyCustID);
				 /* if CustFoodIsReady = 1, Food is ready and can be grabed*/
				 if (CustFoodIsReady==1)
					{
					 Acquire(GrabedFoodLock);
					 GrabedFood[myOTId][MyCustID]=1;/* 1 means food is grabed and 0 means otherwise*/
					 Release(GrabedFoodLock);
					 Print2("OrderTaker[%d] gives food to the Customer[%d]\n",myOTId, MyCustID);
					 MyCustID=-1;
					 Release(ToGoCustWaitingForFoodLock);
					}
				 else
					{
					 /*list of customers to whom token should be handled but shouldnt grab the food
					 /*this Q is as good as saying who gave token number to whom when they wanna wait*/
					  ToGoCustWaitingForFood[MyCustID]=1;
					  Print2("OrderTaker[%d] gives token number to Customer[%d]\n",myOTId, MyCustID);
						MyCustID=-1;
						Release(ToGoCustWaitingForFoodLock);
					}
			}
			else
			{
				Release(ToGoCustWaitingForFoodLock);
				/*Nothing to do
				/*Set OT status to FREE*/
				Acquire(OTStatusUpdateLock);
				OrderTakerStatus[myOTId]=FREE;
				Release(OTStatusUpdateLock);
				Acquire(AliveCustCountLock);
				if(AliveCustCount==0)
				{
					Acquire(ActiveOTCountLock);
					ActiveOTCount--;
					Release(ActiveOTCountLock);
					Release(AliveCustCountLock);
					Exit(1);
				}
				else
					Release(AliveCustCountLock);
			}
		}
	}

  /*Now, OT is ready to take order
  /* Take interaction lock*/
  Acquire(OrderTakerLock[myOTId]);
  /*release hold on CustLineLen
  /*OT should wait until customer signals him with orders*/
	/*Print1(" %d OT waiting for customers to signal\n", myOTId);*/
  Wait(OTWaitingCV[myOTId],OrderTakerLock[myOTId]);
	/*Print1(" %d OT waiting for customers is siganlled!! Yay!!\n", myOTId);*/
  /*When I'm here, Customer has signaled that his order is ready*/
  /*Compute the money and handle the token number.*/

  /*check which customer signalled me?*/
  Acquire(SigCustListLock);
	/*Print2("Acquiried SigCustListLock%d by %d\n",SigCustListLock,myOTId);*/
  i=0;
  for(i=0;i<MAX_SIZE;i++)
  { 
		/*Print("Inside For loop\n");*/
		if(SigCustList[i]==myOTId)
		{
			MyCustID=i;
			SigCustList[i]=-1;
			break;
		}
  }
	i=0;
	/*Print2("Releasing SigCustListLock%d by %d\n",SigCustListLock,myOTId);*/
  
	/*Print1("Cust ID after I poped out %d\n",MyCustID);*/

  Acquire(MonitorAmtOfMoneyLock);
	Acquire(CustDataLock);
  MoneyInRstrnt = (6 * CustData[MyCustID].Food[0] + 3 * CustData[MyCustID].Food[1] + 4 * CustData[MyCustID].Food[2] \
                  + 2 * CustData[MyCustID].Food[3] + CustData[MyCustID].Food[4]);
	
  Release(MonitorAmtOfMoneyLock);
	Release(SigCustListLock);
	Release(CustDataLock);
	
  Print2("OrderTaker[%d] is taking order of the Customer [%d]\n", myOTId, MyCustID);

/*Order Processing
  /* Check the customer style of eating - eat in or to-go?*/
	Acquire(CustDataLock);
  if( CustData[MyCustID].TypeOfFood == 0)
    {
			Release(CustDataLock);
     /*Eat - in customers
     /*If type of food is only Soda, token is handled
     /*and add to GrabedFood*/
     if( MyCustID%5==4)
        {
          /*Update the list which waiter will look to serve customers*/
			Acquire(GrabedFoodLock);
			GrabedFood[myOTId][MyCustID]=1;
			Release(GrabedFoodLock);
        }
      /* Customers with multiple orders*/
      else
        {
         /*For (each) this customer, check if his order is ready for each type of food*/
          CustFoodIsReady = IsCustomerFoodReady (MyCustID);
         /* if CustFoodIsReady = 1, Food is ready and can be grabed*/
         if (CustFoodIsReady==1)
            {
							Acquire(GrabedFoodLock);
							GrabedFood[myOTId][MyCustID]=1;/* 1 means food is grabed and 0 means otherwise*/
							Release(GrabedFoodLock);
							Print2("OrderTaker[%d] gives token number to Customer[%d]\n",myOTId, MyCustID);
            }
        else
            {
             /*list of customers to whom token should be handled but shouldnt grab the food
             /*this Q is as good as saying who gave token number to whom when they wanna wait*/
              Acquire(EatInCustWaitingForFoodLock);
              EatInCustWaitingForFood[MyCustID]=1;
              Release(EatInCustWaitingForFoodLock);
              Print2("OrderTaker[%d] gives token number to Customer[%d]\n",myOTId, MyCustID);
            }


        }

    }
  /* Customers of type togo*/
  else
    {
			Release(CustDataLock);
     if( MyCustID%5 == 4)/* If customer needs only Soda*/
       {
        /*Signal this waiting customer and "wait" for him to acknowledge*/
        /*If acknowledged, signal the waiting customer and Customer threads finishes*/
       }
     /* Customers with multiple orders*/
     else
       {
        /*For (each) this customer, check if his order is ready for each type of food*/
        CustFoodIsReady = IsCustomerFoodReady (MyCustID);
         /* if CustFoodIsReady = 1, Food is ready and can be grabed*/
        if (CustFoodIsReady==1)
           {
            Acquire(ToGoGrabedFoodLock);
            ToGoGrabedFood[MyCustID]=1;
            Release(ToGoGrabedFoodLock);
            Print2("OrderTaker[%d] packed the food for Customer[%d]\n",myOTId, MyCustID);
            /*Signal(OTWaitingCV[myOTId],OrderTakerLock[myOTId]);
            Release(OrderTakerLock[myOTId]);
            continue;*/
           }
        else
           {
            /*list of customers to whom token should be handled but shouldnt grab the food*/
            /*this Q is as good as saying who gave token number to whom when they wanna wait*/
             Acquire(ToGoCustWaitingForFoodLock);
             ToGoCustWaitingForFood[MyCustID]=1;
             Release(ToGoCustWaitingForFoodLock);
             Print2("OrderTaker[%d] gives token number to Customer[%d]\n",myOTId, MyCustID);
           }
       }

    }
    /*Order processed Signal the customer to get out of sleep!*/
    Signal(OTWaitingCV[myOTId],OrderTakerLock[myOTId]);

    Release(OrderTakerLock[myOTId]);
		Acquire(custLineLock);
		/*Are there any waiting customers?*/
		if(custLineLength==0)
		{
			Release(custLineLock);
			Acquire(ActiveOTCountLock);
			ActiveOTCount--;
			Release(ActiveOTCountLock);
			/*Print1("\t\t\t\n\nOT %d is exiting\n\n\n\n",myOTId);*/
			Exit(1);
		}
		else
			Release(custLineLock);

   }/*end of while()*/
	
}/*end of OrderTaker()*/
void Customer()
{
	int CustID=-1;
	int myOT=-1;
	int i=0;
	int j=0;
	int NoOfEatIn=0;

	Acquire(CustCountLock);
	CustID = CustCount++;
	Release(CustCountLock);
	Acquire(custLineLock);
	Acquire(OTStatusUpdateLock);
	for(i=0;i<PersonCount.NoOfOT;i++)
    {
      if(FREE == OrderTakerStatus[i]) /*checking for a free order taker*/
      {
          OrderTakerStatus[i] = BUSY;/*make ith (my) OT busy*/
          myOT=i;
          break;
      }
    }
		i=0;
	Release(OTStatusUpdateLock);
	
	/*Here either I know who is my OT or there are no OT for me*/
	if(-1==myOT) /*get in line*/
    {
		    custLineLength++;
        /*Print1("Customer[%d] has NO OrderTakers, Snoozing!\n", CustID);*/
        Wait(custWaitingCV,custLineLock);	
				/*Print1("Waiting Customer[%d] is signalled by OT\n",	CustID);*/			
    }
	Release(custLineLock);
	/*Get a waiting OT*/
	Acquire(OTStatusUpdateLock);
	for(j=0;j<PersonCount.NoOfOT;j++)
	{
	  if (WAITING == OrderTakerStatus[j])
	  {
			myOT=j;
			OrderTakerStatus[j]=BUSY;
			break;
	  }
	}
	j=0;
	Release(OTStatusUpdateLock);

	 /*Allow OT to manipluate CustLineLength*/
     /*By here, Customer is aware of his OT and ready to order his/her food*/
	
	Acquire(SigCustListLock);
  SigCustList[CustID]=myOT;
  Release(SigCustListLock);

  Print2("Customer[%d] is giving order to OrderTaker[%d]\n",CustID,myOT);
	Acquire(CustDataLock);
  if(CustData[CustID].Food[0] == 0)
  Print1("Customer[%d] is NOT ordering 6-dollar burger\n", CustID);
  else
  Print1("Customer[%d] is ordering 6-dollar burger\n", CustID);
  if(CustData[CustID].Food[1] == 0)
  Print1("Customer[%d] is NOT ordering 3-dollar burger\n", CustID);
  else
  Print1("Customer[%d] is ordering 3-dollar burger\n", CustID);
  if(CustData[CustID].Food[2] == 0)
  Print1("Customer[%d] is NOT ordering veggie burger\n", CustID);
  else
  Print1("Customer[%d] is ordering veggie burger\n", CustID);
  if(CustData[CustID].Food[3] == 0)
  Print1("Customer[%d] is NOT ordering French fries\n", CustID);
  else
  Print1("Customer[%d] is ordering French fries\n", CustID);
  if(CustData[CustID].Food[4] == 0)
  Print1("Customer[%d] is NOT ordering Soda\n", CustID);
  else
  Print1("Customer[%d] is ordering Soda\n", CustID);
	Release(CustDataLock);

	  NoOfEatIn = (2*(PersonCount.NoOfCust))/3;
	  if(CustID <= NoOfEatIn )
		{
		  Print1("Customer [%d] chooses to Eat-in the food\n",CustID);
		}
	  else
		{
		 Print1("Customer [%d] chooses to To-go the food\n",CustID);
		}
  /*Wake-up the WAITING OT who is waiting for my order.*/
  Acquire(OrderTakerLock[myOT]);
  Signal(OTWaitingCV[myOT],OrderTakerLock[myOT]);
	/*Print1("Customer[%d] is waiting for OT to respond for orders(2nd wait)\n",	CustID);*/
  Wait(OTWaitingCV[myOT],OrderTakerLock[myOT]);/* Waiting for my order to be processed*/
  Print3("Customer [%d] is given token number [%d] by the OrderTaker [%d]\n",CustID,CustID,myOT);
  Release(OrderTakerLock[myOT]);

  /*Customer-Manager interaction
    If Customer is Eat-in type
    Wait for Manager to check if there is table for me
      Need lock and CV to go on wait*/
	Acquire(CustDataLock);
  if (CustData[CustID].TypeOfFood == 0)
    {
			Release(CustDataLock);
      Acquire(TblNeededCustLock);
      TblNeededCustList[myOT][CustID]=1;	/*1 indicates that customer needs table*/
      Release(TblNeededCustLock);

      Acquire(NeedTableLock[CustID]);
      Print1("Customer %d is waiting for the table\n", CustID);
      Wait(NeedTableCV[CustID],NeedTableLock[CustID]);
      Signal(NeedTableCV[CustID],NeedTableLock[CustID]);/*Send ack to Mgr*/
      Print1("Eat IN Customer %d got the table\n", CustID);
      /* Manager signals only when there are free tables*/
        /* Here Customers are sure of allocated Table*/
      Release(NeedTableLock[CustID]);

      /*Customer Waits for Waiter
        Eat-in Customer whose food is ready, seated and waiting for waiters to serve them*/
      Acquire(NeedWaitersLock[CustID]);
      Print1("Customer [%d] is waiting for the waiter to serve the food\n",CustID);							  
      Wait(NeedWaitersCV[CustID],NeedWaitersLock[CustID]);
      /*Waiters signals only when Customer Food is ready
        Here Customers are sure of served food and they must leave!*/
	 Print1("Customer [%d] is served by the waiter",CustID);
      Release(NeedWaitersLock[CustID]);
      Print1("\nCustomer[%d] order is leaving the restaurant after having food\n\n\n",CustID );
    }
    else
      {
				 Release(CustDataLock);
         Print2("\nCustomer[%d] is leaving the restaurant after Order Taker[%d] packed the food\n\n\n",CustID,myOT );
      }
  CustLeft++;
	Acquire(AliveCustCountLock);
	AliveCustCount--;
	Release(AliveCustCountLock);
	/*Print1("Customer %d is exiting\n",CustID);*/
  Exit(1);	

}
void Manager()
{
  int MyMgrID=1;
  int MyCustID;
  int MyCookSpec; 
  int MyCookStat;
  int RmvedCookCnt=0;
  int RmvedCook[200]; 
	int a=0;
	int b=0;
	int c=0;
	int d=0;
	int i=0;
	int myOTId=PersonCount.NoOfOT;
	int CustFoodIsReady=0;
  while (1)
  {

    /*Manager should not take customers untill OT finished interaction with them*/
    Acquire(TblNeededCustLock);
		for(a=0;a<MAX_SIZE;a++)	   /*a-OTID b-CUSTID*/
		{
			for(b=0;b<MAX_SIZE;b++)
			{
				/*Print2("a=[%d]b=[%d] in for loop\n",a,b);
				Print1("TblNeededCustList[a][b]=%d outside for loop\n",TblNeededCustList[a][b]);*/
				if (TblNeededCustList[a][b]==1)
				{
					/*There are atleast some customer either waiting for food to be prepared or with food prepared and waiting for table*/
					Acquire(TotalTablesUpdateLock);
					MyCustID=b;
					/* There is a table for Customers
					Alert the customer about this*/
					if ( TotalTables>0 )
					{
						 TotalTables--;
						 Release(TotalTablesUpdateLock);
						 /*Update this table so that waiter is aware of seated customers*/
						 Acquire(TableAllotedCustLock);
						 for(c=0;c<MAX_SIZE;c++)
						 {
							if(TableAllotedCustList[c]==-1)
							{
								TableAllotedCustList[c]=MyCustID;
								TblNeededCustList[a][b]=0;
								/* There is a table for Customers
								Alert the customer about this*/
								Acquire(NeedTableLock[MyCustID]);
								Print2("Customer [%d] receives token number [%d] from the Manager\n",MyCustID,MyCustID);
								Print1("Customer[%d] is informed by the Manager - the restaurant is NOT full\n",MyCustID);
								Print1("Customer [%d] is seated at table\n",MyCustID);
								Signal(NeedTableCV[MyCustID],NeedTableLock[MyCustID]);
								Wait(NeedTableCV[MyCustID],NeedTableLock[MyCustID]);
								Release(NeedTableLock[MyCustID]);
								break;
							}
						 }
						Release(TableAllotedCustLock);
					}
					 /* if there are no tables, just give them the token number*/
					else
					 {
						/*pritnf("Customer [%d] receives token number [%d] from the Manager\n",MyCustID,MyCustID);*/
						Release(TotalTablesUpdateLock);
						Print1("Customer[%d] is informed by the Manager-the restaurant is  full\n",MyCustID);
						Print1("Customer [%d] is waiting to sit on the table\n", MyCustID);
					 }
				}
			}
    }
		a=b=c=0;
    Release(TblNeededCustLock);
        


		/*************************************************************
		* Manager as an OT START
		**************************************************************/
		i=0;
		for(i=0;i<200;i++)
		{
			Acquire(custLineLock);
			if(custLineLength>3*PersonCount.NoOfOT)
			{
				
			}
			Release(custLineLock);
		}
		
		/*************************************************************
		* Manager as an OT END
		**************************************************************/
		/* Manager as food packer*/
	
	
	Acquire(EatInCustWaitingForFoodLock);
	i=0;
	for(i=0;i<MAX_SIZE;i++)
	{
		if(EatInCustWaitingForFood[i]==1)
		{
			EatInCustWaitingForFood[i]=0;
			MyCustID=i;
			break;
		}
	}
	i=0;

	/*For (each) this customer, check if his order is ready for each type of food*/
	if(MyCustID!=-1)
		{
			CustFoodIsReady = IsCustomerFoodReady (MyCustID);
			 /* if CustFoodIsReady = 1, Food is ready and can be grabed*/
			 if (CustFoodIsReady==1)
				{
				 Acquire(GrabedFoodLock);
				 GrabedFood[myOTId][MyCustID]=1;/* 1 means food is grabed and 0 means otherwise*/
				 Release(GrabedFoodLock);
				 Print1("Manager packed food for Customer[%d]\n", MyCustID);
				 MyCustID=-1;
				 Release(EatInCustWaitingForFoodLock);
				}
			 else
				{
				 /*list of customers to whom token should be handled but shouldnt grab the food*/
				 /*this Q is as good as saying who gave token number to whom when they wanna wait*/
				  EatInCustWaitingForFood[MyCustID]=1;
					Print1("Manager gives token number to Customer[%d]\n", MyCustID);
					MyCustID=-1;
					Release(EatInCustWaitingForFoodLock);
				}
		}
	
	 else
		{
			Release(EatInCustWaitingForFoodLock);
			Acquire(ToGoCustWaitingForFoodLock);
			i=0;
			for(i=0;i<MAX_SIZE;i++)
			{
				if(ToGoCustWaitingForFood[i]==1)
				{
					ToGoCustWaitingForFood[i]=0;
					MyCustID=i;
					break;
				}
			}
			i=0;

			if(MyCustID!=-1)
			{
				CustFoodIsReady = IsCustomerFoodReady (MyCustID);
				 /* if CustFoodIsReady = 1, Food is ready and can be grabed*/
				 if (CustFoodIsReady==1)
					{
					 Acquire(GrabedFoodLock);
					 GrabedFood[myOTId][MyCustID]=1;/* 1 means food is grabed and 0 means otherwise*/
					 Release(GrabedFoodLock);
					 Print1("Manager packed the food for Customer[%d]\n", MyCustID);
					 MyCustID=-1;
					 Release(ToGoCustWaitingForFoodLock);
					}
				 else
					{
					 /*list of customers to whom token should be handled but shouldnt grab the food
					 /*this Q is as good as saying who gave token number to whom when they wanna wait*/
					  ToGoCustWaitingForFood[MyCustID]=1;
					  Print1("Manager gives token number to Customer[%d]\n",MyCustID);
						MyCustID=-1;
						Release(ToGoCustWaitingForFoodLock);
					}
			}
			else
			{
					Release(ToGoCustWaitingForFoodLock);
				/*Nothing to do
				/*Set OT status to FREE*/
			}
		}
			/*End of Manager as food packer*/

    
  /* Manager - Waiter Interaction */
  Acquire(TableAllotedCustLock);
		for(d=0;d<MAX_SIZE;d++)
		{
			if(-1!=TableAllotedCustList[d])	  /*List is not empty*/
			{
				Acquire(WaitersQLock);
				Broadcast(WaitersCV,WaitersQLock);
				Print("Manager calls back all Waiters from break\n");
				/*Print(" Manager broadcasted\n");*/
				Release(WaitersQLock);
				break;
			}
		}
		d=0;
    Release(TableAllotedCustLock);
		i=0;
		for (i=0;i<200;i++)
		{
			/*Print1("Manager yeilding%d\n",i);*/
			Yield();
		}
		i=0;
	/* Manager - Waiter Interaction End*/
	
	
		
		Acquire(AliveCustCountLock);
		if(AliveCustCount==0)
		{
			Release(AliveCustCountLock);
			Acquire(SleepingWaiterCountLock);
			/*Print1("Above while SleepingWaiterCount%d\n",SleepingWaiterCount);*/
			if (SleepingWaiterCount!=0)
			{
				while(SleepingWaiterCount!=0)
				{
					/*Print("inside while");*/
					Acquire(WaitersQLock);
					Broadcast(WaitersCV,WaitersQLock);
					Release(WaitersQLock);
					Release(SleepingWaiterCountLock);
					/*Print("Manager Broadcast\n");*/
					for (i=0;i<200;i++)
					{
						/*Print1("Manager yeilding%d\n",i);*/
						Yield();
					}
					Acquire(SleepingWaiterCountLock);
				}
			}
			Release(SleepingWaiterCountLock);
		}
		else
			Release(AliveCustCountLock);
			
		Acquire(AliveCustCountLock);
		if(AliveCustCount==0)
		{		
			Release(AliveCustCountLock);
			Acquire(ActiveOTCountLock);
			if(ActiveOTCount!=0)
			{
				/*Print1("Mgr waiting for OT, AcOT=%d\n",ActiveOTCount);*/
				while(ActiveOTCount!=0)
				{
					Release(ActiveOTCountLock);
					for (i=0;i<200;i++)
					{
						/*Print1("Manager yeilding%d\n",i);*/
						Yield();
					}
					
					Acquire(ActiveOTCountLock);
				}
			}
			Release(ActiveOTCountLock);
			if(DestroyAllLockCV==1)
			{
				/*Print1("SleepingWaiterCount%d\n",SleepingWaiterCount);*/
				Print("End of Simulation!!\n");
				Exit(1);
			}
			else
			{
				for (i=0;i<200;i++)
				{
					/*Print1("Manager yeilding%d\n",i);*/
					Yield();
				}
			}
		}
		else
		{
			Release(AliveCustCountLock);
		}
	}

    
    
}
Beispiel #10
0
int main(){
	
	int departmentOfChoice,goodsFlag=-1,mySalesID,i,goodsIndex,mvValue1,mvValue2,mvValue3;
	
	initialize();
	
	/* Retrieving index */
	AcquireLock(goodsIndexLock);
	Print("\nInside goodsloader"); 
	goodsIndex=GetMV(globalGoodsIndex);
	SetMV(globalGoodsIndex,goodsIndex+1);
	ReleaseLock(goodsIndexLock);
	
	while(1){
		AcquireLock(salesGoodsLock);
		AcquireLock(goodsloaderLock[goodsIndex]);
		if(GetMV(goodsStatus[goodsIndex])==2){ /* Salesman signalled to restock */
			ReleaseLock(salesGoodsLock);
			SignalCV(goodsloaderLock[goodsIndex],goodsloaderCV[goodsIndex]);
			WaitCV(goodsloaderLock[goodsIndex],goodsloaderCV[goodsIndex]);
			AcquireLock(storeroomLock);
			mvValue1 = GetMV(itemToBeRestocked_FromSalesmanToGoodsloader[goodsIndex]);
			AcquireLock(itemLock[mvValue1]);
			departmentOfChoice=mvValue1/10;
			mvValue2=GetMV(salesGoodsId[goodsIndex]);
			if(departmentOfChoice==0)
				Print3("\nGoodsloader [%d] is informed by DepartmentSalesman [%d] of department [0] to restock item%d",goodsIndex,mvValue2,mvValue1);
			else if(departmentOfChoice==1)
				Print3("\nGoodsloader [%d] is informed by DepartmentSalesman [%d] of department [1] to restock item%d",goodsIndex,mvValue2,mvValue1);
			else if(departmentOfChoice==2)
				Print3("\nGoodsloader [%d] is informed by DepartmentSalesman [%d] of department [2] to restock item%d",goodsIndex,mvValue2,mvValue1);
			else if(departmentOfChoice==3)
				Print3("\nGoodsloader [%d] is informed by DepartmentSalesman [%d] of department [3] to restock item%d",goodsIndex,mvValue2,mvValue1);
			else
				Print3("\nGoodsloader [%d] is informed by DepartmentSalesman [%d] of department [4] to restock item%d",goodsIndex,mvValue2,mvValue1);
			
			Print2("\nGoodsloader [%d] is in the StockRoom and got item%d",goodsIndex,mvValue1);
			
			
			SetMV(quantityOnShelf[mvValue1],10);
			Print3("\nGoodsloader [%d] restocked item%d in Department [%d]",goodsIndex,mvValue1,departmentOfChoice);
			Print1("\nGoodsloader [%d] leaves StockRoom",goodsIndex);
			ReleaseLock(storeroomLock);
			ReleaseLock(itemLock[mvValue1]);
			AcquireLock(waitingLock[departmentOfChoice]);
			mvValue3 = GetMV(goodsWaitingLineCount[departmentOfChoice]);
			SetMV(goodsWaitingLineCount[departmentOfChoice],++mvValue3);
			mvValue2=GetMV(salesGoodsId[goodsIndex]);
			AcquireLock(salesmanLock[departmentOfChoice][mvValue2]);
			SignalCV(salesmanLock[departmentOfChoice][mvValue2],salesWaitingCV[departmentOfChoice][mvValue2]);
			ReleaseLock(salesmanLock[departmentOfChoice][mvValue2]);
			WaitCV(waitingLock[departmentOfChoice],goodsWaitingCV[departmentOfChoice]);
			
			mySalesID=-1;
			for(i=0;i<salesmanCount;i++){
				if(GetMV(salesStatus[departmentOfChoice][i]) == 5){
					mySalesID=i;
					SetMV(salesStatus[departmentOfChoice][mySalesID],1);
					break;
				}
			}
			AcquireLock(salesmanLock[departmentOfChoice][mySalesID]);
			ReleaseLock(waitingLock[departmentOfChoice]);
			mvValue1 = GetMV(itemToBeRestocked_FromSalesmanToGoodsloader[goodsIndex]);
			SetMV(restockedItem[departmentOfChoice][mySalesID],mvValue1);
			SetMV(restockingGoodsloader[departmentOfChoice][mySalesID],goodsIndex);
			SignalCV(salesmanLock[departmentOfChoice][mySalesID],salesWaitingCV[departmentOfChoice][mySalesID]);
			WaitCV(salesmanLock[departmentOfChoice][mySalesID],salesWaitingCV[departmentOfChoice][mySalesID]);
			SignalCV(salesmanLock[departmentOfChoice][mySalesID],salesWaitingCV[departmentOfChoice][mySalesID]);
			ReleaseLock(salesmanLock[departmentOfChoice][mySalesID]);
		}
		else{
			ReleaseLock(salesGoodsLock);
		}
		AcquireLock(trolleyEndLock);		
		if(GetMV(trolleyEndCount)>0){ /* If trolley is present at the exit, replace the trolley */
			mvValue1 = GetMV(trolleyEndCount);
			SetMV(trolleyEndCount,--mvValue1);
			ReleaseLock(trolleyEndLock);
			AcquireLock(trolleyFirstLock);
			mvValue1 = GetMV(trolleyFirstCount);
			SetMV(trolleyFirstCount,++mvValue1);
			Print1("\nGoodsloader [%d] replaced the trolley",goodsIndex);
			mvValue1 = GetMV(trolleyWaitingCount);
			if(mvValue1>0){
				SetMV(trolleyWaitingCount,--mvValue1);
				SignalCV(trolleyFirstLock,trolleyWaitingCV);
			}
			ReleaseLock(trolleyFirstLock);
		}
		else{
			ReleaseLock(trolleyEndLock);
		}
		AcquireLock(salesGoodsLock);	
		SetMV(goodsStatus[goodsIndex],0);
		ReleaseLock(salesGoodsLock);
		
		Print1("\nGoodsloader [%d] is waiting for orders to restock",goodsIndex);
		WaitCV(goodsloaderLock[goodsIndex],goodsloaderCV[goodsIndex]);
		ReleaseLock(goodsloaderLock[goodsIndex]);
	}
	Exit(0);
}
Beispiel #11
0
/*****************************************************************************
 Function   : VOS_FidCtrlBlkInit
 Description: Init the control block of FID
 Input      : void
 Return     : VOS_OK on success or errno on failure.
 Other      :
 *****************************************************************************/
VOS_UINT32 VOS_FidCtrlBlkInit(VOS_VOID)
{
    VOS_UINT32               i;
    int                      j;

    VOS_FID_CONTROL_BLOCK    *pFidCtrlBlk = vos_FidCtrlBlk;
    FID_Static_Table_Type    *pFidStaticTable;

    for(i=0; i<(VOS_UINT32)VOS_FID_BUTT; i++)
    {
        pFidCtrlBlk->Fid            = (VOS_INT)i;

        pFidCtrlBlk->InitFunc = FidInitFuncDefault;
        pFidCtrlBlk->TaskFunction = vos_FidTask;
        pFidCtrlBlk->Priority = vos_FidTaskRealPriority[VOS_PRIORITY_BASE];
        pFidCtrlBlk->StackSize  = TASK_STACK_SIZE;
        for ( j=0; j<VOS_MAX_SELF_TASK_OF_FID; j++ )
        {
            pFidCtrlBlk->SelfProcTaskFunc[j] = VOS_NULL_PTR;
            pFidCtrlBlk->SelfProcTaskTid[j] = VOS_NULL_DWORD;
        }
        /* which should be del when only one FID exists */
        pFidCtrlBlk->MAXQidSize = DEFAULT_FID_QUEUE_NUM;
        pFidCtrlBlk++;
    }

    for(i=(VOS_UINT32)VOS_FID_DOPRAEND; i<(VOS_UINT32)VOS_FID_BUTT; i++)
    {
        pFidCtrlBlk     = &vos_FidCtrlBlk[i];
        pFidStaticTable = &g_aFidStaticTable[i];

        if(pFidStaticTable->ulFID != (unsigned long)i)
        {
            Print2("# Fid Init Fid invalid ulFID %d I %d",
                (int)pFidStaticTable->ulFID, i );

            return(VOS_ERR);
        }

        for(j=0; j<VOS_ID_MAX_FID_NAME_LENGTH; j++)
        {
            pFidCtrlBlk->Name[j]    = (char)(pFidStaticTable->achFIDName[j]);
        }
        pFidCtrlBlk->Name[j-1]      = '\0';

        pFidCtrlBlk->InitFunc       = pFidStaticTable->pfnInitFun;
        pFidCtrlBlk->StartOrder     = pFidStaticTable->ulStartOrder;

        if( 0 != pFidStaticTable->ulStackSize )
        {
            pFidCtrlBlk->StackSize  = pFidStaticTable->ulStackSize;

        }
        else
        {
            pFidCtrlBlk->StackSize  = TASK_STACK_SIZE;
        }

        /* which should be del when only one FID exists */
        if( 0 != pFidStaticTable->ulQueueSize )
        {
            pFidCtrlBlk->MAXQidSize  = pFidStaticTable->ulQueueSize;

        }
    }

    return(VOS_OK);
}