--- libelwix/inc/elwix.h 2025/11/17 19:53:08 1.28.4.1 +++ libelwix/inc/elwix.h 2026/07/29 01:09:33 1.32.4.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: elwix.h,v 1.28.4.1 2025/11/17 19:53:08 misho Exp $ +* $Id: elwix.h,v 1.32.4.2 2026/07/29 01:09:33 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2025 +Copyright 2004 - 2026 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -56,6 +56,12 @@ SUCH DAMAGE. #include #include #include +#ifndef __cplusplus + #include +#else + #include + #define _Atomic(X) std::atomic +#endif #ifndef __linux__ #include #include @@ -165,6 +171,87 @@ SUCH DAMAGE. #define powerof2(x) ((((x) - 1) & (x)) == 0) #endif +/* timespec helpers */ +/* Operations on timevals. */ +#ifndef timerclear +#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) +#endif + +#ifndef timerisset +#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#endif + +#ifndef timercmp +#define timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) +#endif + +#ifndef timeradd +#define timeradd(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } while (0) +#endif + +#ifndef timersub +#define timersub(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } while (0) +#endif + +/* Operations on timespecs. */ +#ifndef timespecclear +#define timespecclear(tsp) ((tsp)->tv_sec = (tsp)->tv_nsec = 0) +#endif + +#ifndef timespecisset +#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) +#endif + +#ifndef timespeccmp +#define timespeccmp(tsp, usp, cmp) \ + (((tsp)->tv_sec == (usp)->tv_sec) ? \ + ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ + ((tsp)->tv_sec cmp (usp)->tv_sec)) +#endif + +#ifndef timespecadd +#define timespecadd(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ + if ((vsp)->tv_nsec >= 1000000000L) { \ + (vsp)->tv_sec++; \ + (vsp)->tv_nsec -= 1000000000L; \ + } \ + } while (0) +#endif + +#ifndef timespecsub +#define timespecsub(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ + if ((vsp)->tv_nsec < 0) { \ + (vsp)->tv_sec--; \ + (vsp)->tv_nsec += 1000000000L; \ + } \ + } while (0) +#endif + /* Macros for min/max. */ #ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) @@ -298,6 +385,10 @@ extern int elwix_Debug; #define ELWIX_DEBUG_LOCK 0x20 #define ELWIX_DEBUG_SYS 0x40 #define ELWIX_DEBUG_NET 0x80 +#define ELWIX_DEBUG_1 0x100 +#define ELWIX_DEBUG_2 0x200 +#define ELWIX_DEBUG_3 0x400 +#define ELWIX_DEBUG_4 0x800 #define ELWIX_DEBUG_ANY 0xFFFFFFFF #define EDBG(x) (elwix_Debug & (x))