This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Busy-wait without thread blocking for a period of time
#include <time.h> int nanospin( const struct timespec *when );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The nanospin() function occupies the CPU for the amount of time specified by the argument when without blocking the calling thread. (The thread isn't taken off the ready list.) The function is essentially a do...while loop.
The nanospin*() functions are designed for use with hardware that requires short time delays between accesses. You should use them to delay only for times less than a few milliseconds. For longer delays, use the POSIX timer_*() functions. |
The first time you call nanospin(), the C library invokes nanospin_calibrate() with an argument of 0 (interrupts enabled), if you haven't already called it.
A delay of more than a few milliseconds might not work on some processors. For longer delays, use the POSIX timer_*() functions. |
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | Read the Caveats |
Signal handler | Yes |
Thread | Yes |
You should use busy-waiting only when absolutely necessary for accessing hardware.
It isn't safe to call this function in an interrupt handler if nanospin_calibrate() hasn't been called yet.
nanosleep(), nanospin_calibrate(), nanospin_count(), nanospin_ns(), nanospin_ns_to_count(), sched_yield(), sleep(), timer_create(), timespec