Пример #1
0
struct timespec TimeBase::systemTimespec() const
{
#ifdef _SYSTEM_LXRT_33_
  if (os::isThisLxrtTask())
  {
    struct timespec time = timespec();
    struct timespec global_now;
    os::gettimeofday(&global_now);

    RTIME rtime_rtai_now = rt_get_time();
    RTIME rtime_global_now = timespec2count(&global_now);
    RTIME rtime_time = timespec2count(&time);

    count2timespec(rtime_time + rtime_rtai_now - rtime_global_now, &time);

    return time;
  }
  else
  {
#endif
    return timespec();
#ifdef _SYSTEM_LXRT_33_
  }
#endif
}
Пример #2
0
void timerfdObj::set_periodically(const timespec &it_interval,
				  struct itimerspec *curr_value)

{
	std::lock_guard<std::mutex> lock(objmutex);

	get_curr_value(curr_value);

	if (it_interval.tv_sec == 0 && it_interval.tv_nsec == 0)
	{
		errno=EINVAL;
		timerfd_settime_failed();
	}

	struct kevent kev;

	EV_SET(&kev, 0, EVFILT_TIMER, EV_ADD, 0,
	       it_interval.tv_sec * 1000 + it_interval.tv_nsec / 1000000, NULL);

	if (KEVENT_POLL(filedesc, &kev, 1, NULL, 0) < 0)
		throw SYSEXCEPTION("kevent");

	timerfd_set=true;
	timerfd_value=timespec();
	timerfd_interval=it_interval;
}
Пример #3
0
struct itimerspec timerfdObj::kqueue_gettime_locked()

{
	struct itimerspec its;

	its.it_value=its.it_interval=timespec();

	if (timerfd_set)
	{
		// Punt for a periodic timer

		if (timerfd_interval.tv_sec == 0 &&
		    timerfd_interval.tv_nsec == 0)
		{
			timespec ts=timespec::getclock(timerfd_clock);

			if (ts < timerfd_value)
				its.it_value=timerfd_value - ts;
		}

		its.it_interval=timerfd_interval;
	}

	return its;
}
Пример #4
0
EXPORT_API U32 udpGetHighPrecisionTime()
{
	timespec spec = timespec();
	clock_gettime(CLOCK_MONOTONIC, &spec);

	return (spec.tv_sec * 1000) + (spec.tv_nsec / 1000 / 1000);
}
Пример #5
0
        /**
        * Create a new UHPacket, using an external buffer allocated from 
        * within a MemoryBatch for the packet content storage. This
        * constructor must be used with placement-new, and requires the
        * memory in m_buffer to be contiguously allocated with this object.
        *
        * This constructor is used by alloc_msg_from_buffer() in 
        * MemoryBatch.hpp; Blocks should use that interface instead.
        *
        *  The Packet's layer 2, 3, and 4 headers will be parsed on demand.
        *
        *  @param  buf_displace offset from *this to the first byte of 
        *                    the packet buffer (should be sizeof(Packet)), unless
        *                    called from a derived class
        *  @param  uh_buf    const_buffer pointing to length and bounds of the 
        *                    buffer to copy the packet from.
        *  @param  uh_id     Version of UH packet
        */        
        UHPacket(memory_not_owned_t,
               size_t                       buf_displace,
               const const_buffer<uint8_t>  &uh_buf,
               int                          uh_id)
        : Packet(memory_not_owned, sizeof(Packet), const_buffer<uint8_t>(), timespec(), 0, 0, MSG_ID(Packet))
		{
			parse_uh(uh_buf);
        }
Пример #6
0
void timerfdObj::set(int flags,
		     const timespec &it_value,
		     struct itimerspec *curr_value)
{
	std::lock_guard<std::mutex> lock(objmutex);

	get_curr_value(curr_value);

	timespec ts=it_value;

	if (flags & TFD_TIMER_ABSTIME)
	{
		timespec now=timespec::getclock(timerfd_clock);

		if (now >= ts)
		{
			ts=timespec();
		}
		else
		{
			ts=it_value - now;
		}
	}

	struct kevent kev;

	EV_SET(&kev, 0, EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0,
	       ts.tv_sec * 1000 + ts.tv_nsec / 1000000, NULL);

	if (kev.data == 0)
		kev.data=1;

	ts=it_value;

	if (!(flags & TFD_TIMER_ABSTIME))
		ts += timespec::getclock(timerfd_clock);

	if (KEVENT_POLL(filedesc, &kev, 1, NULL, 0) < 0)
		throw SYSEXCEPTION("kevent");

	timerfd_set=true;
	timerfd_value=it_value;
	timerfd_interval=timespec();
}
Пример #7
0
struct timespec timeval2timespec(const struct timeval* tv) {
  if (!tv) {
    return timespec();
  }

  struct timespec ts;
  ts.tv_sec = tv->tv_sec;
  ts.tv_nsec = tv->tv_usec * 1000;
  return ts;
}
Пример #8
0
struct timespec mstime2timespec(time64_t mst) {
  if (mst < 0) {
    return timespec();
  }

  timespec ts;
  ts.tv_sec = mst / 1000;
  ts.tv_nsec = (mst % 1000) * 1000000;
  return ts;
}
Пример #9
0
void timerfdObj::set(int flags,
		     const timespec &it_value,
		     struct itimerspec *curr_value)
{
	struct itimerspec dummy;
	struct itimerspec its;

	its.it_value=it_value;
	its.it_interval=timespec();

	if (!curr_value)
		curr_value= &dummy;

	if (timerfd_settime(filedesc, flags, &its, curr_value) < 0)
		timerfd_settime_failed();
}
Пример #10
0
 struct timespec TimeBase::Timespec() const
 {
   return timespec();
 }
Пример #11
0
        /**
        *  Create a new UHPacket, copying the packet content from an existing 
        *  buffer to an internal buffer owned by the UHPacket.
        *
        *  FIXME consider replacing the packet buffer here with a slab
        *        allocator.
        *
        *  @param  uh_buf    const_buffer pointing to length and bounds of the 
        *                    buffer to copy the packet from.
        *  @param  uh_id     Version of UH packet
        *                    
        */        
        UHPacket(const const_buffer<uint8_t> &uh_buf,
               int                           uh_id)
        : Packet(const_buffer<uint8_t>(), timespec(), 0, 0, MSG_ID(Packet))
        {
			parse_uh(uh_buf);
        }
Пример #12
0
    //! Default constructor
    timer()
	:running(false),cstart(0),cstop(0)
    {
    	tsstart = timespec();
    	tsstop = timespec();
    }
Пример #13
0
void timerfdObj::cancel()
{
	set(0, timespec());
}