// Copyright 2023 alexevier // licensed under the zlib license #ifndef lexlib_time_h #define lexlib_time_h #include #include"common.h" // accesing its internals is supported but should not be modified // uses real time and millisecond resolution struct LexlibTimer { uint64_t time; uint64_t left; uint64_t last; }; // gets real time. LEXLIB_EXTERN uint64_t lexlibTimeNanos(void); LEXLIB_EXTERN uint64_t lexlibTimeMicros(void); LEXLIB_EXTERN uint64_t lexlibTimeMillis(void); LEXLIB_EXTERN uint64_t lexlibTimeSeconds(void); // gets the cpu time consumed by the thread. LEXLIB_EXTERN uint64_t lexlibThrdNanos(void); LEXLIB_EXTERN uint64_t lexlibThrdMicros(void); LEXLIB_EXTERN uint64_t lexlibThrdMillis(void); LEXLIB_EXTERN uint64_t lexlibThrdSeconds(void); // gets the cpu time consumed by the process. LEXLIB_EXTERN uint64_t lexlibProcNanos(void); LEXLIB_EXTERN uint64_t lexlibProcMicros(void); LEXLIB_EXTERN uint64_t lexlibProcMillis(void); LEXLIB_EXTERN uint64_t lexlibProcSeconds(void); // creates a new LexlibTimer with a initial time. // is started at creation. LEXLIB_EXTERN struct LexlibTimer lexlibTimerNew(uint64_t ms); // sets the time of existing timer LEXLIB_EXTERN void lexlibTimerSet(struct LexlibTimer* timer, uint64_t ms); // add time to a running timer LEXLIB_EXTERN void lexlibTimerAdd(struct LexlibTimer* timer, uint64_t ms); // starts/restarts a timer LEXLIB_EXTERN void lexlibTimerStart(struct LexlibTimer* timer); // updates the state of a timer LEXLIB_EXTERN void lexlibTimerUpdate(struct LexlibTimer* timer); // checks if a timer is done, implicitly calls lexlibTimerUpdate LEXLIB_EXTERN LexlibBool lexlibTimerDone(struct LexlibTimer* timer); // blocks the thread until the timer is done LEXLIB_EXTERN void lexlibTimerUntilDone(struct LexlibTimer* timer); // checks if the timer has finished, does not call lexlibTimerUpdate. LEXLIB_EXTERN LexlibBool lexlibTimerFinished(const struct LexlibTimer* timer); #endif