From: Karol Lewandowski Date: Mon, 27 Nov 2023 23:59:24 +0000 (+0100) Subject: libdlog: Rewrite errnous comments about pthread_atfork() usage X-Git-Tag: accepted/tizen/unified/20240124.011143~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5a5d45e9542cd7ebd3d72c276f7d97dafbb833c0;hp=5262eca576728aa43429da3fad8a6f756a3699df;p=platform%2Fcore%2Fsystem%2Fdlog.git libdlog: Rewrite errnous comments about pthread_atfork() usage Change-Id: I56106fddfddf00b38639b147dd80ab90e0a9f6fa --- diff --git a/src/libdlog/log.c b/src/libdlog/log.c index b9a3a77..023990f 100644 --- a/src/libdlog/log.c +++ b/src/libdlog/log.c @@ -103,8 +103,9 @@ static int fatal_assert; static int limiter_apply_to_all_buffers; static _Atomic log_priority priority_filter_level = DLOG_VERBOSE; -/* Cache pid and tid to avoid up to two syscalls per log. The update function - * is registered to happen when new threads are made (including a full fork). */ +/* Cache pid and tid to avoid up to two syscalls per log. + * PID is reset at fork() via pthread_atfork(). + * TID is reset by being a thread local var. */ static int32_t cached_pid = 0; _Thread_local int32_t cached_tid = 0; @@ -118,10 +119,10 @@ static inline int32_t get_cached_tid() return (cached_tid = cached_tid ?: gettid()); } -static void update_thread_local_ids(void) +static void update_cached_pid() { - cached_pid = 0; - cached_tid = 0; + cached_pid = getpid(); + // tid is reset passively (to 0) by virtue of being thread-local } /* Here, static_config is the original config from /etc/dlog.conf{,.d} which can be overriden, @@ -277,9 +278,7 @@ bool __configure(void) __configure_deduplicate(&both_config); __configure_limiter(&static_config, &both_config); - /* The fork handler also runs when a new thread is made (not just - * when the whole process forks), so we can cache both pid and tid. */ - pthread_atfork(NULL, NULL, update_thread_local_ids); + pthread_atfork(NULL, NULL, update_cached_pid); return true; }