mirror of https://github.com/facebook/rocksdb.git
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:
parent
3f263ef536
commit
b11ff347b4
|
@ -33,10 +33,9 @@ class DisableGCSnapshotChecker : public SnapshotChecker {
|
||||||
// By returning kNotInSnapshot, we prevent all the values from being GCed
|
// By returning kNotInSnapshot, we prevent all the values from being GCed
|
||||||
return SnapshotCheckerResult::kNotInSnapshot;
|
return SnapshotCheckerResult::kNotInSnapshot;
|
||||||
}
|
}
|
||||||
static DisableGCSnapshotChecker* Instance() { return &instance_; }
|
static DisableGCSnapshotChecker* Instance();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static DisableGCSnapshotChecker instance_;
|
|
||||||
explicit DisableGCSnapshotChecker() {}
|
explicit DisableGCSnapshotChecker() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -488,6 +488,7 @@ Env* Env::Default() {
|
||||||
CompressionContextCache::InitSingleton();
|
CompressionContextCache::InitSingleton();
|
||||||
INIT_SYNC_POINT_SINGLETONS();
|
INIT_SYNC_POINT_SINGLETONS();
|
||||||
// ~PosixEnv must be called on exit
|
// ~PosixEnv must be called on exit
|
||||||
|
//**TODO: Can we make this a STATIC_AVOID_DESTRUCTION?
|
||||||
static PosixEnv default_env;
|
static PosixEnv default_env;
|
||||||
return &default_env;
|
return &default_env;
|
||||||
}
|
}
|
||||||
|
@ -496,9 +497,9 @@ Env* Env::Default() {
|
||||||
// Default Posix SystemClock
|
// Default Posix SystemClock
|
||||||
//
|
//
|
||||||
const std::shared_ptr<SystemClock>& SystemClock::Default() {
|
const std::shared_ptr<SystemClock>& SystemClock::Default() {
|
||||||
static std::shared_ptr<SystemClock> default_clock =
|
STATIC_AVOID_DESTRUCTION(std::shared_ptr<SystemClock>, instance)
|
||||||
std::make_shared<PosixClock>();
|
(std::make_shared<PosixClock>());
|
||||||
return default_clock;
|
return instance;
|
||||||
}
|
}
|
||||||
} // namespace ROCKSDB_NAMESPACE
|
} // namespace ROCKSDB_NAMESPACE
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
#include "logging/posix_logger.h"
|
#include "logging/posix_logger.h"
|
||||||
#include "monitoring/iostats_context_imp.h"
|
#include "monitoring/iostats_context_imp.h"
|
||||||
#include "monitoring/thread_status_updater.h"
|
#include "monitoring/thread_status_updater.h"
|
||||||
|
#include "port/lang.h"
|
||||||
#include "port/port.h"
|
#include "port/port.h"
|
||||||
#include "rocksdb/options.h"
|
#include "rocksdb/options.h"
|
||||||
#include "rocksdb/slice.h"
|
#include "rocksdb/slice.h"
|
||||||
|
@ -1210,10 +1211,9 @@ PosixFileSystem::PosixFileSystem()
|
||||||
// Default Posix FileSystem
|
// Default Posix FileSystem
|
||||||
//
|
//
|
||||||
std::shared_ptr<FileSystem> FileSystem::Default() {
|
std::shared_ptr<FileSystem> FileSystem::Default() {
|
||||||
static PosixFileSystem default_fs;
|
STATIC_AVOID_DESTRUCTION(std::shared_ptr<FileSystem>, instance)
|
||||||
static std::shared_ptr<PosixFileSystem> default_fs_ptr(
|
(std::make_shared<PosixFileSystem>());
|
||||||
&default_fs, [](PosixFileSystem*) {});
|
return instance;
|
||||||
return default_fs_ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef ROCKSDB_LITE
|
#ifndef ROCKSDB_LITE
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "monitoring/iostats_context_imp.h"
|
#include "monitoring/iostats_context_imp.h"
|
||||||
#include "monitoring/thread_status_updater.h"
|
#include "monitoring/thread_status_updater.h"
|
||||||
#include "monitoring/thread_status_util.h"
|
#include "monitoring/thread_status_util.h"
|
||||||
|
#include "port/lang.h"
|
||||||
#include "port/port.h"
|
#include "port/port.h"
|
||||||
#include "port/port_dirent.h"
|
#include "port/port_dirent.h"
|
||||||
#include "port/win/io_win.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() {
|
const std::shared_ptr<WinFileSystem>& WinFileSystem::Default() {
|
||||||
static std::shared_ptr<WinFileSystem> fs =
|
STATIC_AVOID_DESTRUCTION(std::shared_ptr<WinFileSystem>, fs)
|
||||||
std::make_shared<WinFileSystem>(WinClock::Default());
|
(std::make_shared<WinFileSystem>(WinClock::Default()));
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1410,8 +1411,8 @@ std::shared_ptr<FileSystem> FileSystem::Default() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<SystemClock>& SystemClock::Default() {
|
const std::shared_ptr<SystemClock>& SystemClock::Default() {
|
||||||
static std::shared_ptr<SystemClock> clock =
|
STATIC_AVOID_DESTRUCTION(std::shared_ptr<SystemClock>, clock)
|
||||||
std::make_shared<port::WinClock>();
|
(std::make_shared<port::WinClock>());
|
||||||
return clock;
|
return clock;
|
||||||
}
|
}
|
||||||
} // namespace ROCKSDB_NAMESPACE
|
} // namespace ROCKSDB_NAMESPACE
|
||||||
|
|
|
@ -24,9 +24,6 @@ struct PersistentCacheOptions {
|
||||||
: persistent_cache(_persistent_cache),
|
: persistent_cache(_persistent_cache),
|
||||||
base_cache_key(_base_cache_key),
|
base_cache_key(_base_cache_key),
|
||||||
statistics(_statistics) {}
|
statistics(_statistics) {}
|
||||||
|
|
||||||
virtual ~PersistentCacheOptions() {}
|
|
||||||
|
|
||||||
std::shared_ptr<PersistentCache> persistent_cache;
|
std::shared_ptr<PersistentCache> persistent_cache;
|
||||||
OffsetableCacheKey base_cache_key;
|
OffsetableCacheKey base_cache_key;
|
||||||
Statistics* statistics = nullptr;
|
Statistics* statistics = nullptr;
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "db/dbformat.h"
|
#include "db/dbformat.h"
|
||||||
|
#include "port/lang.h"
|
||||||
#include "port/port.h"
|
#include "port/port.h"
|
||||||
#include "rocksdb/convenience.h"
|
#include "rocksdb/convenience.h"
|
||||||
#include "rocksdb/slice.h"
|
#include "rocksdb/slice.h"
|
||||||
|
@ -290,17 +291,18 @@ class ComparatorWithU64TsImpl : public Comparator {
|
||||||
}// namespace
|
}// namespace
|
||||||
|
|
||||||
const Comparator* BytewiseComparator() {
|
const Comparator* BytewiseComparator() {
|
||||||
static BytewiseComparatorImpl bytewise;
|
STATIC_AVOID_DESTRUCTION(BytewiseComparatorImpl, bytewise);
|
||||||
return &bytewise;
|
return &bytewise;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Comparator* ReverseBytewiseComparator() {
|
const Comparator* ReverseBytewiseComparator() {
|
||||||
static ReverseBytewiseComparatorImpl rbytewise;
|
STATIC_AVOID_DESTRUCTION(ReverseBytewiseComparatorImpl, rbytewise);
|
||||||
return &rbytewise;
|
return &rbytewise;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Comparator* BytewiseComparatorWithU64Ts() {
|
const Comparator* BytewiseComparatorWithU64Ts() {
|
||||||
static ComparatorWithU64TsImpl<BytewiseComparatorImpl> comp_with_u64_ts;
|
STATIC_AVOID_DESTRUCTION(ComparatorWithU64TsImpl<BytewiseComparatorImpl>,
|
||||||
|
comp_with_u64_ts);
|
||||||
return &comp_with_u64_ts;
|
return &comp_with_u64_ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#endif // ROCKSDB_LITE
|
#endif // ROCKSDB_LITE
|
||||||
|
|
||||||
|
#include "port/lang.h"
|
||||||
#include "utilities/transactions/write_prepared_txn_db.h"
|
#include "utilities/transactions/write_prepared_txn_db.h"
|
||||||
|
|
||||||
namespace ROCKSDB_NAMESPACE {
|
namespace ROCKSDB_NAMESPACE {
|
||||||
|
@ -44,6 +45,9 @@ SnapshotCheckerResult WritePreparedSnapshotChecker::CheckInSnapshot(
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ROCKSDB_LITE
|
#endif // ROCKSDB_LITE
|
||||||
DisableGCSnapshotChecker DisableGCSnapshotChecker::instance_;
|
|
||||||
|
|
||||||
|
DisableGCSnapshotChecker* DisableGCSnapshotChecker::Instance() {
|
||||||
|
STATIC_AVOID_DESTRUCTION(DisableGCSnapshotChecker, instance);
|
||||||
|
return &instance;
|
||||||
|
}
|
||||||
} // namespace ROCKSDB_NAMESPACE
|
} // namespace ROCKSDB_NAMESPACE
|
||||||
|
|
Loading…
Reference in New Issue