--- parser3/src/include/pa_os.h 2023/09/26 20:49:07 1.13 +++ parser3/src/include/pa_os.h 2026/11/21 23:38:25 1.21 @@ -1,20 +1,23 @@ /** @file Parser: commonly used functions. - Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) Authors: Konstantin Morshnev , Alexandr Petrosian */ #ifndef PA_OS_H #define PA_OS_H -#define IDENT_PA_OS_H "$Id: pa_os.h,v 1.13 2023/09/26 20:49:07 moko Exp $" +#define IDENT_PA_OS_H "$Id: pa_os.h,v 1.21 2026/11/21 23:38:25 moko Exp $" #define PA_LOCK_ATTEMPTS 20 #define PA_LOCK_WAIT_TIMEOUT_SECS 0 #define PA_LOCK_WAIT_TIMEOUT_USECS 500000 -extern unsigned int pa_lock_attempts; +#define PA_LOCK_TIME_TO_ATTEMPTS(seconds) ((unsigned int)((seconds)*2)+1) +#define PA_LOCK_ATTEMPTS_TO_TIME(attempts) ((attempts)/2) + +extern unsigned int pa_lock_attempts; // not thread local: never changes // 'blocking' mean we will wait till other process release lock // but we'll make PA_LOCK_ATTEMPTS attempts with PA_LOCK_WAIT_TIMEOUT secs delaus between attempts @@ -28,4 +31,21 @@ int pa_unlock(int fd); /// yields to OS for secs secs and usecs microseconds (1E-6) int pa_sleep(unsigned long secs, unsigned long usecs); +/// ctime in the buffer of the calling thread, valid till the next call; empty string on error +const char *pa_ctime(time_t t); + +/// timer started with pa_timer_start +typedef void *pa_timer; + +/// calls the signal handler in the calling thread after secs seconds and then every interval seconds if it is not 0 +/// The handler interrupts the blocking calls (EINTR), it must be async-signal-safe, one handler is used by all timers +/// needs PA_RESPONSE_TIMEOUT (Linux, FreeBSD), returns false elsewhere or on error +bool pa_timer_start(pa_timer *timer, int secs, int interval, void (*handler)(int)); +void pa_timer_stop(pa_timer timer); + +#ifdef _MSC_VER +/// sets errno from GetLastError(), as CRT does, if the passed windows api call result is zero; returns it +int pa_set_errno(int status); +#endif + #endif