Return new operator for Status allocations for Windows (#4128)

Summary: Windows requires new/delete for memory allocations to be overriden. Refactor to be less intrusive.

Differential Revision: D8878047

Pulled By: siying

fbshipit-source-id: 35f2b5fec2f88ea48c9be926539c6469060aab36
This commit is contained in:
Dmitri Smirnov 2018-07-19 15:07:22 -07:00 committed by Facebook Github Bot
parent f3801528c1
commit 78ab11cd71
5 changed files with 24 additions and 12 deletions

View File

@ -48,6 +48,7 @@ option(WITH_JEMALLOC "build with JeMalloc" OFF)
option(WITH_SNAPPY "build with SNAPPY" OFF)
option(WITH_LZ4 "build with lz4" OFF)
option(WITH_ZLIB "build with zlib" OFF)
option(WITH_ZSTD "build with zstd" OFF)
if(MSVC)
# Defaults currently different for GFLAGS.
# We will address find_package work a little later
@ -108,7 +109,6 @@ else()
list(APPEND THIRDPARTY_LIBS ${LZ4_LIBRARIES})
endif()
option(WITH_ZSTD "build with zstd" OFF)
if(WITH_ZSTD)
find_package(zstd REQUIRED)
add_definitions(-DZSTD)
@ -307,14 +307,6 @@ if(DISABLE_STALL_NOTIF)
add_definitions(-DROCKSDB_DISABLE_STALL_NOTIFICATION)
endif()
# Used to run CI build and tests so we can run faster
set(OPTIMIZE_DEBUG_DEFAULT 0) # Debug build is unoptimized by default use -DOPTDBG=1 to optimize
if(DEFINED OPTDBG)
set(OPTIMIZE_DEBUG ${OPTDBG})
else()
set(OPTIMIZE_DEBUG ${OPTIMIZE_DEBUG_DEFAULT})
endif()
if(DEFINED USE_RTTI)
if(USE_RTTI)
@ -342,8 +334,10 @@ else()
endif()
endif()
# Used to run CI build and tests so we can run faster
option(OPTDBG "Build optimized debug build with MSVC" OFF)
if(MSVC)
if((${OPTIMIZE_DEBUG} EQUAL 1))
if(OPTDBG)
message(STATUS "Debug optimization is enabled")
set(CMAKE_CXX_FLAGS_DEBUG "/Oxt /${RUNTIME_LIBRARY}d")
else()

View File

@ -1822,7 +1822,7 @@ TEST_P(DBTestUniversalCompaction, FinalSortedRunCompactFilesConflict) {
"CompactFilesImpl:1"}});
rocksdb::SyncPoint::GetInstance()->EnableProcessing();
std::thread compact_files_thread([&]() {
port::Thread compact_files_thread([&]() {
ASSERT_OK(dbfull()->CompactFiles(CompactionOptions(), default_cfh,
{first_sst_filename}, num_levels_ - 1));
});

View File

@ -37,10 +37,14 @@ ZSTD_customMem GetJeZstdAllocationOverrides() {
// Global operators to be replaced by a linker when this file is
// a part of the build
namespace rocksdb {
namespace port {
void* jemalloc_aligned_alloc(size_t size, size_t alignment) ROCKSDB_NOEXCEPT {
return je_aligned_alloc(alignment, size);
}
void jemalloc_aligned_free(void* p) ROCKSDB_NOEXCEPT { je_free(p); }
} // port
} // rocksdb
void* operator new(size_t size) {
void* p = je_malloc(size);

View File

@ -9,15 +9,29 @@
#include "rocksdb/status.h"
#include <stdio.h>
#ifdef OS_WIN
#include <string.h>
#endif
#include <cstring>
#include "port/port.h"
namespace rocksdb {
const char* Status::CopyState(const char* state) {
#ifdef OS_WIN
const size_t cch =
std::strlen(state) + 1; // +1 for the null terminator
char* result = new char[cch];
errno_t ret;
ret = strncpy_s(result, cch, state, cch - 1);
result[cch - 1] = '\0';
assert(ret == 0);
return result;
#else
const size_t cch =
std::strlen(state) + 1; // +1 for the null terminator
return std::strncpy(new char[cch], state, cch);
#endif
}
Status::Status(Code _code, SubCode _subcode, const Slice& msg, const Slice& msg2)

View File

@ -185,7 +185,7 @@ void NTAPI WinOnThreadExit(PVOID module, DWORD reason, PVOID reserved) {
// We decided to punt on PROCESS_EXIT
if (DLL_THREAD_DETACH == reason) {
if (thread_local_key != pthread_key_t(-1) && thread_local_inclass_routine != nullptr) {
void* tls = pthread_getspecific(thread_local_key);
void* tls = TlsGetValue(thread_local_key);
if (tls != nullptr) {
thread_local_inclass_routine(tls);
}