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; }
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); }
std::shared_ptr<ShutdownSocketSet> tryGetShutdownSocketSet() { return singleton.try_get(); }