--- libelwix/inc/elwix.h 2024/08/14 16:05:42 1.24 +++ libelwix/inc/elwix.h 2026/07/29 01:10:40 1.33 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: elwix.h,v 1.24 2024/08/14 16:05:42 misho Exp $ +* $Id: elwix.h,v 1.33 2026/07/29 01:10:40 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 - 2024 +Copyright 2004 - 2026 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -47,13 +47,21 @@ SUCH DAMAGE. #define __ELWIX_H +#include #include #include #include +#include #include #include #include #include +#ifndef __cplusplus + #include +#else + #include + #define _Atomic(X) std::atomic +#endif #ifndef __linux__ #include #include @@ -81,6 +89,8 @@ SUCH DAMAGE. #include #include #include +#include +#include #ifndef STRSIZ @@ -161,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)) @@ -179,9 +270,16 @@ SUCH DAMAGE. #define VACUUM_BETWEEN 2 -extern int __isthreaded; +typedef struct { + E_ATOMIC_ALIGN int value; +} e_atomic_int; +#ifdef __cplusplus +extern "C" { +#endif +extern int __isthreaded; + // elwix_SetProg() Set program memory pool name void elwix_SetProg(const char *csProgName); // elwix_GetProg() Get program memory pool name @@ -258,7 +356,7 @@ extern int elwix_Verbose; #define EVERBS(x) if ((x) <= elwix_Verbose) #define EVERBOSE(x, fmt, ...) do { assert((fmt)); \ if ((x) <= elwix_Verbose) { \ - char __str[BUFSIZ] = { [0 ... BUFSIZ - 1] = 0 }; \ + char __str[BUFSIZ] = { 0 }; \ snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ syslog(LOG_INFO, "Verbose(%d):%s(%d): %s\n", \ (x), __func__, __LINE__, __str); \ @@ -266,7 +364,7 @@ extern int elwix_Verbose; } while (0) #define EVERBOSE2(x, fmt, ...) do { assert((fmt)); \ if ((x) <= elwix_Verbose) { \ - char __str[0x10000] = { [0 ... 0xffff] = 0 }; \ + char __str[0x10000] = { 0 }; \ snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ syslog(LOG_INFO, "Verbose(%d):%s(%d): %s\n", \ (x), __func__, __LINE__, __str); \ @@ -287,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)) @@ -295,7 +397,7 @@ extern int elwix_Debug; syslog(LOG_DEBUG, "I'm in %s(%d)\n", __func__, __LINE__) #define EDEBUG(x, fmt, ...) do { assert((fmt)); \ if ((x) & elwix_Debug) { \ - char __str[BUFSIZ] = { [0 ... BUFSIZ - 1] = 0 }; \ + char __str[BUFSIZ] = { 0 }; \ snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ syslog(LOG_DEBUG, "Debug(%d):%s(%d): %s\n", \ (x), __func__, __LINE__, __str); \ @@ -304,21 +406,21 @@ extern int elwix_Debug; /* Logger macro */ #define ELOGGER(x, fmt, ...) do { assert((fmt)); \ - char __str[BUFSIZ] = { [0 ... BUFSIZ - 1] = 0 }; \ + char __str[BUFSIZ] = { 0 }; \ snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ - syslog((x), "Logger:%s(%d): %s\n", \ + syslog((x), "Log:%s(%d): %s\n", \ __func__, __LINE__, __str); \ } while (0) #define EWARNING(x, fmt, ...) do { assert((fmt)); \ - char __str[BUFSIZ] = { [0 ... BUFSIZ - 1] = 0 }; \ + char __str[BUFSIZ] = { 0 }; \ snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ syslog(LOG_WARNING, "Warning:%s(%d): #%d - %s\n", \ __func__, __LINE__, (x), __str); \ } while (0) /* Error state macros */ #define EERROR(x, fmt, ...) do { assert((fmt)); \ - char __str[BUFSIZ] = { [0 ... BUFSIZ - 1] = 0 }; \ + char __str[BUFSIZ] = { 0 }; \ snprintf(__str, sizeof __str, (fmt), ##__VA_ARGS__); \ syslog(LOG_ERR, "Error:%s(%d): #%d - %s\n", \ __func__, __LINE__, (x), __str); \ @@ -339,5 +441,9 @@ extern int elwix_Debug; ait##_GetError()); \ } while (0) + +#ifdef __cplusplus +} +#endif #endif