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.


Origin commit data
------------------
Branch: ni/coolstream
Commit: 5d44bd1e0f
Author: Thilo Graf <dbt@novatux.de>
Date: 2023-05-09 (Tue, 09 May 2023)



------------------
This commit was generated by Migit
This commit is contained in:
2023-05-09 21:04:24 +02:00
committed by vanhofen
parent 17105ed709
commit 6eff819991

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