本文整理汇总了C++中TIMEVAL_TO_TIMESPEC函数的典型用法代码示例。如果您正苦于以下问题:C++ TIMEVAL_TO_TIMESPEC函数的具体用法?C++ TIMEVAL_TO_TIMESPEC怎么用?C++ TIMEVAL_TO_TIMESPEC使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TIMEVAL_TO_TIMESPEC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nc_millisec_to_timespec
struct timespec
nc_millisec_to_timespec (int n_millisec)
{
struct timeval tv = {n_millisec/1000LL, (n_millisec%1000LL)*1000LL};
struct timespec ts;
TIMEVAL_TO_TIMESPEC(&tv, &ts);
return ts;
}
示例2: realtime_gettime
static inline int
realtime_gettime (struct timespec *tp)
{
struct timeval tv;
int retval = gettimeofday (&tv, NULL);
if (retval == 0)
/* Convert into `timespec'. */
TIMEVAL_TO_TIMESPEC (&tv, tp);
return retval;
}
示例3: nc_ms_to_timespec
/*
* Convert ms to timespec structure
*/
struct timespec
nc_ms_to_timespec (int ms)
{
struct timeval tv = {ms/1000LL, (ms%1000LL)*1000LL};
struct timespec ts;
TIMEVAL_TO_TIMESPEC(&tv, &ts);
return ts;
}
示例4: getPthreadTimeout
struct timespec getPthreadTimeout(int millisec) {
timeval now;
struct timespec timeout;
gettimeofday(&now, nullptr);
TIMEVAL_TO_TIMESPEC(&now, &timeout);
timeout.tv_sec += (millisec / 1000);
timeout.tv_nsec += (millisec % 1000) * 1000000;
return timeout;
}
示例5: __futimes
/* Change the access time of the file associated with FD to TVP[0] and
the modification time of FILE to TVP[1].
Starting with 2.6.22 the Linux kernel has the utimensat syscall which
can be used to implement futimes. */
int
__futimes (int fd, const struct timeval tvp[2])
{
/* The utimensat system call expects timespec not timeval. */
struct timespec ts[2];
if (tvp != NULL)
{
if (tvp[0].tv_usec < 0 || tvp[0].tv_usec >= 1000000
|| tvp[1].tv_usec < 0 || tvp[1].tv_usec >= 1000000)
{
__set_errno (EINVAL);
return -1;
}
TIMEVAL_TO_TIMESPEC (&tvp[0], &ts[0]);
TIMEVAL_TO_TIMESPEC (&tvp[1], &ts[1]);
}
return INLINE_SYSCALL (utimensat, 4, fd, NULL, tvp ? &ts : NULL, 0);
}
示例6: unwall_ts
/* time t is wall clock time, convert to time compatible
* with our clock_gettime clock */
time_t unwall_ts(time_t t)
{
struct timespec booth_clk_now, now_tv, res;
struct timeval now;
get_time(&booth_clk_now);
gettimeofday(&now, NULL);
TIMEVAL_TO_TIMESPEC(&now, &now_tv);
time_sub(&now_tv, &booth_clk_now, &res);
return t - res.tv_sec;
}
示例7: __settimeofday
/* Set the current time of day and timezone information.
This call is restricted to the super-user. */
int
__settimeofday (const struct timeval *p, const struct timezone *z)
{
struct timespec tp;
TIMEVAL_TO_TIMESPEC (p, &tp);
if (setntptimeofday (&tp, z)) {
return -1;
}
return 0;
}
示例8: clock_gettime
int
clock_gettime(clockid_t clock_id, struct timespec *tp)
{
struct timeval tv;
int n;
n = gettimeofday(&tv, NULL);
TIMEVAL_TO_TIMESPEC(&tv, tp);
return n;
}
示例9: futimesat
/* Change the access time of FILE relative to FD to TVP[0] and
the modification time of FILE to TVP[1]. */
int
futimesat (int fd, const char *file, const struct timeval tvp[2])
{
struct timespec tsp[2];
int result;
if (tvp)
{
if (tvp[0].tv_usec >= 1000000 || tvp[0].tv_usec < 0 ||
tvp[1].tv_usec >= 1000000 || tvp[1].tv_usec < 0)
{
__set_errno (EINVAL);
return -1;
}
TIMEVAL_TO_TIMESPEC (&tvp[0], &tsp[0]);
TIMEVAL_TO_TIMESPEC (&tvp[1], &tsp[1]);
}
result = INLINE_SYSCALL (utimensat, 4, fd, file, tvp ? tsp : NULL, 0);
return result;
}
示例10: oskit_rtc_get
/*
* Initialize the time of day register.
*/
oskit_error_t
oskit_rtc_get(struct oskit_timespec *time)
{
struct timeval t;
struct timespec ts;
int r = NATIVEOS(gettimeofday)(&t, 0);
/* lets fake local time as MST */
t.tv_sec -= 6 * 60 * 60;
TIMEVAL_TO_TIMESPEC(&t, &ts);
memcpy(time, &ts, sizeof *time);
return r;
}
示例11: reader_thread
static void *
reader_thread (void *nr)
{
struct timespec ts;
struct timespec delay;
int n;
delay.tv_sec = 0;
delay.tv_nsec = DELAY;
for (n = 0; n < READTRIES; ++n)
{
int e;
do
{
struct timeval tv;
(void) gettimeofday (&tv, NULL);
TIMEVAL_TO_TIMESPEC (&tv, &ts);
ts.tv_nsec += TIMEOUT;
if (ts.tv_nsec >= 1000000000)
{
ts.tv_nsec -= 1000000000;
++ts.tv_sec;
}
printf ("reader thread %ld tries again\n", (long int) nr);
e = pthread_rwlock_timedrdlock (&lock, &ts);
if (e != 0 && e != ETIMEDOUT)
{
puts ("timedrdlock failed");
exit (1);
}
}
while (e == ETIMEDOUT);
printf ("reader thread %ld succeeded\n", (long int) nr);
nanosleep (&delay, NULL);
if (pthread_rwlock_unlock (&lock) != 0)
{
puts ("unlock for reader failed");
exit (1);
}
printf ("reader thread %ld released\n", (long int) nr);
}
return NULL;
}
示例12: gettimeofday
/**
* thread which regularly scans hashtable for expired buckets/flows
*/
void BaseAggregator::exporterThread()
{
struct timeval inttimer;
gettimeofday(&inttimer, 0);
//struct timeval difftime;
//REQUIRE(timeval_subtract(&difftime, &stoptime, &starttime) == 0);
/*timespec req;
req.tv_sec = pollInterval / 1000;
req.tv_nsec = (pollInterval % 1000) * 1000;*/
registerCurrentThread();
msg(MSG_INFO, "Polling aggregator each %u msec", pollInterval);
while (!exitFlag) {
addToCurTime(&inttimer, pollInterval);
struct timeval curtime;
gettimeofday(&curtime, 0);
struct timeval difftime;
if (timeval_subtract(&difftime, &inttimer, &curtime)!=1) {
// restart nanosleep with the remaining sleep time
// if we got interrupted by a signal
struct timespec ts;
TIMEVAL_TO_TIMESPEC(&difftime, &ts);
while (nanosleep(&ts, &ts) == -1 && errno == EINTR);
}
gettimeofday(&curtime, 0);
msg(MSG_VDEBUG,"Aggregator: starting Export");
for (size_t i = 0; i < rules->count; i++) {
rules->rule[i]->hashtable->expireFlows();
}
struct timeval endtime;
gettimeofday(&endtime, 0);
timeval_subtract(&difftime, &endtime, &curtime);
msg (MSG_VDEBUG,"Aggregator: export took %.03f secs", (float)difftime.tv_usec/1000000+difftime.tv_sec);
}
if (getShutdownProperly()) {
for (size_t i = 0; i < rules->count; i++) {
rules->rule[i]->hashtable->expireFlows(true);
}
}
unregisterCurrentThread();
}
示例13: pthread_timedjoin_np
extern "C" int pthread_timedjoin_np(pthread_t thread, void **retval,
const struct timespec *abstime)
{
int ret;
if (!dmtcp::ProcessInfo::instance().beginPthreadJoin(thread)) {
return EINVAL;
}
/*
* We continue to call pthread_tryjoin_np (and sleep) until we have gone past
* the abstime provided by the caller
*/
while (1) {
struct timeval tv;
struct timespec ts;
JASSERT(gettimeofday(&tv, NULL) == 0);
TIMEVAL_TO_TIMESPEC(&tv, &ts);
WRAPPER_EXECUTION_DISABLE_CKPT();
ret = _real_pthread_tryjoin_np(thread, retval);
WRAPPER_EXECUTION_ENABLE_CKPT();
if (ret == 0) {
break;
}
if (ts.tv_sec > abstime->tv_sec || (ts.tv_sec == abstime->tv_sec &&
ts.tv_nsec > abstime->tv_nsec)) {
ret = ETIMEDOUT;
break;
}
const struct timespec timeout = {(time_t) 0, (long)100 * 1000 * 1000};
nanosleep(&timeout, NULL);
}
#ifdef PTRACE
/* Wrap the call to pthread_join() to make sure we call
* delete_thread_on_pthread_join().
* FIXME: MTCP:process_pthread_join(thread) is calling threadisdead() THIS
* SHOULDN'T BE NECESSARY.
*/
if (ret == 0) {
mtcpFuncPtrs.process_pthread_join(thread);
}
#endif
dmtcp::ProcessInfo::instance().endPthreadJoin(thread);
return ret;
}
示例14: ca_get_current_time
struct timespec ca_get_current_time()
{
#if defined(__ANDROID__) || _POSIX_TIMERS > 0
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
struct timespec ts;
TIMEVAL_TO_TIMESPEC(&tv, &ts);
return ts;
#endif
}
示例15: tf
static void *
tf (void *a)
{
/* Block SIGUSR1. */
sigset_t ss;
pthread_setschedparam_np(0, SCHED_FIFO, 0, 0xF, PTHREAD_HARD_REAL_TIME_NP);
sigemptyset (&ss);
sigaddset (&ss, SIGUSR1);
if (BLOCK_SIG && pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
{
puts ("child: sigmask failed");
exit (1);
}
if (pthread_mutex_lock (&m) != 0)
{
puts ("child: mutex_lock failed");
exit (1);
}
int e = pthread_barrier_wait (&b);
if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
{
puts ("child: barrier_wait failed");
exit (1);
}
/* Compute timeout. */
struct timeval tv;
(void) gettimeofday (&tv, NULL);
struct timespec ts;
TIMEVAL_TO_TIMESPEC (&tv, &ts);
// RTAI
clock_gettime(CLOCK_MONOTONIC, &ts);
/* Timeout: 1sec. */
ts.tv_sec += 1;
/* This call should never return. */
if (pthread_cond_timedwait (&c, &m, &ts) != ETIMEDOUT)
{
puts ("cond_timedwait didn't time out");
exit (1);
}
return NULL;
}