Sleep utilities and low-CPU waiting.
fpm-watch is primarily poll-based. This module provides two waiting
strategies:
Spin wait (sleep_spin): uses system_clock in a tight loop.
This is portable and offers good timing resolution, but it can consume CPU.
OS sleep (sleep_os): delegates to a small C shim
(fpm_watch_sleep_seconds) which performs an efficient, platform-native
sleep:
Sleep(milliseconds)nanosleep(timespec) (with EINTR retry)The public entry point sleep_seconds dispatches between these strategies
depending on the global low-CPU mode flag set by set_low_cpu.
Sleep or nanosleep) from Fortran can
break linking on the “other” platform even if the routine is never called.sleep_seconds is intentionally lightweight and safe to call frequently.use watch_time, only: set_low_cpu, sleep_seconds
call set_low_cpu(.true.) ! prefer OS sleep (near-zero idle CPU)
call sleep_seconds(0.25) ! sleep for ~250 ms
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| logical, | private, | save | :: | low_cpu_mode | = | .false. |
Global mode switch that selects OS sleep vs spin sleep.
|
C shim providing a portable OS sleep implementation.
The actual platform-specific sleep is implemented in C to prevent
link-time failures that can occur if Fortran directly references
Sleep (Windows) or nanosleep (POSIX) symbols in the same object.
sec: requested sleep duration in seconds.| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=c_double), | value | :: | sec |
Enable or disable low-CPU mode.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| logical, | intent(in) | :: | flag |
Sleep for approximately s seconds.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real, | intent(in) | :: | s |
OS-backed sleep for approximately s seconds.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real, | intent(in) | :: | s |
Busy-wait for approximately s seconds.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real, | intent(in) | :: | s |