system/debug.h: try for more thread save implementation

Replacing printf() with fprintf() in this code section aims to
prevent unpredictable behavior in multi-threaded environments that
could be caused by printf()'s non-atomic nature. The change is
intended to enhance output consistency and prevent potential race conditions.
Additionally, it is important to note that many other plain calls to printf()
in the Neutrino code could also cause issues and require further investigation.
Whether this change will have a positive impact remains to be seen.
This commit is contained in:
2023-05-05 13:19:52 +02:00
parent 749d51926a
commit 6ef0bd0f90

View File

@@ -39,12 +39,29 @@ enum
void setDebugLevel( int level );
#if 0
#define dprintf(debuglevel, fmt, args...) \
do
{ \
if (debug >= debuglevel) \
printf( "[neutrino] " fmt, ## args); \
}
while(0)
#define dperror(str) {perror("[neutrino] " str);}
#else
// more thread save implementation
#define dprintf(debuglevel, fmt, args...) \
do { \
if (debug >= debuglevel) \
printf( "[neutrino] " fmt, ## args); \
fprintf(stderr, "[neutrino] " fmt, ## args); \
} while(0)
#define dperror(str) {perror("[neutrino] " str);}
#define dperror(str) \
do { \
char errbuf[256]; \
strerror_r(errno, errbuf, sizeof(errbuf)); \
fprintf(stderr, "[neutrino] %s: %s\n", str, errbuf); \
} while(0)
#endif
#endif