| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
SDL3.Sys.Timer
Contents
Description
SDL provides time management functionality. It is useful for dealing with (usually) small durations of time.
This is not to be confused with calendar time management, which is provided by CategoryTime.
This category covers measuring time elapsed (, getTicks), putting a thread to sleep for a certain amount of time (getPerformanceCounter, delay, delayNS), and firing a callback function after a certain amount of time has elapsed (delayPrecise, etc).addTimer
There are also useful macros to convert between time units, like and such. Number of milliseconds in a second.secondsToNs
This is always 1000.
FFI conventions
Unsuffixed aliases are unsafe foreign imports; aliases suffixed Safe are safe. Functions whose callbacks fire during the call export only the Safe alias (the genuine unsafe import stays reachable under SDL3.Sys.Bindgen.Timer.Unsafe); functions curated unsafe-only export only the unsuffixed one. Each alias's documentation records its flavor and rationale.
The C shims are functions this package defines in C over what the FFI cannot call directly (variadic functions, function-like macros), each named after what it wraps; the same flavor rules apply. Their raw imports live under SDL3.Sys.Bindgen.TimerShims.
Full conventions: SDL3.Sys.
Since: 3.2.0
Synopsis
- module SDL3.Sys.Bindgen.Timer
- getTicks :: IO Word64
- getTicksNS :: IO Word64
- getPerformanceCounter :: IO Word64
- getPerformanceFrequency :: IO Word64
- delay :: Word32 -> IO ()
- delaySafe :: Word32 -> IO ()
- delayNS :: Word64 -> IO ()
- delayNSSafe :: Word64 -> IO ()
- delayPrecise :: Word64 -> IO ()
- delayPreciseSafe :: Word64 -> IO ()
- addTimer :: Word32 -> SDL_TimerCallback -> Ptr Void -> IO SDL_TimerID
- addTimerSafe :: Word32 -> SDL_TimerCallback -> Ptr Void -> IO SDL_TimerID
- addTimerNS :: Word64 -> SDL_NSTimerCallback -> Ptr Void -> IO SDL_TimerID
- addTimerNSSafe :: Word64 -> SDL_NSTimerCallback -> Ptr Void -> IO SDL_TimerID
- removeTimer :: SDL_TimerID -> IO Bool
- removeTimerSafe :: SDL_TimerID -> IO Bool
- secondsToNs :: Word64 -> IO Word64
- msToNs :: Word64 -> IO Word64
- usToNs :: Word64 -> IO Word64
Documentation
module SDL3.Sys.Bindgen.Timer
Function aliases
getTicks :: IO Word64 Source #
Get the number of milliseconds that have elapsed since the SDL library initialization.
- Returns
- an unsigned 64‑bit integer that represents the number of milliseconds that have elapsed since the SDL library was initialized (typically via a call to SDL_Init).
- Thread safety
- It is safe to call this function from any thread.
- See also
getTicksNS
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_GetTicks. The safe import is not exported : reads a monotonic clock value; cannot block, lock, or call back. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_GetTicks, defined atSDL3/SDL_timer.h 201:36
Since: 3.2.0
getTicksNS :: IO Word64 Source #
Get the number of nanoseconds since SDL library initialization.
- Returns
- an unsigned 64-bit value representing the number of nanoseconds since the SDL library initialized.
- Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_GetTicksNS. The safe import is not exported : reads a monotonic clock value; cannot block, lock, or call back. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_GetTicksNS, defined atSDL3/SDL_timer.h 213:36
Since: 3.2.0
getPerformanceCounter :: IO Word64 Source #
Get the current value of the high resolution counter.
This function is typically used for profiling.
The counter values are only meaningful relative to each other. Differences between values can be converted to times by using .getPerformanceFrequency
- Returns
- the current counter value.
- Thread safety
- It is safe to call this function from any thread.
- See also
getPerformanceFrequency
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_GetPerformanceCounter. The safe import is not exported : reads a monotonic clock value; cannot block, lock, or call back. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_GetPerformanceCounter, defined atSDL3/SDL_timer.h 232:36
Since: 3.2.0
getPerformanceFrequency :: IO Word64 Source #
Get the count per second of the high resolution counter.
- Returns
- a platform-specific count per second.
- Thread safety
- It is safe to call this function from any thread.
- See also
getPerformanceCounter
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_GetPerformanceFrequency. The safe import is not exported : reads a monotonic clock value; cannot block, lock, or call back. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_GetPerformanceFrequency, defined atSDL3/SDL_timer.h 245:36
Since: 3.2.0
Wait a specified number of milliseconds before returning.
This function waits a specified number of milliseconds before returning. It waits at least the specified time, but possibly longer due to OS scheduling.
- Thread safety
- It is safe to call this function from any thread.
- See also
delayNS,delayPrecise
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_Delay. The safe flavor isdelaySafe: sleeps the OS thread; an unsafe call stalls every capability and GC for the duration. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_Delay, defined atSDL3/SDL_timer.h 263:34
Since: 3.2.0
Wait a specified number of milliseconds before returning.
This function waits a specified number of milliseconds before returning. It waits at least the specified time, but possibly longer due to OS scheduling.
- Thread safety
- It is safe to call this function from any thread.
- See also
delayNS,delayPrecise
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_Delay. The unsafe flavor isdelay: sleeps the OS thread; an unsafe call stalls every capability and GC for the duration. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_Delay, defined atSDL3/SDL_timer.h 263:34
Since: 3.2.0
Wait a specified number of nanoseconds before returning.
This function waits a specified number of nanoseconds before returning. It waits at least the specified time, but possibly longer due to OS scheduling.
- Thread safety
- It is safe to call this function from any thread.
- See also
delay,delayPrecise
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_DelayNS. The safe flavor isdelayNSSafe: sleeps the OS thread; an unsafe call stalls every capability and GC for the duration. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_DelayNS, defined atSDL3/SDL_timer.h 281:34
Since: 3.2.0
Wait a specified number of nanoseconds before returning.
This function waits a specified number of nanoseconds before returning. It waits at least the specified time, but possibly longer due to OS scheduling.
- Thread safety
- It is safe to call this function from any thread.
- See also
delay,delayPrecise
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_DelayNS. The unsafe flavor isdelayNS: sleeps the OS thread; an unsafe call stalls every capability and GC for the duration. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_DelayNS, defined atSDL3/SDL_timer.h 281:34
Since: 3.2.0
Wait a specified number of nanoseconds before returning.
This function waits a specified number of nanoseconds before returning. It will attempt to wait as close to the requested time as possible, busy waiting if necessary, but could return later due to OS scheduling.
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_DelayPrecise. The safe flavor isdelayPreciseSafe: sleeps the OS thread; an unsafe call stalls every capability and GC for the duration. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_DelayPrecise, defined atSDL3/SDL_timer.h 299:34
Since: 3.2.0
Wait a specified number of nanoseconds before returning.
This function waits a specified number of nanoseconds before returning. It will attempt to wait as close to the requested time as possible, busy waiting if necessary, but could return later due to OS scheduling.
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_DelayPrecise. The unsafe flavor isdelayPrecise: sleeps the OS thread; an unsafe call stalls every capability and GC for the duration. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_DelayPrecise, defined atSDL3/SDL_timer.h 299:34
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> SDL_TimerCallback |
|
| -> Ptr Void |
|
| -> IO SDL_TimerID |
Call a callback function at a future time.
The callback function is passed the current timer interval and the user supplied parameter from the call and should return the next timer interval. If the value returned from the callback is 0, the timer is canceled and will be removed.addTimer
The callback is run on a separate thread, and for short timeouts can potentially be called before this function returns.
Timers take into account the amount of time it took to execute the callback. For example, if the callback took 250 ms to execute and returned 1000 (ms), the timer would only wait another 750 ms before its next iteration.
Timing may be inexact due to OS scheduling. Be sure to note the current time with or getTicksNS in case your callback needs to adjust for variances.getPerformanceCounter
- Returns
- a timer ID or 0 on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
addTimerNS,removeTimer
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_AddTimer. The safe flavor isaddTimerSafe: registration; the timer fires on SDL's timer thread. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_AddTimer, defined atSDL3/SDL_timer.h 368:41
Since: 3.2.0
Arguments
| :: Word32 |
|
| -> SDL_TimerCallback |
|
| -> Ptr Void |
|
| -> IO SDL_TimerID |
Call a callback function at a future time.
The callback function is passed the current timer interval and the user supplied parameter from the call and should return the next timer interval. If the value returned from the callback is 0, the timer is canceled and will be removed.addTimer
The callback is run on a separate thread, and for short timeouts can potentially be called before this function returns.
Timers take into account the amount of time it took to execute the callback. For example, if the callback took 250 ms to execute and returned 1000 (ms), the timer would only wait another 750 ms before its next iteration.
Timing may be inexact due to OS scheduling. Be sure to note the current time with or getTicksNS in case your callback needs to adjust for variances.getPerformanceCounter
- Returns
- a timer ID or 0 on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
addTimerNS,removeTimer
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_AddTimer. The unsafe flavor isaddTimer: registration; the timer fires on SDL's timer thread. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_AddTimer, defined atSDL3/SDL_timer.h 368:41
Since: 3.2.0
Arguments
| :: Word64 |
|
| -> SDL_NSTimerCallback |
|
| -> Ptr Void |
|
| -> IO SDL_TimerID |
Call a callback function at a future time.
The callback function is passed the current timer interval and the user supplied parameter from the call and should return the next timer interval. If the value returned from the callback is 0, the timer is canceled and will be removed.addTimerNS
The callback is run on a separate thread, and for short timeouts can potentially be called before this function returns.
Timers take into account the amount of time it took to execute the callback. For example, if the callback took 250 ns to execute and returned 1000 (ns), the timer would only wait another 750 ns before its next iteration.
Timing may be inexact due to OS scheduling. Be sure to note the current time with or getTicksNS in case your callback needs to adjust for variances.getPerformanceCounter
- Returns
- a timer ID or 0 on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
addTimer,removeTimer
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_AddTimerNS. The safe flavor isaddTimerNSSafe: registration; the timer fires on SDL's timer thread. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_AddTimerNS, defined atSDL3/SDL_timer.h 430:41
Since: 3.2.0
Arguments
| :: Word64 |
|
| -> SDL_NSTimerCallback |
|
| -> Ptr Void |
|
| -> IO SDL_TimerID |
Call a callback function at a future time.
The callback function is passed the current timer interval and the user supplied parameter from the call and should return the next timer interval. If the value returned from the callback is 0, the timer is canceled and will be removed.addTimerNS
The callback is run on a separate thread, and for short timeouts can potentially be called before this function returns.
Timers take into account the amount of time it took to execute the callback. For example, if the callback took 250 ns to execute and returned 1000 (ns), the timer would only wait another 750 ns before its next iteration.
Timing may be inexact due to OS scheduling. Be sure to note the current time with or getTicksNS in case your callback needs to adjust for variances.getPerformanceCounter
- Returns
- a timer ID or 0 on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
addTimer,removeTimer
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_AddTimerNS. The unsafe flavor isaddTimerNS: registration; the timer fires on SDL's timer thread. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_AddTimerNS, defined atSDL3/SDL_timer.h 430:41
Since: 3.2.0
Arguments
| :: SDL_TimerID |
|
| -> IO Bool |
Remove a timer created with .addTimer
- Returns
- true on success or false on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
addTimer
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
SDL_RemoveTimer. The safe flavor isremoveTimerSafe. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_RemoveTimer, defined atSDL3/SDL_timer.h 445:34
Since: 3.2.0
Arguments
| :: SDL_TimerID |
|
| -> IO Bool |
Remove a timer created with .addTimer
- Returns
- true on success or false on failure; call
getErrorfor more information. - Thread safety
- It is safe to call this function from any thread.
- See also
addTimer
sdl3-bindgen-sys notes
- FFI safety
- Safe foreign import of
SDL_RemoveTimer. The unsafe flavor isremoveTimer. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
SDL_RemoveTimer, defined atSDL3/SDL_timer.h 445:34
Since: 3.2.0
C shims
Convert seconds to nanoseconds.
The SDL_SECONDS_TO_NS macro as a function. This only converts whole numbers, not fractional seconds.
- Returns
s, expressed in nanoseconds.- Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
lithon_SDL_SECONDS_TO_NS. The safe import is not exported : pure math on immediate values; cannot block, lock, or call back. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
lithon_SDL_SECONDS_TO_NS, defined atsdl3-bindgen-sys/SDL_timer_shims.h 37:26
Since: 3.2.0
Convert milliseconds to nanoseconds.
The SDL_MS_TO_NS macro as a function. This only converts whole numbers, not fractional milliseconds.
- Returns
ms, expressed in nanoseconds.- Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
lithon_SDL_MS_TO_NS. The safe import is not exported : pure math on immediate values; cannot block, lock, or call back. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
lithon_SDL_MS_TO_NS, defined atsdl3-bindgen-sys/SDL_timer_shims.h 55:26
Since: 3.2.0
Convert microseconds to nanoseconds.
The SDL_US_TO_NS macro as a function. This only converts whole numbers, not fractional microseconds.
- Returns
us, expressed in nanoseconds.- Thread safety
- It is safe to call this function from any thread.
sdl3-bindgen-sys notes
- FFI safety
- Unsafe foreign import of
lithon_SDL_US_TO_NS. The safe import is not exported : pure math on immediate values; cannot block, lock, or call back. - Scalars
- The binding generation has mapped C scalars to native Haskell scalars for this function. Pointers and structs are untouched by this best-effort mapping. Higher-level bindings are expected to map structs and pointers as appropriate.
- C declaration
lithon_SDL_US_TO_NS, defined atsdl3-bindgen-sys/SDL_timer_shims.h 73:26
Since: 3.2.0