结构
core
初始化
通过static core_ptr get()
来初始化,其过程为
BOOST_LOG_API core_ptr core::get()
{
return implementation::get();
}
会调用implementation的静态get方法,由于implementation继承lazy_singleton,其调用的是 lazy_singleton的get方法
template< typename DerivedT, typename StorageT = DerivedT >
class lazy_singleton {
public:
static StorageT& get()
{
BOOST_LOG_ONCE_BLOCK()
{
DerivedT::init_instance();
}
return get_instance();
}
};
会调用implementation的init_instance方法,其会调用lazy_singleton的get_instance方法
static void init_instance()
{
base_type::get_instance().reset(new core());
}
lazy_singleton的get_instance方法得到shared_ptr<core>
static StorageT& get_instance()
{
static StorageT instance;
return instance;
}