aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-06-12 01:38:59 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-06-12 01:42:37 +0200
commitf2a2fddcd5c3700e31872d7e67c3a72e67e4f916 (patch)
treee68903ee5bd4a0e5a4441ba17b3e8851be201ea9
parentlog: prefix with thread ID (diff)
downloadcimple-f2a2fddcd5c3700e31872d7e67c3a72e67e4f916.tar.gz
cimple-f2a2fddcd5c3700e31872d7e67c3a72e67e4f916.zip
log: thread-safe logging
Diffstat (limited to '')
-rw-r--r--src/log.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/log.h b/src/log.h
index 9b0c945..da12efe 100644
--- a/src/log.h
+++ b/src/log.h
@@ -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) \