ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
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 UTIL_TIME_TEMP_BUFFER_SIZE   64
#define SOKOL_TIME_IMPL

Functions

void time_sleep_ns (uint64_t ns)
 Configuration for adaptive sleep behavior.
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.
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 a compact duration with configurable sub-minute 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 time.c.

Macro Definition Documentation

◆ SOKOL_TIME_IMPL

#define SOKOL_TIME_IMPL

Definition at line 14 of file time.c.

◆ UTIL_TIME_TEMP_BUFFER_SIZE

#define UTIL_TIME_TEMP_BUFFER_SIZE   64

Definition at line 8 of file time.c.

Referenced by time_pretty().

Variable Documentation

◆ lifecycle

lifecycle_t lifecycle

Lifecycle state machine for init/shutdown synchronization.

Definition at line 40 of file time.c.

◆ rwlock

rwlock_t rwlock

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

Definition at line 39 of file time.c.

Referenced by debug_sync_rwlock_rdlock(), debug_sync_rwlock_rdunlock(), debug_sync_rwlock_wrlock(), debug_sync_rwlock_wrunlock(), rwlock_log_state(), rwlock_on_rdlock(), rwlock_on_unlock(), and rwlock_on_wrlock().

◆ timers

timer_record_t* timers

Hash table of active timers (uthash head pointer).

Definition at line 38 of file time.c.