ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
time.c File Reference

⏱️ High-precision timing utilities implementation More...

Go to the source code of this file.

Macros

#define SOKOL_TIME_IMPL
 

Functions

uint64_t time_get_ns (void)
 Get current monotonic time in nanoseconds.
 
uint64_t time_get_realtime_ns (void)
 Get current wall-clock (real) time in nanoseconds.
 
void time_sleep_ns (uint64_t ns)
 Sleep for specified nanoseconds.
 
uint64_t time_elapsed_ns (uint64_t start_ns, uint64_t end_ns)
 Calculate elapsed time with wraparound safety.
 
uint64_t time_timespec_to_ns (const struct timespec *ts)
 Convert struct timespec to nanoseconds.
 
void time_ns_to_timespec (uint64_t ns, struct timespec *ts)
 Convert nanoseconds to struct timespec.
 
bool timer_system_init (void)
 Initialize the timing system.
 
void timer_system_destroy (void)
 Cleanup the timing system.
 
bool timer_start (const char *name)
 Start a named timer.
 
double timer_stop (const char *name)
 Stop a named timer and return elapsed time.
 
bool timer_is_initialized (void)
 Check if timing system is initialized.
 
int format_uptime_hms (int hours, int minutes, int seconds, char *buffer, size_t buffer_size)
 Format uptime as HH:MM:SS string.
 
int time_pretty (uint64_t nanoseconds, int decimals, char *buffer, size_t buffer_size)
 Format nanoseconds as pretty duration with spaces and configurable precision.
 
int time_pretty_now (int decimals, char *buffer, size_t buffer_size)
 Format current monotonic time as pretty duration.
 
int time_human_readable_unsigned (uint64_t nanoseconds, char *buffer, size_t buffer_size)
 Format elapsed time as human-readable relative duration (unsigned version)
 
int time_human_readable (int64_t nanoseconds, char *buffer, size_t buffer_size)
 Format nanoseconds as human-readable relative duration (moment.js style)
 
int time_human_readable_now (char *buffer, size_t buffer_size)
 Format current monotonic time as human-readable relative duration.
 
void adaptive_sleep_init (adaptive_sleep_state_t *state, const adaptive_sleep_config_t *config)
 Initialize adaptive sleep state with configuration.
 
uint64_t adaptive_sleep_calculate (adaptive_sleep_state_t *state, size_t queue_depth, size_t target_depth)
 Calculate adaptive sleep time based on queue depth.
 
void adaptive_sleep_do (adaptive_sleep_state_t *state, size_t queue_depth, size_t target_depth)
 Calculate sleep time and immediately sleep for that duration.
 
bool time_format_is_valid_strftime (const char *format_str)
 Validate strftime format string against known safe specifiers.
 
int time_format_now (const char *format_str, char *buf, size_t buf_size)
 Format current time using strftime format string.
 
asciichat_error_t time_format_safe (const char *format_str, char *buf, size_t buf_size)
 Safe wrapper for time formatting with validation and error codes.
 

Detailed Description

⏱️ High-precision timing utilities implementation

Definition in file util/time.c.

Macro Definition Documentation

◆ SOKOL_TIME_IMPL

#define SOKOL_TIME_IMPL

Definition at line 11 of file util/time.c.

Variable Documentation

◆ lifecycle

lifecycle_t lifecycle

Lifecycle state machine for init/shutdown synchronization.

Definition at line 35 of file util/time.c.

◆ rwlock

rwlock_t rwlock

Read-write lock for thread-safe access (uthash requires external locking)

Definition at line 34 of file util/time.c.

Referenced by rwlock_format_state(), rwlock_init(), rwlock_log_state(), rwlock_on_rdlock(), rwlock_on_unlock(), rwlock_on_wrlock(), rwlock_rdlock_impl(), rwlock_rdunlock_impl(), rwlock_wrlock_impl(), and rwlock_wrunlock_impl().

◆ timers

timer_record_t* timers

Hash table of active timers (uthash head pointer)

Definition at line 33 of file util/time.c.