/***************************************************************************** Function : VOS_FidsInitOnePhase Description: one step of FID initialization Input : InitPhrase -- the step of INit Return : VOS_OK on success or errno on failure. Other : *****************************************************************************/ VOS_UINT32 VOS_FidsInitOnePhase(enum VOS_INIT_PHASE_DEFINE InitPhrase) { VOS_UINT32 i; VOS_UINT32 ulReturnValue, ulErrorCounter; ulErrorCounter = 0; for(i=VOS_FID_DOPRAEND; i<VOS_FID_BUTT; i++) { if(VOS_NULL_PTR == vos_FidCtrlBlk[i].InitFunc) { continue; } ulReturnValue = vos_FidCtrlBlk[i].InitFunc(InitPhrase); if(VOS_OK != ulReturnValue) { Print3("# InitPhrase %ld i %ld ulReturnValue %ld", InitPhrase, i, ulReturnValue); ulErrorCounter++; } } return(ulErrorCounter); }
VOS_UINT32 VOS_SmP( VOS_SEM Sm_ID, VOS_UINT32 ulTimeOutInMillSec ) { SEM_CONTROL_BLOCK *temp_Ptr; VOS_UINT32 ulTimeOut; VOS_UINT32 ulResult; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; #if (VOS_YES == VOS_CHECK_PARA) if( temp_Ptr != temp_Ptr->SemId ) { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_IDERR); /*lint +e534*/ return (VOS_ERRNO_SEMA4_P_IDERR); } if (VOS_SEM_CTRL_BLK_IDLE == temp_Ptr->Flag) { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_NOTACTIVE); /*lint +e534*/ return(VOS_ERRNO_SEMA4_P_NOTACTIVE); } #endif ulTimeOut = (0 == ulTimeOutInMillSec) ? (VOS_UINT32)(-1) : ulTimeOutInMillSec/MILLISECONDS_PER_TICK; ulResult = SRE_SemPend( temp_Ptr->RTOSckSemId, ulTimeOut ); if ( SRE_OK == ulResult ) { return(VOS_OK); } /*lint -e534*/ Print3("# semTake ID %x Name %s errno %x.\r\n", Sm_ID, temp_Ptr->Name, ulResult ); /*lint +e534*/ if ( OS_ERRNO_SEM_TIMEOUT == ulResult ) { /*lint -e534*/ VOS_SetErrorNo (VOS_ERRNO_SEMA4_P_TIMEOUT); /*lint +e534*/ return VOS_ERRNO_SEMA4_P_TIMEOUT; } /*lint -e534*/ VOS_SetErrorNo (VOS_ERRNO_SEMA4_P_CANOTP); /*lint +e534*/ return VOS_ERRNO_SEMA4_P_CANOTP; }
VOS_UINT32 VOS_SmV( VOS_SEM Sm_ID ) { SEM_CONTROL_BLOCK *temp_Ptr; VOS_UINT32 ulResult; temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID; if( temp_Ptr == temp_Ptr->SemId ) { #if (VOS_YES == VOS_CHECK_PARA) if( temp_Ptr->Flag == VOS_SEM_CTRL_BLK_IDLE) { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_NOTACTIVE); /*lint +e534*/ return(VOS_ERRNO_SEMA4_V_NOTACTIVE); } #endif ulResult = SRE_SemPost( temp_Ptr->RTOSckSemId ); if ( SRE_OK == ulResult ) { return(VOS_OK); } else { /*lint -e534*/ Print3("# semGive ID %x Name %s errno %x.\r\n", Sm_ID, temp_Ptr->Name, ulResult ); VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_CANOTV); /*lint +e534*/ return(VOS_ERRNO_SEMA4_V_CANOTV); } } else { /*lint -e534*/ VOS_SetErrorNo(VOS_ERRNO_SEMA4_V_IDERR); /*lint +e534*/ return(VOS_ERRNO_SEMA4_V_IDERR); } }
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 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); }
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); }