Exemple #1
0
void
rqstat_sum(rqst_stats_t *sum, rqst_stats_t *incr)
{
    addtime( &(sum->totalresponsetime),   &(incr->totalresponsetime));
    mintime( &(sum->minresponsetime),     &(incr->minresponsetime));
    maxtime( &(sum->maxresponsetime),     &(incr->maxresponsetime));
    sum->totalresponsetimesq += incr->totalresponsetimesq;

    addtime( &(sum->totalconnecttime),    &(incr->totalconnecttime));
    mintime( &(sum->minconnecttime),      &(incr->minconnecttime));
    maxtime( &(sum->maxconnecttime),      &(incr->maxconnecttime));
    sum->totalconnecttimesq += incr->totalconnecttimesq;

    sum->totalconnects += incr->totalconnects;
    sum->totalerrs     += incr->totalerrs;
    addtime( &(sum->totalerrortime), &(incr->totalerrortime));

    sum->totalbytes    += incr->totalbytes;

    sum->totalbytessq  += incr->totalbytessq;
    sum->minbytes      =  min(sum->minbytes, incr->minbytes);
    sum->maxbytes      =  max(sum->maxbytes, incr->maxbytes);

    sum->totalbody     += incr->totalbody;

    sum->totalbodysq   += incr->totalbodysq;
    sum->minbody       =  min(sum->minbody, incr->minbody);
    sum->maxbody       =  max(sum->maxbody, incr->maxbody);

}
	void mywait(pthread_cond_t *cond, pthread_mutex_t *mutex)
	{
#ifdef __S3E__
		timespec ts;
		clock_gettime(CLOCK_REALTIME, &ts);
		addtime(ts, 300);		
		pthread_cond_timedwait(cond, mutex, &ts);
#elif __ANDROID__
		timespec ts;
		clock_gettime(CLOCK_REALTIME, &ts);
		addtime(ts, 500);		
		pthread_cond_timedwait(cond, mutex, &ts);
#else
		pthread_cond_wait(cond, mutex);		
#endif
	}
Exemple #3
0
int
evtimer_add(struct timeout *h, struct timespec *t)
{
    struct timespec now, sum;
    evtimer_gettime(&now);
    sum = addtime(now, *t);
    if (h->th.i == -1)
        return timeheap_insert(&h->th, &sum);
    else {
        timeheap_change(&h->th, &sum);
        return 0;
    }
}
Exemple #4
0
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
{
    scene = new QGraphicsScene();
    view = new QGraphicsView(scene,this);
    view->setFixedSize(1010,710);
    view->setSceneRect(0,0,1000,700);
    view->show();
    root = new list();
    next=root;
    placeborders();
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(addtime()));
    ui->setupUi(this);
    timer->start(1/fps*1000);
}
Exemple #5
0
int main()
{
	int hr, mn, et;

	printf("enter hour:");
	scanf("%d",&hr);
	printf("enter minutes:");
	scanf("%d",&mn);
	printf("enter elapsed time: ");
	scanf("%d",&et);

	addtime(&hr,&mn,et);

	printf("\n\nhours: %d \nminutes: %d\n\n",hr,mn);

	return 0;

}
Exemple #6
0
static
void* update_thread(void* data)
{
	struct timespec ts;
	int ret;
	unsigned int diff, ntot, seed;
	struct gtec_device* gtdev = data;
	pthread_mutex_t* lock = &(gtdev->updatelock);
	struct random_data rdata = {.rand_type = 0};
	int32_t randnum = 0;
	char state[128] = {0};

	// Initialize random generator
	clock_gettime(CLOCK_REALTIME, &ts);
	seed = ts.tv_nsec;
	initstate_r(seed, state, sizeof(state), &rdata);

	// Wait for acquisition start
	pthread_mutex_lock(&acqlock);
	while (!acquiring) {
		pthread_cond_wait(&acqcond, &acqlock);	
	}
	pthread_mutex_unlock(&acqlock);
	
	memcpy(&ts, &org, sizeof(ts));
	random_r(&rdata, &randnum);
	addtime(&ts, 0, 7000000 + randnum/2500);

	pthread_mutex_lock(lock);
	while (gtdev->running) {
		ret = pthread_cond_timedwait(&gtdev->cond, lock, &ts);
		if (ret == ETIMEDOUT) {
			diff = difftime_ms(&ts, &org);
			ntot = (diff*gtdev->conf.sample_rate)/1000;
			gtdev->nsample = ntot;

			pthread_mutex_unlock(lock);
			gtdev->callback(gtdev->callback_data);
			random_r(&rdata, &randnum);
			addtime(&ts, 0, 7000000 + randnum/2500);
			pthread_mutex_lock(lock);
		}
	}
	pthread_mutex_unlock(lock);

	return NULL;	
}


API_EXPORTED
void GT_ShowDebugInformation( gt_bool show )
{
	(void)show;	
}


API_EXPORTED
gt_bool   GT_UpdateDevices()
{
	static int isinit = 0;
	int i;

	if (isinit)
		return GT_TRUE;

	for (i=0; i<NUMDEV; i++)
		initialize_device(&gtdevices[i]);

	isinit = 1;

	return GT_TRUE;
}


API_EXPORTED
gt_size GT_GetDeviceListSize()
{
	return NUMDEV;
}


API_EXPORTED
char** GT_GetDeviceList()
{
	int i;
	char** devlist;
	
	devlist = malloc(NUMDEV*sizeof(devlist[0]));
	for (i=0; i<NUMDEV; i++) {
		devlist[i] = malloc(strlen(devname[i])+1);
		strcpy(devlist[i], devname[i]);
	}
	
	return devlist;
}
Exemple #7
0
/*--------------------*/ void calthread(void *tag) {
Ttime ct,deltaTtime; w32 delta; int sddburst=0;
//printf("calthread:\n");
threadactive=1;
if(DBGCMDS) {
  char msg[100];
  sprintf(msg, "calthread start. DFS.ffala:%d", DFS->getffala());
  prtLog(msg);
};
while(1) {
  int ndit;
  heartbeat++; if(heartbeat>0xfffffff0) heartbeat=0;
  ndit= findnextcDET();   // find closest one in time. ndit: index into ACTIVEDETS
  //printf("det:%s %d %d\n", ACTIVEDETS[ndit].name, ACTIVEDETS[ndit].caltime.secs, ACTIVEDETS[ndit].caltime.usecs);
  if(ndit==-1) goto STP;  // cal. triggers not needed, stop thread
  if(globalcalDET(ndit)==0) {
    delDET(ndit); if(NACTIVE==0) goto STP;
    continue;
  };
  getcurtime(&ct); 
  if( ACTIVEDETS[ndit].caltime.secs>0) {
    w32 milisecs; int rcgt;
    delta=diffnowbefore(&ACTIVEDETS[ndit].caltime, &ct);
    if(delta>100) {
      usleep(delta);
    };
    if(globalcalDET(ndit)==0) {
      delDET(ndit); if(NACTIVE==0) goto STP;
      continue;
    };
    // generate calib. trigger:
    if(cshmGlobFlag(FLGignoreGCALIB)==0) {
      w32 orbitn[3];   // orbitn tsec tusec
      rcgt= GenSwtrg(1, 'c', ACTIVEDETS[ndit].logroc&0xf, ACTIVEDETS[ndit].calbc,1<<ndit, 
        swtriggers_gcalib, orbitn);
      ct.secs= orbitn[1]; ct.usecs= orbitn[2];
      if(rcgt==12345678) {
        delDET(ndit); if(NACTIVE==0) goto STP;
        continue;
      } else {
        w32 rcgtold;
        rcgtold= rcgt;
        if((rcgt & 0xffffff00)== 0xffffff00) {   // spec. case: one cal. trigger
          char line[80];
          rcgt= rcgt & 0xff;
          // update pp_N.data file: det tsec tusec orbitid rc
          sprintf(line,"%x %x %x %x %x\n", ndit, orbitn[1], orbitn[2],orbitn[0], rcgt);
          DFS->write_df(ndit, line);
        } else {
          char msg[100];
         sprintf(msg,"ERROR: got 0x%x instead of 0xffffff.., deactivating det. %d...",
            rcgtold, ndit);
          prtLog(msg);
          delDET(ndit); if(NACTIVE==0) goto STP;
          continue;
        };
      };
      ACTIVEDETS[ndit].attempts++;
    } else {
      rcgt=0; // cal. trigger not generated (disabled during start/stop part)
    };
    // getcurtime(&ct); // time of cal. trigger just attempted to be generated. Commented out 8.1.2017
    // movd up ACTIVEDETS[ndit].attempts++;
    if(rcgt==4) {    // 4:l2a OK, generated
      if(ACTIVEDETS[ndit].lasttime.secs==0) {
        milisecs=0;
      } else {
        milisecs= diffnowbefore(&ct, &ACTIVEDETS[ndit].lasttime)/1000;
      };
      ACTIVEDETS[ndit].sent++;
      //printf("CT:%s \t %d\t%d ms:%d\n", ACTIVEDETS[ndit].name, ct.secs, ct.usecs, milisecs);
      //printf("CT:%s ms:%d\n", ACTIVEDETS[ndit].name, milisecs);
      ACTIVEDETS[ndit].lasttime.secs= ct.secs;
      ACTIVEDETS[ndit].lasttime.usecs= ct.usecs;
    };
    // usleep(100);  // do we need this (waiting for the completion)?
    /* if(ACTIVEDETS[ndit].attempts > 200 ) {
      emptyDET(); goto STP;
    }; */
  };
  // the planning of next cal. trigger for ndit detector:
  // NextTime= CurrentTime + periodms[ndit] i.e.
  // IS THE SAME IN EITHER CASE (successful or unsuccsessful)
  if( ACTIVEDETS[ndit].caltime.secs==0) {   // wait 2 secs before 1st cal. event
    char msg[200];
    sprintf(msg, "1st planning:%s \t %d\t%d", ACTIVEDETS[ndit].name, ct.secs, ct.usecs);
    prtLog(msg);
    deltaTtime.secs=2; deltaTtime.usecs=0;
  } else {
    deltaTtime.secs=0; deltaTtime.usecs=1000*ACTIVEDETS[ndit].periodms;
  };
  if(ndit==SDD) {   // SDD 3x50ms every 15minutes
    sddburst++;
    if(sddburst==3) {
      sddburst=0;
      deltaTtime.usecs= 15*60*1000000;
    };
  };
  addtime(&ct, &deltaTtime);
  ACTIVEDETS[ndit].caltime.secs= ct.secs;
  ACTIVEDETS[ndit].caltime.usecs= ct.usecs;
  //printf("det:%s next:%d %d\n", ACTIVEDETS[ndit].name, ct.secs,ct.usecs); 
};
STP:
threadactive=0;
if(DBGCMDS) {
  prtLog("calthread stop.");
};
}
Exemple #8
0
/*--------------------*/ void calthread(void *tag) {
    Ttime ct,deltaTtime;
    w32 delta;
    int sddburst=0;
//printf("calthread:\n");
    threadactive=1;
    if(DBGCMDS) {
        prtLog("calthread start.");
    };
    while(1) {
        int ndit;
        heartbeat++;
        if(heartbeat>0xfffffff0) heartbeat=0;
        ndit= findnextcDET();   // find closest one in time
        //printf("det:%s %d %d\n", ACTIVEDETS[ndit].name, ACTIVEDETS[ndit].caltime.secs, ACTIVEDETS[ndit].caltime.usecs);
        if(ndit==-1) goto STP;
        if(globalcalDET(ndit)==0) {
            delDET(ndit);
            if(NACTIVE==0) goto STP;
            continue;
        };
        getcurtime(&ct);
        if( ACTIVEDETS[ndit].caltime.secs>0) {
            w32 milisecs;
            int rcgt;
            delta=diffnowbefore(&ACTIVEDETS[ndit].caltime, &ct);
            if(delta>100) {
                usleep(delta);
            };
            if(globalcalDET(ndit)==0) {
                delDET(ndit);
                if(NACTIVE==0) goto STP;
                continue;
            };
            // generate calib. trigger:
            if(cshmGlobFlag(FLGignoreGCALIB)==0) {
                w32 orbitn;
                rcgt= GenSwtrg(1, 'c', ACTIVEDETS[ndit].roc, ACTIVEDETS[ndit].calbc,1<<ndit,
                               swtriggers_gcalib, &orbitn);
                if(rcgt==12345678) {
                    delDET(ndit);
                    if(NACTIVE==0) goto STP;
                    continue;
                };
                ACTIVEDETS[ndit].attempts++;
            } else {
                rcgt=0; // cal. trigger not generated (disabled during start/stop part)
            };
            getcurtime(&ct); // time of cal. trigger just attempted to be generated
            // movd up ACTIVEDETS[ndit].attempts++;
            if(rcgt==1) {
                if(ACTIVEDETS[ndit].lasttime.secs==0) {
                    milisecs=0;
                } else {
                    milisecs= diffnowbefore(&ct, &ACTIVEDETS[ndit].lasttime)/1000;
                };
                ACTIVEDETS[ndit].sent++;
                //printf("CT:%s \t %d\t%d ms:%d\n", ACTIVEDETS[ndit].name, ct.secs, ct.usecs, milisecs);
                //printf("CT:%s ms:%d\n", ACTIVEDETS[ndit].name, milisecs);
                ACTIVEDETS[ndit].lasttime.secs= ct.secs;
                ACTIVEDETS[ndit].lasttime.usecs= ct.usecs;
            };
            // usleep(100);  // do we need this (waiting for the completion)?
            /* if(ACTIVEDETS[ndit].attempts > 200 ) {
              emptyDET(); goto STP;
            }; */
        };
        // the planning of next cal. trigger for ndit detector:
        // NextTime= CurrentTime + period[ndit] i.e.
        // IS THE SAME IN EITHER CASE (successful or unsuccsessful)
        if( ACTIVEDETS[ndit].caltime.secs==0) {   // wait 2 secs before 1st cal. event
            char msg[200];
            sprintf(msg, "1st planning:%s \t %d\t%d", ACTIVEDETS[ndit].name, ct.secs, ct.usecs);
            prtLog(msg);
            deltaTtime.secs=2;
            deltaTtime.usecs=0;
        } else {
            deltaTtime.secs=0;
            deltaTtime.usecs=1000*ACTIVEDETS[ndit].period;
        };
        if(ndit==SDD) {   // SDD 3x50ms every 15minutes
            sddburst++;
            if(sddburst==3) {
                sddburst=0;
                deltaTtime.usecs= 15*60*1000000;
            };
        };
        addtime(&ct, &deltaTtime);
        ACTIVEDETS[ndit].caltime.secs= ct.secs;
        ACTIVEDETS[ndit].caltime.usecs= ct.usecs;
        //printf("det:%s next:%d %d\n", ACTIVEDETS[ndit].name, ct.secs,ct.usecs);
    };
STP:
    threadactive=0;
    if(DBGCMDS) {
        prtLog("calthread stop.");
    };
}