diff --git a/db/snapshot_checker.h b/db/snapshot_checker.h index 1d2c2c316b..0bfb1aa07a 100644 --- a/db/snapshot_checker.h +++ b/db/snapshot_checker.h @@ -33,10 +33,9 @@ class DisableGCSnapshotChecker : public SnapshotChecker { // By returning kNotInSnapshot, we prevent all the values from being GCed return SnapshotCheckerResult::kNotInSnapshot; } - static DisableGCSnapshotChecker* Instance() { return &instance_; } + static DisableGCSnapshotChecker* Instance(); protected: - static DisableGCSnapshotChecker instance_; explicit DisableGCSnapshotChecker() {} }; diff --git a/env/env_posix.cc b/env/env_posix.cc index f7f71c1e73..66848d11f3 100644 --- a/env/env_posix.cc +++ b/env/env_posix.cc @@ -488,6 +488,7 @@ Env* Env::Default() { CompressionContextCache::InitSingleton(); INIT_SYNC_POINT_SINGLETONS(); // ~PosixEnv must be called on exit + //**TODO: Can we make this a STATIC_AVOID_DESTRUCTION? static PosixEnv default_env; return &default_env; } @@ -496,9 +497,9 @@ Env* Env::Default() { // Default Posix SystemClock // const std::shared_ptr& SystemClock::Default() { - static std::shared_ptr default_clock = - std::make_shared(); - return default_clock; + STATIC_AVOID_DESTRUCTION(std::shared_ptr, instance) + (std::make_shared()); + return instance; } } // namespace ROCKSDB_NAMESPACE diff --git a/env/fs_posix.cc b/env/fs_posix.cc index 51d4393f7a..545dfade13 100644 --- a/env/fs_posix.cc +++ b/env/fs_posix.cc @@ -51,6 +51,7 @@ #include "logging/posix_logger.h" #include "monitoring/iostats_context_imp.h" #include "monitoring/thread_status_updater.h" +#include "port/lang.h" #include "port/port.h" #include "rocksdb/options.h" #include "rocksdb/slice.h" @@ -1210,10 +1211,9 @@ PosixFileSystem::PosixFileSystem() // Default Posix FileSystem // std::shared_ptr FileSystem::Default() { - static PosixFileSystem default_fs; - static std::shared_ptr default_fs_ptr( - &default_fs, [](PosixFileSystem*) {}); - return default_fs_ptr; + STATIC_AVOID_DESTRUCTION(std::shared_ptr, instance) + (std::make_shared()); + return instance; } #ifndef ROCKSDB_LITE diff --git a/port/win/env_win.cc b/port/win/env_win.cc index 7ee58a85b7..c5038bbfc9 100644 --- a/port/win/env_win.cc +++ b/port/win/env_win.cc @@ -28,6 +28,7 @@ #include "monitoring/iostats_context_imp.h" #include "monitoring/thread_status_updater.h" #include "monitoring/thread_status_util.h" +#include "port/lang.h" #include "port/port.h" #include "port/port_dirent.h" #include "port/win/io_win.h" @@ -192,8 +193,8 @@ WinFileSystem::WinFileSystem(const std::shared_ptr& clock) } const std::shared_ptr& WinFileSystem::Default() { - static std::shared_ptr fs = - std::make_shared(WinClock::Default()); + STATIC_AVOID_DESTRUCTION(std::shared_ptr, fs) + (std::make_shared(WinClock::Default())); return fs; } @@ -1410,8 +1411,8 @@ std::shared_ptr FileSystem::Default() { } const std::shared_ptr& SystemClock::Default() { - static std::shared_ptr clock = - std::make_shared(); + STATIC_AVOID_DESTRUCTION(std::shared_ptr, clock) + (std::make_shared()); return clock; } } // namespace ROCKSDB_NAMESPACE diff --git a/table/persistent_cache_options.h b/table/persistent_cache_options.h index bd1daaac65..b543ab3a31 100644 --- a/table/persistent_cache_options.h +++ b/table/persistent_cache_options.h @@ -24,9 +24,6 @@ struct PersistentCacheOptions { : persistent_cache(_persistent_cache), base_cache_key(_base_cache_key), statistics(_statistics) {} - - virtual ~PersistentCacheOptions() {} - std::shared_ptr persistent_cache; OffsetableCacheKey base_cache_key; Statistics* statistics = nullptr; diff --git a/util/comparator.cc b/util/comparator.cc index 9fbc111b48..d04031e39b 100644 --- a/util/comparator.cc +++ b/util/comparator.cc @@ -17,6 +17,7 @@ #include #include "db/dbformat.h" +#include "port/lang.h" #include "port/port.h" #include "rocksdb/convenience.h" #include "rocksdb/slice.h" @@ -290,17 +291,18 @@ class ComparatorWithU64TsImpl : public Comparator { }// namespace const Comparator* BytewiseComparator() { - static BytewiseComparatorImpl bytewise; + STATIC_AVOID_DESTRUCTION(BytewiseComparatorImpl, bytewise); return &bytewise; } const Comparator* ReverseBytewiseComparator() { - static ReverseBytewiseComparatorImpl rbytewise; + STATIC_AVOID_DESTRUCTION(ReverseBytewiseComparatorImpl, rbytewise); return &rbytewise; } const Comparator* BytewiseComparatorWithU64Ts() { - static ComparatorWithU64TsImpl comp_with_u64_ts; + STATIC_AVOID_DESTRUCTION(ComparatorWithU64TsImpl, + comp_with_u64_ts); return &comp_with_u64_ts; } diff --git a/utilities/transactions/snapshot_checker.cc b/utilities/transactions/snapshot_checker.cc index 9c43bef43b..76d16681a1 100644 --- a/utilities/transactions/snapshot_checker.cc +++ b/utilities/transactions/snapshot_checker.cc @@ -9,6 +9,7 @@ #include #endif // ROCKSDB_LITE +#include "port/lang.h" #include "utilities/transactions/write_prepared_txn_db.h" namespace ROCKSDB_NAMESPACE { @@ -44,6 +45,9 @@ SnapshotCheckerResult WritePreparedSnapshotChecker::CheckInSnapshot( } #endif // ROCKSDB_LITE -DisableGCSnapshotChecker DisableGCSnapshotChecker::instance_; +DisableGCSnapshotChecker* DisableGCSnapshotChecker::Instance() { + STATIC_AVOID_DESTRUCTION(DisableGCSnapshotChecker, instance); + return &instance; +} } // namespace ROCKSDB_NAMESPACE