Пример #1
0
/*
 * plc_LoopWait()
 *
 * Description:
 *  Returns FALSE if a slip is detected.
 */ 
pwr_tBoolean plc_LoopWait (
    int		*WaitResult,     /* Set to 1 when Event */
    pwr_tVaxTime	*DeltaTime,
    pwr_tVaxTime	*NextTime,
    unsigned long Event
)
{
    pwr_tStatus sts;
    pwr_tVaxTime NextLoop, UpTime, DiffTime;
    pwr_tBoolean Result;

    sts = lib$add_times(NextTime, DeltaTime, &NextLoop);
    *NextTime = NextLoop;
    ker$get_uptime(&sts, &UpTime);
    
    sts = lib$sub_times(NextTime, &UpTime, &DiffTime);
    if (sts == LIB$_NEGTIM) 
	Result = FALSE; /* Slip */
    else  if (NextTime->high == UpTime.high && NextTime->low == UpTime.low)
	Result = TRUE; /* Equal Times */
    else {
	if (Event)
	    ker$wait_any(&sts, WaitResult, &DiffTime, Event);
	else
	    ker$wait_any(&sts, WaitResult, &DiffTime);
	Result = TRUE;
    }	

    return Result;
}
Пример #2
0
/**@brief neighboring transformations
should be similar
@param tIdx index of the triangle being proecssed
@param mat vector of transformations for each triangle

assumes m already contains adjacency matrix
*/
void smooth_mat(Mesh & m,
                std::vector<Mat3>&mat,
                float wS, CCS&ccs)
{
  //each triangle has 9 constraints for
  //each number in the transformation matrix
for(int axis=0; axis<3; axis++) {

    for(size_t tIdx=0; tIdx<m.t.size(); tIdx++) {

      for(int ii=0; ii<3; ii++) {
        std::map<int,real>rowVal;
        std::map<int,real>neiborRowVal;
        add_coef(m.t[tIdx],ii,mat[tIdx],rowVal);
        for(size_t nbr =0; nbr<m.adjMat[tIdx].size(); nbr++) {
          int nbrIdx = m.adjMat[tIdx][nbr];
          add_coef(m.t[nbrIdx],ii,mat[nbrIdx],neiborRowVal);
        }
        add_times(rowVal, neiborRowVal,-(1.0/m.adjMat[tIdx].size()));
        scale(rowVal, wS);
//if(axis==0 && ii==0 && tIdx==0){	
//	  std::cout<<"rowVal"<<rowVal[m.t[0][0]]<<"\n";
//	}
        addrow(rowVal, ccs, nvar*axis);
      }
    }
  }
}
Пример #3
0
struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result)
{
    struct tm *ts = NULL;

#if defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32) && (!defined(OPENSSL_SYS_VMS) || defined(gmtime_r)) && !defined(OPENSSL_SYS_MACOSX)
    /*
     * should return &data, but doesn't on some systems, so we don't even
     * look at the return value
     */
    gmtime_r(timer, result);
    ts = result;
#elif !defined(OPENSSL_SYS_VMS) || defined(VMS_GMTIME_OK)
    ts = gmtime(timer);
    if (ts == NULL)
        return NULL;

    memcpy(result, ts, sizeof(struct tm));
    ts = result;
#endif
#if defined( OPENSSL_SYS_VMS) && !defined( VMS_GMTIME_OK)
    if (ts == NULL) {
        static $DESCRIPTOR(tabnam, "LNM$DCL_LOGICAL");
        static $DESCRIPTOR(lognam, "SYS$TIMEZONE_DIFFERENTIAL");
        char logvalue[256];
        unsigned int reslen = 0;
        struct {
            short buflen;
            short code;
            void *bufaddr;
            unsigned int *reslen;
        } itemlist[] = {
            {
                0, LNM$_STRING, 0, 0
            },
            {
                0, 0, 0, 0
            },
        };
        int status;
        time_t t;

        /* Get the value for SYS$TIMEZONE_DIFFERENTIAL */
        itemlist[0].buflen = sizeof(logvalue);
        itemlist[0].bufaddr = logvalue;
        itemlist[0].reslen = &reslen;
        status = sys$trnlnm(0, &tabnam, &lognam, 0, itemlist);
        if (!(status & 1))
            return NULL;
        logvalue[reslen] = '\0';

        t = *timer;

/* The following is extracted from the DEC C header time.h */
        /*
         **  Beginning in OpenVMS Version 7.0 mktime, time, ctime, strftime
         **  have two implementations.  One implementation is provided
         **  for compatibility and deals with time in terms of local time,
         **  the other __utc_* deals with time in terms of UTC.
         */
        /*
         * We use the same conditions as in said time.h to check if we should
         * assume that t contains local time (and should therefore be
         * adjusted) or UTC (and should therefore be left untouched).
         */
# if __CRTL_VER < 70000000 || defined _VMS_V6_SOURCE
        /* Get the numerical value of the equivalence string */
        status = atoi(logvalue);

        /* and use it to move time to GMT */
        t -= status;
# endif

        /* then convert the result to the time structure */

        /*
         * Since there was no gmtime_r() to do this stuff for us, we have to
         * do it the hard way.
         */
        {
            /*-
             * The VMS epoch is the astronomical Smithsonian date,
               if I remember correctly, which is November 17, 1858.
               Furthermore, time is measure in tenths of microseconds
               and stored in quadwords (64 bit integers).  unix_epoch
               below is January 1st 1970 expressed as a VMS time.  The
               following code was used to get this number:

               #include <stdio.h>
               #include <stdlib.h>
               #include <lib$routines.h>
               #include <starlet.h>

               main()
               {
                 unsigned long systime[2];
                 unsigned short epoch_values[7] =
                   { 1970, 1, 1, 0, 0, 0, 0 };

                 lib$cvt_vectim(epoch_values, systime);

                 printf("%u %u", systime[0], systime[1]);
               }
            */
            unsigned long unix_epoch[2] = { 1273708544, 8164711 };
            unsigned long deltatime[2];
            unsigned long systime[2];
            struct vms_vectime {
                short year, month, day, hour, minute, second, centi_second;
            } time_values;
            long operation;

            /*
             * Turn the number of seconds since January 1st 1970 to an
             * internal delta time. Note that lib$cvt_to_internal_time() will
             * assume that t is signed, and will therefore break on 32-bit
             * systems some time in 2038.
             */
            operation = LIB$K_DELTA_SECONDS;
            status = lib$cvt_to_internal_time(&operation, &t, deltatime);

            /*
             * Add the delta time with the Unix epoch and we have the current
             * UTC time in internal format
             */
            status = lib$add_times(unix_epoch, deltatime, systime);

            /* Turn the internal time into a time vector */
            status = sys$numtim(&time_values, systime);

            /* Fill in the struct tm with the result */
            result->tm_sec = time_values.second;
            result->tm_min = time_values.minute;
            result->tm_hour = time_values.hour;
            result->tm_mday = time_values.day;
            result->tm_mon = time_values.month - 1;
            result->tm_year = time_values.year - 1900;

            operation = LIB$K_DAY_OF_WEEK;
            status = lib$cvt_from_internal_time(&operation,
                                                &result->tm_wday, systime);
            result->tm_wday %= 7;

            operation = LIB$K_DAY_OF_YEAR;
            status = lib$cvt_from_internal_time(&operation,
                                                &result->tm_yday, systime);
            result->tm_yday--;

            result->tm_isdst = 0; /* There's no way to know... */

            ts = result;
        }
    }
#endif
    return ts;
}
Пример #4
0
void	ccp_tr_writedb1(ccp_action_record *rec)
{
	ccp_action_record	request;
	ccp_db_header		*db;
	jnl_buffer		*jb;
	sgmnt_addrs		*csa;
	int4			curr_time[2];
	uint4		status, *p1, *p2, *top;


	if ((db = rec->v.h) == NULL)
		return;

	csa = db->segment;
	assert(csa->nl->ccp_state == CCST_RDMODE  ||  csa->nl->ccp_state == CCST_CLOSED  ||  csa->nl->ccp_state == CCST_OPNREQ);

	if (JNL_ENABLED(csa->hdr))
	{
		assert(csa->jnl->channel != 0);

		jb = csa->jnl->jnl_buff;

		if (jb->blocked != 0)
		{
			/* jnl writes from a previous write mode are not done yet;  try again later */
			if ((status = sys$setimr(0, delta_100_msec, ccp_writedb5, db, 0)) != SS$_NORMAL)
				ccp_signal_cont(status);	/***** Is this reasonable? *****/
			return;
		}

		jb->epoch_tn = db->wm_iosb.valblk[CCP_VALBLK_EPOCH_TN];
		jb->freeaddr = jb->dskaddr
			     = ROUND_UP(db->wm_iosb.valblk[CCP_VALBLK_JNL_ADDR], DISK_BLOCK_SIZE);
		/* lastaddr is no longer a field in jnl_buff
		 *	jb->lastaddr = db->wm_iosb.valblk[CCP_VALBLK_LST_ADDR];
		 */
		jb->free = jb->dsk
			 = 0;
	}

	/* Note:  We must clear these flags prior to changing state or a set from ccp_exitwm_blkast may be missed */
	db->quantum_expired = FALSE;
	db->tick_in_progress = FALSE;

	if (db->remote_wakeup)
	{
		for (p2 = NULL, p1 = csa->lock_addrs[0], top = p1 + SIZEOF(int4) * NUM_CLST_LCKS;
		     *p1 != 0  &&  p1 <= top;
		     ++p1)
		{
			if ((*p1 & NODENUMBER) == (process_id & NODENUMBER))
			{
				crit_wake(p1);
				if (p2 == NULL)
					p2 = p1;
				*p1 = 0;
			}
			else
				if (p2 != NULL)
				{
					*p2++ = *p1;
					*p1 = 0;
				}
		}

		db->remote_wakeup = FALSE;

		status = ccp_enq(0, LCK$K_CRMODE, &db->lock_iosb, LCK$M_CONVERT | LCK$M_SYNCSTS, NULL, 0,
				 ccp_lkrqwake1, db, ccp_lkdowake_blkast, PSL$C_USER, 0);
		/***** Check error status here? *****/
	}

	db->glob_sec->freeze = 0;
	/* db->glob_sec->wcs_active_lvl = db->glob_sec->n_bts / 2; */
	db->drop_lvl = 0;

	sys$gettim(curr_time);
	lib$add_times(curr_time, db->glob_sec->ccp_quantum_interval, &db->start_wm_time);

	csa->nl->ccp_state = CCST_WRTGNT;

	if (db->blocking_ast_received)
	{
		status = sys$dclast(ccp_exitwm_blkast, &db->exitwm_timer_id, PSL$C_USER);
		if (status != SS$_NORMAL)
			ccp_signal_cont(status);	/***** Is this reasonable? *****/
	}

	csa->nl->ccp_crit_blocked = FALSE;
	++csa->nl->ccp_cycle;

	status = sys$setimr(0, &db->glob_sec->ccp_quantum_interval, ccp_quantum_interrupt, &db->quantum_timer_id, 0);
	if (status != SS$_NORMAL)
		ccp_signal_cont(status);	/***** Is this reasonable? *****/

	db->dirty_buffers_acquired = FALSE;
	ccp_pndg_proc_wake(&db->write_wait);

	status = ccp_enq(0, LCK$K_EXMODE, &db->flush_iosb, LCK$M_CONVERT | LCK$M_SYNCSTS, NULL, 0,
			 ccp_reqdrtbuf_interrupt, db, NULL, PSL$C_USER, 0);
	if (status == SS$_SYNCH)
	{
		request.action = CCTR_GOTDRT;
		request.pid = 0;
		request.v.h = db;
		ccp_act_request(&request);
	}
	/***** Check error status here? *****/

}
Пример #5
0
pwr_tUInt32 bck_WaitBackup (
		void *context,
		pwr_tBoolean timeout)
{
  pwr_tUInt32 sts;
  pwr_tObjid objid;
  pwr_tInt32 c;
  pwr_tTime t;
  pwr_tVaxTime tmo;
  pwr_tVaxTime tmptime;
  pwr_sClass_Backup_Conf *backup_confp;	/* Backup_Conf object pointer */
  $DESCRIPTOR (timeunitdsc, "0 0:0:0.1");	/* 0.1 second units */
  int cycletime;

#ifdef OS_ELN
  pwr_tInt32 res;
  pwr_tVaxTime *tmop;
#endif

#ifdef OS_VMS
  $DESCRIPTOR (efcname, BCK_EFC_NAME);
#endif

/*
 * Initialize
 */

#ifdef OS_ELN
  if (!areas_mapped) {
    BCK_MAP_AREAS;
    areas_mapped = TRUE;
  }
#endif

/*
 * Find the local Backup_Conf object
 */

  sts = gdh_GetClassList (pwr_cClass_Backup_Conf, &objid);
  while (ODD (sts)) {
    sts = gdh_ObjidToPointer (objid, (pwr_tAddress *)&backup_confp);
    if (ODD (sts)) break;
    sts = gdh_GetNextObject (objid, &objid);
  }
  if (EVEN (sts)) return sts;		/* Something wrong, quit */

/*
 * Pick up argument information
 */

  if (context == NULL) time_GetTime(&t);
  else {
    t = *(pwr_tTime *)context;
    free (context);
  }

#ifdef OS_ELN
  tmop = NULL;
#else
  timed_out = FALSE;  
  sts = sys$ascefc (BCK_EFC, &efcname, 0, 0);
  if (EVEN (sts)) lib$signal (sts);			/* BUG */
#endif

  if (timeout) {
    cycletime = backup_confp->CycleSlow * 2;
    if (cycletime == 0) cycletime = BCK_DEFAULT_SLOW * 2;

#ifdef OS_ELN
    tmo = eln$time_value (&timeunitdsc);
#else
    sts = sys$bintim (&timeunitdsc, &tmo);
    if (EVEN (sts)) lib$signal (sts);		/* BUG, should not happen */
#endif

    lib$mult_delta_time (
		&cycletime,		/* multiplier */
		&tmo);			/* delta_time (modified) */
    sys$gettim (&tmptime);
    lib$add_times (&tmo, &tmptime, &tmo); /* Make absolute time */

#ifdef OS_ELN
    tmop = &tmo;
#else
    sts = sys$setimr (BCK_WRITE_DONE, &tmo, &astrtn, 4711, 0);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */
#endif
  }

/*
 * Loop, and wait for things to happen
 */

  while (TRUE) {
#ifdef OS_ELN
    ker$clear_event (NULL, bck_write_done);
    ker$wait_any (NULL, &res, tmop, bck_write_done);

    /* Check for timeout */

    if (res == 0) return SS$_TIMEOUT;
#else

    sts = sys$clref (BCK_WRITE_DONE);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */
    sts = sys$waitfr (BCK_WRITE_DONE);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */

    /* Check for timeout */

    if (timed_out) return SS$_TIMEOUT;

#endif

    /* Check if both cycles done */

    if (time_Acomp(&backup_confp->ObjTimeSlow, &t) < 0) 
        continue;
    if (time_Acomp(&backup_confp->ObjTimeFast, &t) < 0) 
        continue;

    break;

  } /* Loop */

#ifdef OS_VMS
  sys$cantim (4711, 0);
#endif

  return 1;	/* Done. */

} /* bck_WaitBackup */
Пример #6
0
struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result)
	{
	struct tm *ts = NULL;

#if defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_OS2) && !defined(__CYGWIN32__) && (!defined(OPENSSL_SYS_VMS) || defined(gmtime_r)) && !defined(OPENSSL_SYS_MACOSX) && !defined(OPENSSL_SYS_SUNOS)
	/* should return &data, but doesn't on some systems,
	   so we don't even look at the return value */
	gmtime_r(timer,result);
	ts = result;
#elif !defined(OPENSSL_SYS_VMS)
	ts = gmtime(timer);
	if (ts == NULL)
		return NULL;

	memcpy(result, ts, sizeof(struct tm));
	ts = result;
#endif
#ifdef OPENSSL_SYS_VMS
	if (ts == NULL)
		{
		static $DESCRIPTOR(tabnam,"LNM$DCL_LOGICAL");
		static $DESCRIPTOR(lognam,"SYS$TIMEZONE_DIFFERENTIAL");
		char logvalue[256];
		unsigned int reslen = 0;
		struct {
			short buflen;
			short code;
			void *bufaddr;
			unsigned int *reslen;
		} itemlist[] = {
			{ 0, LNM$_STRING, 0, 0 },
			{ 0, 0, 0, 0 },
		};
		int status;
		time_t t;

		/* Get the value for SYS$TIMEZONE_DIFFERENTIAL */
		itemlist[0].buflen = sizeof(logvalue);
		itemlist[0].bufaddr = logvalue;
		itemlist[0].reslen = &reslen;
		status = sys$trnlnm(0, &tabnam, &lognam, 0, itemlist);
		if (!(status & 1))
			return NULL;
		logvalue[reslen] = '\0';

		/* Get the numerical value of the equivalence string */
		status = atoi(logvalue);

		/* and use it to move time to GMT */
		t = *timer - status;

		/* then convert the result to the time structure */
#ifndef OPENSSL_THREADS
		ts=(struct tm *)localtime(&t);
#else
		/* Since there was no gmtime_r() to do this stuff for us,
		   we have to do it the hard way. */
		{
		/* The VMS epoch is the astronomical Smithsonian date,
		   if I remember correctly, which is November 17, 1858.
		   Furthermore, time is measure in thenths of microseconds
		   and stored in quadwords (64 bit integers).  unix_epoch
		   below is January 1st 1970 expressed as a VMS time.  The
		   following code was used to get this number:

		   #include <stdio.h>
		   #include <stdlib.h>
		   #include <lib$routines.h>
		   #include <starlet.h>

		   main()
		   {
		     unsigned long systime[2];
		     unsigned short epoch_values[7] =
		       { 1970, 1, 1, 0, 0, 0, 0 };

		     lib$cvt_vectim(epoch_values, systime);

		     printf("%u %u", systime[0], systime[1]);
		   }
		*/
		unsigned long unix_epoch[2] = { 1273708544, 8164711 };
		unsigned long deltatime[2];
		unsigned long systime[2];
		struct vms_vectime
			{
			short year, month, day, hour, minute, second,
				centi_second;
			} time_values;
		long operation;

		/* Turn the number of seconds since January 1st 1970 to
		   an internal delta time.
		   Note that lib$cvt_to_internal_time() will assume
		   that t is signed, and will therefore break on 32-bit
		   systems some time in 2038.
		*/
		operation = LIB$K_DELTA_SECONDS;
		status = lib$cvt_to_internal_time(&operation,
			&t, deltatime);

		/* Add the delta time with the Unix epoch and we have
		   the current UTC time in internal format */
		status = lib$add_times(unix_epoch, deltatime, systime);

		/* Turn the internal time into a time vector */
		status = sys$numtim(&time_values, systime);

		/* Fill in the struct tm with the result */
		result->tm_sec = time_values.second;
		result->tm_min = time_values.minute;
		result->tm_hour = time_values.hour;
		result->tm_mday = time_values.day;
		result->tm_mon = time_values.month - 1;
		result->tm_year = time_values.year - 1900;

		operation = LIB$K_DAY_OF_WEEK;
		status = lib$cvt_from_internal_time(&operation,
			&result->tm_wday, systime);
		result->tm_wday %= 7;

		operation = LIB$K_DAY_OF_YEAR;
		status = lib$cvt_from_internal_time(&operation,
			&result->tm_yday, systime);
		result->tm_yday--;

		result->tm_isdst = 0; /* There's no way to know... */

		ts = result;
#endif
		}
		}
#endif
	return ts;
	}