clang format files under port/ (#10849)

Summary:
Run "clang-format" against files under port to make it happy.

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

Test Plan: Watch existing CI to pass.

Reviewed By: anand1976

Differential Revision: D40645839

fbshipit-source-id: 582b4215503223795cf6234af90cc4e8e4eba773
main
sdong 2 years ago committed by Facebook GitHub Bot
parent 4d9cb433fa
commit 7cf27eae0a
  1. 4
      port/lang.h
  2. 4
      port/port_dirent.h
  3. 47
      port/port_posix.cc
  4. 9
      port/port_posix.h
  5. 2
      port/stack_trace.cc
  6. 2
      port/sys_time.h
  7. 3
      port/win/io_win.h
  8. 16
      port/win/port_win.h
  9. 1
      port/win/win_jemalloc.cc
  10. 6
      port/win/win_logger.cc
  11. 3
      port/win/win_logger.h
  12. 47
      port/win/win_thread.cc
  13. 2
      port/win/win_thread.h
  14. 69
      port/win/xpress_win.cc
  15. 4
      port/win/xpress_win.h

@ -11,7 +11,9 @@
#elif defined(__GNUC__) && __GNUC__ >= 7
#define FALLTHROUGH_INTENDED [[gnu::fallthrough]]
#else
#define FALLTHROUGH_INTENDED do {} while (0)
#define FALLTHROUGH_INTENDED \
do { \
} while (0)
#endif
#endif

@ -33,11 +33,11 @@ int closedir(DIR* dirp);
} // namespace port
using port::dirent;
using port::closedir;
using port::DIR;
using port::dirent;
using port::opendir;
using port::readdir;
using port::closedir;
} // namespace ROCKSDB_NAMESPACE

@ -64,12 +64,10 @@ Mutex::Mutex(bool adaptive) {
} else {
pthread_mutexattr_t mutex_attr;
PthreadCall("init mutex attr", pthread_mutexattr_init(&mutex_attr));
PthreadCall("set mutex attr",
pthread_mutexattr_settype(&mutex_attr,
PTHREAD_MUTEX_ADAPTIVE_NP));
PthreadCall("set mutex attr", pthread_mutexattr_settype(
&mutex_attr, PTHREAD_MUTEX_ADAPTIVE_NP));
PthreadCall("init mutex", pthread_mutex_init(&mu_, &mutex_attr));
PthreadCall("destroy mutex attr",
pthread_mutexattr_destroy(&mutex_attr));
PthreadCall("destroy mutex attr", pthread_mutexattr_destroy(&mutex_attr));
}
#else
PthreadCall("init mutex", pthread_mutex_init(&mu_, nullptr));
@ -108,8 +106,7 @@ void Mutex::AssertHeld() {
#endif
}
CondVar::CondVar(Mutex* mu)
: mu_(mu) {
CondVar::CondVar(Mutex* mu) : mu_(mu) {
PthreadCall("init cv", pthread_cond_init(&cv_, nullptr));
}
@ -146,9 +143,7 @@ bool CondVar::TimedWait(uint64_t abs_time_us) {
return false;
}
void CondVar::Signal() {
PthreadCall("signal", pthread_cond_signal(&cv_));
}
void CondVar::Signal() { PthreadCall("signal", pthread_cond_signal(&cv_)); }
void CondVar::SignalAll() {
PthreadCall("broadcast", pthread_cond_broadcast(&cv_));
@ -158,28 +153,40 @@ RWMutex::RWMutex() {
PthreadCall("init mutex", pthread_rwlock_init(&mu_, nullptr));
}
RWMutex::~RWMutex() { PthreadCall("destroy mutex", pthread_rwlock_destroy(&mu_)); }
RWMutex::~RWMutex() {
PthreadCall("destroy mutex", pthread_rwlock_destroy(&mu_));
}
void RWMutex::ReadLock() { PthreadCall("read lock", pthread_rwlock_rdlock(&mu_)); }
void RWMutex::ReadLock() {
PthreadCall("read lock", pthread_rwlock_rdlock(&mu_));
}
void RWMutex::WriteLock() { PthreadCall("write lock", pthread_rwlock_wrlock(&mu_)); }
void RWMutex::WriteLock() {
PthreadCall("write lock", pthread_rwlock_wrlock(&mu_));
}
void RWMutex::ReadUnlock() { PthreadCall("read unlock", pthread_rwlock_unlock(&mu_)); }
void RWMutex::ReadUnlock() {
PthreadCall("read unlock", pthread_rwlock_unlock(&mu_));
}
void RWMutex::WriteUnlock() { PthreadCall("write unlock", pthread_rwlock_unlock(&mu_)); }
void RWMutex::WriteUnlock() {
PthreadCall("write unlock", pthread_rwlock_unlock(&mu_));
}
int PhysicalCoreID() {
#if defined(ROCKSDB_SCHED_GETCPU_PRESENT) && defined(__x86_64__) && \
(__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 22))
// sched_getcpu uses VDSO getcpu() syscall since 2.22. I believe Linux offers VDSO
// support only on x86_64. This is the fastest/preferred method if available.
// sched_getcpu uses VDSO getcpu() syscall since 2.22. I believe Linux offers
// VDSO support only on x86_64. This is the fastest/preferred method if
// available.
int cpuno = sched_getcpu();
if (cpuno < 0) {
return -1;
}
return cpuno;
#elif defined(__x86_64__) || defined(__i386__)
// clang/gcc both provide cpuid.h, which defines __get_cpuid(), for x86_64 and i386.
// clang/gcc both provide cpuid.h, which defines __get_cpuid(), for x86_64 and
// i386.
unsigned eax, ebx = 0, ecx, edx;
if (!__get_cpuid(1, &eax, &ebx, &ecx, &edx)) {
return -1;
@ -229,9 +236,7 @@ void *cacheline_aligned_alloc(size_t size) {
#endif
}
void cacheline_aligned_free(void *memblock) {
free(memblock);
}
void cacheline_aligned_free(void* memblock) { free(memblock); }
static size_t GetPageSize() {
#if defined(OS_LINUX) || defined(_SC_PAGESIZE)

@ -39,8 +39,8 @@
#endif
#include <alloca.h>
#elif defined(OS_AIX)
#include <sys/types.h>
#include <arpa/nameser_compat.h>
#include <sys/types.h>
#define PLATFORM_IS_LITTLE_ENDIAN (BYTE_ORDER == LITTLE_ENDIAN)
#include <alloca.h>
#elif defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_NETBSD) || \
@ -52,9 +52,9 @@
#include <endian.h>
#endif
#include <pthread.h>
#include <stdint.h>
#include <string.h>
#include <limits>
#include <string>
@ -71,8 +71,8 @@
#define fflush_unlocked fflush
#endif
#if defined(OS_MACOSX) || defined(OS_FREEBSD) ||\
defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD)
#if defined(OS_MACOSX) || defined(OS_FREEBSD) || defined(OS_OPENBSD) || \
defined(OS_DRAGONFLYBSD)
// Use fsync() on platforms without fdatasync()
#define fdatasync fsync
#endif
@ -154,6 +154,7 @@ class CondVar {
bool TimedWait(uint64_t abs_time_us);
void Signal();
void SignalAll();
private:
pthread_cond_t cv_;
Mutex* mu_;

@ -24,13 +24,13 @@ void* SaveStack(int* /*num_frames*/, int /*first_frames_to_skip*/) {
#else
#include <cxxabi.h>
#include <execinfo.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <cxxabi.h>
#if defined(OS_FREEBSD)
#include <sys/sysctl.h>

@ -39,8 +39,8 @@ inline struct tm* LocalTimeR(const time_t* timep, struct tm* result) {
} // namespace ROCKSDB_NAMESPACE
#else
#include <time.h>
#include <sys/time.h>
#include <time.h>
namespace ROCKSDB_NAMESPACE {

@ -40,8 +40,7 @@ inline IOStatus IOError(const std::string& context, int err_number) {
return (err_number == ENOSPC)
? IOStatus::NoSpace(context, errnoStr(err_number).c_str())
: (err_number == ENOENT)
? IOStatus::PathNotFound(context,
errnoStr(err_number).c_str())
? IOStatus::PathNotFound(context, errnoStr(err_number).c_str())
: IOStatus::IOError(context, errnoStr(err_number).c_str());
}

@ -38,7 +38,6 @@
#undef DeleteFile
#undef GetCurrentTime
#ifndef strcasecmp
#define strcasecmp _stricmp
#endif
@ -133,12 +132,9 @@ class Mutex {
void operator=(const Mutex&) = delete;
private:
friend class CondVar;
std::mutex& getLock() {
return mutex_;
}
std::mutex& getLock() { return mutex_; }
std::mutex mutex_;
#ifndef NDEBUG
@ -170,8 +166,7 @@ class RWMutex {
class CondVar {
public:
explicit CondVar(Mutex* mu) : mu_(mu) {
}
explicit CondVar(Mutex* mu) : mu_(mu) {}
~CondVar();
void Wait();
@ -191,7 +186,6 @@ class CondVar {
Mutex* mu_;
};
#ifdef _POSIX_THREADS
using Thread = std::thread;
#else
@ -204,7 +198,6 @@ using Thread = WindowsThread;
// Posix semantics with initialization
// adopted in the project
struct OnceType {
struct Init {};
OnceType() {}
@ -322,7 +315,6 @@ bool GenerateRfcUuid(std::string* output);
} // namespace port
#ifdef ROCKSDB_WINDOWS_UTF8_FILENAMES
#define RX_FILESTRING std::wstring
@ -376,11 +368,11 @@ bool GenerateRfcUuid(std::string* output);
#endif
using port::pthread_key_t;
using port::pthread_getspecific;
using port::pthread_key_create;
using port::pthread_key_delete;
using port::pthread_key_t;
using port::pthread_setspecific;
using port::pthread_getspecific;
using port::truncate;
} // namespace ROCKSDB_NAMESPACE

@ -14,6 +14,7 @@
#endif
#include <stdexcept>
#include "jemalloc/jemalloc.h"
#include "port/win/port_win.h"

@ -57,9 +57,7 @@ void WinLogger::DebugWriter(const char* str, int len) {
WinLogger::~WinLogger() { CloseInternal().PermitUncheckedError(); }
Status WinLogger::CloseImpl() {
return CloseInternal();
}
Status WinLogger::CloseImpl() { return CloseInternal(); }
Status WinLogger::CloseInternal() {
Status s;
@ -187,7 +185,7 @@ void WinLogger::Logv(const char* format, va_list ap) {
size_t WinLogger::GetLogFileSize() const { return log_size_; }
}
} // namespace port
} // namespace ROCKSDB_NAMESPACE

@ -45,7 +45,6 @@ class WinLogger : public ROCKSDB_NAMESPACE::Logger {
void DebugWriter(const char* str, int len);
protected:
Status CloseImpl() override;
private:
@ -60,6 +59,6 @@ protected:
const static uint64_t flush_every_seconds_ = 5;
};
}
} // namespace port
} // namespace ROCKSDB_NAMESPACE

@ -28,14 +28,10 @@ namespace ROCKSDB_NAMESPACE {
namespace port {
struct WindowsThread::Data {
std::function<void()> func_;
uintptr_t handle_;
Data(std::function<void()>&& func) :
func_(std::move(func)),
handle_(0) {
}
Data(std::function<void()>&& func) : func_(std::move(func)), handle_(0) {}
Data(const Data&) = delete;
Data& operator=(const Data&) = delete;
@ -43,36 +39,30 @@ struct WindowsThread::Data {
static unsigned int __stdcall ThreadProc(void* arg);
};
void WindowsThread::Init(std::function<void()>&& func) {
data_ = std::make_shared<Data>(std::move(func));
// We create another instance of std::shared_ptr to get an additional ref
// since we may detach and destroy this instance before the threadproc
// may start to run. We choose to allocate this additional ref on the heap
// so we do not need to synchronize and allow this thread to proceed
std::unique_ptr<std::shared_ptr<Data>> th_data(new std::shared_ptr<Data>(data_));
std::unique_ptr<std::shared_ptr<Data>> th_data(
new std::shared_ptr<Data>(data_));
data_->handle_ = _beginthreadex(NULL,
0, // stack size
&Data::ThreadProc,
th_data.get(),
&Data::ThreadProc, th_data.get(),
0, // init flag
&th_id_);
if (data_->handle_ == 0) {
throw std::system_error(std::make_error_code(
std::errc::resource_unavailable_try_again),
throw std::system_error(
std::make_error_code(std::errc::resource_unavailable_try_again),
"Unable to create a thread");
}
th_data.release();
}
WindowsThread::WindowsThread() :
data_(nullptr),
th_id_(0)
{}
WindowsThread::WindowsThread() : data_(nullptr), th_id_(0) {}
WindowsThread::~WindowsThread() {
// Must be joined or detached
@ -87,13 +77,11 @@ WindowsThread::~WindowsThread() {
}
}
WindowsThread::WindowsThread(WindowsThread&& o) noexcept :
WindowsThread() {
WindowsThread::WindowsThread(WindowsThread&& o) noexcept : WindowsThread() {
*this = std::move(o);
}
WindowsThread& WindowsThread::operator=(WindowsThread&& o) noexcept {
if (joinable()) {
assert(false);
std::terminate();
@ -107,9 +95,7 @@ WindowsThread& WindowsThread::operator=(WindowsThread&& o) noexcept {
return *this;
}
bool WindowsThread::joinable() const {
return (data_ && data_->handle_ != 0);
}
bool WindowsThread::joinable() const { return (data_ && data_->handle_ != 0); }
WindowsThread::native_handle_type WindowsThread::native_handle() const {
return reinterpret_cast<native_handle_type>(data_->handle_);
@ -120,11 +106,9 @@ unsigned WindowsThread::hardware_concurrency() {
}
void WindowsThread::join() {
if (!joinable()) {
assert(false);
throw std::system_error(
std::make_error_code(std::errc::invalid_argument),
throw std::system_error(std::make_error_code(std::errc::invalid_argument),
"Thread is no longer joinable");
}
@ -135,13 +119,12 @@ void WindowsThread::join() {
"Can not join itself");
}
auto ret = WaitForSingleObject(reinterpret_cast<HANDLE>(data_->handle_),
INFINITE);
auto ret =
WaitForSingleObject(reinterpret_cast<HANDLE>(data_->handle_), INFINITE);
if (ret != WAIT_OBJECT_0) {
auto lastError = GetLastError();
assert(false);
throw std::system_error(static_cast<int>(lastError),
std::system_category(),
throw std::system_error(static_cast<int>(lastError), std::system_category(),
"WaitForSingleObjectFailed: thread join");
}
@ -157,11 +140,9 @@ void WindowsThread::join() {
}
bool WindowsThread::detach() {
if (!joinable()) {
assert(false);
throw std::system_error(
std::make_error_code(std::errc::invalid_argument),
throw std::system_error(std::make_error_code(std::errc::invalid_argument),
"Thread is no longer available");
}

@ -11,8 +11,8 @@
#ifndef _POSIX_THREADS
#include <memory>
#include <functional>
#include <memory>
#include <type_traits>
#include "rocksdb/rocksdb_namespace.h"

@ -10,12 +10,13 @@
#if defined(OS_WIN)
#include "port/win/xpress_win.h"
#include <windows.h>
#include <cassert>
#include <memory>
#include <limits>
#include <iostream>
#include <limits>
#include <memory>
#ifdef XPRESS
@ -41,10 +42,9 @@ auto CloseDecompressorFun = [](void* h) {
::CloseDecompressor(reinterpret_cast<DECOMPRESSOR_HANDLE>(h));
}
};
}
} // namespace
bool Compress(const char* input, size_t length, std::string* output) {
assert(input != nullptr);
assert(output != nullptr);
@ -57,27 +57,26 @@ bool Compress(const char* input, size_t length, std::string* output) {
COMPRESSOR_HANDLE compressor = NULL;
BOOL success = CreateCompressor(
COMPRESS_ALGORITHM_XPRESS, // Compression Algorithm
BOOL success =
CreateCompressor(COMPRESS_ALGORITHM_XPRESS, // Compression Algorithm
allocRoutinesPtr, // Optional allocation routine
&compressor); // Handle
if (!success) {
#ifdef _DEBUG
std::cerr << "XPRESS: Failed to create Compressor LastError: " <<
GetLastError() << std::endl;
std::cerr << "XPRESS: Failed to create Compressor LastError: "
<< GetLastError() << std::endl;
#endif
return false;
}
std::unique_ptr<void, decltype(CloseCompressorFun)>
compressorGuard(compressor, CloseCompressorFun);
std::unique_ptr<void, decltype(CloseCompressorFun)> compressorGuard(
compressor, CloseCompressorFun);
SIZE_T compressedBufferSize = 0;
// Query compressed buffer size.
success = ::Compress(
compressor, // Compressor Handle
success = ::Compress(compressor, // Compressor Handle
const_cast<char*>(input), // Input buffer
length, // Uncompressed data size
NULL, // Compressed Buffer
@ -85,14 +84,13 @@ bool Compress(const char* input, size_t length, std::string* output) {
&compressedBufferSize); // Compressed Data size
if (!success) {
auto lastError = GetLastError();
if (lastError != ERROR_INSUFFICIENT_BUFFER) {
#ifdef _DEBUG
std::cerr <<
"XPRESS: Failed to estimate compressed buffer size LastError " <<
lastError << std::endl;
std::cerr
<< "XPRESS: Failed to estimate compressed buffer size LastError "
<< lastError << std::endl;
#endif
return false;
}
@ -106,8 +104,7 @@ bool Compress(const char* input, size_t length, std::string* output) {
SIZE_T compressedDataSize = 0;
// Compress
success = ::Compress(
compressor, // Compressor Handle
success = ::Compress(compressor, // Compressor Handle
const_cast<char*>(input), // Input buffer
length, // Uncompressed data size
&result[0], // Compressed Buffer
@ -116,8 +113,8 @@ bool Compress(const char* input, size_t length, std::string* output) {
if (!success) {
#ifdef _DEBUG
std::cerr << "XPRESS: Failed to compress LastError " <<
GetLastError() << std::endl;
std::cerr << "XPRESS: Failed to compress LastError " << GetLastError()
<< std::endl;
#endif
return false;
}
@ -141,12 +138,11 @@ char* Decompress(const char* input_data, size_t input_length,
DECOMPRESSOR_HANDLE decompressor = NULL;
BOOL success = CreateDecompressor(
COMPRESS_ALGORITHM_XPRESS, // Compression Algorithm
BOOL success =
CreateDecompressor(COMPRESS_ALGORITHM_XPRESS, // Compression Algorithm
allocRoutinesPtr, // Optional allocation routine
&decompressor); // Handle
if (!success) {
#ifdef _DEBUG
std::cerr << "XPRESS: Failed to create Decompressor LastError "
@ -155,13 +151,12 @@ char* Decompress(const char* input_data, size_t input_length,
return nullptr;
}
std::unique_ptr<void, decltype(CloseDecompressorFun)>
compressorGuard(decompressor, CloseDecompressorFun);
std::unique_ptr<void, decltype(CloseDecompressorFun)> compressorGuard(
decompressor, CloseDecompressorFun);
SIZE_T decompressedBufferSize = 0;
success = ::Decompress(
decompressor, // Compressor Handle
success = ::Decompress(decompressor, // Compressor Handle
const_cast<char*>(input_data), // Compressed data
input_length, // Compressed data size
NULL, // Buffer set to NULL
@ -169,7 +164,6 @@ char* Decompress(const char* input_data, size_t input_length,
&decompressedBufferSize); // Decompressed Data size
if (!success) {
auto lastError = GetLastError();
if (lastError != ERROR_INSUFFICIENT_BUFFER) {
@ -190,19 +184,14 @@ char* Decompress(const char* input_data, size_t input_length,
SIZE_T decompressedDataSize = 0;
success = ::Decompress(
decompressor,
const_cast<char*>(input_data),
input_length,
outputBuffer.get(),
decompressedBufferSize,
&decompressedDataSize);
success = ::Decompress(decompressor, const_cast<char*>(input_data),
input_length, outputBuffer.get(),
decompressedBufferSize, &decompressedDataSize);
if (!success) {
#ifdef _DEBUG
std::cerr <<
"XPRESS: Failed to decompress LastError " <<
GetLastError() << std::endl;
std::cerr << "XPRESS: Failed to decompress LastError " << GetLastError()
<< std::endl;
#endif
return nullptr;
}
@ -212,8 +201,8 @@ char* Decompress(const char* input_data, size_t input_length,
// Return the raw buffer to the caller supporting the tradition
return outputBuffer.release();
}
}
}
} // namespace xpress
} // namespace port
} // namespace ROCKSDB_NAMESPACE
#endif

@ -21,6 +21,6 @@ bool Compress(const char* input, size_t length, std::string* output);
char* Decompress(const char* input_data, size_t input_length,
size_t* uncompressed_size);
}
}
} // namespace xpress
} // namespace port
} // namespace ROCKSDB_NAMESPACE

Loading…
Cancel
Save