SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
time.h File Reference

POSIX time extensions for STK: clock_gettime(), clock_getres(), nanosleep(), clock_nanosleep(), usleep(), sleep(), timespec_get() and POSIX timers (timer_create() and friends). Implemented by stk_c_pthread.cpp (no dependency on the STK C API). More...

#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>
Include dependency graph for time.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  sigval
struct  sigevent
struct  itimerspec

Macros

#define _SYS__PTHREADTYPES_H_
#define STK_C_PTHREADTYPES_GUARD
#define CLOCK_REALTIME   (0)
#define CLOCK_MONOTONIC   (1)
#define TIMER_ABSTIME   (1)
#define TIME_UTC   (1)
#define STK_C_DEFINE_SIGEVENT   (1)
 1: this header defines union sigval / struct sigevent / SIGEV_* itself (toolchains which have no definition of their own). 0 (default for newlib and glibc, detected automatically): they come from the toolchain's <signal.h>, include the layer's signal.h to use them with timer_create().
#define SIGEV_NONE   (0)
#define SIGEV_SIGNAL   (1)
#define SIGEV_THREAD   (2)
#define STK_C_TIMERS_MAX   (8U)
 Number of POSIX timers which can exist at the same time.

Typedefs

typedef void * timer_t

Functions

int clock_gettime (clockid_t clk_id, struct timespec *ts)
 Get the current time of a clock.
int clock_getres (clockid_t clk_id, struct timespec *res)
 Get the resolution (one kernel tick) of a clock.
int timespec_get (struct timespec *ts, int base)
 C11 timespec_get(): base must be TIME_UTC (reports the same STK timeline).
int nanosleep (const struct timespec *req, struct timespec *rem)
 Suspend the calling task for a relative time (rounded UP to whole ticks). Cancellation point.
int clock_nanosleep (clockid_t clk_id, int flags, const struct timespec *req, struct timespec *rem)
 Suspend for a relative time or until an absolute time (flags = TIMER_ABSTIME). Cancellation point.
int usleep (useconds_t usec)
 Suspend for usec microseconds. Cancellation point.
unsigned int sleep (unsigned int seconds)
 Suspend for seconds seconds. Cancellation point.
void stk_posix_set_wall_time (int64_t unix_seconds)
 Set the current wall time used by time() and gettimeofday() (see sys/time.h).
void stk_posix_timer_bind_host (void *timer_host)
 Provide the timer host which runs POSIX timers.
int timer_create (clockid_t clk_id, struct sigevent *sevp, timer_t *timerid)
 Create a timer.
int timer_delete (timer_t timerid)
 Delete a timer (waits until a running notification has returned).
int timer_settime (timer_t timerid, int flags, const struct itimerspec *new_value, struct itimerspec *old_value)
 Arm (it_value != 0) or disarm (it_value == 0) a timer.
int timer_gettime (timer_t timerid, struct itimerspec *curr_value)
 Get the time until the next expiration and the period.
int timer_getoverrun (timer_t timerid)
 Get the overrun count. STK does not track overruns.

Detailed Description

POSIX time extensions for STK: clock_gettime(), clock_getres(), nanosleep(), clock_nanosleep(), usleep(), sleep(), timespec_get() and POSIX timers (timer_create() and friends). Implemented by stk_c_pthread.cpp (no dependency on the STK C API).

This header EXTENDS the toolchain's <time.h>: it first includes the standard header (via #include_next on GCC/Clang, or the header named by STK_C_SYSTEM_TIME_H on other compilers) and then adds the declarations above, so it can be placed ahead of the toolchain on the include path.

Clocks: STK has a single time source, the kernel tick counter. CLOCK_MONOTONIC and CLOCK_REALTIME both report the time since the kernel was started (there is no calendar time), with the resolution of a kernel tick. All absolute deadlines of the pthread/semaphore/mqueue timed calls use the same timeline.

Sleeping functions are cancellation points of pthread_cancel() and can be interrupted early (EINTR) by IKernelService::SleepCancel(); timers are provided on top of an application-owned stk::time::TimerHost, see stk_posix_timer_bind_host().

Note
nanosleep()/sleep()/usleep() are ISR-unsafe and not available in HRT mode.

Definition in file time.h.

Macro Definition Documentation

◆ _SYS__PTHREADTYPES_H_

#define _SYS__PTHREADTYPES_H_

Definition at line 36 of file time.h.

◆ CLOCK_MONOTONIC

#define CLOCK_MONOTONIC   (1)

Definition at line 92 of file time.h.

◆ CLOCK_REALTIME

#define CLOCK_REALTIME   (0)

Definition at line 89 of file time.h.

◆ SIGEV_NONE

#define SIGEV_NONE   (0)

Definition at line 185 of file time.h.

Referenced by timer_create().

◆ SIGEV_SIGNAL

#define SIGEV_SIGNAL   (1)

Definition at line 186 of file time.h.

◆ SIGEV_THREAD

#define SIGEV_THREAD   (2)

Definition at line 187 of file time.h.

Referenced by timer_create().

◆ STK_C_DEFINE_SIGEVENT

#define STK_C_DEFINE_SIGEVENT   (1)

1: this header defines union sigval / struct sigevent / SIGEV_* itself (toolchains which have no definition of their own). 0 (default for newlib and glibc, detected automatically): they come from the toolchain's <signal.h>, include the layer's signal.h to use them with timer_create().

Definition at line 166 of file time.h.

◆ STK_C_PTHREADTYPES_GUARD

#define STK_C_PTHREADTYPES_GUARD

Definition at line 37 of file time.h.

◆ STK_C_TIMERS_MAX

#define STK_C_TIMERS_MAX   (8U)

Number of POSIX timers which can exist at the same time.

Definition at line 207 of file time.h.

Referenced by sysconf(), timer_create(), and TimerOf().

◆ TIME_UTC

#define TIME_UTC   (1)

Definition at line 98 of file time.h.

Referenced by timespec_get().

◆ TIMER_ABSTIME

#define TIMER_ABSTIME   (1)

Definition at line 95 of file time.h.

Referenced by clock_nanosleep(), and timer_settime().

Typedef Documentation

◆ timer_t

typedef void* timer_t

Definition at line 157 of file time.h.

Function Documentation

◆ clock_getres()

int clock_getres ( clockid_t clk_id,
struct timespec * res )

Get the resolution (one kernel tick) of a clock.

Returns
0, or -1 with errno = EINVAL.
Warning
ISR-unsafe.

Definition at line 3145 of file stk_c_pthread.cpp.

3146{
3147 int result = -1;
3148
3149 if (!IsSupportedClock(clk_id))
3150 {
3151 errno = EINVAL;
3152 }
3153 else
3154 {
3155 if (res != nullptr)
3156 {
3157 TicksToTimespec(1, res);
3158 }
3159
3160 result = 0;
3161 }
3162
3163 return result;
3164}
static void TicksToTimespec(int64_t ticks, struct timespec *ts)
static bool IsSupportedClock(clockid_t clock_id)

References stk::pthread::IsSupportedClock(), and stk::pthread::TicksToTimespec().

Here is the call graph for this function:

◆ clock_gettime()

int clock_gettime ( clockid_t clk_id,
struct timespec * ts )

Get the current time of a clock.

Parameters
[in]clk_idCLOCK_REALTIME or CLOCK_MONOTONIC (the same STK kernel timeline).
Returns
0, or -1 with errno = EINVAL.
Warning
ISR-unsafe.

Definition at line 3128 of file stk_c_pthread.cpp.

3129{
3130 int result = -1;
3131
3132 if ((ts == nullptr) || !IsSupportedClock(clk_id))
3133 {
3134 errno = EINVAL;
3135 }
3136 else
3137 {
3138 TicksToTimespec(static_cast<int64_t>(stk::GetTicks()), ts); // one timeline for both clocks
3139 result = 0;
3140 }
3141
3142 return result;
3143}
static Ticks GetTicks()
Get number of ticks elapsed since kernel start.
Definition stk_helper.h:448

References stk::GetTicks(), stk::pthread::IsSupportedClock(), and stk::pthread::TicksToTimespec().

Referenced by timespec_get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clock_nanosleep()

int clock_nanosleep ( clockid_t clk_id,
int flags,
const struct timespec * req,
struct timespec * rem )

Suspend for a relative time or until an absolute time (flags = TIMER_ABSTIME). Cancellation point.

Returns
0, or the error number (EINVAL, EINTR); unlike nanosleep() it does not use errno.

Definition at line 3206 of file stk_c_pthread.cpp.

3207{
3208 int result = EINVAL;
3209
3210 if (IsSupportedClock(clk_id) && IsValidTimespec(req) && (req->tv_sec >= 0))
3211 {
3212 if ((flags & TIMER_ABSTIME) != 0)
3213 {
3215
3216 // absolute deadline: sleep for what is left of it (the deadline may be in the past: no sleep)
3217 const Timeout left = TimespecToRelativeTimeout(req);
3218 const int64_t not_slept = (left != NO_WAIT) ? SleepTicksInterruptible(static_cast<int64_t>(left)) : 0LL;
3219
3221
3222 result = (not_slept == 0LL) ? 0 : EINTR;
3223 }
3224 else
3225 {
3226 result = (nanosleep(req, rem) == 0) ? 0 : errno;
3227 }
3228 }
3229
3230 return result;
3231}
#define TIMER_ABSTIME
Definition time.h:95
int nanosleep(const struct timespec *req, struct timespec *rem)
Suspend the calling task for a relative time (rounded UP to whole ticks). Cancellation point.
static constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Definition stk_common.h:280
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:216
static Timeout TimespecToRelativeTimeout(const struct timespec *abstime)
static bool IsValidTimespec(const struct timespec *ts)
static void TestCancelPoint()
static int64_t SleepTicksInterruptible(int64_t ticks)

References stk::pthread::IsSupportedClock(), stk::pthread::IsValidTimespec(), nanosleep(), stk::NO_WAIT, stk::pthread::SleepTicksInterruptible(), stk::pthread::TestCancelPoint(), TIMER_ABSTIME, and stk::pthread::TimespecToRelativeTimeout().

Here is the call graph for this function:

◆ nanosleep()

int nanosleep ( const struct timespec * req,
struct timespec * rem )

Suspend the calling task for a relative time (rounded UP to whole ticks). Cancellation point.

Parameters
[out]remReceives the remaining time if interrupted (may be NULL).
Returns
0, or -1 with errno = EINVAL (invalid req) or EINTR (woken early).

Definition at line 3171 of file stk_c_pthread.cpp.

3172{
3173 int result = -1;
3174
3175 if (!IsValidTimespec(req) || (req->tv_sec < 0))
3176 {
3177 errno = EINVAL;
3178 }
3179 else
3180 {
3182
3183 const int64_t left = SleepTicksInterruptible(
3184 RelativeTicksCeil(static_cast<int64_t>(req->tv_sec), static_cast<int64_t>(req->tv_nsec)));
3185
3187
3188 if (left == 0LL)
3189 {
3190 result = 0;
3191 }
3192 else
3193 {
3194 if (rem != nullptr)
3195 {
3196 TicksToTimespec(left, rem);
3197 }
3198
3199 errno = EINTR;
3200 }
3201 }
3202
3203 return result;
3204}
static int64_t RelativeTicksCeil(int64_t sec, int64_t nsec)

References stk::pthread::IsValidTimespec(), stk::pthread::RelativeTicksCeil(), stk::pthread::SleepTicksInterruptible(), stk::pthread::TestCancelPoint(), and stk::pthread::TicksToTimespec().

Referenced by clock_nanosleep(), sleep(), thrd_sleep(), and usleep().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sleep()

unsigned int sleep ( unsigned int seconds)

Suspend for seconds seconds. Cancellation point.

Returns
0 if the full time elapsed, otherwise the unslept seconds.
Examples
sync/example.cpp.

Definition at line 3243 of file stk_c_pthread.cpp.

3244{
3245 struct timespec ts;
3246 struct timespec rem;
3247 unsigned int result = 0U;
3248
3249 ts.tv_sec = static_cast<time_t>(seconds);
3250 ts.tv_nsec = 0;
3251
3252 if (nanosleep(&ts, &rem) != 0)
3253 {
3254 // unslept seconds, rounded up
3255 result = static_cast<unsigned int>(rem.tv_sec) + ((rem.tv_nsec != 0) ? 1U : 0U);
3256 }
3257
3258 return result;
3259}

References nanosleep().

Referenced by stk::Kernel< TMode, TSize, TStrategy, TPlatform >::KernelTask::HrtOnSwitchedOut(), stk::Kernel< TMode, TSize, TStrategy, TPlatform >::InitTraps(), and CtrlTask< _AccessMode >::Run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stk_posix_set_wall_time()

void stk_posix_set_wall_time ( int64_t unix_seconds)

Set the current wall time used by time() and gettimeofday() (see sys/time.h).

Parameters
[in]unix_secondsSeconds since 1970-01-01 00:00:00 UTC at the moment of the call.
Note
Only time() and gettimeofday() are shifted, the kernel timeline of clock_gettime() and of all deadlines is not changed. Thread-safe, ISR-unsafe.

Definition at line 3360 of file stk_c_pthread.cpp.

3361{
3362 SetWallTimeUs(unix_seconds * 1000000LL);
3363}
static void SetWallTimeUs(int64_t unix_us)

References SetWallTimeUs().

Here is the call graph for this function:

◆ stk_posix_timer_bind_host()

void stk_posix_timer_bind_host ( void * timer_host)

Provide the timer host which runs POSIX timers.

Parameters
[in]timer_hostPointer to an initialized stk::time::TimerHost (task mode), or NULL to unbind. The host is owned by the application (it decides weights, stacks and thread count); without a bound host timer_create() fails with EAGAIN.
Note
Notifications run in a handler task of the host, keep them short.

Definition at line 3594 of file stk_c_pthread.cpp.

3595{
3596 s_TimerHost = static_cast<stk::time::TimerHost *>(timer_host);
3597}
static stk::time::TimerHost * s_TimerHost
Software timer multiplexer that manages multiple Timer instances on top of a small fixed set of kerne...

References s_TimerHost.

◆ timer_create()

int timer_create ( clockid_t clk_id,
struct sigevent * sevp,
timer_t * timerid )

Create a timer.

Parameters
[in]sevpSIGEV_THREAD (the function is called from a timer handler task) or SIGEV_NONE (poll with timer_gettime()). NULL means SIGEV_NONE (there are no signals). SIGEV_SIGNAL gives ENOTSUP.
Returns
0, or -1 with errno = EINVAL, ENOTSUP, EAGAIN (no host bound or no free timer).

Definition at line 3599 of file stk_c_pthread.cpp.

3600{
3601 int err = 0;
3602
3603 if ((timerid == nullptr) || !IsSupportedClock(clk_id))
3604 {
3605 err = EINVAL;
3606 }
3607 else if ((sevp != nullptr) && (sevp->sigev_notify != SIGEV_NONE) && (sevp->sigev_notify != SIGEV_THREAD))
3608 {
3609 err = ENOTSUP; // no signals
3610 }
3611 else if ((sevp != nullptr) && (sevp->sigev_notify == SIGEV_THREAD) && (sevp->sigev_notify_function == nullptr))
3612 {
3613 err = EINVAL;
3614 }
3615 else if (s_TimerHost == nullptr)
3616 {
3617 err = EAGAIN; // stk_posix_timer_bind_host() has not been called
3618 }
3619 else
3620 {
3621 PosixTimer *slot = nullptr;
3622
3623 {
3624 const CsLock cs_;
3625
3626 for (std::size_t i = 0U; (i < STK_C_TIMERS_MAX) && (slot == nullptr); ++i)
3627 {
3628 if (!s_PosixTimers[i].m_used)
3629 {
3630 slot = &s_PosixTimers[i];
3631 slot->m_used = true;
3632 }
3633 }
3634 }
3635
3636 if (slot == nullptr)
3637 {
3638 err = EAGAIN;
3639 }
3640 else
3641 {
3642 const bool thread_notify = (sevp != nullptr) && (sevp->sigev_notify == SIGEV_THREAD);
3643
3644 slot->m_notify = thread_notify ? sevp->sigev_notify_function : nullptr;
3645 slot->m_value = thread_notify ? sevp->sigev_value : slot->m_value;
3646 *timerid = (timer_t)(uintptr_t)slot;
3647 }
3648 }
3649
3650 if (err != 0)
3651 {
3652 errno = err;
3653 }
3654
3655 return (err == 0) ? 0 : -1;
3656}
#define STK_C_TIMERS_MAX
Number of POSIX timers which can exist at the same time.
Definition time.h:207
#define SIGEV_THREAD
Definition time.h:187
void * timer_t
Definition time.h:157
#define SIGEV_NONE
Definition time.h:185
stk::hw::CriticalSection::ScopedLock CsLock
static PosixTimer s_PosixTimers[(8U)]
void(* sigev_notify_function)(union sigval)
Definition time.h:181
union sigval sigev_value
Definition time.h:180
int sigev_notify
Definition time.h:178
void(* m_notify)(union sigval)
union sigval m_value

References stk::pthread::IsSupportedClock(), PosixTimer::m_notify, PosixTimer::m_used, PosixTimer::m_value, s_PosixTimers, s_TimerHost, SIGEV_NONE, sigevent::sigev_notify, sigevent::sigev_notify_function, SIGEV_THREAD, sigevent::sigev_value, and STK_C_TIMERS_MAX.

Here is the call graph for this function:

◆ timer_delete()

int timer_delete ( timer_t timerid)

Delete a timer (waits until a running notification has returned).

Returns
0, or -1 with errno = EINVAL.

Definition at line 3658 of file stk_c_pthread.cpp.

3659{
3660 PosixTimer *const tmr = TimerOf(timerid);
3661 int result = -1;
3662
3663 if ((tmr == nullptr) || (s_TimerHost == nullptr))
3664 {
3665 errno = EINVAL;
3666 }
3667 else
3668 {
3669 // waits until a notification already started by a handler task has returned: the storage can be reused
3670 (void)s_TimerHost->StopSync(*tmr);
3671
3672 {
3673 const CsLock cs_;
3674
3675 tmr->m_notify = nullptr;
3676 tmr->m_used = false;
3677 }
3678
3679 result = 0;
3680 }
3681
3682 return result;
3683}
static PosixTimer * TimerOf(timer_t id)

References PosixTimer::m_notify, PosixTimer::m_used, s_TimerHost, and TimerOf().

Here is the call graph for this function:

◆ timer_getoverrun()

int timer_getoverrun ( timer_t timerid)

Get the overrun count. STK does not track overruns.

Returns
Always 0 for a valid timer, -1 with errno = EINVAL otherwise.

Definition at line 3763 of file stk_c_pthread.cpp.

3764{
3765 int result = 0;
3766
3767 if (TimerOf(timerid) == nullptr)
3768 {
3769 errno = EINVAL;
3770 result = -1;
3771 }
3772
3773 return result;
3774}

References TimerOf().

Here is the call graph for this function:

◆ timer_gettime()

int timer_gettime ( timer_t timerid,
struct itimerspec * curr_value )

Get the time until the next expiration and the period.

Returns
0, or -1 with errno = EINVAL.

Definition at line 3685 of file stk_c_pthread.cpp.

3686{
3687 PosixTimer *const tmr = TimerOf(timerid);
3688 int err = EINVAL;
3689
3690 if ((tmr != nullptr) && (curr_value != nullptr) && (s_TimerHost != nullptr))
3691 {
3693
3694 err = TimerResultToErrno(s_TimerHost->QuerySync(*tmr, info));
3695
3696 if (err == 0)
3697 {
3698 TicksToTimespec(info.active ? static_cast<int64_t>(info.remaining) : 0LL, &curr_value->it_value);
3699 TicksToTimespec(static_cast<int64_t>(info.period), &curr_value->it_interval);
3700 }
3701 }
3702
3703 if (err != 0)
3704 {
3705 errno = err;
3706 }
3707
3708 return (err == 0) ? 0 : -1;
3709}
static int TimerResultToErrno(stk::time::TimerHost::EResult res)
Consistent snapshot of a timer, see QuerySync().
uint32_t remaining
Ticks until the next expiration, 0 if not active or overdue.
uint32_t period
Reload period, 0 for a one-shot timer.
bool active
True if the timer is active.
struct timespec it_interval
Definition time.h:198
struct timespec it_value
Definition time.h:199

References stk::time::TimerHost::TimerInfo::active, itimerspec::it_interval, itimerspec::it_value, stk::time::TimerHost::TimerInfo::period, stk::time::TimerHost::TimerInfo::remaining, s_TimerHost, stk::pthread::TicksToTimespec(), TimerOf(), and TimerResultToErrno().

Referenced by timer_settime().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timer_settime()

int timer_settime ( timer_t timerid,
int flags,
const struct itimerspec * new_value,
struct itimerspec * old_value )

Arm (it_value != 0) or disarm (it_value == 0) a timer.

Parameters
[in]flags0 (relative) or TIMER_ABSTIME. Times are rounded up to whole ticks.
[out]old_valuePrevious setting (may be NULL).
Returns
0, or -1 with errno = EINVAL, EAGAIN (host command queue full), EINTR.
Warning
ISR-unsafe. Do not delete or re-arm a timer from the notification of another timer's host task if that would wait for it (see TimerHost "Synchronous API").

Definition at line 3711 of file stk_c_pthread.cpp.

3712{
3713 PosixTimer *const tmr = TimerOf(timerid);
3714 int err = EINVAL;
3715
3716 if ((tmr != nullptr) && (new_value != nullptr) && (s_TimerHost != nullptr) &&
3717 IsValidTimespec(&new_value->it_value) && IsValidTimespec(&new_value->it_interval) &&
3718 (new_value->it_value.tv_sec >= 0) && (new_value->it_interval.tv_sec >= 0))
3719 {
3720 err = 0;
3721
3722 if (old_value != nullptr)
3723 {
3724 err = (timer_gettime(timerid, old_value) == 0) ? 0 : errno;
3725 }
3726
3727 if (err == 0)
3728 {
3729 const bool disarm = (new_value->it_value.tv_sec == 0) && (new_value->it_value.tv_nsec == 0);
3730
3731 if (disarm)
3732 {
3733 err = TimerResultToErrno(s_TimerHost->StopSync(*tmr));
3734 }
3735 else
3736 {
3737 // first expiration: relative, or what is left until the absolute time (at least one tick)
3738 int64_t delay = ((flags & TIMER_ABSTIME) != 0) ?
3739 static_cast<int64_t>(TimespecToRelativeTimeout(&new_value->it_value)) :
3740 RelativeTicksCeil(static_cast<int64_t>(new_value->it_value.tv_sec),
3741 static_cast<int64_t>(new_value->it_value.tv_nsec));
3742 if (delay < 1LL)
3743 {
3744 delay = 1LL;
3745 }
3746
3747 const int64_t period = RelativeTicksCeil(static_cast<int64_t>(new_value->it_interval.tv_sec),
3748 static_cast<int64_t>(new_value->it_interval.tv_nsec));
3749
3750 err = TimerResultToErrno(s_TimerHost->RestartSync(*tmr, ClampTicks32(delay), ClampTicks32(period)));
3751 }
3752 }
3753 }
3754
3755 if (err != 0)
3756 {
3757 errno = err;
3758 }
3759
3760 return (err == 0) ? 0 : -1;
3761}
int timer_gettime(timer_t timerid, struct itimerspec *curr_value)
Get the time until the next expiration and the period.
static uint32_t ClampTicks32(int64_t ticks)

References ClampTicks32(), stk::pthread::IsValidTimespec(), itimerspec::it_interval, itimerspec::it_value, stk::pthread::RelativeTicksCeil(), s_TimerHost, TIMER_ABSTIME, timer_gettime(), TimerOf(), TimerResultToErrno(), and stk::pthread::TimespecToRelativeTimeout().

Here is the call graph for this function:

◆ timespec_get()

int timespec_get ( struct timespec * ts,
int base )

C11 timespec_get(): base must be TIME_UTC (reports the same STK timeline).

Returns
base on success, 0 otherwise.

Definition at line 3166 of file stk_c_pthread.cpp.

3167{
3168 return ((base == TIME_UTC) && (clock_gettime(CLOCK_REALTIME, ts) == 0)) ? base : 0;
3169}
#define CLOCK_REALTIME
Definition semaphore.h:54
#define TIME_UTC
Definition time.h:98
int clock_gettime(clockid_t clk_id, struct timespec *ts)
Get the current time of a clock.

References clock_gettime(), CLOCK_REALTIME, and TIME_UTC.

Here is the call graph for this function:

◆ usleep()

int usleep ( useconds_t usec)

Suspend for usec microseconds. Cancellation point.

Returns
0, or -1 with errno = EINTR.

Definition at line 3233 of file stk_c_pthread.cpp.

3234{
3235 struct timespec ts;
3236
3237 ts.tv_sec = static_cast<time_t>(usec / 1000000UL);
3238 ts.tv_nsec = static_cast<long>((usec % 1000000UL) * 1000UL);
3239
3240 return nanosleep(&ts, nullptr);
3241}

References nanosleep().

Here is the call graph for this function: