BAN: Make debug output thread safe

Now file lock is only acquired once per message, not once per character
This commit is contained in:
Bananymous 2026-01-09 20:30:35 +02:00
parent 12489a4c6b
commit 90deb9fb43
1 changed files with 7 additions and 1 deletions

View File

@ -9,29 +9,35 @@
#include <BAN/Formatter.h> #include <BAN/Formatter.h>
#include <stdio.h> #include <stdio.h>
#define __debug_putchar [](int c) { putc(c, stddbg); } #define __debug_putchar [](int c) { putc_unlocked(c, stddbg); }
#define dprintln(...) \ #define dprintln(...) \
do { \ do { \
flockfile(stddbg); \
BAN::Formatter::print(__debug_putchar, __VA_ARGS__); \ BAN::Formatter::print(__debug_putchar, __VA_ARGS__); \
BAN::Formatter::print(__debug_putchar,"\n"); \ BAN::Formatter::print(__debug_putchar,"\n"); \
fflush(stddbg); \ fflush(stddbg); \
funlockfile(stddbg); \
} while (false) } while (false)
#define dwarnln(...) \ #define dwarnln(...) \
do { \ do { \
flockfile(stddbg); \
BAN::Formatter::print(__debug_putchar, "\e[33m"); \ BAN::Formatter::print(__debug_putchar, "\e[33m"); \
BAN::Formatter::print(__debug_putchar, __VA_ARGS__); \ BAN::Formatter::print(__debug_putchar, __VA_ARGS__); \
BAN::Formatter::print(__debug_putchar, "\e[m\n"); \ BAN::Formatter::print(__debug_putchar, "\e[m\n"); \
fflush(stddbg); \ fflush(stddbg); \
funlockfile(stddbg); \
} while(false) } while(false)
#define derrorln(...) \ #define derrorln(...) \
do { \ do { \
flockfile(stddbg); \
BAN::Formatter::print(__debug_putchar, "\e[31m"); \ BAN::Formatter::print(__debug_putchar, "\e[31m"); \
BAN::Formatter::print(__debug_putchar, __VA_ARGS__); \ BAN::Formatter::print(__debug_putchar, __VA_ARGS__); \
BAN::Formatter::print(__debug_putchar, "\e[m\n"); \ BAN::Formatter::print(__debug_putchar, "\e[m\n"); \
fflush(stddbg); \ fflush(stddbg); \
funlockfile(stddbg); \
} while(false) } while(false)
#define dprintln_if(cond, ...) \ #define dprintln_if(cond, ...) \