/***************************************************************************** Function : VOS_PidsInit Description: Init PID Input : void Return : VOS_OK on success or errno on failure. Other : *****************************************************************************/ VOS_UINT32 VOS_PidsInit(VOS_VOID) { VOS_UINT32 ulStartUpFailStage = VOS_PID_INIT_ERR_BASE; VOS_UINT32 ulInitPhase; for (ulInitPhase = VOS_IP_LOAD_CONFIG; ulInitPhase <= VOS_IP_BUTT; ulInitPhase++) { g_usPidInitStep = (VOS_UINT16)ulInitPhase; if ( VOS_OK != VOS_PidsInitOnePhase( (enum VOS_INIT_PHASE_DEFINE)ulInitPhase) ) { Print1("# VOS_PidsInitOnePhase VOS_IP_LOAD_CONFIG Error. InitPhase: 0x%x\r\n",ulInitPhase); g_ulOmPidInit |= (ulInitPhase << 16); ulStartUpFailStage |= ulInitPhase; return(ulStartUpFailStage); } } return VOS_OK; }
/***************************************************************************** Function : VOS_PidsInitOnePhase Description: one step of PID initialization Input : InitPhrase -- the step of INit Return : VOS_OK on success or errno on failure. Other : *****************************************************************************/ VOS_UINT32 VOS_PidsInitOnePhase( enum VOS_INIT_PHASE_DEFINE InitPhrase) { int i; VOS_UINT32 ulReturnValue, ulErrorCounter; ulErrorCounter = 0; for(i=VOS_PID_DOPRAEND; i<VOS_PID_BUTT; i++) { g_usPidInitId = (VOS_UINT16)i; if( vos_PidRecords[i-VOS_PID_DOPRAEND].InitFunc == VOS_NULL_PTR) { continue; } ulReturnValue = vos_PidRecords[i-VOS_PID_DOPRAEND].InitFunc(InitPhrase); if(ulReturnValue != VOS_OK) { Print1("# VOS_PidsInitOnePhase Error. Pid 0x%x\r\n",i); g_ulOmPidInit |= (i & VOS_NULL_WORD); ulErrorCounter++; } } return(ulErrorCounter); }
int main() { int i, j, k; for (i = 0; i < Dim; i++) /* first initialize the matrices */ for (j = 0; j < Dim; j++) { A[i][j] = i; B[i][j] = j; C[i][j] = 0; } for (i = 0; i < Dim; i++) /* then multiply them together */ for (j = 0; j < Dim; j++) for (k = 0; k < Dim; k++) C[i][j] += A[i][k] * B[k][j]; Print("\n"); Print("\n"); Print("\n"); Print1("THE OUTPUT OF THE MATMULT OPERATION IS %d !!!!!!!!!!!!!!!!!!!! \n",C[Dim-1][Dim-1]); Print("\n"); Print("\n"); Exit(C[Dim-1][Dim-1]); /* and then we're done */ }
void testCase1() { int conditionId = -1; int i; Print("CREATE CONDITION SYSTEM CALL TEST\n\n"); Print("PASSING CONDITION NAME LENGTH > MAX_CV_NAME \n\n"); conditionId = CreateCondition((char*)"ConditionName",400); Print("------------------------------------------------------\n"); Print("PASSING CONDITION NAME LENGTH < 0 \n\n"); conditionId = CreateCondition((char*)"ConditionName",-4); Print("------------------------------------------------------\n"); Print("PASSING INVALID VIRTUAL ADDR \n\n"); conditionId = CreateCondition((char*)0xdeadbeef,10); Print("------------------------------------------------------\n"); Print("CREATING MORE number of Conditions than MAX_CVS = 2000 \n\n"); for(i = 0;i<2001;i++) { conditionId = CreateCondition((char*)"ConditionNo",10); Print1("CONDITION ID RECEIVED IS %d\n",conditionId); } Print("------------------------------------------------------\n"); Print("CREATING CONDITION SUCCESS CASE \n"); conditionId = CreateCondition((char*)"ConditionNo",10); Print("------------------------------------------------------\n"); }
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); }
static void dbg_found_read_dep_error (check_ctx_t *ctx, int *dst, int *dst2, int idx) { char *res = RTmalloc (1024); lts_type_t ltstype = GBgetLTStype (ctx->parent); int typeno = lts_type_get_state_typeno (ltstype, idx); print_chunk (ctx->parent, res, 1024, typeno, dst[idx]); Print1 (lerror, "Found missing read dependency in group %d (diff slot: %d -- %s != %s).\\" "Identifying culprit read slot...", ctx->group, idx, str_slot(ctx, dst2, idx), res); RTfree (res); }
/***************************************************************************** Function : vos_FidTask Description: the process entry of every FID Input : ulQueueID -- the queue of the FID : the ID of the FID Return : VOS_VOID *****************************************************************************/ VOS_VOID vos_FidTask( VOS_UINT32 ulQueueID, VOS_UINT32 FID_value, VOS_UINT32 Para1, VOS_UINT32 Para2 ) { MSG_CB *pMsg; VOS_UINT32 iThePid; VOS_UINT32 Msg_Address; for ( ; ; ) { if ( VOS_ERR == VOS_FixedQueueRead(ulQueueID, &Msg_Address)) { Print1("# FID fetch message error. the Q ID is %ld.\r\n", (VOS_INT)ulQueueID); continue; } Msg_Address += VOS_MSG_BLK_HEAD_LEN; pMsg = (MSG_CB *)Msg_Address; iThePid = pMsg->uwReceiverPid; if(!VOS_PidCheck(iThePid)) { Print("# vos_FidTask Pid too big.\r\n"); VOS_FreeMsg( iThePid, pMsg ); continue; } if( VOS_ID_PID_BELONG_TO_FID == vos_FidCtrlBlk[FID_value].PidsBelong[VOS_PidIdx(iThePid)] ) { /* 接收消息时调用hook */ if ( VOS_NULL_PTR != g_pfVosHookFuncTable[OS_HOOK_TYPE_MSG_GET] ) { ((VOS_MSG_HOOK_FUNC)g_pfVosHookFuncTable[OS_HOOK_TYPE_MSG_GET])(pMsg); } (vos_PidRecords[VOS_PidIdx(iThePid)].MsgFunction)(pMsg); } else { Print("# vos_FidTask Pid not belong the Fid.\r\n"); } VOS_FreeMsg( iThePid, pMsg ); } }
void testCase2() { int negativeCVId=-1; int negativeLockId=-1; int hugeLockId=9999; int hugeCVId=9999; #if 0 Print("WAIT/SIGNAL/BROADCAST SYSTEM CALL TEST \n"); Print(" WAITING on invalid LOCK/CONDITION .. Passing -VE CONDITION ID and LOCK ID\n"); Wait(negativeCVId,negativeLockId); Print(" WAITING on invalid LOCK/CONDITION .. Passing CONDITION ID > MAX_CVS and LOCK ID > MAX_LOCKS\n"); Wait(hugeCVId,hugeLockId); Print(" SIGNAL on invalid LOCK/CONDITION .. Passing -VE CONDITION ID and LOCK ID\n"); Signal(negativeCVId,negativeLockId); Print(" SIGNAL on invalid LOCK/CONDITION .. Passing CONDITION ID > MAX_CVS and LOCK ID > MAX_LOCKS\n"); Signal(hugeCVId,hugeLockId); Print(" BROADCAST on invalid LOCK/CONDITION .. Passing -VE CONDITION ID and LOCK ID\n"); Broadcast(negativeCVId,negativeLockId); Print(" BROADCAST on invalid LOCK/CONDITION .. Passing CONDITION ID > MAX_CVS and LOCK ID > MAX_LOCKS\n"); Broadcast(hugeCVId,hugeLockId); Print("SIGNAL , BROADCAST, WAIT SUCCESS CASE\n"); Print("FORKING THREE THREADS TO SIMULATE Wait/Signal/Broadcast System calls \n"); #endif lockNumber1 = CreateLock("lock1",5); Print1("LOCK ID RECEIVED IS %d\n",lockNumber1); cvNumber1 = CreateCondition("cond1",5); Print1("CONDITION ID RECEIVED IS %d\n",cvNumber1); Fork(testfunc); Fork(testfunc1); Print("TestCase 2 Exiting \n"); }
model_t GBaddCheck (model_t model) { HREassert (model != NULL, "No model"); if (!PINS_CORRECTNESS_CHECK) return model; Print1 (info, "Matrix checking layer activated."); model_t check = GBcreateBase (); check_ctx_t *ctx = RTmalloc (sizeof(check_ctx_t)); ctx->N = pins_get_state_variable_count (model); ctx->K = pins_get_group_count (model); ctx->L = pins_get_edge_label_count (model); ctx->S = pins_get_state_label_count (model); ctx->src2 = RTmalloc(sizeof(int[ctx->N])); ctx->check_must = ci_create (ctx->N); ctx->read = (ci_list **) dm_rows_to_idx_table (GBgetDMInfoRead(model)); ctx->must = (ci_list **) dm_rows_to_idx_table (GBgetDMInfoMustWrite(model)); ctx->may = GBgetDMInfoMayWrite(model); ctx->stack = isba_create (ctx->N); ctx->parent = model; ctx->magic[0] = RTmalloc(sizeof(int[ctx->N])); ctx->magic[1] = RTmalloc(sizeof(int[ctx->N])); for (int i = 0; i < ctx->N; i++) { int max = type_max (ctx, i); int min = type_min (ctx, i); int c = max - min; HREassert (c > 0, "Empty type range for slot: %d -- %s", i, str_slot(ctx, NULL, i)); ctx->magic[0][i] = min; ctx->magic[1][i] = min + 1; } ctx->reentrent = 0; GBsetContext (check, ctx); GBsetNextStateAll (check, check_all); GBsetNextStateLong (check, check_long); GBsetNextStateShort (check, check_short); //GBsetActionsLong (check, check_long); //GBsetActionsShort (check, check_short); GBinitModelDefaults (&check, model); return check; }
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); }
/***************************************************************************** Function : CreateFidsQueque Description: create queue of one FID Input : VOS_VOID Return : VOS_OK on success or errno on failure *****************************************************************************/ VOS_UINT32 CreateFidsQueque(VOS_VOID) { VOS_UINT32 i; VOS_UINT32 ulReturnValue; for(i=VOS_FID_DOPRAEND; i<VOS_FID_BUTT; i++) { ulReturnValue = VOS_FixedQueueCreate( vos_FidCtrlBlk[i].MaxMsgNumber, &(vos_FidCtrlBlk[i].Qid)); if( VOS_OK != ulReturnValue ) { Print1("# create %ld FID queue error.\r\n", i); return( ulReturnValue ); } } return( VOS_OK ); }
/***************************************************************************** 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); }
/***************************************************************************** Function : CreateFidsQueque Description: create queue of one FID Input : void Return : VOS_OK on success or errno on failure *****************************************************************************/ VOS_UINT32 CreateFidsQueque(VOS_VOID) { VOS_UINT32 i; VOS_UINT32 ulReturnValue; for(i=(VOS_UINT32)VOS_FID_DOPRAEND; i<(VOS_UINT32)VOS_FID_BUTT; i++) { ulReturnValue = VOS_FixedQueueCreate( VOS_FID_QUEUE_LENGTH , &(vos_FidCtrlBlk[i].Qid) , VOS_MSG_Q_FIFO , VOS_FID_MAX_MSG_LENGTH , vos_FidCtrlBlk[i].MAXQidSize ); if( ulReturnValue != VOS_OK ) { Print1("# create %d FID queue error.\r\n", i); return( ulReturnValue ); } } return( VOS_OK ); }
void sort() { int A[1024]; int i, j, tmp; /* first initialize the array, in reverse sorted order */ for (i = 0; i < 1024; i++){ A[i] = 1024 - i; Print1("\nInside sort: %d",A[i]); } /* then sort! */ for (i = 0; i < 1023; i++) for (j = i; j < (1023 - i); j++) if (A[j] > A[j + 1]) { /* out of order -> need to swap ! */ tmp = A[j]; A[j] = A[j + 1]; A[j + 1] = tmp; } Exit(A[0]); /* and then we're done -- should be 0! */ }
/***************************************************************************** Function : VOS_show_sem_info Description: print the usage info of Sem Input : VOS_VOID Return : VOS_VOID Other : *****************************************************************************/ VOS_VOID VOS_show_sem_info( VOS_VOID ) { Print1("Max be used sem is %ld.\r\n",vos_SemMaxSemId); }
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); }
VOS_UINT32 VOS_Startup( enum VOS_STARTUP_PHASE ph ) { VOS_UINT32 ulReturnValue; VOS_UINT32 ulStartUpFailStage = 0; switch(ph) { case VOS_STARTUP_INIT_DOPRA_SOFEWARE_RESOURCE : vos_StartUpStage = 0x00010000; if ( VOS_OK != VOS_MemInit() ) { ulStartUpFailStage |= 0x0001; break; } VOS_SemCtrlBlkInit(); VOS_QueueCtrlBlkInit(); VOS_TaskCtrlBlkInit(); VOS_TimerCtrlBlkInit(); OM_RecordMemInit(); if ( VOS_OK != RTC_TimerCtrlBlkInit() ) { ulStartUpFailStage |= 0x0100; } #if (OSA_CPU_CCPU == VOS_OSA_CPU) if ( VOS_OK != VOS_DrxTimerCtrlBlkInit()) { ulStartUpFailStage |= 0x0200; } #endif if ( VOS_OK != VOS_PidCtrlBlkInit() ) { ulStartUpFailStage |= 0x0400; } if ( VOS_OK != VOS_FidCtrlBlkInit() ) { ulStartUpFailStage |= 0x0800; } if ( VOS_OK != CreateFidsQueque() ) { ulStartUpFailStage |= 0x1000; } break; case VOS_STARTUP_SET_TIME_INTERRUPT: vos_StartUpStage = 0x00020000; break; case VOS_STARTUP_CREATE_TICK_TASK: vos_StartUpStage = 0x00040000; /* create soft timer task */ if ( VOS_OK != VOS_TimerTaskCreat() ) { ulStartUpFailStage |= 0x0001; } if ( VOS_OK != RTC_TimerTaskCreat() ) { ulStartUpFailStage |= 0x0002; } #if (OSA_CPU_CCPU == VOS_OSA_CPU) if ( VOS_OK != VOS_DrxTimerTaskCreat() ) { ulStartUpFailStage |= 0x0004; } #endif break; case VOS_STARTUP_CREATE_ROOT_TASK: vos_StartUpStage = 0x00080000; if ( VOS_OK != VOS_StartCallBackRelTimer(&g_VosProtectInitTimer, DOPRA_PID_TIMER, 20000, 0, 0, VOS_RELTIMER_NOLOOP, VOS_ProtectInit, VOS_TIMER_NO_PRECISION) ) { ulStartUpFailStage |= 0x0001; } g_ulVosStartStep = 0x0000; ulReturnValue = VOS_OutsideInit(); if(VOS_OK != ulReturnValue) { ulStartUpFailStage |= ulReturnValue; } g_ulVosStartStep = 0x0004; if ( VOS_OK != WD_TaskCreat() ) { ulStartUpFailStage |= 0x0004; } g_ulVosStartStep = 0x0008; if ( VOS_OK != VOS_FidsInit() ) { ulStartUpFailStage |= 0x0008; } g_ulVosStartStep = 0x0010; #if 0 /* 创建VOS各FID任务之前,锁任务 */ if ( VOS_OK != VOS_TaskLock() ) { ulStartUpFailStage |= 0x0010; } #endif g_ulVosStartStep = 0x0020; /* create FID task & selftask task */ if ( VOS_OK != CreateFidsTask() ) { ulStartUpFailStage |= 0x0020; } #if (VOS_WIN32 != VOS_OS_VER) g_ulVosStartStep = 0x0040; /* suspend FID task & selftask task */ if ( VOS_OK != VOS_SuspendFidsTask() ) { ulStartUpFailStage |= 0x0040; } #endif g_ulVosStartStep = 0x0080; #if 0 /* 创建VOS各FID任务完成后解锁 */ if ( VOS_OK != VOS_TaskUnlock() ) { ulStartUpFailStage |= 0x0080; } #endif g_ulVosStartStep = 0x0100; if ( VOS_OK != VOS_PidsInit() ) { ulStartUpFailStage |= 0x0100; } break; case VOS_STARTUP_SUSPEND_MAIN_TASK: vos_StartUpStage = 0x00100000; g_ulVosStartStep = 0x0001; /* Resume任务之前,锁任务 */ if ( VOS_OK != VOS_TaskLock() ) { ulStartUpFailStage |= 0x0001; } #if (VOS_WIN32 != VOS_OS_VER) g_ulVosStartStep = 0x0002; /* Resume FID task & selftask task */ if ( VOS_OK != VOS_ResumeFidsTask() ) { ulStartUpFailStage |= 0x0002; } #endif g_ulVosStartStep = 0x0004; /* Resume任务之后解锁 */ if ( VOS_OK != VOS_TaskUnlock() ) { ulStartUpFailStage |= 0x0004; } g_ulVosStartStep = 0x0008; /* stop protect timer */ VOS_StopRelTimer(&g_VosProtectInitTimer); #if (OSA_CPU_CCPU == VOS_OSA_CPU) /* OSA初始化完成,需要调用DRV函数通知DRV OSA启动完成 */ if ( VOS_OK != DRV_CCPU_RESET_OVER() ) { ulStartUpFailStage |= 0x0008; } #endif #if (VOS_LINUX == VOS_OS_VER) VOS_RunTask(); #endif break; default: break; } /* calculate return value */ if( 0 != ulStartUpFailStage ) { ulReturnValue = vos_StartUpStage; ulReturnValue |= ulStartUpFailStage; Print1("startup retuen value is %x.\r\n",ulReturnValue); /* reboot */ VOS_ProtectionReboot(OSA_INIT_ERROR, (VOS_INT)ulReturnValue, (VOS_INT)g_ulOmPidInit, (VOS_CHAR *)&g_ulOmFidInit, sizeof(VOS_UINT32)); return(ulReturnValue); } else { return(VOS_OK); } }
/***************************************************************************** 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 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); } } }
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); }