本文整理汇总了C++中clock_get_time函数的典型用法代码示例。如果您正苦于以下问题:C++ clock_get_time函数的具体用法?C++ clock_get_time怎么用?C++ clock_get_time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clock_get_time函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process_execute
void process_execute(void)
{
// Find first non-empty queue
int qi = 0;
while (qi < NB_PROCESS_EVENT_PRIORITIES && queues[qi].count == 0) {
qi += 1;
}
if (qi == NB_PROCESS_EVENT_PRIORITIES) {
// No events to process
return;
}
// Process one event from the selected queue
struct event e;
struct event_queue* q = &queues[qi];
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
e = q->queue[q->first];
q->count -= 1;
q->first = (q->first + 1) % PROCESS_CONF_EVENT_QUEUE_SIZE;
}
#ifdef PROCESS_STATS
clock_time_t clock_before = clock_get_time();
#endif
e.p->thread(e.p, e.ev, e.data);
#ifdef PROCESS_STATS
clock_time_t duration = clock_get_time() - clock_before;
e.p->time += duration;
#endif
}
示例2: nvstusb_print_refresh_rate
/* Refresh rate calculation */
static void nvstusb_print_refresh_rate(void)
{
static int i_it = 0;
static uint64_t i_last = 0;
static uint64_t i_first = 0;
static uint64_t i_acc_var = 0;
double f_mean, f_var;
/* First frame */
if(i_it == 0) {
struct timespec s_tmp;
#ifdef __MACH__
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
s_tmp.tv_sec = mts.tv_sec;
s_tmp.tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_REALTIME, &s_tmp);
#endif
i_first = (uint64_t)s_tmp.tv_sec*1000000+(uint64_t)s_tmp.tv_nsec/1000;
i_last = i_first;
f_mean = 0;
f_var = 0;
} else {
struct timespec s_tmp;
#ifdef __MACH__
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
s_tmp.tv_sec = mts.tv_sec;
s_tmp.tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_REALTIME, &s_tmp);
#endif
uint64_t i_new = (uint64_t)s_tmp.tv_sec*1000000+(uint64_t)s_tmp.tv_nsec/1000;
/* Update average */
f_mean = (double)(i_new-i_first)/(i_it);
/* Calculate variance */
i_acc_var += pow((double)(i_new-i_last)-f_mean, 2);
/* std dev */
f_var = (double)sqrt(i_acc_var/i_it);
i_last = i_new;
/* Display each 512 frame */
if(i_it % 512 == 0) {
fprintf(stderr,"nvstusb: frame:%d (%0.2f s) mean: %f Hz (%0.2f us) sqrt(var): %0.2f us (%0.1f %%)\n",i_it,f_mean*i_it/1000000.0, 1000000/f_mean, f_mean, f_var, 100.0*f_var/f_mean);
}
}
/* Increment frame counter */
i_it++;
}
示例3: nanosleep
int
nanosleep(const struct timespec *requested_time, struct timespec *remaining_time) {
kern_return_t kret;
int ret;
mach_timespec_t current;
mach_timespec_t completion;
if (__unix_conforming == 0)
__unix_conforming = 1;
#ifdef VARIANT_CANCELABLE
pthread_testcancel();
#endif /* VARIANT_CANCELABLE */
if ((requested_time == NULL) || (requested_time->tv_sec < 0) || (requested_time->tv_nsec >= NSEC_PER_SEC)) {
errno = EINVAL;
return -1;
}
if (remaining_time != NULL) {
/* once we add requested_time, this will be the completion time */
kret = clock_get_time(clock_port, &completion);
if (kret != KERN_SUCCESS) {
fprintf(stderr, "clock_get_time() failed: %s\n", mach_error_string(kret));
errno = EINVAL;
return -1;
}
}
ret = SEMWAIT_SIGNAL(clock_sem, MACH_PORT_NULL, 1, 1, (int64_t)requested_time->tv_sec, (int32_t)requested_time->tv_nsec);
if (ret < 0) {
if (errno == ETIMEDOUT) {
return 0;
} else if (errno == EINTR) {
if (remaining_time != NULL) {
ret = clock_get_time(clock_port, ¤t);
if (ret != KERN_SUCCESS) {
fprintf(stderr, "clock_get_time() failed: %s\n", mach_error_string(ret));
return -1;
}
/* This depends on the layout of a mach_timespec_t and timespec_t being equivalent */
ADD_MACH_TIMESPEC(&completion, requested_time);
/* We have to compare first, since mach_timespect_t contains unsigned integers */
if(CMP_MACH_TIMESPEC(&completion, ¤t) > 0) {
SUB_MACH_TIMESPEC(&completion, ¤t);
remaining_time->tv_sec = completion.tv_sec;
remaining_time->tv_nsec = completion.tv_nsec;
} else {
bzero(remaining_time, sizeof(*remaining_time));
}
}
} else {
errno = EINVAL;
}
}
return -1;
}
示例4: smaccm_thread_calendar
void smaccm_thread_calendar() {
if ((smaccm_calendar_counter % (100 / smaccm_tick_interval)) == 0) {
// MWW: modification of time type to match Ivory/Tower (CAmkES time server uses uint64_t)
int64_t the_time = (int64_t)clock_get_time();
PixhawkProxy_periodic_dispatcher_write_int64_t(&the_time);
}if ((smaccm_calendar_counter % (100 / smaccm_tick_interval)) == 0) {
// MWW: modification of time type to match Ivory/Tower (CAmkES time server uses uint64_t)
int64_t the_time = (int64_t)clock_get_time();
Input_periodic_dispatcher_write_int64_t(&the_time);
}
smaccm_calendar_counter = (smaccm_calendar_counter + 1) % smaccm_hyperperiod_subdivisions;
smaccm_calendar_ticks++;
}
示例5: wTimeNow
void wTimeNow(wTime* time)
{
#if defined(__APPLE__)
// Mac OS does not have clock_gettime, use clock_get_time
// Another option is to use gettimeofday() for both Linux and Mac
// but it's deprecated and not recommended due to not being monotonic
mach_timespec_t mts;
int ret = clock_get_time(gClockServ, &mts);
assert(ret == 0);
time->tv_sec = mts.tv_sec;
time->tv_nsec = mts.tv_nsec;
#elif defined(__linux__)
int ret = clock_gettime(CLOCK_REALTIME, time);
assert(ret == 0);
#elif defined(__WIN32__)
int ret = QueryPerformanceCounter(time);
assert(ret != 0);
#endif
}
示例6: clock_gettime
/*
* Synopsis:
* Emulate Posix clock_gettime() using Mach system routines.
*/
int clock_gettime(clockid_t id, struct timespec *tp)
{
clock_serv_t service_id;
clock_id_t mach_id;
mach_timespec_t now;
kern_return_t status;
switch (id) {
case CLOCK_REALTIME:
mach_id = CALENDAR_CLOCK;
break;
case CLOCK_MONOTONIC:
mach_id = SYSTEM_CLOCK;
break;
default:
errno = EINVAL;
return -1;
}
status = host_get_clock_service(mach_host_self(), mach_id, &service_id);
if (status != KERN_SUCCESS) {
errno = EINVAL;
return -1;
}
status = clock_get_time(service_id, &now);
if (status != KERN_SUCCESS) {
errno = EINVAL;
return -1;
}
tp->tv_sec = now.tv_sec;
tp->tv_nsec = now.tv_nsec;
return 0;
}
示例7: bsp_time
double bsp_time() {
//get init data
const struct mcbsp_thread_data * const data = mcbsp_internal_const_prefunction();
//get stop time
#ifdef __MACH__
//get rights for accessing Mach's timers
const kern_return_t rc1 = host_get_clock_service( mach_host_self(), SYSTEM_CLOCK, &(data->clock) );
if( rc1 != KERN_SUCCESS ) {
fprintf( stderr, "Could not access the Mach system timer (%s)\n", mach_error_string( rc1 ) );
mcbsp_util_fatal();
}
mach_timespec_t stop;
const kern_return_t rc2 = clock_get_time( data->clock, &stop );
if( rc2 != KERN_SUCCESS ) {
fprintf( stderr, "Could not get time at call to bsp_time (%s)\n", mach_error_string( rc2 ) );
mcbsp_util_fatal();
}
#else
struct timespec stop;
clock_gettime( CLOCK_MONOTONIC, &stop);
#endif
//return time
double time = (stop.tv_sec-data->start.tv_sec);
time += (stop.tv_nsec-data->start.tv_nsec)/1000000000.0;
return time;
}
示例8: current_time_monotonic
/* return current monotonic time in milliseconds (ms). */
uint64_t current_time_monotonic(void)
{
uint64_t time;
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
time = (uint64_t)GetTickCount() + add_monotime;
if (time < last_monotime) { /* Prevent time from ever decreasing because of 32 bit wrap. */
uint32_t add = ~0;
add_monotime += add;
time += add;
}
last_monotime = time;
#else
struct timespec monotime;
#if defined(__linux__) && defined(CLOCK_MONOTONIC_RAW)
clock_gettime(CLOCK_MONOTONIC_RAW, &monotime);
#elif defined(__APPLE__)
clock_serv_t muhclock;
mach_timespec_t machtime;
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &muhclock);
clock_get_time(muhclock, &machtime);
mach_port_deallocate(mach_task_self(), muhclock);
monotime.tv_sec = machtime.tv_sec;
monotime.tv_nsec = machtime.tv_nsec;
#else
clock_gettime(CLOCK_MONOTONIC, &monotime);
#endif
time = 1000ULL * monotime.tv_sec + (monotime.tv_nsec / 1000000ULL);
#endif
return time;
}
示例9: ctime_adapter
/*
std::string timestamp::to_string( bool local ) const {
return ctime_adapter(*this).strftime( "%Y-%m-%d, %H:%M:%S" , local);
}
*/
timestamp timestamp::now( void ) {
#if defined( __codex_win32__ )
FILETIME ft;
GetSystemTimeAsFileTime( &ft );
LARGE_INTEGER qp;
qp.HighPart = ft.dwHighDateTime;
qp.LowPart = ft.dwLowDateTime;
int64_t value = qp.QuadPart / 10;
static const int64_t TICK_OFFSET = -11644473600 * 1000 * 1000;
value += TICK_OFFSET;
return timestamp(value);
#elif defined( __codex_linux__ )
struct timespec ts;
int64_t value= 0;
if( clock_gettime( CLOCK_REALTIME , &ts ) == -1 ) {
value = std::time(nullptr) * 1000 * 1000;
} else {
value = ( ts.tv_sec * 1000 * 1000 ) + (ts.tv_nsec / 1000);
}
return timestamp(value);
#elif defined( __codex_apple__ )
struct timespec ts;
int64_t value = 0;
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self() , CALENDAR_CLOCK , &cclock );
clock_get_time( cclock , &mts );
mach_port_deallocate(mach_task_self() , cclock );
ts.tv_sec = mts.tv_sec;
ts.tv_nsec = mts.tv_nsec;
value = ( ts.tv_sec * 1000 * 1000 ) + (ts.tv_nsec / 1000);
return timestamp(value);
#endif
}
示例10: scond_wait_timeout
bool scond_wait_timeout(scond_t *cond, slock_t *lock, unsigned timeout_ms)
{
struct timespec now;
#ifdef __MACH__ // OSX doesn't have clock_gettime ... :(
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
now.tv_sec = mts.tv_sec;
now.tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_REALTIME, &now);
#endif
now.tv_sec += timeout_ms / 1000;
now.tv_nsec += timeout_ms * 1000000L;
now.tv_sec += now.tv_nsec / 1000000000L;
now.tv_nsec = now.tv_nsec % 1000000000L;
int ret = pthread_cond_timedwait(&cond->cond, &lock->lock, &now);
return ret == 0;
}
示例11: hwtimer_arch_now
unsigned long hwtimer_arch_now(void)
{
struct timespec t;
DEBUG("hwtimer_arch_now()\n");
_native_syscall_enter();
#ifdef __MACH__
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
t.tv_sec = mts.tv_sec;
t.tv_nsec = mts.tv_nsec;
#else
if (real_clock_gettime(CLOCK_MONOTONIC, &t) == -1) {
err(EXIT_FAILURE, "hwtimer_arch_now: clock_gettime");
}
#endif
_native_syscall_leave();
native_hwtimer_now = ts2ticks(&t) - time_null;
struct timeval tv;
ticks2tv(native_hwtimer_now, &tv);
DEBUG("hwtimer_arch_now(): it is now %lu s %lu us\n",
(unsigned long)tv.tv_sec, (unsigned long)tv.tv_usec);
DEBUG("hwtimer_arch_now(): returning %lu\n", native_hwtimer_now);
return native_hwtimer_now;
}
示例12: pthread_mutex_lock
bool cResetEvent::Wait(unsigned msec)//Wait for signal , then reset
{
pthread_mutex_lock( &mutx );
if (!state)
{
struct timespec ts;
#if HOST_OS == OS_DARWIN
// OSX doesn't have clock_gettime.
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
ts.tv_sec = mts.tv_sec;
ts.tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_REALTIME, &ts);
#endif
ts.tv_sec += msec / 1000;
ts.tv_nsec += (msec % 1000) * 1000000;
while (ts.tv_nsec > 1000000000)
{
ts.tv_nsec -= 1000000000;
ts.tv_sec++;
}
pthread_cond_timedwait( &cond, &mutx, &ts );
}
bool rc = state;
state=false;
pthread_mutex_unlock( &mutx );
return rc;
}
示例13: hwtimer_arch_now
unsigned long hwtimer_arch_now(void)
{
struct timespec t;
DEBUG("hwtimer_arch_now()\n");
_native_in_syscall = 1;
#ifdef __MACH__
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
t.tv_sec = mts.tv_sec;
t.tv_nsec = mts.tv_nsec;
#else
if (clock_gettime(CLOCK_MONOTONIC, &t) == -1) {
err(1, "hwtimer_arch_now: clock_gettime");
}
#endif
_native_in_syscall = 0;
native_hwtimer_now = ts2ticks(&t) - time_null;
DEBUG("hwtimer_arch_now(): it is now %lu s %lu ns\n",
(unsigned long)t.tv_sec, (unsigned long)t.tv_nsec);
DEBUG("hwtimer_arch_now(): returning %lu\n", native_hwtimer_now);
return native_hwtimer_now;
}
示例14: osfmach3_get_time
void
osfmach3_get_time(
struct timeval *xtime)
{
tvalspec_t cur_time;
#ifdef __powerpc__
if (use_highres && MACH_PORT_VALID(rt_clock)) {
kern_return_t kr;
/*
* We want a higher resolution time: ask the microkernel.
* XXX this doesn't work on MP PowerMac systems.
*/
kr = clock_get_time(rt_clock, &cur_time);
if (kr != KERN_SUCCESS) {
MACH3_DEBUG(2, kr,
("osfmach3_get_time: clock_get_time(0x%x)",
rt_clock));
/* use mapped time */
MTS_TO_TS(serv_mtime, &cur_time);
}
} else {
MTS_TO_TS(serv_mtime, &cur_time);
}
#else /* __powerpc__ */
MTS_TO_TS(serv_mtime, &cur_time);
#endif /* __powerpc__ */
xtime->tv_sec = cur_time.tv_sec + base_time.tv_sec;
xtime->tv_usec = (cur_time.tv_nsec + base_time.tv_nsec) / 1000;
if (xtime->tv_usec >= USEC_PER_SEC) {
xtime->tv_sec++;
xtime->tv_usec -= USEC_PER_SEC;
}
}
示例15: uclock_std_to_uclock
/** @This allocates a new uclock structure.
*
* @param flags flags for the creation of a uclock structure
* @return pointer to uclock, or NULL in case of error
*/
struct uclock *uclock_std_alloc(enum uclock_std_flags flags)
{
#ifdef __MACH__
clock_serv_t cclock;
mach_timespec_t ts;
if (unlikely(host_get_clock_service(mach_host_self(), unlikely(flags & UCLOCK_FLAG_REALTIME) ? CALENDAR_CLOCK : REALTIME_CLOCK, &cclock) < 0)) {
return NULL;
}
if(unlikely(clock_get_time(cclock, &ts) < 0)) {
mach_port_deallocate(mach_task_self(), cclock);
return NULL;
}
#else
struct timespec ts;
if (unlikely(clock_gettime(unlikely(flags & UCLOCK_FLAG_REALTIME) ?
CLOCK_REALTIME : CLOCK_MONOTONIC, &ts) == -1))
return NULL;
#endif
struct uclock_std *uclock_std = malloc(sizeof(struct uclock_std));
if (unlikely(uclock_std == NULL))
return NULL;
uclock_std->flags = flags;
urefcount_init(uclock_std_to_urefcount(uclock_std), uclock_std_free);
uclock_std->uclock.refcount = uclock_std_to_urefcount(uclock_std);
uclock_std->uclock.uclock_now = uclock_std_now;
uclock_std->uclock.uclock_to_real = uclock_std_to_real;
uclock_std->uclock.uclock_from_real = uclock_std_from_real;
#ifdef __MACH__
memcpy(&uclock_std->cclock, &cclock, sizeof(cclock));
#endif
return uclock_std_to_uclock(uclock_std);
}