From patchwork Mon Mar 13 20:41:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dufresne X-Patchwork-Id: 18390 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0066ABD80A for ; Mon, 13 Mar 2023 20:44:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4A423626D9; Mon, 13 Mar 2023 21:44:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678740288; bh=SuBAYov8WSgivIUm8GhL31Nd0UNTaweAN+fdeAW7/9s=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=mNLYwrCnwZgXN21Fvh1vDenIMzCRDXjJjtu+K7hVPryur17d+ic+uHZpPizQxo1e6 X/fKBPALRqWpqfbqjskUUvMgxXx+PD9z+0O1aZTKNo3LCS1FooTdNkT8NYxtye+qfn yv2JBc3jAI4pVfgRGKM2bkjInyPLnIE4GWW1y4A+Fnv4XddQl7SAdRzZLh22lqrayZ 9lUG7Wp7+RoOYveDTxguCGpi88Hvg9qbpKIc0jfiGJ/7y9QID2DdavlCn5JvPf3MQn mnfsF6ksckkdOZTrSJyW9cFlA8HOsdXpRgAeyTb33oCdqoP/1vkpH1cgl0vEQu20zf oWpCXd1lfGgMQ== Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 235AC62674 for ; Mon, 13 Mar 2023 21:44:46 +0100 (CET) Received: from nicolas-tpx395.lan (192-222-136-102.qc.cable.ebox.net [192.222.136.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nicolas) by madras.collabora.co.uk (Postfix) with ESMTPSA id 7A02E6603082; Mon, 13 Mar 2023 20:44:45 +0000 (GMT) To: libcamera-devel@lists.libcamera.org Date: Mon, 13 Mar 2023 16:41:35 -0400 Message-Id: <20230313204134.2769860-1-nicolas@ndufresne.ca> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH] libcamera: base: Make the registration of log categories atomic X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Nicolas Dufresne via libcamera-devel From: Nicolas Dufresne Reply-To: Nicolas Dufresne Cc: Nicolas Dufresne Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Nicolas Dufresne Logger:::create() is not currently thread safe and causes crashes noticeable on RaspberryPi 4. This adds a mutex around the creation of categories. Signed-off-by: Nicolas Dufresne Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/base/log.cpp | 3 +++ 1 file changed, 3 insertions(+) This is a quick fix. The crash I'm getting is very frequent, the backtrace is the following. Pretty much 50% of the time on Raspberry Pi using: gst-launch-1.0 libcamerasrc ! queue ! xvimagesink Thread 6 "gst-launch-1.0" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7ff48cc180 (LWP 88100)] 0x0000007ff5f48a40 in std::__cxx11::basic_string, std::allocator >::compare(char const*) const () from /lib/aarch64-linux-gnu/libstdc++.so.6 (gdb) bt #0 0x0000007ff5f48a40 in std::__cxx11::basic_string, std::allocator >::compare(char const*) const () at /lib/aarch64-linux-gnu/libstdc++.so.6 #1 0x0000007ff664efe0 in std::operator==, std::allocator >(std::__cxx11::basic_string, std::allocator > const&, char const*) (__lhs=, __rhs=0x7ff61c4a28 "Event") at /usr/include/c++/10/bits/basic_string.h:6187 #2 0x0000007ff61b48d4 in operator()(libcamera::LogCategory*) const (__closure=0x7ff48cb008, c=0x705f317073696b72) at ../src/libcamera/base/log.cpp:748 #3 0x0000007ff61b4910 in __gnu_cxx::__ops::_Iter_pred >::operator()<__gnu_cxx::__normal_iterator > >(__gnu_cxx::__normal_iterator > >) (this=0x7ff48cb008, __it=0x705f317073696b72) at /usr/include/c++/10/bits/predefined_ops.h:316 #4 0x0000007ff61b487c in std::__find_if<__gnu_cxx::__normal_iterator >, __gnu_cxx::__ops::_Iter_pred > >(__gnu_cxx::__normal_iterator > >, __gnu_cxx::__normal_iterator > >, __gnu_cxx::__ops::_Iter_pred >, std::random_access_iterator_tag) (__first=0x705f317073696b72, __last=0x303100736d617261, __pred=...) at /usr/include/c++/10/bits/stl_algobase.h:1959 #5 0x0000007ff61b46b4 in std::__find_if<__gnu_cxx::__normal_iterator >, __gnu_cxx::__ops::_Iter_pred > >(__gnu_cxx::__normal_iterator > >, __gnu_cxx::__normal_iterator > >, __gnu_cxx::__ops::_Iter_pred >) (__first=0x555582c130, __last=0x303100736d617261, __pred=...) at /usr/include/c++/10/bits/stl_algobase.h:1974 #6 0x0000007ff61b4648 in std::find_if<__gnu_cxx::__normal_iterator >, libcamera::Logger::findCategory(char const*) const:: >(__gnu_cxx::__normal_iterator > >, __gnu_cxx::__normal_iterator > >, struct {...}) (__first=0x555582c130, __last=0x303100736d617261, __pred=...) at /usr/include/c++/10/bits/stl_algo.h:3929 #7 0x0000007ff61b3f60 in libcamera::Logger::findCategory(char const*) const (this=0x7ff61ec968 , name=0x7ff61c4a28 "Event") at ../src/libcamera/base/log.cpp:748 #8 0x0000007ff61b3fc4 in libcamera::LogCategory::create(char const*) (name=0x7ff61c4a28 "Event") at ../src/libcamera/base/log.cpp:791 #9 0x0000007ff61a9ffc in libcamera::logCategoryEvent() () at ../src/libcamera/base/event_dispatcher.cpp:17 #10 0x0000007ff61aac5c in libcamera::EventDispatcherPoll::poll(std::vector >*) (this=0x7fe8006f90, pollfds=0x7ff48cb3e8) at ../src/libcamera/base/event_dispatcher_poll.cpp:216 #11 0x0000007ff61aa8fc in libcamera::EventDispatcherPoll::processEvents() (this=0x7fe8006f90) at ../src/libcamera/base/event_dispatcher_poll.cpp:160 #12 0x0000007ff61be0bc in libcamera::Thread::exec() (this=0x55555d0380) at ../src/libcamera/base/thread.cpp:341 #13 0x0000007ff6643e88 in libcamera::CameraManager::Private::run() (this=0x55555d0370) at ../src/libcamera/camera_manager.cpp:122 #14 0x0000007ff61be038 in libcamera::Thread::startThread() (this=0x55555d0380) at ../src/libcamera/base/thread.cpp:319 #15 0x0000007ff61c2070 in std::__invoke_impl(std::__invoke_memfun_deref, void (libcamera::Thread::*&&)(), libcamera::Thread*&&) (__f=@0x5555852ef0: (void (libcamera::Thread::*)(class libcamera::Thread * const)) 0x7ff61bdf38 , __t=@0x5555852ee8: 0x55555d0380) at /usr/include/c++/10/bits/invoke.h:73 #16 0x0000007ff61c1f88 in std::__invoke(void (libcamera::Thread::*&&)(), libcamera::Thread*&&) (__fn=@0x5555852ef0: (void (libcamera::Thread::*)(class libcamera::Thread * const)) 0x7ff61bdf38 ) at /usr/include/c++/10/bits/invoke.h:95 #17 0x0000007ff61c1eec in std::thread::_Invoker >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) (this=0x5555852ee8) at /usr/include/c++/10/thread:264 #18 0x0000007ff61c1ea4 in std::thread::_Invoker >::operator()() (this=0x5555852ee8) at /usr/include/c++/10/thread:271 #19 0x0000007ff61c1e84 in std::thread::_State_impl > >::_M_run() (this=0x5555852ee0) at /usr/include/c++/10/thread:215 #20 0x0000007ff5ee1cac in () at /lib/aarch64-linux-gnu/libstdc++.so.6 #21 0x0000007ff7c78648 in start_thread (arg=0x7ff48cba80) at pthread_create.c:477 #22 0x0000007ff7bcec1c in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78 diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index 55fbd7b0..c8045ef7 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -788,6 +789,8 @@ LogCategory *Logger::findCategory(const char *name) const */ LogCategory *LogCategory::create(const char *name) { + static Mutex mutex_; + MutexLocker locker(mutex_); LogCategory *category = Logger::instance()->findCategory(name); if (!category) {