folly/folly/Singleton.cpp

/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <folly/Singleton.h>

#ifndef _WIN32
#include <dlfcn.h>
#include <signal.h>
#include <time.h>
#endif

#include <atomic>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <fmt/chrono.h>
#include <fmt/format.h>

#include <folly/Demangle.h>
#include <folly/ScopeGuard.h>
#include <folly/experimental/symbolizer/Symbolizer.h>
#include <folly/lang/SafeAssert.h>
#include <folly/portability/Config.h>
#include <folly/portability/FmtCompile.h>
// Before registrationComplete() we cannot assume that glog has been
// initialized, so we need to use RAW_LOG for any message that may be logged
// before that.
#include <glog/raw_logging.h>

#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__)
#define FOLLY_SINGLETON_HAVE_DLSYM
#endif

namespace folly {

#if FOLLY_SINGLETON_HAVE_DLSYM
namespace detail {
static void singleton_hs_init_weak(int* argc, char** argv[])
    __attribute__((__weakref__("hs_init")));
} // namespace detail
#endif

SingletonVault::Type SingletonVault::defaultVaultType() {}

namespace detail {

std::string TypeDescriptor::name() const {}

[[noreturn]] void singletonWarnDoubleRegistrationAndAbort(
    const TypeDescriptor& type) {}

[[noreturn]] void singletonWarnLeakyDoubleRegistrationAndAbort(
    const TypeDescriptor& type) {}

[[noreturn]] void singletonWarnLeakyInstantiatingNotRegisteredAndAbort(
    const TypeDescriptor& type) {}

[[noreturn]] void singletonWarnRegisterMockEarlyAndAbort(
    const TypeDescriptor& type) {}

void singletonWarnDestroyInstanceLeak(
    const TypeDescriptor& type, const void* ptr) {}

[[noreturn]] void singletonWarnCreateCircularDependencyAndAbort(
    const TypeDescriptor& type) {}

[[noreturn]] void singletonWarnCreateUnregisteredAndAbort(
    const TypeDescriptor& type) {}

[[noreturn]] void singletonWarnCreateBeforeRegistrationCompleteAndAbort(
    const TypeDescriptor& type) {}

void singletonPrintDestructionStackTrace(const TypeDescriptor& type) {}

[[noreturn]] void singletonThrowNullCreator(const std::type_info& type) {}

[[noreturn]] void singletonThrowGetInvokedAfterDestruction(
    const TypeDescriptor& type) {}

} // namespace detail

namespace {

struct FatalHelper {};

#if defined(__APPLE__) || defined(_MSC_VER)
// OS X doesn't support constructor priorities.
FatalHelper fatalHelper;
#else
FatalHelper __attribute__((__init_priority__(101))) fatalHelper;
#endif

} // namespace

SingletonVault::SingletonVault(Type type) noexcept :{}

SingletonVault::~SingletonVault() {}

void SingletonVault::registerSingleton(detail::SingletonHolderBase* entry) {}

void SingletonVault::addEagerInitSingleton(detail::SingletonHolderBase* entry) {}

void SingletonVault::addEagerInitOnReenableSingleton(
    detail::SingletonHolderBase* entry) {}

void SingletonVault::registrationComplete() {}

void SingletonVault::doEagerInit() {}

void SingletonVault::doEagerInitVia(Executor& exe, folly::Baton<>* done) {}

void SingletonVault::destroyInstances() {}

void SingletonVault::reenableInstances() {}

void SingletonVault::scheduleDestroyInstances() {}

void SingletonVault::destroyInstancesFinal() {}

void SingletonVault::addToShutdownLog(std::string message) {}

#if FOLLY_HAVE_LIBRT
namespace {
[[noreturn]] void fireShutdownSignalHelper(sigval_t sigval) {
  static_cast<SingletonVault*>(sigval.sival_ptr)->fireShutdownTimer();
}
} // namespace
#endif

void SingletonVault::startShutdownTimer() {}

[[noreturn]] void SingletonVault::fireShutdownTimer() {}

} // namespace folly