Suspend a thread until a timeout or signal occurs, using a specified clock
#include <time.h> int clock_nanosleep( clockid_t clock_id, int flags, const struct timespec * rqtp, struct timespec * rmtp );
While the processor isn't in a power-saving mode, CLOCK_SOFTTIME behaves the same as CLOCK_REALTIME.
The clock_nanosleep() function fails if the clock_id argument refers to the CPU-time clock of the calling thread.
For more information about the different clocks, see Other clock sources in the Clocks, Timers, and Getting a Kick Every So Often of Getting Started with QNX Neutrino.
If, at the time of the call, the time value specified by rqtp is less than or equal to the time value of the specified clock, then clock_nanosleep() returns immediately, and the calling process isn't suspended.
When TIMER_ABSTIME is not set, the time specified by the rqtp argument is an interval. The current thread is suspended from execution until this interval has elapsed.
Calling clock_nanosleep() with TIMER_ABSTIME not set and clock_id set to CLOCK_REALTIME is equivalent to calling nanosleep() with the same rqtp and rmtp arguments.
Although timespec has a resolution of nanoseconds, the resolution on the sleep period depends on the clock used (usually ClockPeriod()).
For the relative clock_nanosleep() function, if rmtp isn't NULL, the timespec structure referenced by it is updated to contain the amount of time remaining in the interval (the requested time minus the time actually slept). If it's NULL, the remaining time isn't returned.
The absolute clock_nanosleep() function has no effect on the structure referenced by rmtp.
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The clock_nanosleep() function suspends the current thread from execution until:
Or:
Or:
At the end of the suspension, the thread becomes READY and is scheduled to run as normal, based on priority and the scheduling algorithm.
The nanosleep() function always uses CLOCK_REALTIME.
The suspension time may be longer than requested because the argument value is rounded up to a multiple of the sleep resolution (see the Understanding the Microkernel's Concept of Time chapter of the QNX Neutrino Programmer's Guide) or because of scheduling and other system activity. Except for the case of being interrupted by a signal, the suspension time for:
Using the clock_nanosleep() function has no effect on the action or blockage of any signal.
Zero if the requested time has elapsed, or a corresponding error value if clock_nanosleep() has been interrupted by a signal, or fails.
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |