Skip to content

Commit

Permalink
clang format files under port/ (facebook#10849)
Browse files Browse the repository at this point in the history
Summary:
Run "clang-format" against files under port to make it happy.

Pull Request resolved: facebook#10849

Test Plan: Watch existing CI to pass.

Reviewed By: anand1976

Differential Revision: D40645839

fbshipit-source-id: 582b4215503223795cf6234af90cc4e8e4eba773
  • Loading branch information
siying authored and facebook-github-bot committed Oct 24, 2022
1 parent 4d9cb43 commit 7cf27ea
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 222 deletions.
4 changes: 3 additions & 1 deletion port/lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions port/likely.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions port/port_dirent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
59 changes: 32 additions & 27 deletions port/port_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_)); }
Expand Down Expand Up @@ -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_)); }
Expand Down Expand Up @@ -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_));
Expand All @@ -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;
Expand Down Expand Up @@ -217,21 +224,19 @@ 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
return malloc(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)
Expand Down
61 changes: 31 additions & 30 deletions port/port_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,54 @@

#undef PLATFORM_IS_LITTLE_ENDIAN
#if defined(OS_MACOSX)
#include <machine/endian.h>
#if defined(__DARWIN_LITTLE_ENDIAN) && defined(__DARWIN_BYTE_ORDER)
#define PLATFORM_IS_LITTLE_ENDIAN \
(__DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN)
#endif
#include <machine/endian.h>
#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 <sys/isa_defs.h>
#ifdef _LITTLE_ENDIAN
#define PLATFORM_IS_LITTLE_ENDIAN true
#else
#define PLATFORM_IS_LITTLE_ENDIAN false
#endif
#include <alloca.h>
#include <sys/isa_defs.h>
#ifdef _LITTLE_ENDIAN
#define PLATFORM_IS_LITTLE_ENDIAN true
#else
#define PLATFORM_IS_LITTLE_ENDIAN false
#endif
#include <alloca.h>
#elif defined(OS_AIX)
#include <sys/types.h>
#include <arpa/nameser_compat.h>
#define PLATFORM_IS_LITTLE_ENDIAN (BYTE_ORDER == LITTLE_ENDIAN)
#include <alloca.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) || \
defined(OS_DRAGONFLYBSD) || defined(OS_ANDROID)
#include <sys/endian.h>
#include <sys/types.h>
#define PLATFORM_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN)
#include <sys/endian.h>
#include <sys/types.h>
#define PLATFORM_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN)
#else
#include <endian.h>
#include <endian.h>
#endif
#include <pthread.h>

#include <stdint.h>
#include <string.h>

#include <limits>
#include <string>

#ifndef PLATFORM_IS_LITTLE_ENDIAN
#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
#define fwrite_unlocked fwrite
#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
Expand Down Expand Up @@ -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 {
Expand All @@ -154,6 +154,7 @@ class CondVar {
bool TimedWait(uint64_t abs_time_us);
void Signal();
void SignalAll();

private:
pthread_cond_t cv_;
Mutex* mu_;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion port/stack_trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion port/sys_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
13 changes: 6 additions & 7 deletions port/win/io_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 7cf27ea

Please sign in to comment.