void initTimer() { /* @TODO start the timer task and forward timer*/ initCallbackInfo(); g_timer_switcher = 1; g_timer_tick_sem = initSemaphore(); g_timer_end_sem = initSemaphore(); createTask(decreaseTimerNode, 0); sysClkConnect(increaseTick, 0); sysClkRateSet(1000 / TICK); sysClkEnable(); timer_debug("initTimer: getrate %d", sysClkRateGet()); }
void test_initSemaphore(){ SemaphoreData semaphore; initSemaphore(&semaphore, 3); TEST_ASSERT_NOT_NULL(&semaphore); TEST_ASSERT_EQUAL(3, semaphore.counter); TEST_ASSERT_EQUAL(3, semaphore.maxCounter); TEST_ASSERT_NULL(semaphore.waitingQueue.head); TEST_ASSERT_NULL(semaphore.waitingQueue.tail); }
//>>=========================================================================== RELATIONSHIP_CLASS::RELATIONSHIP_CLASS() // DESCRIPTION : Constructor. // PRECONDITIONS : // POSTCONDITIONS : // EXCEPTIONS : // NOTES : //<<=========================================================================== { // constructor activities // - initialise the access semaphore initSemaphore(); }
int main() { int key1=ftok(".",1); int key2=ftok(".",2); int key3=ftok(".",3); printf("%d %d %d",key1,key2,key3); int semid =createSemaphore(key1,2);//S1 S2 int shmid1=createSharedMemory(key2,10);//x printf("shmid1 %d from main\n",shmid1); char *X =(char *)attachSharedMemory(shmid1); // int shmid2=createSharedMemory(key3,10);//y // printf("shmid2 %d from main\n",shmid2); char *Y ; //=//(char *)attachSharedMemory(shmid2); int *values=(int *)malloc(sizeof(int *)*2); *values=0;*(values+1)=0; initSemaphore(semid,values); /* V(semid,0); printf("hi"); P(semid,0); */ int x=0,y=0,i; while(1) { // write(x) i=0; printf("P1 X=%d Y=%d\n",x,y); while(x>0) { *X=x%10-'0';x/=10;X++;i++; } printf("*\n"); *X='\0'; printf("*\n"); X-=i;//X Points to start of shared memory //V(1) V(semid,0); //P(2) P(semid,1); //Read Y i=0; while(*Y!='\0') { y=y*10+(*Y+'0');Y++;i++; } Y-=i; //X=Y+1; x=y+1; printf("P1 X=%d Y=%d\n",x,y); } }
//*************************************************************************** //* * //* BOOL init(ULONG bufsize) * //* * //* This inits the ASPI library and ASPI router driver. * //* Allocates the data buffer and passes its address to the driver * //* Returns: * //* TRUE - Success * //* FALSE - Unsuccessful initialization of driver and library * //* * //* Preconditions: ASPI router device driver has to be loaded * //* * //*************************************************************************** BOOL scsiObj::init(ULONG bufsize) { BOOL success; ULONG rc; rc = DosAllocMem(&buffer, bufsize, OBJ_TILE | PAG_READ | PAG_WRITE | PAG_COMMIT); if (rc) return FALSE; success=openDriver(); // call openDriver member function if (!success) return FALSE; success=initSemaphore(); // call initSemaphore member function if (!success) return FALSE; success=initBuffer(); return TRUE; }
OBJECT_WAREHOUSE_CLASS::OBJECT_WAREHOUSE_CLASS() // DESCRIPTION : Constructor. // PRECONDITIONS : // POSTCONDITIONS : // EXCEPTIONS : // NOTES : //<<=========================================================================== { // constructor activities registerTransferSyntaxes(); registerApplicationContextNames(); registerVerificationSopClass(); // initialise the access semaphore initSemaphore(); // set the reference tag referenceTagM = TAG_UNDEFINED; }
int initMutex(mutex_t *p_mutex) { return initSemaphore(&(p_mutex->lock), 1); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { static bool firstTime = true; initSemaphore(&stepSEM); attachSEM(&stepSEM, STEP_SEM); initSharedMemory(&stepSHM, sizeof(episode_steps)); attachSHM(&stepSHM, STEP_SHM, &stepSEM); readSHMemory(&stepSHM, &episodeStep, &stepSEM); int numStates = (int) *mxGetPr(prhs[0]); int numSteps = episodeStep.numTransmittedSteps; fprintf(stderr, "NumSteps: %d\n",numSteps); plhs[0] = mxCreateDoubleMatrix(N_DOFS, numSteps, mxREAL); plhs[1] = mxCreateDoubleMatrix(N_DOFS, numSteps, mxREAL); plhs[2] = mxCreateDoubleMatrix(N_DOFS, numSteps, mxREAL); plhs[3] = mxCreateDoubleMatrix(N_DOFS, numSteps, mxREAL); plhs[4] = mxCreateDoubleMatrix(N_DOFS, numSteps, mxREAL); plhs[5] = mxCreateDoubleMatrix(N_DOFS, numSteps, mxREAL); plhs[6] = mxCreateDoubleMatrix(N_DOFS, numSteps, mxREAL); plhs[7] = mxCreateDoubleMatrix(7, numSteps, mxREAL); plhs[8] = mxCreateDoubleMatrix(numStates, numSteps, mxREAL); plhs[9] = mxCreateDoubleMatrix(1, numSteps, mxREAL); plhs[10] = mxCreateDoubleMatrix(1, numSteps, mxREAL); plhs[10] = mxCreateDoubleMatrix(1, numSteps, mxREAL); double *joints = mxGetPr(plhs[0]); double *jointsVel = mxGetPr(plhs[1]); double *jointsAcc = mxGetPr(plhs[2]); double *jointsDes = mxGetPr(plhs[3]); double *jointsVelDes = mxGetPr(plhs[4]); double *jointsAccDes = mxGetPr(plhs[5]); double *torque = mxGetPr(plhs[6]); double *cart = mxGetPr(plhs[7]); double *state = mxGetPr(plhs[8]); double *commandIdx = mxGetPr(plhs[9]); double *stepInTrajectory = mxGetPr(plhs[10]); double *doMotionIdx = mxGetPr(plhs[10]); memcpy(joints, episodeStep.joints, sizeof(double) * numSteps * N_DOFS); memcpy(jointsVel, episodeStep.jointsVel, sizeof(double) * numSteps * N_DOFS); memcpy(jointsAcc, episodeStep.jointsAcc, sizeof(double) * numSteps * N_DOFS); memcpy(jointsDes, episodeStep.jointsDes, sizeof(double) * numSteps * N_DOFS); memcpy(jointsVelDes, episodeStep.jointsVelDes, sizeof(double) * numSteps * N_DOFS); memcpy(jointsAccDes, episodeStep.jointsAccDes, sizeof(double) * numSteps * N_DOFS); memcpy(torque, episodeStep.torque, sizeof(double) * numSteps * N_DOFS); memcpy(cart, episodeStep.cart, sizeof(double) * numSteps * 7); // printf("doMotionIdx :"); // for (int i = 0; i < numSteps; i ++) // printf(" %d",episodeStep.doMotionIdx[i]); // printf(" \n"); for (int i = 0; i < numSteps; i ++) { for (int j = 0; j < numStates; j ++) { state[i * numStates + j] = episodeStep.state[i][j]; // printf("%f ", episodeStep.state[i][j]); } // printf("\n"); } for (int i = 0; i < numSteps; i ++) { commandIdx[i] = episodeStep.commandIdx[i]; doMotionIdx[i] = episodeStep.doMotionIdx[i]; } for (int i = 0; i < numSteps; i ++) { stepInTrajectory[i] = episodeStep.stepInTrajectory[i]; } deleteSemaphore(&stepSEM); deleteSharedMemory(&stepSHM); }
void initTimerGlobalLock() { g_timer_global_info_sem = initSemaphore(); postSemaphore(g_timer_global_info_sem); }