Int32 AVSYNC_Init() { Int32 status = 0; Int64 curTime; Int32* key = NULL; AVSYNC_AvSyncEnable_t AVSYNC_AvSyncEnable; status = AVSYNC_GetSharedDataStructure(); status = GateMP_open (AVSYNC_GATE_MP_NAME, pAvsyncMPGate); #ifdef ENABLE_AVSYNC_STATS_LOG avsyncLogThr_exit = 0; status = AVSYNC_LogThrCreate(); OSA_assert(status == OSA_SOK); #endif AVSYNC_AvSyncEnable.avSyncCompEnable = TRUE; AVSYNC_Control(AVSync_ComponentEnable, &AVSYNC_AvSyncEnable ); curTime = AVSYNC_GetCurrentTime(); printf ("\n\n=============== AVSYNC_curTime = %lld ==================\n", curTime); AVSYNC_LockSharedDataStructure(key); pAvSyncInfo_obj->timeInfo.wallTimeInTicks = curTime; AVSYNC_ReleaseSharedDataStructure(key); return OSA_SOK; }
/* * ======== Server_exec ======== */ Int Server_exec() { Int status; GateMPApp_Msg * msg; MessageQ_QueueId queId; UInt32 physAddr; volatile UInt32 * intPtr = 0; Int num = 0; Int prevNum = 0; UInt i = 0; IArg gateKey = 0; Log_print0(Diags_ENTRY | Diags_INFO, "--> Server_exec:"); /* wait for inbound message */ status = MessageQ_get(Module.slaveQue, (MessageQ_Msg *)&msg, MessageQ_FOREVER); if (status < 0) { goto leave; } if (msg->cmd != GATEMPAPP_CMD_SPTR_ADDR) { status = GATEMPAPP_E_UNEXPECTEDMSG; goto leave; } /* Get physical address of shared memory */ physAddr = msg->payload; /* translate the physical address to slave virtual addr */ if (Resource_physToVirt(physAddr, (UInt32 *)&intPtr)) { Log_error1("Server_exec: Failed to translate phys addr %p to virt addr", physAddr); goto leave; } /* send message back */ queId = MessageQ_getReplyQueue(msg); /* type-cast not needed */ msg->cmd = GATEMPAPP_CMD_SPTR_ADDR_ACK; MessageQ_put(queId, (MessageQ_Msg)msg); Log_print0(Diags_INFO,"Server_exec: Modifying shared variable " "value"); /* open host-created GateMP */ do { status = GateMP_open(GATEMP_HOST_NAME, &Module.hostGateMPHandle); } while (status == GateMP_E_NOTFOUND); if (status < 0) { Log_error0("Server_exec: Failed to open host-created GateMP"); status = GATEMPAPP_E_FAILURE; goto leave; } Log_print0(Diags_INFO,"Server_exec: Opened GateMP successfully"); Log_print0(Diags_INFO,"Server_exec: Using host-created gate"); for (i = 0;i < LOOP_ITR; i++) { /* modify the shared variable as long as no one else is currently * accessing it */ /* enter GateMP */ gateKey = GateMP_enter(Module.hostGateMPHandle); /* read shared variable value */ prevNum = *intPtr; /* randomly modify the shared variable */ if ( rand() % 2) { *intPtr -= 1; } else { *intPtr += 1; } /* read shared variable value again */ num = *intPtr; if ((prevNum != num + 1) && (prevNum != num - 1)) { Log_print0(Diags_INFO, "Server_exec: unexpected variable value." \ "Test failed."); Log_print2(Diags_INFO, "Server_exec: Previous shared variable " "value %d, current value=%d", prevNum, num); status = GATEMPAPP_E_FAILURE; goto leave; } /* leave Gate */ GateMP_leave(Module.hostGateMPHandle, gateKey); } /* wait for sync message before we switch gates */ status = MessageQ_get(Module.slaveQue, (MessageQ_Msg *)&msg, MessageQ_FOREVER); if (status < 0) { goto leave; } if (msg->cmd != GATEMPAPP_CMD_SYNC) { status = GATEMPAPP_E_UNEXPECTEDMSG; goto leave; } queId = MessageQ_getReplyQueue(msg); MessageQ_put(queId, (MessageQ_Msg)msg); Log_print0(Diags_INFO,"Server_exec: Using slave-created gate"); for (i = 0;i < LOOP_ITR; i++) { /* modify the shared variable as long as no one else is currently * accessing it */ /* enter GateMP */ gateKey = GateMP_enter(Module.slaveGateMPHandle); /* read shared variable value */ prevNum = *intPtr; /* randomly modify the shared variable */ if ( rand() % 2) { *intPtr -= 1; } else { *intPtr += 1; } /* read shared variable value again */ num = *intPtr; if ((prevNum != num - 1) && (prevNum != num + 1)) { Log_print0(Diags_INFO, "Server_exec: unexpected variable value." \ "Test failed."); Log_print2(Diags_INFO, "Server_exec: Previous " "value=%d, current value=%d", prevNum, num); status = GATEMPAPP_E_FAILURE; goto leave; } /* leave Gate */ GateMP_leave(Module.slaveGateMPHandle, gateKey); } leave: /* close host GateMP */ if (Module.hostGateMPHandle) { GateMP_close(&Module.hostGateMPHandle); } Log_print0(Diags_ENTRY, "Server_exec: host GateMP closed"); Log_print1(Diags_EXIT, "<-- Server_exec: %d", (IArg)status); return(status); }