From d12f698dbb65df1079cc98605c8738aa8224d301 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Tue, 17 Sep 2019 18:38:58 +0200 Subject: logging: Introduce mutex API to manage log_target in multi-thread envs log_enable_multithread() enables use of locks inside the implementation. Lock use is disabled by default, this way only multi-thread processes need to enable it and suffer related complexity/performance penalties. Locks are required around osmo_log_target_list and items inside it, since targets can be used, modified and deleted by different threads concurrently (for instance, user writing "logging disable" in VTY while another thread is willing to write into that target). Multithread apps and libraries aiming at being used in multithread apps should update their code to use the locks introduced here when containing code iterating over osmo_log_target_list explictly or implicitly by obtaining a log_target (eg. osmo_log_vty2tgt()). Related: OS#4088 Change-Id: Id7711893b34263baacac6caf4d489467053131bb --- include/osmocom/core/logging.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'include/osmocom') diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h index 1a2d60bc..139d2916 100644 --- a/include/osmocom/core/logging.h +++ b/include/osmocom/core/logging.h @@ -380,4 +380,18 @@ void log_del_target(struct log_target *target); struct log_target *log_target_find(int type, const char *fname); +void log_enable_multithread(void); + +void log_tgt_mutex_lock_impl(void); +void log_tgt_mutex_unlock_impl(void); +#define LOG_MTX_DEBUG 0 +#if LOG_MTX_DEBUG + #include + #define log_tgt_mutex_lock() do { fprintf(stderr, "[%lu] %s:%d [%s] lock\n", pthread_self(), __FILE__, __LINE__, __func__); log_tgt_mutex_lock_impl(); } while (0) + #define log_tgt_mutex_unlock() do { fprintf(stderr, "[%lu] %s:%d [%s] unlock\n", pthread_self(), __FILE__, __LINE__, __func__); log_tgt_mutex_unlock_impl(); } while (0) +#else + #define log_tgt_mutex_lock() log_tgt_mutex_lock_impl() + #define log_tgt_mutex_unlock() log_tgt_mutex_unlock_impl() +#endif + /*! @} */ -- cgit v1.2.3