mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-22 09:28:58 +00:00
orb: add a separate uORB::Manager::initialize() method
This fixes a race condition: uORB::Manager::get_instance() is used in a multi-thread context, but the singleton initialization was not thread-safe. Further, this avoids having to check for nullptr every time the singleton is accessed. uORB::Manager::initialize() is called when uorb is started. No one else accesses the singleton before that point, because it is only used in the orb_* methods, and in muorb. Both require uorb to be started already when they are used.
This commit is contained in:
@@ -49,13 +49,13 @@ uORB::Manager *uORB::Manager::_Instance = nullptr;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
uORB::Manager *uORB::Manager::get_instance()
|
||||
bool uORB::Manager::initialize()
|
||||
{
|
||||
if (_Instance == nullptr) {
|
||||
_Instance = new uORB::Manager();
|
||||
}
|
||||
|
||||
return _Instance;
|
||||
return _Instance != nullptr;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user