mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-27 23:42:58 +02:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user