ProcessManager Singleton

Christian Rauch Rauch.Christian at gmx.de
Tue Apr 22 23:31:21 CEST 2025


Hi,

The "libcamera::ProcessManager" and hence the "libcamera::CameraManager" 
(via "CameraManager::Private") can only be instantiated once in a 
process. I have two questions regarding the reason for this and about 
the way this is currently implemented. Since this is a design decision 
and "not a bug", I am posting this on the "devel" mailing list. Let me 
know if I should move this somewhere else.

The "CameraManager" as well as the "ProcessManager" maintain a static 
"self_" and check this when they are instantiated. However, when 
instantiating a second "CameraManager" the "CameraManager::self_"-check 
is actually never reached as the process will quit already at the 
"ProcessManager::self_" check via a "Fatal" log and its "std::abort()". 
At least the "CameraManager::self_"-check appears redundant to me.

Q1: Is the constraint that either the "CameraManager" or the 
"ProcessManager" must not be instantiated multiple times? Why is this 
the case? If the constraint is on the "ProcessManager", what is the 
purpose of the "CameraManager::self_"-check, which is never reached?

Having the Fatal log / std::abort() triggered for additional instances 
in the same process has some unexpected implications. While a single 
"CameraManager" instance can easily be managed within the same code 
base, this is not really possible when dealing with dynamically loaded 
objects. Let's assume a plugin system, where plugins are loaded from 
shared object files into the same process / address space. Loading a 
"Raspberry Pi" plugin to handle specifically Raspberry Pi camera modules 
would instantiate the first "CameraManager". When a second "UVC" plugin 
is loaded for generic USB cameras, this would also instantiate a 
"CameraManager", trigger the "abort" and crash the whole process.

Q2: Is the "abort" really required? If there can really be only a single 
"CameraManager" (and/or "ProcessManager") instance, why can't different 
sections of the code, or different plugins in the example above, share a 
common static "ProcessManager" singleton?

Best,
Christian



More information about the libcamera-devel mailing list