removed the fdbrpc version of platform.h

This commit is contained in:
Evan Tschannen 2020-02-28 14:56:10 -08:00
parent 6054c05963
commit c11c24b79d
14 changed files with 59 additions and 182 deletions

View File

@ -36,7 +36,7 @@
#include "fdbclient/BlobStore.h" #include "fdbclient/BlobStore.h"
#include "fdbclient/json_spirit/json_spirit_writer_template.h" #include "fdbclient/json_spirit/json_spirit_writer_template.h"
#include "fdbrpc/Platform.h" #include "flow/Platform.h"
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>

View File

@ -32,7 +32,7 @@
#include "fdbclient/FDBOptions.g.h" #include "fdbclient/FDBOptions.g.h"
#include "flow/DeterministicRandom.h" #include "flow/DeterministicRandom.h"
#include "fdbrpc/Platform.h" #include "flow/Platform.h"
#include "flow/SimpleOpt.h" #include "flow/SimpleOpt.h"

View File

@ -25,7 +25,7 @@
#include "flow/UnitTest.h" #include "flow/UnitTest.h"
#include "flow/Hash3.h" #include "flow/Hash3.h"
#include "fdbrpc/AsyncFileReadAhead.actor.h" #include "fdbrpc/AsyncFileReadAhead.actor.h"
#include "fdbrpc/Platform.h" #include "flow/Platform.h"
#include "fdbclient/AsyncFileBlobStore.actor.h" #include "fdbclient/AsyncFileBlobStore.actor.h"
#include "fdbclient/Status.h" #include "fdbclient/Status.h"
#include "fdbclient/SystemData.h" #include "fdbclient/SystemData.h"

View File

@ -23,7 +23,7 @@
#include "flow/ActorCollection.h" #include "flow/ActorCollection.h"
#include "flow/UnitTest.h" #include "flow/UnitTest.h"
#include "fdbrpc/genericactors.actor.h" #include "fdbrpc/genericactors.actor.h"
#include "fdbrpc/Platform.h" #include "flow/Platform.h"
#include "flow/actorcompiler.h" // has to be last include #include "flow/actorcompiler.h" // has to be last include
std::pair< std::string, bool > ClusterConnectionFile::lookupClusterFileName( std::string const& filename ) { std::pair< std::string, bool > ClusterConnectionFile::lookupClusterFileName( std::string const& filename ) {

View File

@ -18,7 +18,6 @@ set(FDBRPC_SRCS
Locality.cpp Locality.cpp
Net2FileSystem.cpp Net2FileSystem.cpp
networksender.actor.h networksender.actor.h
Platform.cpp
QueueModel.cpp QueueModel.cpp
ReplicationPolicy.cpp ReplicationPolicy.cpp
ReplicationTypes.cpp ReplicationTypes.cpp

View File

@ -1,130 +0,0 @@
/*
* Platform.cpp
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
*
* 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 "fdbrpc/Platform.h"
#include <algorithm>
#include "flow/ActorCollection.h"
#include "flow/FaultInjection.h"
#ifdef _WIN32
#include <windows.h>
#undef max
#undef min
#include <io.h>
#include <psapi.h>
#include <stdio.h>
#include <conio.h>
#include <pdh.h>
#include <pdhmsg.h>
#pragma comment(lib, "pdh.lib")
// for SHGetFolderPath
#include <ShlObj.h>
#pragma comment(lib, "Shell32.lib")
#define CANONICAL_PATH_SEPARATOR '\\'
#endif
#ifdef __unixish__
#define CANONICAL_PATH_SEPARATOR '/'
#include <dirent.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <unistd.h>
#include <ftw.h>
#include <pwd.h>
#include <sched.h>
#include <cpuid.h>
#ifdef __APPLE__
#include <sys/uio.h>
#include <sys/syslimits.h>
#include <mach/mach.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/sysctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/storage/IOBlockStorageDriver.h>
#include <IOKit/storage/IOMedia.h>
#include <IOKit/IOBSD.h>
#endif
#endif
extern bool onlyBeforeSimulatorInit();
namespace platform {
// Because the lambda used with nftw below cannot capture
int __eraseDirectoryRecurseiveCount;
int eraseDirectoryRecursive(std::string const& dir) {
__eraseDirectoryRecurseiveCount = 0;
#ifdef _WIN32
system( ("rd /s /q \"" + dir + "\"").c_str() );
#elif defined(__linux__) || defined(__APPLE__)
int error =
nftw(dir.c_str(),
[](const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) -> int {
int r = remove(fpath);
if(r == 0)
++__eraseDirectoryRecurseiveCount;
return r;
},
64, FTW_DEPTH | FTW_PHYS);
/* Looks like calling code expects this to continue silently if
the directory we're deleting doesn't exist in the first
place */
if (error && errno != ENOENT) {
Error e = systemErrorCodeToError();
TraceEvent(SevError, "EraseDirectoryRecursiveError").detail("Directory", dir).GetLastError().error(e);
throw e;
}
#else
#error Port me!
#endif
//INJECT_FAULT( platform_error, "eraseDirectoryRecursive" );
return __eraseDirectoryRecurseiveCount;
}
bool isSse42Supported()
{
#if defined(_WIN32)
int info[4];
__cpuid(info, 1);
return (info[2] & (1 << 20)) != 0;
#elif defined(__unixish__)
uint32_t eax, ebx, ecx, edx, level = 1, count = 0;
__cpuid_count(level, count, eax, ebx, ecx, edx);
return ((ecx >> 20) & 1) != 0;
#else
#error Port me!
#endif
}
} // namespace platform

View File

@ -1,37 +0,0 @@
/*
* Platform.h
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
*
* 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.
*/
#ifndef FDBRPC_UTILS_H
#define FDBRPC_UTILS_H
#pragma once
#include "flow/Platform.h"
#include <string>
namespace platform {
// Avoid in production code: not atomic, not fast, not reliable in all environments
int eraseDirectoryRecursive(std::string const& directory);
bool isSse42Supported();
} // namespace platform
#endif

View File

@ -20,7 +20,6 @@
<ActorCompiler Include="genericactors.actor.cpp" /> <ActorCompiler Include="genericactors.actor.cpp" />
<ActorCompiler Include="FlowTransport.actor.cpp" /> <ActorCompiler Include="FlowTransport.actor.cpp" />
<ActorCompiler Include="IAsyncFile.actor.cpp" /> <ActorCompiler Include="IAsyncFile.actor.cpp" />
<ClCompile Include="Platform.cpp" />
<ClCompile Include="AsyncFileWriteChecker.cpp" /> <ClCompile Include="AsyncFileWriteChecker.cpp" />
<ClCompile Include="libcoroutine\Common.c" /> <ClCompile Include="libcoroutine\Common.c" />
<ClCompile Include="libcoroutine\Coro.c" /> <ClCompile Include="libcoroutine\Coro.c" />
@ -84,7 +83,6 @@
</ActorCompiler> </ActorCompiler>
<ClInclude Include="IAsyncFile.h" /> <ClInclude Include="IAsyncFile.h" />
<ClInclude Include="IRateControl.h" /> <ClInclude Include="IRateControl.h" />
<ClInclude Include="Platform.h" />
<ClInclude Include="fdbrpc.h" /> <ClInclude Include="fdbrpc.h" />
<ClInclude Include="FlowTransport.h" /> <ClInclude Include="FlowTransport.h" />
<ClInclude Include="libcoroutine\Base.h" /> <ClInclude Include="libcoroutine\Base.h" />

View File

@ -70,7 +70,6 @@
<Filter>zlib</Filter> <Filter>zlib</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Net2FileSystem.cpp" /> <ClCompile Include="Net2FileSystem.cpp" />
<ClCompile Include="Platform.cpp" />
<ClCompile Include="QueueModel.cpp" /> <ClCompile Include="QueueModel.cpp" />
<ClCompile Include="TraceFileIO.cpp" /> <ClCompile Include="TraceFileIO.cpp" />
<ClCompile Include="Replication.cpp" /> <ClCompile Include="Replication.cpp" />
@ -131,7 +130,6 @@
<ClInclude Include="FlowTransport.h" /> <ClInclude Include="FlowTransport.h" />
<ClInclude Include="IAsyncFile.h" /> <ClInclude Include="IAsyncFile.h" />
<ClInclude Include="Net2FileSystem.h" /> <ClInclude Include="Net2FileSystem.h" />
<ClInclude Include="Platform.h" />
<ClInclude Include="ActorFuzz.h" /> <ClInclude Include="ActorFuzz.h" />
<ClInclude Include="ContinuousSample.h" /> <ClInclude Include="ContinuousSample.h" />
<ClInclude Include="fdbrpc.h" /> <ClInclude Include="fdbrpc.h" />

View File

@ -95,10 +95,6 @@ public:
}; };
} }
bool onlyBeforeSimulatorInit() {
return g_network->isSimulated() && g_simulator.getAllProcesses().empty();
}
const UID TOKEN_ENDPOINT_NOT_FOUND(-1, -1); const UID TOKEN_ENDPOINT_NOT_FOUND(-1, -1);
ISimulator* g_pSimulator = 0; ISimulator* g_pSimulator = 0;

View File

@ -52,7 +52,6 @@
#include <time.h> #include <time.h>
#include "fdbserver/Status.h" #include "fdbserver/Status.h"
#include "fdbrpc/Net2FileSystem.h" #include "fdbrpc/Net2FileSystem.h"
#include "fdbrpc/Platform.h"
#include "fdbrpc/AsyncFileCached.actor.h" #include "fdbrpc/AsyncFileCached.actor.h"
#include "fdbserver/CoroFlow.h" #include "fdbserver/CoroFlow.h"
#include "flow/TLSPolicy.h" #include "flow/TLSPolicy.h"

View File

@ -77,6 +77,7 @@
#include <ftw.h> #include <ftw.h>
#include <pwd.h> #include <pwd.h>
#include <sched.h> #include <sched.h>
#include <cpuid.h>
/* Needed for disk capacity */ /* Needed for disk capacity */
#include <sys/statvfs.h> #include <sys/statvfs.h>
@ -2502,6 +2503,54 @@ void outOfMemory() {
criticalError(FDB_EXIT_NO_MEM, "OutOfMemory", "Out of memory"); criticalError(FDB_EXIT_NO_MEM, "OutOfMemory", "Out of memory");
} }
// Because the lambda used with nftw below cannot capture
int __eraseDirectoryRecurseiveCount;
int eraseDirectoryRecursive(std::string const& dir) {
__eraseDirectoryRecurseiveCount = 0;
#ifdef _WIN32
system( ("rd /s /q \"" + dir + "\"").c_str() );
#elif defined(__linux__) || defined(__APPLE__)
int error =
nftw(dir.c_str(),
[](const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) -> int {
int r = remove(fpath);
if(r == 0)
++__eraseDirectoryRecurseiveCount;
return r;
},
64, FTW_DEPTH | FTW_PHYS);
/* Looks like calling code expects this to continue silently if
the directory we're deleting doesn't exist in the first
place */
if (error && errno != ENOENT) {
Error e = systemErrorCodeToError();
TraceEvent(SevError, "EraseDirectoryRecursiveError").detail("Directory", dir).GetLastError().error(e);
throw e;
}
#else
#error Port me!
#endif
//INJECT_FAULT( platform_error, "eraseDirectoryRecursive" );
return __eraseDirectoryRecurseiveCount;
}
bool isSse42Supported()
{
#if defined(_WIN32)
int info[4];
__cpuid(info, 1);
return (info[2] & (1 << 20)) != 0;
#elif defined(__unixish__)
uint32_t eax, ebx, ecx, edx, level = 1, count = 0;
__cpuid_count(level, count, eax, ebx, ecx, edx);
return ((ecx >> 20) & 1) != 0;
#else
#error Port me!
#endif
}
} // namespace platform } // namespace platform
extern "C" void criticalError(int exitCode, const char *type, const char *message) { extern "C" void criticalError(int exitCode, const char *type, const char *message) {

View File

@ -388,6 +388,11 @@ size_t raw_backtrace(void** addresses, int maxStackDepth);
std::string get_backtrace(); std::string get_backtrace();
std::string format_backtrace(void **addresses, int numAddresses); std::string format_backtrace(void **addresses, int numAddresses);
// Avoid in production code: not atomic, not fast, not reliable in all environments
int eraseDirectoryRecursive(std::string const& directory);
bool isSse42Supported();
} // namespace platform } // namespace platform
#ifdef __linux__ #ifdef __linux__

View File

@ -34,7 +34,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <random> #include <random>
#include <algorithm> #include <algorithm>
#include "fdbrpc/Platform.h" #include "flow/Platform.h"
#include "crc32c-generated-constants.cpp" #include "crc32c-generated-constants.cpp"
static uint32_t append_trivial(uint32_t crc, const uint8_t * input, size_t length) static uint32_t append_trivial(uint32_t crc, const uint8_t * input, size_t length)