| Updated: October 28, 2024 |
Busy-wait without blocking for a number of iterations
#include <time.h> void nanospin_count( unsigned long count );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The nanospin_count() function busy-waits for the number of iterations specified in count. Use nanospin_ns_to_count() to turn a number of nanoseconds into an iteration count suitable for nanospin_count().
Busy-wait for at least 100 nanoseconds:
#include <time.h>
#include <sys/syspage.h>
unsigned long time = 100;
…
/* Wake up the hardware, then wait for it to be ready. */
const unsigned long count = nanospin_ns_to_count( time );
if ( count != -1UL ) {
nanospin_count( count );
} else {
/* Check errno and handle error here somehow */
}
/* Use the hardware. */
…
| Safety: | |
|---|---|
| Cancellation point | No |
| Interrupt handler | Yes |
| Signal handler | Yes |
| Thread | Yes |
You should use busy-waiting only when absolutely necessary for accessing hardware.