nanospin_ns()

Updated: April 19, 2023

Busy-wait without blocking for a period of time

Synopsis:

#include <time.h>

int nanospin_ns( unsigned long nsec );

Arguments:

nsec
The number of nanoseconds that you want to busy-wait for.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The nanospin_ns() function busy-waits for the number of nanoseconds specified in nsec, without blocking the calling thread.

Note: 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.

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 Neutrino Programmer's Guide.

Returns:

EOK
Success.
E2BIG
The delay specified by nsec 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:

QNX Neutrino

Safety:  
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes

Caveats:

You should use busy-waiting only when absolutely necessary for accessing hardware.