Exemplo n.º 1
0
static void
cgd_cipher(struct cgd_softc *cs, void *dstv, void *srcv,
    size_t len, daddr_t blkno, size_t secsize, int dir)
{
	char		*dst = dstv;
	char 		*src = srcv;
	cfunc_cipher	*cipher = cs->sc_cfuncs->cf_cipher;
	struct uio	dstuio;
	struct uio	srcuio;
	struct iovec	dstiov[2];
	struct iovec	srciov[2];
	size_t		blocksize = cs->sc_cdata.cf_blocksize;
	size_t		todo;
	char		sink[CGD_MAXBLOCKSIZE];
	char		zero_iv[CGD_MAXBLOCKSIZE];
	char		blkno_buf[CGD_MAXBLOCKSIZE];

	DPRINTF_FOLLOW(("cgd_cipher() dir=%d\n", dir));

	DIAGCONDPANIC(len % blocksize != 0,
	    ("cgd_cipher: len %% blocksize != 0"));

	/* ensure that sizeof(daddr_t) <= blocksize (for encblkno IVing) */
	DIAGCONDPANIC(sizeof(daddr_t) > blocksize,
	    ("cgd_cipher: sizeof(daddr_t) > blocksize"));

	memset(zero_iv, 0x0, blocksize);

	dstuio.uio_iov = dstiov;
	dstuio.uio_iovcnt = 2;

	srcuio.uio_iov = srciov;
	srcuio.uio_iovcnt = 2;

	dstiov[0].iov_base = sink;
	dstiov[0].iov_len  = blocksize;
	srciov[0].iov_base = blkno_buf;
	srciov[0].iov_len  = blocksize;

	for (; len > 0; len -= todo) {
		todo = MIN(len, secsize);

		dstiov[1].iov_base = dst;
		srciov[1].iov_base = src;
		dstiov[1].iov_len  = todo;
		srciov[1].iov_len  = todo;

		memset(blkno_buf, 0x0, blocksize);
		blkno2blkno_buf(blkno_buf, blkno);
		if (dir == CGD_CIPHER_DECRYPT) {
			dstuio.uio_iovcnt = 1;
			srcuio.uio_iovcnt = 1;
			IFDEBUG(CGDB_CRYPTO, hexprint("step 0: blkno_buf",
			    blkno_buf, blocksize));
			cipher(cs->sc_cdata.cf_priv, &dstuio, &srcuio,
			    zero_iv, CGD_CIPHER_ENCRYPT);
			memcpy(blkno_buf, sink, blocksize);
			dstuio.uio_iovcnt = 2;
			srcuio.uio_iovcnt = 2;
		}

		IFDEBUG(CGDB_CRYPTO, hexprint("step 1: blkno_buf",
		    blkno_buf, blocksize));
		cipher(cs->sc_cdata.cf_priv, &dstuio, &srcuio, zero_iv, dir);
		IFDEBUG(CGDB_CRYPTO, hexprint("step 2: sink",
		    sink, blocksize));

		dst += todo;
		src += todo;
		blkno++;
	}
}
AREXPORT void ArServerHandlerCamera::setCameraRel(
	double pan, double tilt, double zoom, bool lockRobot)
{
  if ((myRobot == NULL) || (myCamera == NULL)) {
    return;
  }

  IFDEBUG(ArLog::log(ArLog::Normal,
                    "ArServerHandlerCamera::doSetCameraRel() p = %f, t = %f, z = %f",
                    pan, tilt, zoom));

  // The camera mode is set to position only if the pan or tilt changed.

  double invAtZoom = 1;

  if (myCamera->getMaxZoom() - myCamera->getMinZoom() != 0)
  {
    // see what zoom we're at so we can modify total pan and tilt amounts by it
    invAtZoom = 1 - getCurrentZoomRatio();

    //totalPanAmount /= atZoom / (100 / (double) totalPanAmount);
    //totalTiltAmount /= atZoom / (100 / (double) totalTiltAmount);
    if (invAtZoom < .01)
      invAtZoom = .01;
    if (invAtZoom > 1.01)
      invAtZoom = 1;
  }
  else
  {
    invAtZoom = 1;
  }

  if (pan > 0)
    pan = ceil(pan * invAtZoom);
  else
    pan = floor(pan * invAtZoom);

  if (tilt > 0)
    tilt = ceil(tilt * invAtZoom);
  else
    tilt = floor(tilt * invAtZoom);

  if (lockRobot)
    myRobot->lock();

  if (zoom != 0)
  {
    double newZoomPct = (getCurrentZoomRatio() * 100.0) + zoom;

    double newAbsZoom = myCamera->getMinZoom() + ((newZoomPct / 100.0) * getZoomRange());

    IFDEBUG(ArLog::log(ArLog::Normal,
                      "ArServerHandlerCamera::handleSetCameraRel() newZoomPct = %f, newAbsZoom = %f",
                       newZoomPct, newAbsZoom));

    myCamera->zoom(ArMath::roundInt(newAbsZoom));

  } // end if zoom change
  
  // Only want to pan...
  if ((pan == 0) && (tilt != 0)) 
  {
    cameraModePosition();
    myCamera->tiltRel(tilt);
  }
  // Only want to tilt...
  else if ((pan != 0) && (tilt == 0)) 
  {
    cameraModePosition();
    myCamera->panRel(pan);
  }
  else if (pan != 0 && tilt != 0) 
  { // pan and tilt...
    cameraModePosition();
    myCamera->panTiltRel(pan, tilt);
  }

  if (lockRobot)
    myRobot->unlock();

} // end method doSetCameraRel
Exemplo n.º 3
0
static int arlan_hw_test_memory(struct net_device *dev)
{
	u_char *ptr;
	int i;
	int memlen = sizeof(struct arlan_shmem) - 0xF;	/* avoid control register */
	volatile char *arlan_mem = (char *) (dev->mem_start);
	volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;
	char pattern;

	ptr = NULL;

	/* hold card in reset state */
	setHardwareReset(dev);

	/* test memory */
	pattern = 0;
	for (i = 0; i < memlen; i++)
		WRITESHM(arlan_mem[i], ((u_char) pattern++), u_char);

	pattern = 0;
	for (i = 0; i < memlen; i++)
	{
		char res;
		READSHM(res, arlan_mem[i], char);
		if (res != pattern++)
		{
			printk(KERN_ERR "Arlan driver memory test 1 failed \n");
			return -1;
		}
	}

	pattern = 0;
	for (i = 0; i < memlen; i++)
		WRITESHM(arlan_mem[i], ~(pattern++), char);

	pattern = 0;
	for (i = 0; i < memlen; i++)
	{
		char res;
		READSHM(res, arlan_mem[i], char);
		if (res != ~(pattern++))
		{
			printk(KERN_ERR "Arlan driver memory test 2 failed \n");
			return -1;
		}
	}

	/* zero memory */
	for (i = 0; i < memlen; i++)
		WRITESHM(arlan_mem[i], 0x00, char);

	IFDEBUG(1) printk(KERN_INFO "Arlan: memory tests ok\n");

	/* set reset flag and then release reset */
	WRITESHM(arlan->resetFlag, 0xff, u_char);

	clearChannelAttention(dev);
	clearHardwareReset(dev);

	/* wait for reset flag to become zero, we'll wait for two seconds */
	if (arlan_command(dev, ARLAN_COMMAND_LONG_WAIT_NOW))
	{
		printk(KERN_ERR "%s arlan: failed to come back from memory test\n", dev->name);
		return -1;
	}
	return 0;
}
Exemplo n.º 4
0
static int arlan_setup_card_by_book(struct net_device *dev)
{
	u_char irqLevel, configuredStatusFlag;
	volatile struct arlan_shmem *arlan = ((struct arlan_private *) dev->priv)->card;

//	ARLAN_DEBUG_ENTRY("arlan_setup_card");

	READSHM(configuredStatusFlag, arlan->configuredStatusFlag, u_char);

	IFDEBUG(10)
	if (configuredStatusFlag != 0)
		IFDEBUG(10) printk("arlan: CARD IS CONFIGURED\n");
	else
		IFDEBUG(10) printk("arlan: card is NOT configured\n");

	if (testMemory || (READSHMB(arlan->diagnosticInfo) != 0xff))
		if (arlan_hw_test_memory(dev))
			return -1;

	DEBUGSHM(4, "arlan configuredStatus = %d \n", arlan->configuredStatusFlag, u_char);
	DEBUGSHM(4, "arlan driver diagnostic: 0x%2x\n", arlan->diagnosticInfo, u_char);

	/* issue nop command - no interupt */
	arlan_command(dev, ARLAN_COMMAND_NOOP);
	if (arlan_command(dev, ARLAN_COMMAND_WAIT_NOW) != 0)
		return -1;

	IFDEBUG(50) printk("1st Noop successfully executed !!\n");

	/* try to turn on the arlan interrupts */
	clearClearInterrupt(dev);
	setClearInterrupt(dev);
	setInterruptEnable(dev);

	/* issue nop command - with interrupt */

	arlan_command(dev, ARLAN_COMMAND_NOOPINT);
	if (arlan_command(dev, ARLAN_COMMAND_WAIT_NOW) != 0)
		return -1;


	IFDEBUG(50) printk("2nd Noop successfully executed !!\n");

	READSHM(irqLevel, arlan->irqLevel, u_char)
	
	if (irqLevel != dev->irq)
	{
		IFDEBUG(1) printk(KERN_WARNING "arlan dip switches set irq to %d\n", irqLevel);
		printk(KERN_WARNING "device driver irq set to %d - does not match\n", dev->irq);
		dev->irq = irqLevel;
	}
	else
		IFDEBUG(2) printk("irq level is OK\n");


	IFDEBUG(3) arlan_print_diagnostic_info(dev);

	arlan_command(dev, ARLAN_COMMAND_CONF);

	READSHM(configuredStatusFlag, arlan->configuredStatusFlag, u_char);
	if (configuredStatusFlag == 0)
	{
		printk(KERN_WARNING "arlan configure failed\n");
		return -1;
	}
	arlan_command(dev, ARLAN_COMMAND_LONG_WAIT_NOW);
	arlan_command(dev, ARLAN_COMMAND_RX);
	arlan_command(dev, ARLAN_COMMAND_LONG_WAIT_NOW);
	printk(KERN_NOTICE "%s: arlan driver version %s loaded\n",
	       dev->name, arlan_version);

//	ARLAN_DEBUG_EXIT("arlan_setup_card");

	return 0;		/* no errors */
}
void
ConditionManagerTimeInterval::startMonitor() {
    IFDEBUG(qDebug() << Q_FUNC_INFO);
}
void
ConditionManagerTimeInterval::rulesChanged() {
    IFDEBUG(qDebug() << Q_FUNC_INFO);

    _clearVarsForInvalidation();
}
void
ConditionManagerLocationCell::rulesChanged() {
    IFDEBUG(qDebug() << "ConditionManagerLocationCell::rulesChanged");

    _clearVarsForInvalidating();
}
void
ConditionManagerLocationCell::startMonitor() {
    IFDEBUG(qDebug() << "ConditionManagerLocationCell::startMonitor");
    connect(&_networkInfo, SIGNAL(cellIdChanged(int)), this, SLOT(cellIdChanged(int)));
}
Exemplo n.º 9
0
Arquivo: ewn.c Projeto: rolk/ug
static INT EWNSolver (NP_EW_SOLVER *theNP, INT level, INT New, VECDATA_DESC **ev, DOUBLE *ew, NP_NL_ASSEMBLE *Assemble, VEC_SCALAR abslimit, VEC_SCALAR reduction, EWRESULT *ewresult)
{
  NP_EWN     *np    = (NP_EWN *) theNP;
  MULTIGRID *theMG = theNP->base.mg;
  INT i,j,iter,done,result,DoLS;
  char text[DISPLAY_WIDTH+4],format2[64],format3[64],formatr1[64],formatr2[64],formats[64];
  DOUBLE shift,shift_old,cnorm[MAX_NUMBER_EW],norm_x1x2,norm_yx2,norm_yx1,delta;
  DOUBLE A[MAX_NUMBER_EW][MAX_NUMBER_EW];
  DOUBLE B[MAX_NUMBER_EW][MAX_NUMBER_EW];
  DOUBLE E[MAX_NUMBER_EW][MAX_NUMBER_EW];
  DOUBLE ew_re[MAX_NUMBER_EW],ew_im[MAX_NUMBER_EW];
  DOUBLE ew_re_out,ew_im_out;
  DOUBLE tmp_re[MAX_NUMBER_EW],tmp_im[MAX_NUMBER_EW];
  DOUBLE old_re[MAX_NUMBER_EW],old_im[MAX_NUMBER_EW],norm;
  DOUBLE* table[MAX_NUMBER_EW];
  INT index[MAX_NUMBER_EW];
  INT bl = 0;

  ewresult->error_code = 0;
  CenterInPattern(text,DISPLAY_WIDTH,ENVITEM_NAME(np),'§',"\n"); UserWrite(text);
  sprintf(text,"%d.%d",np->c_d+1,np->c_d-1);
  strcpy(formats," %-3d    S:  % "); strcat(formats,text); strcat(formats,"e\n");
  strcpy(format2,"      %3d: (% "); strcat(format2,text); strcat(format2,"e, % "); strcat(format2,text); strcat(format2,"e)");
  strcpy(format3,"      %3d: [% "); strcat(format3,text); strcat(format3,"e, % "); strcat(format3,text); strcat(format3,"e]");
  strcpy(formatr1," %-3d   res: %3d: (% "); strcat(formatr1,text); strcat(formatr1,"e, % "); strcat(formatr1,text); strcat(formatr1,"e)\n");
  strcpy(formatr2,"            %3d: (% "); strcat(formatr2,text); strcat(formatr2,"e, % "); strcat(formatr2,text); strcat(formatr2,"e)\n");
  shift=np->shift_min; DoLS=0; shift_old=shift-1;
  for (iter=0; iter<np->maxiter; iter++)
  {
    /* preprocess if */
    if (iter==0 || DoLS)
    {
      if (dmatcopy(theNP->base.mg,bl,level,ALL_VECTORS,np->M,np->N)) return(1);
      if (dcopy(theNP->base.mg,bl,level,ALL_VECTORS,np->t,np->E)) return(1);
      if (dscal(theNP->base.mg,bl,level,ALL_VECTORS,np->t,-shift)) return(1);
      if (dmassadd(theNP->base.mg,bl,level,ALL_VECTORS,np->M,np->t,np->type)) return(1);
      if (np->LS->PreProcess != NULL) if ((*np->LS->PreProcess)(np->LS,level,ev[0],np->r,np->M, &np->baselevel,&result)) return(1);
    }
    for (i=0; i<New; i++)
    {
      if (np->conv_mode==1)
        if (dcopy(theMG,bl,level,ALL_VECTORS,np->s[i],ev[i])) NP_RETURN(1,ewresult->error_code);
      if (dcopy(theMG,bl,level,ALL_VECTORS,np->t,ev[i])) NP_RETURN(1,ewresult->error_code);
      if (dmassdot(theMG,bl,level,ALL_VECTORS,np->t,np->E,np->type)) NP_RETURN(1,ewresult->error_code);
      if (np->LS->Defect!=NULL) if ((*np->LS->Defect)(np->LS,level,ev[i],np->t,np->M, &ewresult->error_code)) NP_RETURN(1,ewresult->error_code);
      if (np->LS->Residuum!=NULL) if ((*np->LS->Residuum)(np->LS,0,level,ev[i],np->t,np->M, &ewresult->lresult[i])) NP_RETURN(1,ewresult->error_code);
      if ((*np->LS->Solver)(np->LS,level,ev[i],np->t,np->M, abslimit,reduction, &ewresult->lresult[i])) NP_RETURN(1,ewresult->error_code);
      if (np->Project != NULL) if (np->Project->Project(np->Project,bl,level, ev[i],&ewresult->error_code) != NUM_OK) NP_RETURN(1,ewresult->error_code);
    }
    for (i=0; i<New; i++)
    {
      if (ddot(theMG,0,level,ON_SURFACE,ev[i],ev[i],&B[i][i])) NP_RETURN(1,ewresult->error_code);
      if (dscal(theMG,0,level,ALL_VECTORS,ev[i],1/sqrt(B[i][i])) != NUM_OK) NP_RETURN(1,ewresult->error_code);
    }
    for (i=0; i<New; i++)
    {
      if (dmatmul (theMG,0,level,ON_SURFACE,np->t,np->M,ev[i]) != NUM_OK) NP_RETURN(1,ewresult->error_code);
      for (j=0; j<New; j++)
        if (ddotw(theMG,0,level,ON_SURFACE,np->t,ev[j],np->weight,&A[i][j])) NP_RETURN(1,ewresult->error_code);
    }
    for (i=0; i<New; i++)
    {
      if (dcopy(theMG,bl,level,ALL_VECTORS,np->t,ev[i])) NP_RETURN(1,ewresult->error_code);
      if (dmassdot(theMG,bl,level,ALL_VECTORS,np->t,np->E,np->type)) NP_RETURN(1,ewresult->error_code);
      for (j=0; j<New; j++)
        if (ddotw(theMG,0,level,ON_SURFACE,np->t,ev[j],np->weight,&B[i][j])) NP_RETURN(1,ewresult->error_code);
    }

    /* Special Eigenvalue problem  G E_i = lambda E_i */
    SmallEWNSolver_Sci(New,A,B,ew_re,ew_im,E);

    IFDEBUG(np,1)
    UserWriteF("A\n"); for (i=0; i<New; i++) { for (j=0; j<New; j++) UserWriteF("%8.4f\t",A[i][j]);UserWriteF("\n"); }
    UserWriteF("B\n"); for (i=0; i<New; i++) { for (j=0; j<New; j++) UserWriteF("%8.4f\t",B[i][j]);UserWriteF("\n"); }
    UserWriteF("E\n"); for (i=0; i<New; i++) { for (j=0; j<New; j++) UserWriteF("%8.4f\t",E[i][j]);UserWriteF("\n"); }
    ENDDEBUG

    for (i=0; i<New; i++)
      if (AllocVDFromVD(theMG,bl,level,ev[0],&np->e[i])) NP_RETURN(1,ewresult->error_code);
    for (i=0; i<New; i++)
    {
      if (dset(theMG,bl,level,ALL_VECTORS,np->e[i],0.0)) NP_RETURN(1,ewresult->error_code);
      for (j=0; j<New; j++)
        if (daxpy(theMG,bl,level,ALL_VECTORS,np->e[i],E[j][i],ev[j]) != NUM_OK) NP_RETURN(1,ewresult->error_code);
      ddotw(theMG,bl,level,ON_SURFACE,np->e[i],np->e[i],np->weight,&norm); norm=sqrt(norm);
      dscal(theMG,bl,level,ALL_VECTORS,np->e[i],1.0/norm);
    }

    /* sort eigen-values/vectors */
    for (i=0; i<New; i++)
    {
      tmp_re[i]=ew_re[i]; tmp_im[i]=ew_im[i];
      switch (np->order)
      {
      case ORDER_REAL_UP :
        ew[i]=ew_re[i];
        break;
      case ORDER_REAL_DOWN :
        ew[i]=-ew_re[i];
        break;
      case ORDER_ABS_UP :
        ew[i]=ew_re[i]*ew_re[i]+ew_im[i]*ew_im[i];
        break;
      case ORDER_ABS_DOWN :
        ew[i]=-ew_re[i]*ew_re[i]-ew_im[i]*ew_im[i];
        break;
      }
      table[i] = &ew[i];
    }
    qsort(table, New, sizeof(*table),(int (*)(const void *, const void *))EWCompare);
    for (i=0; i<New; i++)
      for (j=0; j<New; j++)
        if (table[i]==&ew[j])
          index[i] = j;

    for (i=0; i<New; i++)
    {
      if (dcopy(theMG,bl,level,ALL_VECTORS,ev[i],np->e[index[i]])) NP_RETURN(1,ewresult->error_code);
      ew_re[i]=tmp_re[index[i]]; ew_im[i]=tmp_im[index[i]];
    }

    /* shift back eigenvalues */
    for (i=0; i<np->ew.nev; i++) ew_re[i]+=shift;

    /* check convergence */
    if (iter>0)
    {
      done=1;
      if (np->conv_mode==0)
      {
        /* convergence according to eigenvalues */
        for (i=0; i<np->c_n; i++)
        {
          if (Round(ew_re[i],np->c_d)!=Round(old_re[i],np->c_d)) done=0;
          if (Round(ABS(ew_im[i]),np->c_d)!=Round(ABS(old_im[i]),np->c_d)) done=0;
        }
      }
      else
      {
        /* convergence according to eigenvectors */
        for (i=0; i<New; i++)
          if (ew_im[i]==0.0)
          {
            ddotw(theMG,bl,level,ON_SURFACE,np->s[i],np->e[index[i]],np->weight,&norm);
            cnorm[i]=1-ABS(norm);
            if (cnorm[i]>pow(0.1,np->c_d) && i<np->c_n) done=0;
          }
          else
          {
            ddotw(theMG,bl,level,ON_SURFACE,np->s[i],np->s[i+1],np->weight,&norm_x1x2);
            ddotw(theMG,bl,level,ON_SURFACE,np->s[i],np->e[index[i]],np->weight,&norm_yx1);
            ddotw(theMG,bl,level,ON_SURFACE,np->s[i+1],np->e[index[i]],np->weight,&norm_yx2);
            norm=(norm_yx1*norm_yx1+norm_yx2*norm_yx2-2.0*norm_x1x2*norm_yx1*norm_yx2)/(1.0-norm_x1x2*norm_x1x2);
            cnorm[i]=1-ABS(norm);
            if (cnorm[i]>pow(0.1,np->c_d) && i<np->c_n) done=0;
            ddotw(theMG,bl,level,ON_SURFACE,np->s[i],np->e[index[i+1]],np->weight,&norm_yx1);
            ddotw(theMG,bl,level,ON_SURFACE,np->s[i+1],np->e[index[i+1]],np->weight,&norm_yx2);
            i++;
            norm=(norm_yx1*norm_yx1+norm_yx2*norm_yx2-2.0*norm_x1x2*norm_yx1*norm_yx2)/(1.0-norm_x1x2*norm_x1x2);
            cnorm[i]=1-ABS(norm);
            if (cnorm[i]>pow(0.1,np->c_d) && i<np->c_n) done=0;
          }
      }
    }
    else
      done=0;

    for (i=0; i<New; i++)
    {
      old_re[i]=ew_re[i];
      old_im[i]=ew_im[i];
    }

    /* display */
    if (np->display > PCR_NO_DISPLAY)
    {
      UserWriteF(formats,iter,shift*np->scale);
      if (np->conv_mode==0)
      {
        /* conv_mode val */
        for (i=0; i<np->ew.nev; i++)
        {
          ew_re_out=np->scale*ew_re[i];
          ew_im_out=np->scale*ew_im[i];
          if (i<np->c_n)  { UserWriteF(format2,(int)i,ew_re_out,ew_im_out); UserWriteF("\n"); }
          else                    { UserWriteF(format3,(int)i,ew_re_out,ew_im_out); UserWriteF("\n"); }
        }
        UserWriteF("\n");
      }
      else
      {
        /* conv_mode vec */
        for (i=0; i<np->ew.nev; i++)
        {
          ew_re_out=np->scale*ew_re[i];
          ew_im_out=np->scale*ew_im[i];
          if (i<np->c_n)  { UserWriteF(format2,(int)i,ew_re_out,ew_im_out); UserWriteF("      (%8.6e)\n",cnorm[i]); }
          else                    { UserWriteF(format3,(int)i,ew_re_out,ew_im_out); UserWriteF("      [%8.6e]\n",cnorm[i]); }
        }
        UserWriteF("\n");
      }
    }

    /* free VEC_DATADESC's */
    for (i=0; i<New; i++)
      if (FreeVD(theMG,bl,level,np->e[i])) NP_RETURN(1,ewresult->error_code);

    /* convergence of smallest */
    UserWriteF("convergence of smallest\n");
    UserWriteF("-----------------------\n");
    delta=0.0; for (i=0; i<New; i++) delta=MAX(delta,(ew_re[i]-shift)*(ew_re[i]-shift)+ew_im[i]*ew_im[i]);
    delta=((ew_re[0]-shift)*(ew_re[0]-shift)+ew_im[0]*ew_im[0])/delta; delta=sqrt(delta);
    UserWriteF("gamma: %e\n\n",delta);

    /* calculate shift */
    delta=0.0; for (i=0; i<New; i++) delta=MAX(delta,ABS(ew_im[i]));delta=MAX(delta,np->imag_max);
    shift=ew_re[0]+delta*delta/(ew_re[0]-ew_re[New-1]);
    delta=0.0; for (i=0; i<New; i++) { delta=ew_re[0]-ew_re[i]; if (delta!=0.0) break;}
    shift=MIN(shift,ew_re[0]+0.5*delta);
    shift=MAX(shift,np->shift_min);
    shift=MIN(shift,np->shift_max);
    DoLS=0; if (shift!=shift_old) DoLS=1;shift_old=shift;

    /* postprocess if */
    if (done || iter==np->maxiter-1 || DoLS)
    {
      if (np->LS->PostProcess!=NULL)
        if ((*np->LS->PostProcess)(np->LS,level,ev[0],np->r,np->M,&result)) return(1);
    }

    /* done? */
    if (done) break;
  }

  /* print result */
  for (i=0; i<np->c_n; i++)
  {
    ew_re_out=np->scale*ew_re[i];
    ew_im_out=np->scale*ew_im[i];
    if (i==0)
      UserWriteF(formatr1,(int)iter,(int)i,ew_re_out,ew_im_out);
    else
      UserWriteF(formatr2,(int)i,ew_re_out,ew_im_out);
  }
  UserWriteF("\n");

  return (0);
}
Exemplo n.º 10
0
void AutomAllocator::deallocateTransitions(Transition* tr, int cap) {
  IFDEBUG(deallocTrCalls++);
  for(int i=0; i<cap; i++)
    tr[i](-1, -1);
  pools[cap].push(tr);
}
Exemplo n.º 11
0
Arquivo: ach.c Projeto: Tarrasch/ach
enum ach_status
ach_create( const char *channel_name,
            size_t frame_cnt, size_t frame_size,
            ach_create_attr_t *attr) {
    ach_header_t *shm;
    int fd;
    size_t len;
    /* fixme: truncate */
    /* open shm */
    {
        len = sizeof( ach_header_t) +
            frame_cnt*sizeof( ach_index_t ) +
            frame_cnt*frame_size +
            3*sizeof(uint64_t);

        if( attr && attr->map_anon ) {
            /* anonymous (heap) */
            shm = (ach_header_t *) malloc( len );
            fd = -1;
        }else {
            int oflag = O_EXCL | O_CREAT;
            /* shm */
            if( ! channel_name_ok( channel_name ) )
                return ACH_INVALID_NAME;
            if( attr ) {
                if( attr->truncate ) oflag &= ~O_EXCL;
            }
            if( (fd = fd_for_channel_name( channel_name, oflag )) < 0 ) {
                return check_errno();;
            }

            { /* make file proper size */
                /* FreeBSD needs ftruncate before mmap, Linux can do either order */
                int r;
                int i = 0;
                do {
                    r = ftruncate( fd, (off_t) len );
                }while(-1 == r && EINTR == errno && i++ < ACH_INTR_RETRY);
                if( -1 == r ) {
                    DEBUG_PERROR( "ftruncate");
                    return ACH_FAILED_SYSCALL;
                }
            }

            /* mmap */
            if( (shm = (ach_header_t *)mmap( NULL, len, PROT_READ|PROT_WRITE,
                                             MAP_SHARED, fd, 0) )
                == MAP_FAILED ) {
                DEBUG_PERROR("mmap");
                DEBUGF("mmap failed %s, len: %"PRIuPTR", fd: %d\n", strerror(errno), len, fd);
                return ACH_FAILED_SYSCALL;
            }

        }

        memset( shm, 0, len );
        shm->len = len;
    }

    { /* initialize synchronization */
        { /* initialize condition variables */
            int r;
            pthread_condattr_t cond_attr;
            if( (r = pthread_condattr_init(&cond_attr)) ) {
                DEBUG_PERROR("pthread_condattr_init");
                return ACH_FAILED_SYSCALL;
            }
            /* Process Shared */
            if( ! (attr && attr->map_anon) ) {
                /* Set shared if not anonymous mapping
                   Default will be private. */
                if( (r = pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED)) ) {
                    DEBUG_PERROR("pthread_condattr_setpshared");
                    return ACH_FAILED_SYSCALL;
                }
            }
            /* Clock */
            if( attr && attr->set_clock ) {
                if( (r = pthread_condattr_setclock(&cond_attr, attr->clock)) ) {
                    DEBUG_PERROR("pthread_condattr_setclock");
                    return ACH_FAILED_SYSCALL;
                }
            } else {
                if( (r = pthread_condattr_setclock(&cond_attr, ACH_DEFAULT_CLOCK)) ) {
                    DEBUG_PERROR("pthread_condattr_setclock");
                    return ACH_FAILED_SYSCALL;
                }
            }

            if( (r = pthread_cond_init(&shm->sync.cond, &cond_attr)) ) {
                DEBUG_PERROR("pthread_cond_init");
                return ACH_FAILED_SYSCALL;
            }

            if( (r = pthread_condattr_destroy(&cond_attr)) ) {
                DEBUG_PERROR("pthread_condattr_destroy");
                return ACH_FAILED_SYSCALL;
            }
        }
        { /* initialize mutex */
            int r;
            pthread_mutexattr_t mutex_attr;
            if( (r = pthread_mutexattr_init(&mutex_attr)) ) {
                DEBUG_PERROR("pthread_mutexattr_init");
                return ACH_FAILED_SYSCALL;
            }
            if( (r = pthread_mutexattr_setpshared(&mutex_attr,
                                                  PTHREAD_PROCESS_SHARED)) ) {
                DEBUG_PERROR("pthread_mutexattr_setpshared");
                return ACH_FAILED_SYSCALL;
            }
            /* Error Checking Mutex */
#ifdef PTHREAD_MUTEX_ERRORCHECK_NP
            if( (r = pthread_mutexattr_settype(&mutex_attr,
                                               PTHREAD_MUTEX_ERRORCHECK_NP)) ) {
                DEBUG_PERROR("pthread_mutexattr_settype");
                return ACH_FAILED_SYSCALL;
            }
#endif
            /* Priority Inheritance Mutex */
#ifdef PTHREAD_PRIO_INHERIT
            if( (r = pthread_mutexattr_setprotocol(&mutex_attr,
                                                   PTHREAD_PRIO_INHERIT)) ) {
                DEBUG_PERROR("pthread_mutexattr_setprotocol");
                return ACH_FAILED_SYSCALL;
            }
#endif

            if( (r = pthread_mutex_init(&shm->sync.mutex, &mutex_attr)) ) {
                DEBUG_PERROR("pthread_mutexattr_init");
                return ACH_FAILED_SYSCALL;
            }

            if( (r = pthread_mutexattr_destroy(&mutex_attr)) ) {
                DEBUG_PERROR("pthread_mutexattr_destroy");
                return ACH_FAILED_SYSCALL;
            }
        }
    }
    /* initialize name */
    strncpy( shm->name, channel_name, ACH_CHAN_NAME_MAX );
    /* initialize counts */
    shm->index_cnt = frame_cnt;
    shm->index_head = 0;
    shm->index_free = frame_cnt;
    shm->data_head = 0;
    shm->data_free = frame_cnt * frame_size;
    shm->data_size = frame_cnt * frame_size;
    assert( sizeof( ach_header_t ) +
            shm->index_free * sizeof( ach_index_t ) +
            shm->data_free + 3*sizeof(uint64_t) ==  len );

    *ACH_SHM_GUARD_HEADER(shm) = ACH_SHM_GUARD_HEADER_NUM;
    *ACH_SHM_GUARD_INDEX(shm) = ACH_SHM_GUARD_INDEX_NUM;
    *ACH_SHM_GUARD_DATA(shm) = ACH_SHM_GUARD_DATA_NUM;
    shm->magic = ACH_SHM_MAGIC_NUM;

    if( attr && attr->map_anon ) {
        attr->shm = shm;
    } else {
        int r;
        /* remove mapping */
        r = munmap(shm, len);
        if( 0 != r ){
            DEBUG_PERROR("munmap");
            return ACH_FAILED_SYSCALL;
        }
        /* close file */
        int i = 0;
        do {
            IFDEBUG( i ? DEBUGF("Retrying close()\n"):0 );
            r = close(fd);
        }while( -1 == r && EINTR == errno && i++ < ACH_INTR_RETRY );
        if( -1 == r ){
            DEBUG_PERROR("close");
            return ACH_FAILED_SYSCALL;
        }
    }
    return ACH_OK;
}