nanospin()
Busy-wait without thread blocking for a period of time
Synopsis:
#include <time.h>
int nanospin( const struct timespec *when );
Arguments:
- when
- A pointer to a timespec structure that specifies the amount of time to busy-wait for. This is a duration, not an absolute time.
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
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.) This function is essentially a busy-wait loop based on the value returned by ClockCycles().
Because of the nature of time measurement,
the function might actually wait longer than the specified time.
For more information, see the
Understanding the Microkernel's Concept of Time
chapter of the QNX OS Programmer's Guide.
Returns:
- EOK
- Success.
- E2BIG
- The delay specified by when is greater than 500 milliseconds.
Note:A delay of more than a few milliseconds might not work on some processors. For longer delays, use the POSIX timer_*() functions.
- ERANGE
- The frequency of ClockCycles() is greater than 36 GHz and would cause problems with 64-bit math for larger spin times.
Classification:
Safety: | |
---|---|
Cancellation point | No |
Signal handler | Yes |
Thread | Yes |
Caveats:
You should use busy-waiting only when absolutely necessary for accessing hardware.