Use STATIC_AVOID_DESTRUCTION for static objects with non-trivial destructors (#9958)

Summary:
Changed the static objects that had non-trivial destructors to use the STATIC_AVOID_DESTRUCTION construct.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/9958

Reviewed By: pdillinger

Differential Revision: D36442982

Pulled By: mrambacher

fbshipit-source-id: 029d47b1374d30d198bfede369a4c0ae7a4eb519
This commit is contained in:
mrambacher 2022-05-17 09:39:22 -07:00 committed by Facebook GitHub Bot
parent 3f263ef536
commit b11ff347b4
7 changed files with 24 additions and 20 deletions

View File

@ -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() {}
};

7
env/env_posix.cc vendored
View File

@ -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>& SystemClock::Default() {
static std::shared_ptr<SystemClock> default_clock =
std::make_shared<PosixClock>();
return default_clock;
STATIC_AVOID_DESTRUCTION(std::shared_ptr<SystemClock>, instance)
(std::make_shared<PosixClock>());
return instance;
}
} // namespace ROCKSDB_NAMESPACE

8
env/fs_posix.cc vendored
View File

@ -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> FileSystem::Default() {
static PosixFileSystem default_fs;
static std::shared_ptr<PosixFileSystem> default_fs_ptr(
&default_fs, [](PosixFileSystem*) {});
return default_fs_ptr;
STATIC_AVOID_DESTRUCTION(std::shared_ptr<FileSystem>, instance)
(std::make_shared<PosixFileSystem>());
return instance;
}
#ifndef ROCKSDB_LITE

View File

@ -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<SystemClock>& clock)
}
const std::shared_ptr<WinFileSystem>& WinFileSystem::Default() {
static std::shared_ptr<WinFileSystem> fs =
std::make_shared<WinFileSystem>(WinClock::Default());
STATIC_AVOID_DESTRUCTION(std::shared_ptr<WinFileSystem>, fs)
(std::make_shared<WinFileSystem>(WinClock::Default()));
return fs;
}
@ -1410,8 +1411,8 @@ std::shared_ptr<FileSystem> FileSystem::Default() {
}
const std::shared_ptr<SystemClock>& SystemClock::Default() {
static std::shared_ptr<SystemClock> clock =
std::make_shared<port::WinClock>();
STATIC_AVOID_DESTRUCTION(std::shared_ptr<SystemClock>, clock)
(std::make_shared<port::WinClock>());
return clock;
}
} // namespace ROCKSDB_NAMESPACE

View File

@ -24,9 +24,6 @@ struct PersistentCacheOptions {
: persistent_cache(_persistent_cache),
base_cache_key(_base_cache_key),
statistics(_statistics) {}
virtual ~PersistentCacheOptions() {}
std::shared_ptr<PersistentCache> persistent_cache;
OffsetableCacheKey base_cache_key;
Statistics* statistics = nullptr;

View File

@ -17,6 +17,7 @@
#include <sstream>
#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<BytewiseComparatorImpl> comp_with_u64_ts;
STATIC_AVOID_DESTRUCTION(ComparatorWithU64TsImpl<BytewiseComparatorImpl>,
comp_with_u64_ts);
return &comp_with_u64_ts;
}

View File

@ -9,6 +9,7 @@
#include <assert.h>
#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