aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cubeb_log.h
diff options
context:
space:
mode:
authorPaul Adenot <[email protected]>2022-09-21 16:22:45 -0700
committerPaul Adenot <[email protected]>2022-09-22 23:36:04 +0200
commite9abb07824b14f8ff0b9168be733fc431cac8cdf (patch)
treeda22c52435083cb671fa7073d99e037f7d4f3b60 /src/cubeb_log.h
parentbc0450628e120dbee89fb8ad0b29abbd24dc3729 (diff)
downloadcubeb-e9abb07824b14f8ff0b9168be733fc431cac8cdf.tar.gz
cubeb-e9abb07824b14f8ff0b9168be733fc431cac8cdf.zip
Make the log callback and level atomic
It's useful to be able to enable logging dynamically while the program is running, and this can now be done on any thread. Various threads are logging (directly or asynchronously via the ring buffer), it's better to have those atomic. Both values are always checked before logging, and both must be non-null to log.
Diffstat (limited to 'src/cubeb_log.h')
-rw-r--r--src/cubeb_log.h26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/cubeb_log.h b/src/cubeb_log.h
index fcc9c89..906ea03 100644
--- a/src/cubeb_log.h
+++ b/src/cubeb_log.h
@@ -30,8 +30,16 @@ extern "C" {
(strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#endif
-extern cubeb_log_level g_cubeb_log_level;
-extern cubeb_log_callback g_cubeb_log_callback PRINTF_FORMAT(1, 2);
+void
+cubeb_log_set(cubeb_log_level log_level, cubeb_log_callback log_callback);
+cubeb_log_level
+cubeb_log_get_level();
+cubeb_log_callback
+cubeb_log_get_callback();
+void
+cubeb_log_internal_no_format(const char * msg);
+void
+cubeb_log_internal(const char * filename, uint32_t line, const char * fmt, ...);
void
cubeb_async_log(const char * fmt, ...);
void
@@ -44,24 +52,16 @@ cubeb_async_log_reset_threads(void);
#define LOGV(msg, ...) LOG_INTERNAL(CUBEB_LOG_VERBOSE, msg, ##__VA_ARGS__)
#define LOG(msg, ...) LOG_INTERNAL(CUBEB_LOG_NORMAL, msg, ##__VA_ARGS__)
-#define LOG_INTERNAL_NO_FORMAT(level, fmt, ...) \
- do { \
- if (g_cubeb_log_callback && level <= g_cubeb_log_level) { \
- g_cubeb_log_callback(fmt, __VA_ARGS__); \
- } \
- } while (0)
-
#define LOG_INTERNAL(level, fmt, ...) \
do { \
- if (g_cubeb_log_callback && level <= g_cubeb_log_level) { \
- g_cubeb_log_callback("%s:%d: " fmt "\n", __FILENAME__, __LINE__, \
- ##__VA_ARGS__); \
+ if (cubeb_log_get_level() <= level && cubeb_log_get_callback()) { \
+ cubeb_log_internal(__FILENAME__, __LINE__, fmt, ##__VA_ARGS__); \
} \
} while (0)
#define ALOG_INTERNAL(level, fmt, ...) \
do { \
- if (level <= g_cubeb_log_level) { \
+ if (cubeb_log_get_level() <= level && cubeb_log_get_callback()) { \
cubeb_async_log(fmt, ##__VA_ARGS__); \
} \
} while (0)