From 7cf27eae0ada5c34e00e09eeca6b1be0c6336a5d Mon Sep 17 00:00:00 2001 From: sdong Date: Mon, 24 Oct 2022 16:56:01 -0700 Subject: [PATCH] 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 --- port/lang.h | 4 +- port/likely.h | 4 +- port/port_dirent.h | 4 +- port/port_posix.cc | 59 ++++++++++---------- port/port_posix.h | 61 ++++++++++----------- port/stack_trace.cc | 2 +- port/sys_time.h | 2 +- port/win/io_win.h | 13 +++-- port/win/port_win.h | 32 +++++------ port/win/win_jemalloc.cc | 9 ++-- port/win/win_logger.cc | 8 ++- port/win/win_logger.h | 7 ++- port/win/win_thread.cc | 79 +++++++++++---------------- port/win/win_thread.h | 10 ++-- port/win/xpress_win.cc | 113 ++++++++++++++++++--------------------- port/win/xpress_win.h | 4 +- 16 files changed, 189 insertions(+), 222 deletions(-) diff --git a/port/lang.h b/port/lang.h index 754f99bf2..52c597acd 100644 --- a/port/lang.h +++ b/port/lang.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 diff --git a/port/likely.h b/port/likely.h index 397d75713..0bd90d701 100644 --- a/port/likely.h +++ b/port/likely.h @@ -10,9 +10,9 @@ #pragma once #if defined(__GNUC__) && __GNUC__ >= 4 -#define LIKELY(x) (__builtin_expect((x), 1)) +#define LIKELY(x) (__builtin_expect((x), 1)) #define UNLIKELY(x) (__builtin_expect((x), 0)) #else -#define LIKELY(x) (x) +#define LIKELY(x) (x) #define UNLIKELY(x) (x) #endif diff --git a/port/port_dirent.h b/port/port_dirent.h index 192abec4d..2b23e2f07 100644 --- a/port/port_dirent.h +++ b/port/port_dirent.h @@ -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 diff --git a/port/port_posix.cc b/port/port_posix.cc index 935c8a978..3872293b8 100644 --- a/port/port_posix.cc +++ b/port/port_posix.cc @@ -57,23 +57,21 @@ static int PthreadCall(const char* label, int result) { } Mutex::Mutex(bool adaptive) { - (void) adaptive; + (void)adaptive; #ifdef ROCKSDB_PTHREAD_ADAPTIVE_MUTEX if (!adaptive) { PthreadCall("init mutex", pthread_mutex_init(&mu_, nullptr)); } 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)); -#endif // ROCKSDB_PTHREAD_ADAPTIVE_MUTEX +#endif // ROCKSDB_PTHREAD_ADAPTIVE_MUTEX } Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); } @@ -108,9 +106,8 @@ void Mutex::AssertHeld() { #endif } -CondVar::CondVar(Mutex* mu) - : mu_(mu) { - PthreadCall("init cv", pthread_cond_init(&cv_, nullptr)); +CondVar::CondVar(Mutex* mu) : mu_(mu) { + PthreadCall("init cv", pthread_cond_init(&cv_, nullptr)); } CondVar::~CondVar() { PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); } @@ -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; @@ -217,11 +224,11 @@ int GetMaxOpenFiles() { return -1; } -void *cacheline_aligned_alloc(size_t size) { +void* cacheline_aligned_alloc(size_t size) { #if __GNUC__ < 5 && defined(__SANITIZE_ADDRESS__) return malloc(size); -#elif ( _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || defined(__APPLE__)) - void *m; +#elif (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || defined(__APPLE__)) + void* m; errno = posix_memalign(&m, CACHE_LINE_SIZE, size); return errno ? nullptr : m; #else @@ -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) diff --git a/port/port_posix.h b/port/port_posix.h index cd7bc1a6b..ec6aa281d 100644 --- a/port/port_posix.h +++ b/port/port_posix.h @@ -25,36 +25,36 @@ #undef PLATFORM_IS_LITTLE_ENDIAN #if defined(OS_MACOSX) - #include - #if defined(__DARWIN_LITTLE_ENDIAN) && defined(__DARWIN_BYTE_ORDER) - #define PLATFORM_IS_LITTLE_ENDIAN \ - (__DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN) - #endif +#include +#if defined(__DARWIN_LITTLE_ENDIAN) && defined(__DARWIN_BYTE_ORDER) +#define PLATFORM_IS_LITTLE_ENDIAN \ + (__DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN) +#endif #elif defined(OS_SOLARIS) - #include - #ifdef _LITTLE_ENDIAN - #define PLATFORM_IS_LITTLE_ENDIAN true - #else - #define PLATFORM_IS_LITTLE_ENDIAN false - #endif - #include +#include +#ifdef _LITTLE_ENDIAN +#define PLATFORM_IS_LITTLE_ENDIAN true +#else +#define PLATFORM_IS_LITTLE_ENDIAN false +#endif +#include #elif defined(OS_AIX) - #include - #include - #define PLATFORM_IS_LITTLE_ENDIAN (BYTE_ORDER == LITTLE_ENDIAN) - #include +#include +#include +#define PLATFORM_IS_LITTLE_ENDIAN (BYTE_ORDER == LITTLE_ENDIAN) +#include #elif defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_NETBSD) || \ defined(OS_DRAGONFLYBSD) || defined(OS_ANDROID) - #include - #include - #define PLATFORM_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN) +#include +#include +#define PLATFORM_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN) #else - #include +#include #endif #include - #include #include + #include #include @@ -62,8 +62,8 @@ #define PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN) #endif -#if defined(OS_MACOSX) || defined(OS_SOLARIS) || defined(OS_FREEBSD) ||\ - defined(OS_NETBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD) ||\ +#if defined(OS_MACOSX) || defined(OS_SOLARIS) || defined(OS_FREEBSD) || \ + defined(OS_NETBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD) || \ defined(OS_ANDROID) || defined(CYGWIN) || defined(OS_AIX) // Use fread/fwrite/fflush on platforms without _unlocked variants #define fread_unlocked fread @@ -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 @@ -139,10 +139,10 @@ class RWMutex { void WriteLock(); void ReadUnlock(); void WriteUnlock(); - void AssertHeld() { } + void AssertHeld() {} private: - pthread_rwlock_t mu_; // the underlying platform mutex + pthread_rwlock_t mu_; // the underlying platform mutex }; class CondVar { @@ -154,6 +154,7 @@ class CondVar { bool TimedWait(uint64_t abs_time_us); void Signal(); void SignalAll(); + private: pthread_cond_t cv_; Mutex* mu_; @@ -205,9 +206,9 @@ extern void InitOnce(OnceType* once, void (*initializer)()); static_assert((CACHE_LINE_SIZE & (CACHE_LINE_SIZE - 1)) == 0, "Cache line size must be a power of 2 number of bytes"); -extern void *cacheline_aligned_alloc(size_t size); +extern void* cacheline_aligned_alloc(size_t size); -extern void cacheline_aligned_free(void *memblock); +extern void cacheline_aligned_free(void* memblock); #if defined(__aarch64__) // __builtin_prefetch(..., 1) turns into a prefetch into prfm pldl3keep. On @@ -236,5 +237,5 @@ int64_t GetProcessID(); // true on success or false on failure. bool GenerateRfcUuid(std::string* output); -} // namespace port +} // namespace port } // namespace ROCKSDB_NAMESPACE diff --git a/port/stack_trace.cc b/port/stack_trace.cc index afb8baf3b..ef7144947 100644 --- a/port/stack_trace.cc +++ b/port/stack_trace.cc @@ -24,13 +24,13 @@ void* SaveStack(int* /*num_frames*/, int /*first_frames_to_skip*/) { #else +#include #include #include #include #include #include #include -#include #if defined(OS_FREEBSD) #include diff --git a/port/sys_time.h b/port/sys_time.h index d4dd2e07f..f2137526b 100644 --- a/port/sys_time.h +++ b/port/sys_time.h @@ -39,8 +39,8 @@ inline struct tm* LocalTimeR(const time_t* timep, struct tm* result) { } // namespace ROCKSDB_NAMESPACE #else -#include #include +#include namespace ROCKSDB_NAMESPACE { diff --git a/port/win/io_win.h b/port/win/io_win.h index d5a079052..a4fee8346 100644 --- a/port/win/io_win.h +++ b/port/win/io_win.h @@ -27,9 +27,9 @@ std::string GetWindowsErrSz(DWORD err); inline IOStatus IOErrorFromWindowsError(const std::string& context, DWORD err) { return ((err == ERROR_HANDLE_DISK_FULL) || (err == ERROR_DISK_FULL)) ? IOStatus::NoSpace(context, GetWindowsErrSz(err)) - : ((err == ERROR_FILE_NOT_FOUND) || (err == ERROR_PATH_NOT_FOUND)) - ? IOStatus::PathNotFound(context, GetWindowsErrSz(err)) - : IOStatus::IOError(context, GetWindowsErrSz(err)); + : ((err == ERROR_FILE_NOT_FOUND) || (err == ERROR_PATH_NOT_FOUND)) + ? IOStatus::PathNotFound(context, GetWindowsErrSz(err)) + : IOStatus::IOError(context, GetWindowsErrSz(err)); } inline IOStatus IOErrorFromLastWindowsError(const std::string& context) { @@ -39,10 +39,9 @@ inline IOStatus IOErrorFromLastWindowsError(const std::string& context) { 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::IOError(context, errnoStr(err_number).c_str()); + : (err_number == ENOENT) + ? IOStatus::PathNotFound(context, errnoStr(err_number).c_str()) + : IOStatus::IOError(context, errnoStr(err_number).c_str()); } class WinFileData; diff --git a/port/win/port_win.h b/port/win/port_win.h index 9ac8d045d..989b5620b 100644 --- a/port/win/port_win.h +++ b/port/win/port_win.h @@ -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,15 +198,14 @@ using Thread = WindowsThread; // Posix semantics with initialization // adopted in the project struct OnceType { + struct Init {}; - struct Init {}; - - OnceType() {} - OnceType(const Init&) {} - OnceType(const OnceType&) = delete; - OnceType& operator=(const OnceType&) = delete; + OnceType() {} + OnceType(const Init&) {} + OnceType(const OnceType&) = delete; + OnceType& operator=(const OnceType&) = delete; - std::once_flag flag_; + std::once_flag flag_; }; #define LEVELDB_ONCE_INIT port::OnceType::Init() @@ -228,7 +221,7 @@ void* jemalloc_aligned_alloc(size_t size, size_t alignment) noexcept; void jemalloc_aligned_free(void* p) noexcept; #endif -inline void *cacheline_aligned_alloc(size_t size) { +inline void* cacheline_aligned_alloc(size_t size) { #ifdef ROCKSDB_JEMALLOC return jemalloc_aligned_alloc(size, CACHE_LINE_SIZE); #else @@ -236,7 +229,7 @@ inline void *cacheline_aligned_alloc(size_t size) { #endif } -inline void cacheline_aligned_free(void *memblock) { +inline void cacheline_aligned_free(void* memblock) { #ifdef ROCKSDB_JEMALLOC jemalloc_aligned_free(memblock); #else @@ -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 diff --git a/port/win/win_jemalloc.cc b/port/win/win_jemalloc.cc index 691ebc27e..cf38f55b7 100644 --- a/port/win/win_jemalloc.cc +++ b/port/win/win_jemalloc.cc @@ -10,10 +10,11 @@ #if defined(OS_WIN) #ifndef ROCKSDB_JEMALLOC -# error This file can only be part of jemalloc aware build +#error This file can only be part of jemalloc aware build #endif #include + #include "jemalloc/jemalloc.h" #include "port/win/port_win.h" @@ -31,10 +32,10 @@ void JemallocDeallocateForZSTD(void* /* opaque */, void* address) { ZSTD_customMem GetJeZstdAllocationOverrides() { return {JemallocAllocateForZSTD, JemallocDeallocateForZSTD, nullptr}; } -} // namespace port +} // namespace port } // namespace ROCKSDB_NAMESPACE -#endif // (ZSTD_VERSION_NUMBER >= 500) -#endif // defined(ZSTD) defined(ZSTD_STATIC_LINKING_ONLY) +#endif // (ZSTD_VERSION_NUMBER >= 500) +#endif // defined(ZSTD) defined(ZSTD_STATIC_LINKING_ONLY) // Global operators to be replaced by a linker when this file is // a part of the build diff --git a/port/win/win_logger.cc b/port/win/win_logger.cc index 6773699d1..072ea419a 100644 --- a/port/win/win_logger.cc +++ b/port/win/win_logger.cc @@ -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; @@ -160,7 +158,7 @@ void WinLogger::Logv(const char* format, va_list ap) { DWORD bytesWritten = 0; BOOL ret = WriteFile(file_, base, static_cast(write_size), - &bytesWritten, NULL); + &bytesWritten, NULL); if (ret == FALSE) { std::string errSz = GetWindowsErrSz(GetLastError()); fprintf(stderr, "%s", errSz.c_str()); @@ -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 diff --git a/port/win/win_logger.h b/port/win/win_logger.h index 809c7d5a2..1ca4610e9 100644 --- a/port/win/win_logger.h +++ b/port/win/win_logger.h @@ -44,9 +44,8 @@ class WinLogger : public ROCKSDB_NAMESPACE::Logger { void DebugWriter(const char* str, int len); -protected: - - Status CloseImpl() override; + protected: + Status CloseImpl() override; private: HANDLE file_; @@ -60,6 +59,6 @@ protected: const static uint64_t flush_every_seconds_ = 5; }; -} +} // namespace port } // namespace ROCKSDB_NAMESPACE diff --git a/port/win/win_thread.cc b/port/win/win_thread.cc index 86dffea35..3c82e736e 100644 --- a/port/win/win_thread.cc +++ b/port/win/win_thread.cc @@ -17,7 +17,7 @@ #include "port/win/win_thread.h" #include -#include // __beginthreadex +#include // __beginthreadex #include #include @@ -28,14 +28,10 @@ namespace ROCKSDB_NAMESPACE { namespace port { struct WindowsThread::Data { - std::function func_; - uintptr_t handle_; + uintptr_t handle_; - Data(std::function&& func) : - func_(std::move(func)), - handle_(0) { - } + Data(std::function&& 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&& func) { - data_ = std::make_shared(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> th_data(new std::shared_ptr(data_)); + std::unique_ptr> th_data( + new std::shared_ptr(data_)); data_->handle_ = _beginthreadex(NULL, - 0, // stack size - &Data::ThreadProc, - th_data.get(), - 0, // init flag - &th_id_); + 0, // stack size + &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), - "Unable to create a thread"); + 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(data_->handle_); @@ -120,36 +106,33 @@ unsigned WindowsThread::hardware_concurrency() { } void WindowsThread::join() { - if (!joinable()) { assert(false); - throw std::system_error( - std::make_error_code(std::errc::invalid_argument), - "Thread is no longer joinable"); + throw std::system_error(std::make_error_code(std::errc::invalid_argument), + "Thread is no longer joinable"); } if (GetThreadId(GetCurrentThread()) == th_id_) { assert(false); throw std::system_error( - std::make_error_code(std::errc::resource_deadlock_would_occur), - "Can not join itself"); + std::make_error_code(std::errc::resource_deadlock_would_occur), + "Can not join itself"); } - auto ret = WaitForSingleObject(reinterpret_cast(data_->handle_), - INFINITE); + auto ret = + WaitForSingleObject(reinterpret_cast(data_->handle_), INFINITE); if (ret != WAIT_OBJECT_0) { auto lastError = GetLastError(); assert(false); - throw std::system_error(static_cast(lastError), - std::system_category(), - "WaitForSingleObjectFailed: thread join"); + throw std::system_error(static_cast(lastError), std::system_category(), + "WaitForSingleObjectFailed: thread join"); } BOOL rc #if defined(_MSC_VER) - = FALSE; + = FALSE; #else - __attribute__((__unused__)); + __attribute__((__unused__)); #endif rc = CloseHandle(reinterpret_cast(data_->handle_)); assert(rc != 0); @@ -157,12 +140,10 @@ void WindowsThread::join() { } bool WindowsThread::detach() { - if (!joinable()) { assert(false); - throw std::system_error( - std::make_error_code(std::errc::invalid_argument), - "Thread is no longer available"); + throw std::system_error(std::make_error_code(std::errc::invalid_argument), + "Thread is no longer available"); } BOOL ret = CloseHandle(reinterpret_cast(data_->handle_)); @@ -171,18 +152,18 @@ bool WindowsThread::detach() { return (ret != 0); } -void WindowsThread::swap(WindowsThread& o) { +void WindowsThread::swap(WindowsThread& o) { data_.swap(o.data_); std::swap(th_id_, o.th_id_); } -unsigned int __stdcall WindowsThread::Data::ThreadProc(void* arg) { +unsigned int __stdcall WindowsThread::Data::ThreadProc(void* arg) { auto ptr = reinterpret_cast*>(arg); std::unique_ptr> data(ptr); (*data)->func_(); return 0; } -} // namespace port +} // namespace port } // namespace ROCKSDB_NAMESPACE #endif // !_POSIX_THREADS diff --git a/port/win/win_thread.h b/port/win/win_thread.h index 89cfd0221..916033b77 100644 --- a/port/win/win_thread.h +++ b/port/win/win_thread.h @@ -11,8 +11,8 @@ #ifndef _POSIX_THREADS -#include #include +#include #include #include "rocksdb/rocksdb_namespace.h" @@ -31,8 +31,8 @@ namespace port { class WindowsThread { struct Data; - std::shared_ptr data_; - unsigned int th_id_; + std::shared_ptr data_; + unsigned int th_id_; void Init(std::function&&); @@ -104,7 +104,7 @@ class WindowsThread { void swap(WindowsThread&); }; -} // namespace port +} // namespace port } // namespace ROCKSDB_NAMESPACE namespace std { @@ -112,6 +112,6 @@ inline void swap(ROCKSDB_NAMESPACE::port::WindowsThread& th1, ROCKSDB_NAMESPACE::port::WindowsThread& th2) { th1.swap(th2); } -} // namespace std +} // namespace std #endif // !_POSIX_THREADS diff --git a/port/win/xpress_win.cc b/port/win/xpress_win.cc index 9039ec89b..21904d502 100644 --- a/port/win/xpress_win.cc +++ b/port/win/xpress_win.cc @@ -10,12 +10,13 @@ #if defined(OS_WIN) #include "port/win/xpress_win.h" + #include #include -#include -#include #include +#include +#include #ifdef XPRESS @@ -41,10 +42,9 @@ auto CloseDecompressorFun = [](void* h) { ::CloseDecompressor(reinterpret_cast(h)); } }; -} +} // namespace bool Compress(const char* input, size_t length, std::string* output) { - assert(input != nullptr); assert(output != nullptr); @@ -57,42 +57,40 @@ bool Compress(const char* input, size_t length, std::string* output) { COMPRESSOR_HANDLE compressor = NULL; - BOOL success = CreateCompressor( - COMPRESS_ALGORITHM_XPRESS, // Compression Algorithm - allocRoutinesPtr, // Optional allocation routine - &compressor); // Handle + 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 - compressorGuard(compressor, CloseCompressorFun); + std::unique_ptr compressorGuard( + compressor, CloseCompressorFun); SIZE_T compressedBufferSize = 0; // Query compressed buffer size. - success = ::Compress( - compressor, // Compressor Handle - const_cast(input), // Input buffer - length, // Uncompressed data size - NULL, // Compressed Buffer - 0, // Compressed Buffer size - &compressedBufferSize); // Compressed Data size + success = ::Compress(compressor, // Compressor Handle + const_cast(input), // Input buffer + length, // Uncompressed data size + NULL, // Compressed Buffer + 0, // Compressed Buffer size + &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,18 +104,17 @@ bool Compress(const char* input, size_t length, std::string* output) { SIZE_T compressedDataSize = 0; // Compress - success = ::Compress( - compressor, // Compressor Handle - const_cast(input), // Input buffer - length, // Uncompressed data size - &result[0], // Compressed Buffer - compressedBufferSize, // Compressed Buffer size - &compressedDataSize); // Compressed Data size + success = ::Compress(compressor, // Compressor Handle + const_cast(input), // Input buffer + length, // Uncompressed data size + &result[0], // Compressed Buffer + compressedBufferSize, // Compressed Buffer size + &compressedDataSize); // Compressed Data size 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,42 +138,39 @@ char* Decompress(const char* input_data, size_t input_length, DECOMPRESSOR_HANDLE decompressor = NULL; - BOOL success = CreateDecompressor( - COMPRESS_ALGORITHM_XPRESS, // Compression Algorithm - allocRoutinesPtr, // Optional allocation routine - &decompressor); // Handle - + 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 " - << GetLastError() << std::endl; + << GetLastError() << std::endl; #endif return nullptr; } - std::unique_ptr - compressorGuard(decompressor, CloseDecompressorFun); + std::unique_ptr compressorGuard( + decompressor, CloseDecompressorFun); SIZE_T decompressedBufferSize = 0; - success = ::Decompress( - decompressor, // Compressor Handle - const_cast(input_data), // Compressed data - input_length, // Compressed data size - NULL, // Buffer set to NULL - 0, // Buffer size set to 0 - &decompressedBufferSize); // Decompressed Data size + success = ::Decompress(decompressor, // Compressor Handle + const_cast(input_data), // Compressed data + input_length, // Compressed data size + NULL, // Buffer set to NULL + 0, // Buffer size set to 0 + &decompressedBufferSize); // Decompressed Data size if (!success) { - auto lastError = GetLastError(); if (lastError != ERROR_INSUFFICIENT_BUFFER) { #ifdef _DEBUG std::cerr - << "XPRESS: Failed to estimate decompressed buffer size LastError " - << lastError << std::endl; + << "XPRESS: Failed to estimate decompressed buffer size LastError " + << lastError << std::endl; #endif return nullptr; } @@ -190,19 +184,14 @@ char* Decompress(const char* input_data, size_t input_length, SIZE_T decompressedDataSize = 0; - success = ::Decompress( - decompressor, - const_cast(input_data), - input_length, - outputBuffer.get(), - decompressedBufferSize, - &decompressedDataSize); + success = ::Decompress(decompressor, const_cast(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 diff --git a/port/win/xpress_win.h b/port/win/xpress_win.h index d491f963d..187adffa6 100644 --- a/port/win/xpress_win.h +++ b/port/win/xpress_win.h @@ -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