diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-06-12 01:38:59 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-06-12 01:42:37 +0200 |
commit | f2a2fddcd5c3700e31872d7e67c3a72e67e4f916 (patch) | |
tree | e68903ee5bd4a0e5a4441ba17b3e8851be201ea9 /src | |
parent | log: prefix with thread ID (diff) | |
download | cimple-f2a2fddcd5c3700e31872d7e67c3a72e67e4f916.tar.gz cimple-f2a2fddcd5c3700e31872d7e67c3a72e67e4f916.zip |
log: thread-safe logging
Diffstat (limited to 'src')
-rw-r--r-- | src/log.h | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -56,20 +56,26 @@ static inline void log_prefix(FILE *dest) #define log(...) \ do { \ + flockfile(stdout); \ log_prefix(stdout); \ printf(__VA_ARGS__); \ + funlockfile(stdout); \ } while (0) #define log_err(...) \ do { \ + flockfile(stderr); \ log_err_prefix(); \ fprintf(stderr, __VA_ARGS__); \ + funlockfile(stderr); \ } while (0) #define log_errno(s) \ do { \ + flockfile(stderr); \ log_err_prefix(); \ perror(s); \ + funlockfile(stderr); \ } while (0) #define log_errno_if(expr, s) \ |