Thread: Add name parameter

For debugging purposes, threads can be assigned a name, which eases
distinguishing between them in e.g. htop or gdb. This uses a
Linux-specific API for now which is limited to 15 characters (+ null
terminator), so truncation is done and names for existing thread
instantiations were chosen to be consise.

[Kieran: Apply checkstyle suggestions, rebase on proxy rework]
Signed-off-by: Schulz, Andreas <andreas.schulz2@karlstorz.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Schulz, Andreas
2025-11-04 18:50:02 +00:00
committed by Kieran Bingham
parent 6af90deaf2
commit 559128b1f1
6 changed files with 17 additions and 7 deletions

View File

@@ -8,6 +8,7 @@
#pragma once
#include <memory>
#include <string>
#include <sys/types.h>
#include <thread>
@@ -30,7 +31,7 @@ class ThreadMain;
class Thread
{
public:
Thread();
Thread(std::string name = {});
virtual ~Thread();
void start();
@@ -74,6 +75,7 @@ private:
void moveObject(Object *object, ThreadData *currentData,
ThreadData *targetData);
std::string name_;
std::thread thread_;
std::unique_ptr<ThreadData> data_;
};

View File

@@ -10,6 +10,7 @@
#include <atomic>
#include <list>
#include <optional>
#include <pthread.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
@@ -144,6 +145,7 @@ class ThreadMain : public Thread
{
public:
ThreadMain()
: Thread("libcamera-main")
{
data_->running_ = true;
}
@@ -234,8 +236,9 @@ ThreadData *ThreadData::current()
/**
* \brief Create a thread
*/
Thread::Thread()
: data_(std::make_unique<ThreadData>(this))
Thread::Thread(std::string name)
: name_(std::move(name)),
data_(std::make_unique<ThreadData>(this))
{
}
@@ -288,6 +291,10 @@ void Thread::startThread()
data_->tid_ = syscall(SYS_gettid);
currentThreadData = data_.get();
if (!name_.empty())
pthread_setname_np(thread_.native_handle(),
name_.substr(0, 15).c_str());
run();
}

View File

@@ -39,7 +39,7 @@ LOG_DEFINE_CATEGORY(Camera)
#ifndef __DOXYGEN_PUBLIC__
CameraManager::Private::Private()
: initialized_(false)
: Thread("CameraManager"), initialized_(false)
{
ipaManager_ = std::make_unique<IPAManager>(this->configuration());
}

View File

@@ -115,7 +115,7 @@ private:
VirtualCameraData::VirtualCameraData(PipelineHandler *pipe,
const std::vector<Resolution> &supportedResolutions)
: Camera::Private(pipe)
: Camera::Private(pipe), Thread("VirtualCamera")
{
config_.resolutions = supportedResolutions;
for (const auto &resolution : config_.resolutions) {

View File

@@ -75,7 +75,8 @@ LOG_DEFINE_CATEGORY(SoftwareIsp)
*/
SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,
ControlInfoMap *ipaControls)
: dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |
: ispWorkerThread_("SWIspWorker"),
dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |
DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |
DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf)
{

View File

@@ -46,7 +46,7 @@ namespace {{ns}} {
{%- endif %}
{{proxy_name}}Threaded::{{proxy_name}}Threaded(IPAModule *ipam, const GlobalConfiguration &configuration)
: {{proxy_name}}(ipam, configuration)
: {{proxy_name}}(ipam, configuration), thread_("{{proxy_name}}")
{
LOG(IPAProxy, Debug)
<< "initializing {{module_name}} proxy in thread: loading IPA from "