本文整理汇总了C++中Singleton::try_get方法的典型用法代码示例。如果您正苦于以下问题:C++ Singleton::try_get方法的具体用法?C++ Singleton::try_get怎么用?C++ Singleton::try_get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Singleton
的用法示例。
在下文中一共展示了Singleton::try_get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: guard
std::shared_ptr<Exe> getExecutor(
Singleton<std::weak_ptr<Exe>>& sExecutor,
Singleton<std::shared_ptr<DefaultExe>>& sDefaultExecutor,
Singleton<RWSpinLock, LockTag>& sExecutorLock) {
std::shared_ptr<Exe> executor;
auto singleton = sExecutor.try_get();
auto lock = sExecutorLock.try_get();
{
RWSpinLock::ReadHolder guard(lock.get());
if ((executor = sExecutor.try_get()->lock())) {
return executor;
}
}
RWSpinLock::WriteHolder guard(lock.get());
executor = singleton->lock();
if (!executor) {
std::weak_ptr<Exe> defaultExecutor = *sDefaultExecutor.try_get().get();
executor = defaultExecutor.lock();
sExecutor.try_get().get()->swap(defaultExecutor);
}
return executor;
}
示例2: setExecutor
void setExecutor(
std::shared_ptr<Exe> executor,
Singleton<std::weak_ptr<Exe>>& sExecutor,
Singleton<RWSpinLock, LockTag>& sExecutorLock) {
auto lock = sExecutorLock.try_get();
RWSpinLock::WriteHolder guard(*lock);
std::weak_ptr<Exe> executor_weak = executor;
sExecutor.try_get().get()->swap(executor_weak);
}
示例3: tryGetShutdownSocketSet
std::shared_ptr<ShutdownSocketSet> tryGetShutdownSocketSet() {
return singleton.try_get();
}