aboutsummaryrefslogtreecommitdiffstats
path: root/util/system
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.ru>2022-02-10 16:45:12 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:12 +0300
commit49116032d905455a7b1c994e4a696afc885c1e71 (patch)
treebe835aa92c6248212e705f25388ebafcf84bc7a1 /util/system
parent4e839db24a3bbc9f1c610c43d6faaaa99824dcca (diff)
downloadydb-49116032d905455a7b1c994e4a696afc885c1e71.tar.gz
Restoring authorship annotation for <thegeorg@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system')
-rw-r--r--util/system/backtrace.cpp4
-rw-r--r--util/system/backtrace.h4
-rw-r--r--util/system/byteorder.h20
-rw-r--r--util/system/compiler.h26
-rw-r--r--util/system/context.cpp18
-rw-r--r--util/system/context.h8
-rw-r--r--util/system/context_ut.cpp12
-rw-r--r--util/system/demangle_impl.h42
-rw-r--r--util/system/execpath.cpp14
-rw-r--r--util/system/execpath.h2
-rw-r--r--util/system/file_lock.h4
-rw-r--r--util/system/fstat.h4
-rw-r--r--util/system/hostname.h2
-rw-r--r--util/system/mem_info.cpp22
-rw-r--r--util/system/mutex.cpp16
-rw-r--r--util/system/mutex.h8
-rw-r--r--util/system/progname.h2
-rw-r--r--util/system/shellcommand.cpp4
-rw-r--r--util/system/src_root.h6
-rw-r--r--util/system/sys_alloc.h6
-rw-r--r--util/system/thread.cpp70
-rw-r--r--util/system/thread.h12
-rw-r--r--util/system/thread_ut.cpp12
-rw-r--r--util/system/type_name.cpp64
-rw-r--r--util/system/type_name.h4
-rw-r--r--util/system/type_name_ut.cpp12
-rw-r--r--util/system/user.h2
-rw-r--r--util/system/winint.h2
28 files changed, 201 insertions, 201 deletions
diff --git a/util/system/backtrace.cpp b/util/system/backtrace.cpp
index f53a5ce809..b77fe58fb1 100644
--- a/util/system/backtrace.cpp
+++ b/util/system/backtrace.cpp
@@ -1,5 +1,5 @@
#include "dynlib.h"
-#include "demangle_impl.h"
+#include "demangle_impl.h"
#include "platform.h"
#include "backtrace.h"
@@ -142,7 +142,7 @@ TResolvedSymbol ResolveSymbol(void* sym, char* buf, size_t len) {
Zero(dli);
if (dladdr(sym, &dli) && dli.dli_sname) {
- ret.Name = CopyTo(NPrivate::TCppDemangler().Demangle(dli.dli_sname), buf, len);
+ ret.Name = CopyTo(NPrivate::TCppDemangler().Demangle(dli.dli_sname), buf, len);
ret.NearestSymbol = dli.dli_saddr;
}
diff --git a/util/system/backtrace.h b/util/system/backtrace.h
index f6576c64d5..2fce7585c3 100644
--- a/util/system/backtrace.h
+++ b/util/system/backtrace.h
@@ -1,7 +1,7 @@
#pragma once
-#include <util/generic/fwd.h>
-#include <util/system/defaults.h>
+#include <util/generic/fwd.h>
+#include <util/system/defaults.h>
class IOutputStream;
diff --git a/util/system/byteorder.h b/util/system/byteorder.h
index b8a2c05f81..94b9fea515 100644
--- a/util/system/byteorder.h
+++ b/util/system/byteorder.h
@@ -30,28 +30,28 @@
#define SwapBytes32 OSSwapInt32
#define SwapBytes64 OSSwapInt64
#endif
-#endif
+#endif
-#ifndef SwapBytes16
+#ifndef SwapBytes16
inline ui16 SwapBytes16(ui16 val) noexcept {
- #define byte_n(__val, __n) ((((unsigned char*)(&__val))[__n]))
+ #define byte_n(__val, __n) ((((unsigned char*)(&__val))[__n]))
DoSwap(byte_n(val, 0), byte_n(val, 1));
return val;
- #undef byte_n
+ #undef byte_n
}
-#endif
+#endif
-#ifndef SwapBytes32
+#ifndef SwapBytes32
inline ui32 SwapBytes32(ui32 val) noexcept {
- #define byte_n(__val, __n) ((((unsigned char*)(&__val))[__n]))
+ #define byte_n(__val, __n) ((((unsigned char*)(&__val))[__n]))
DoSwap(byte_n(val, 0), byte_n(val, 3));
DoSwap(byte_n(val, 1), byte_n(val, 2));
return val;
- #undef byte_n
+ #undef byte_n
}
-#endif
+#endif
-#ifndef SwapBytes64
+#ifndef SwapBytes64
inline ui64 SwapBytes64(ui64 val) noexcept {
union {
ui64 val;
diff --git a/util/system/compiler.h b/util/system/compiler.h
index 70f316e171..b373edcc46 100644
--- a/util/system/compiler.h
+++ b/util/system/compiler.h
@@ -158,9 +158,9 @@
#endif
#ifdef __GNUC__
- #define Y_PACKED __attribute__((packed))
+ #define Y_PACKED __attribute__((packed))
#else
- #define Y_PACKED
+ #define Y_PACKED
#endif
#if defined(__GNUC__)
@@ -262,7 +262,7 @@ _YandexAbort();
* }
* @endcode
*/
-#if defined(__GNUC__)
+#if defined(__GNUC__)
#define Y_UNREACHABLE() __builtin_unreachable()
#elif defined(_MSC_VER)
#define Y_UNREACHABLE() __assume(false)
@@ -626,21 +626,21 @@ _YandexAbort();
#ifdef __cplusplus
-void UseCharPointerImpl(volatile const char*);
+void UseCharPointerImpl(volatile const char*);
-template <typename T>
-Y_FORCE_INLINE void DoNotOptimizeAway(T&& datum) {
+template <typename T>
+Y_FORCE_INLINE void DoNotOptimizeAway(T&& datum) {
#if defined(_MSC_VER)
- UseCharPointerImpl(&reinterpret_cast<volatile const char&>(datum));
- _ReadWriteBarrier();
+ UseCharPointerImpl(&reinterpret_cast<volatile const char&>(datum));
+ _ReadWriteBarrier();
#elif defined(__GNUC__) && defined(_x86_)
- asm volatile(""
- :
- : "X"(datum));
+ asm volatile(""
+ :
+ : "X"(datum));
#else
- Y_FAKE_READ(datum);
+ Y_FAKE_READ(datum);
#endif
-}
+}
/**
* Use this macro to prevent unused variables elimination.
diff --git a/util/system/context.cpp b/util/system/context.cpp
index 17acc793c5..ad99309088 100644
--- a/util/system/context.cpp
+++ b/util/system/context.cpp
@@ -54,11 +54,11 @@ extern "C" int __mysetjmp(__myjmp_buf env) __attribute__((__returns_twice__));
namespace {
class TStackType {
public:
- inline TStackType(TArrayRef<char> range) noexcept
+ inline TStackType(TArrayRef<char> range) noexcept
#if defined(STACK_GROW_DOWN)
- : Data_(range.data() + range.size())
+ : Data_(range.data() + range.size())
#else
- : Data_(range.data() + STACK_ALIGN)
+ : Data_(range.data() + STACK_ALIGN)
#endif
{
ReAlign();
@@ -206,10 +206,10 @@ void TContMachineContext::SwitchTo(TContMachineContext* next) noexcept {
#endif
}
}
-#elif defined(_win_) && defined(_32_)
-void __stdcall ContextTrampoLine(void* arg) {
- Run(arg);
-}
+#elif defined(_win_) && defined(_32_)
+void __stdcall ContextTrampoLine(void* arg) {
+ Run(arg);
+}
#else
void ContextTrampoLine(void* arg) {
Run(arg);
@@ -225,7 +225,7 @@ TContMachineContext::TContMachineContext()
}
TContMachineContext::TContMachineContext(const TContClosure& c)
- : Fiber_(CreateFiber(c.Stack.size(), (LPFIBER_START_ROUTINE)ContextTrampoLine, (LPVOID)c.TrampoLine))
+ : Fiber_(CreateFiber(c.Stack.size(), (LPFIBER_START_ROUTINE)ContextTrampoLine, (LPVOID)c.TrampoLine))
, MainFiber_(false)
{
Y_ENSURE(Fiber_, TStringBuf("fiber error"));
@@ -258,7 +258,7 @@ struct TContMachineContext::TImpl {
: TL(c.TrampoLine)
, Finish(false)
{
- Thread.Reset(new TThread(TThread::TParams(Run, this).SetStackSize(c.Stack.size()).SetStackPointer((void*)c.Stack.data())));
+ Thread.Reset(new TThread(TThread::TParams(Run, this).SetStackSize(c.Stack.size()).SetStackPointer((void*)c.Stack.data())));
Thread->Start();
}
diff --git a/util/system/context.h b/util/system/context.h
index c65f97bef9..d2a349bfc5 100644
--- a/util/system/context.h
+++ b/util/system/context.h
@@ -5,7 +5,7 @@
#include "compiler.h"
#include "sanitizers.h"
-#include <util/generic/array_ref.h>
+#include <util/generic/array_ref.h>
#include <util/generic/utility.h>
#include <util/generic/yexception.h>
@@ -53,7 +53,7 @@ struct ITrampoLine {
struct TContClosure {
ITrampoLine* TrampoLine;
- TArrayRef<char> Stack;
+ TArrayRef<char> Stack;
const char* ContName = nullptr;
};
@@ -70,8 +70,8 @@ public:
getcontext(&Ctx_);
Ctx_.uc_link = 0;
- Ctx_.uc_stack.ss_sp = (void*)c.Stack.data();
- Ctx_.uc_stack.ss_size = c.Stack.size();
+ Ctx_.uc_stack.ss_sp = (void*)c.Stack.data();
+ Ctx_.uc_stack.ss_size = c.Stack.size();
Ctx_.uc_stack.ss_flags = 0;
extern void ContextTrampoLine(void* arg);
diff --git a/util/system/context_ut.cpp b/util/system/context_ut.cpp
index 96ea007958..45cb0249f7 100644
--- a/util/system/context_ut.cpp
+++ b/util/system/context_ut.cpp
@@ -3,7 +3,7 @@
#include <library/cpp/testing/unittest/registar.h>
#include <util/generic/deque.h>
-#include <util/generic/yexception.h>
+#include <util/generic/yexception.h>
Y_UNIT_TEST_SUITE(TestContext) {
template <class F>
@@ -26,17 +26,17 @@ Y_UNIT_TEST_SUITE(TestContext) {
auto& tw = w.emplace_back(&f);
- return {&tw, TArrayRef(tw.Buf, sizeof(tw.Buf))};
+ return {&tw, TArrayRef(tw.Buf, sizeof(tw.Buf))};
}
Y_UNIT_TEST(TestExceptionSafety) {
TExceptionSafeContext main;
TExceptionSafeContext* volatile nextPtr = nullptr;
- bool hasUncaught = true;
+ bool hasUncaught = true;
- auto func = [&]() {
- hasUncaught = UncaughtException();
+ auto func = [&]() {
+ hasUncaught = UncaughtException();
nextPtr->SwitchTo(&main);
};
@@ -66,6 +66,6 @@ Y_UNIT_TEST_SUITE(TestContext) {
}
UNIT_ASSERT(throwed);
- UNIT_ASSERT(!hasUncaught);
+ UNIT_ASSERT(!hasUncaught);
}
}
diff --git a/util/system/demangle_impl.h b/util/system/demangle_impl.h
index dffe4c8e2e..081004f976 100644
--- a/util/system/demangle_impl.h
+++ b/util/system/demangle_impl.h
@@ -1,21 +1,21 @@
-#pragma once
-
-#include <util/generic/ptr.h>
-#include <util/generic/string.h>
-
-namespace NPrivate {
-
- /*
- * cxxabi::__cxa_demangle (and thus TCppDemanger) have terrible memory ownership model.
- *
- * Consider using CppDemangle instead. It is slow, but robust.
- */
- class TCppDemangler {
- public:
- const char* Demangle(const char* name);
-
- private:
- THolder<char, TFree> TmpBuf_;
- };
-
-} //namespace NPrivate
+#pragma once
+
+#include <util/generic/ptr.h>
+#include <util/generic/string.h>
+
+namespace NPrivate {
+
+ /*
+ * cxxabi::__cxa_demangle (and thus TCppDemanger) have terrible memory ownership model.
+ *
+ * Consider using CppDemangle instead. It is slow, but robust.
+ */
+ class TCppDemangler {
+ public:
+ const char* Demangle(const char* name);
+
+ private:
+ THolder<char, TFree> TmpBuf_;
+ };
+
+} //namespace NPrivate
diff --git a/util/system/execpath.cpp b/util/system/execpath.cpp
index 5692f23959..33198af58b 100644
--- a/util/system/execpath.cpp
+++ b/util/system/execpath.cpp
@@ -58,12 +58,12 @@ static inline TString FreeBSDGetExecPath() {
if (r == 0) {
return TString(buf.Data(), buf.Filled() - 1);
} else if (r == ENOTSUP) { // older FreeBSD version
- /*
- * BSD analogue for /proc/self is /proc/curproc.
- * See:
- * https://www.freebsd.org/cgi/man.cgi?query=procfs&sektion=5&format=html
- */
- TString path("/proc/curproc/file");
+ /*
+ * BSD analogue for /proc/self is /proc/curproc.
+ * See:
+ * https://www.freebsd.org/cgi/man.cgi?query=procfs&sektion=5&format=html
+ */
+ TString path("/proc/curproc/file");
return NFs::ReadLink(path);
} else {
return TString();
@@ -128,7 +128,7 @@ static TString GetExecPathImpl() {
}
}
#elif defined(_linux_) || defined(_cygwin_)
- TString path("/proc/self/exe");
+ TString path("/proc/self/exe");
return NFs::ReadLink(path);
// TODO(yoda): check if the filename ends with " (deleted)"
#elif defined(_freebsd_)
diff --git a/util/system/execpath.h b/util/system/execpath.h
index d92d60ae20..4b914b8e85 100644
--- a/util/system/execpath.h
+++ b/util/system/execpath.h
@@ -1,6 +1,6 @@
#pragma once
-#include <util/generic/fwd.h>
+#include <util/generic/fwd.h>
// NOTE: This function has rare sporadic failures (throws exceptions) on FreeBSD. See REVIEW:54297
const TString& GetExecPath();
diff --git a/util/system/file_lock.h b/util/system/file_lock.h
index 65748f89a5..b2aaff5baf 100644
--- a/util/system/file_lock.h
+++ b/util/system/file_lock.h
@@ -1,8 +1,8 @@
#pragma once
-#include <util/generic/fwd.h>
+#include <util/generic/fwd.h>
#include <util/generic/noncopyable.h>
-#include <util/system/file.h>
+#include <util/system/file.h>
enum class EFileLockType {
Exclusive,
diff --git a/util/system/fstat.h b/util/system/fstat.h
index 9f744c90aa..64e79e1b55 100644
--- a/util/system/fstat.h
+++ b/util/system/fstat.h
@@ -1,7 +1,7 @@
#pragma once
-#include <util/generic/fwd.h>
-#include <util/system/fhandle.h>
+#include <util/generic/fwd.h>
+#include <util/system/fhandle.h>
class TFile;
class TFsPath;
diff --git a/util/system/hostname.h b/util/system/hostname.h
index d5b88d52a7..0839ee2b59 100644
--- a/util/system/hostname.h
+++ b/util/system/hostname.h
@@ -1,6 +1,6 @@
#pragma once
-#include <util/generic/fwd.h>
+#include <util/generic/fwd.h>
const char* GetHostName();
const TString& HostName();
diff --git a/util/system/mem_info.cpp b/util/system/mem_info.cpp
index e9aa910aaf..aa51ae3b16 100644
--- a/util/system/mem_info.cpp
+++ b/util/system/mem_info.cpp
@@ -109,12 +109,12 @@ namespace NMemInfo {
#endif
#if defined(_linux_) || defined(_cygwin_)
- TString path;
- if (!pid) {
- path = "/proc/self/statm";
- } else {
- path = TStringBuilder() << TStringBuf("/proc/") << pid << TStringBuf("/statm");
- }
+ TString path;
+ if (!pid) {
+ path = "/proc/self/statm";
+ } else {
+ path = TStringBuilder() << TStringBuf("/proc/") << pid << TStringBuf("/statm");
+ }
const TString stats = TUnbufferedFileInput(path).ReadAll();
TStringBuf statsiter(stats);
@@ -143,9 +143,9 @@ namespace NMemInfo {
result.VMS = proc.ki_size;
result.RSS = proc.ki_rssize * pagesize;
#elif defined(_darwin_) && !defined(_arm_) && !defined(__IOS__)
- if (!pid) {
- pid = getpid();
- }
+ if (!pid) {
+ pid = getpid();
+ }
struct proc_taskinfo taskInfo;
const int r = proc_pidinfo(pid, PROC_PIDTASKINFO, 0, &taskInfo, sizeof(taskInfo));
@@ -157,7 +157,7 @@ namespace NMemInfo {
result.VMS = taskInfo.pti_virtual_size;
result.RSS = taskInfo.pti_resident_size;
#elif defined(__MACH__) && defined(__APPLE__)
- Y_UNUSED(pid);
+ Y_UNUSED(pid);
struct mach_task_basic_info taskInfo;
mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
@@ -170,7 +170,7 @@ namespace NMemInfo {
result.VMS = taskInfo.virtual_size;
result.RSS = taskInfo.resident_size;
#elif defined(_arm_)
- Y_UNUSED(pid);
+ Y_UNUSED(pid);
ythrow yexception() << "arm is not supported";
#endif
#elif defined(_win_)
diff --git a/util/system/mutex.cpp b/util/system/mutex.cpp
index cd2653fc6e..4041402db9 100644
--- a/util/system/mutex.cpp
+++ b/util/system/mutex.cpp
@@ -9,7 +9,7 @@
#include <pthread.h>
#endif
-class TMutex::TImpl {
+class TMutex::TImpl {
public:
inline TImpl() {
#if defined(_win_)
@@ -120,27 +120,27 @@ private:
#endif
};
-TMutex::TMutex()
+TMutex::TMutex()
: Impl_(new TImpl())
{
}
-TMutex::TMutex(TMutex&&) = default;
+TMutex::TMutex(TMutex&&) = default;
-TMutex::~TMutex() = default;
+TMutex::~TMutex() = default;
-void TMutex::Acquire() noexcept {
+void TMutex::Acquire() noexcept {
Impl_->Acquire();
}
-bool TMutex::TryAcquire() noexcept {
+bool TMutex::TryAcquire() noexcept {
return Impl_->TryAcquire();
}
-void TMutex::Release() noexcept {
+void TMutex::Release() noexcept {
Impl_->Release();
}
-void* TMutex::Handle() const noexcept {
+void* TMutex::Handle() const noexcept {
return Impl_->Handle();
}
diff --git a/util/system/mutex.h b/util/system/mutex.h
index 319b89f366..032630d134 100644
--- a/util/system/mutex.h
+++ b/util/system/mutex.h
@@ -33,11 +33,11 @@ public:
~TFakeMutex() = default;
};
-class TMutex {
+class TMutex {
public:
- TMutex();
- TMutex(TMutex&&);
- ~TMutex();
+ TMutex();
+ TMutex(TMutex&&);
+ ~TMutex();
void Acquire() noexcept;
bool TryAcquire() noexcept;
diff --git a/util/system/progname.h b/util/system/progname.h
index 1862ea721c..e5e2a0eee2 100644
--- a/util/system/progname.h
+++ b/util/system/progname.h
@@ -1,6 +1,6 @@
#pragma once
-#include <util/generic/fwd.h>
+#include <util/generic/fwd.h>
void SetProgramName(const char* argv0);
diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp
index 7459e87119..b1989b5c8c 100644
--- a/util/system/shellcommand.cpp
+++ b/util/system/shellcommand.cpp
@@ -282,7 +282,7 @@ private:
public:
inline TImpl(const TStringBuf cmd, const TList<TString>& args, const TShellCommandOptions& options, const TString& workdir)
: Pid(0)
- , Command(ToString(cmd))
+ , Command(ToString(cmd))
, Arguments(args)
, WorkDir(workdir)
, ExecutionStatus(SHELL_NONE)
@@ -334,7 +334,7 @@ public:
if (AtomicGet(ExecutionStatus) == SHELL_RUNNING) {
ythrow yexception() << "You cannot change command parameters while process is running";
}
- Arguments.push_back(ToString(argument));
+ Arguments.push_back(ToString(argument));
}
inline const TString& GetOutput() const {
diff --git a/util/system/src_root.h b/util/system/src_root.h
index a09ec7b87c..4f2d9f5ee6 100644
--- a/util/system/src_root.h
+++ b/util/system/src_root.h
@@ -1,7 +1,7 @@
#pragma once
#include "compiler.h"
-#include "defaults.h"
+#include "defaults.h"
#include <type_traits>
@@ -29,8 +29,8 @@ namespace NPrivate {
#define STATIC_BUF(x) ::NPrivate::TStaticBuf(x, sizeof(x) - 1)
- constexpr TStaticBuf ArcRoot = STATIC_BUF(Y_STRINGIZE(ARCADIA_ROOT));
- constexpr TStaticBuf BuildRoot = STATIC_BUF(Y_STRINGIZE(ARCADIA_BUILD_ROOT));
+ constexpr TStaticBuf ArcRoot = STATIC_BUF(Y_STRINGIZE(ARCADIA_ROOT));
+ constexpr TStaticBuf BuildRoot = STATIC_BUF(Y_STRINGIZE(ARCADIA_BUILD_ROOT));
constexpr Y_FORCE_INLINE bool IsProperPrefix(const TStaticBuf prefix, const TStaticBuf string) noexcept {
if (prefix.Len < string.Len) {
diff --git a/util/system/sys_alloc.h b/util/system/sys_alloc.h
index 3d496ed4f4..4221a28f8c 100644
--- a/util/system/sys_alloc.h
+++ b/util/system/sys_alloc.h
@@ -3,13 +3,13 @@
#include <util/system/compiler.h>
#include <cstdlib>
-#include <new>
+#include <new>
inline void* y_allocate(size_t n) {
void* r = malloc(n);
if (r == nullptr) {
- throw std::bad_alloc();
+ throw std::bad_alloc();
}
return r;
@@ -36,7 +36,7 @@ inline void* y_reallocate(void* p, size_t new_sz) {
void* r = realloc(p, new_sz);
if (r == nullptr) {
- throw std::bad_alloc();
+ throw std::bad_alloc();
}
return r;
diff --git a/util/system/thread.cpp b/util/system/thread.cpp
index 8b56b2302c..6236746c2d 100644
--- a/util/system/thread.cpp
+++ b/util/system/thread.cpp
@@ -9,21 +9,21 @@
#include "yassert.h"
#include <utility>
-#if defined(_glibc_)
- #if !__GLIBC_PREREQ(2, 30)
- #include <sys/syscall.h>
- #endif
-#endif
-
-#if defined(_unix_)
+#if defined(_glibc_)
+ #if !__GLIBC_PREREQ(2, 30)
+ #include <sys/syscall.h>
+ #endif
+#endif
+
+#if defined(_unix_)
#include <pthread.h>
- #include <sys/types.h>
-#elif defined(_win_)
+ #include <sys/types.h>
+#elif defined(_win_)
#include "dynlib.h"
#include <util/charset/wide.h>
#include <util/generic/scope.h>
-#else
- #error "FIXME"
+#else
+ #error "FIXME"
#endif
bool SetHighestThreadPriority() {
@@ -328,30 +328,30 @@ TThread::TId TThread::CurrentThreadId() noexcept {
return SystemCurrentThreadId();
}
-TThread::TId TThread::CurrentThreadNumericId() noexcept {
-#if defined(_win_)
- return GetCurrentThreadId();
-#elif defined(_darwin_)
- // There is no gettid() on MacOS and SYS_gettid returns completely unrelated numbers.
- // See: http://elliotth.blogspot.com/2012/04/gettid-on-mac-os.html
- uint64_t threadId;
- pthread_threadid_np(nullptr, &threadId);
- return threadId;
-#elif defined(_musl_) || defined(_bionic_)
- // both musl and android libc provide gettid() function
- return gettid();
-#elif defined(_glibc_)
- #if __GLIBC_PREREQ(2, 30)
- return gettid();
- #else
- // gettid() was introduced in glibc=2.30, previous versions lack neat syscall wrapper
- return syscall(SYS_gettid);
- #endif
-#else
- #error "Implement me"
-#endif
-}
-
+TThread::TId TThread::CurrentThreadNumericId() noexcept {
+#if defined(_win_)
+ return GetCurrentThreadId();
+#elif defined(_darwin_)
+ // There is no gettid() on MacOS and SYS_gettid returns completely unrelated numbers.
+ // See: http://elliotth.blogspot.com/2012/04/gettid-on-mac-os.html
+ uint64_t threadId;
+ pthread_threadid_np(nullptr, &threadId);
+ return threadId;
+#elif defined(_musl_) || defined(_bionic_)
+ // both musl and android libc provide gettid() function
+ return gettid();
+#elif defined(_glibc_)
+ #if __GLIBC_PREREQ(2, 30)
+ return gettid();
+ #else
+ // gettid() was introduced in glibc=2.30, previous versions lack neat syscall wrapper
+ return syscall(SYS_gettid);
+ #endif
+#else
+ #error "Implement me"
+#endif
+}
+
TThread::TId TThread::ImpossibleThreadId() noexcept {
return Max<TThread::TId>();
}
diff --git a/util/system/thread.h b/util/system/thread.h
index 3e3cbf584b..a6e8abdb5b 100644
--- a/util/system/thread.h
+++ b/util/system/thread.h
@@ -104,12 +104,12 @@ public:
static TId ImpossibleThreadId() noexcept;
static TId CurrentThreadId() noexcept;
- /*
- * Returns numeric thread id, as visible in e. g. htop.
- * Consider using this value for logging.
- */
- static TId CurrentThreadNumericId() noexcept;
-
+ /*
+ * Returns numeric thread id, as visible in e. g. htop.
+ * Consider using this value for logging.
+ */
+ static TId CurrentThreadNumericId() noexcept;
+
// NOTE: Content of `name` will be copied.
//
// NOTE: On Linux thread name is limited to 15 symbols which is probably the smallest one among
diff --git a/util/system/thread_ut.cpp b/util/system/thread_ut.cpp
index b99a200864..d820898fd5 100644
--- a/util/system/thread_ut.cpp
+++ b/util/system/thread_ut.cpp
@@ -2,8 +2,8 @@
#include <library/cpp/testing/unittest/registar.h>
-#include <atomic>
-
+#include <atomic>
+
Y_UNIT_TEST_SUITE(TSysThreadTest) {
struct TIdTester {
inline TIdTester()
@@ -22,13 +22,13 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) {
inline void Run() {
Cur = TThread::CurrentThreadId();
Real = Thr->Id();
- Numeric = TThread::CurrentThreadNumericId();
+ Numeric = TThread::CurrentThreadNumericId();
}
TThread* Thr;
TThread::TId Cur;
TThread::TId Real;
- TThread::TId Numeric;
+ TThread::TId Numeric;
};
Y_UNIT_TEST(TestThreadId) {
@@ -42,8 +42,8 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) {
UNIT_ASSERT_EQUAL(tst.Cur, tst.Real);
UNIT_ASSERT(tst.Cur != 0);
- UNIT_ASSERT(tst.Numeric != 0);
- UNIT_ASSERT(tst.Numeric != tst.Real);
+ UNIT_ASSERT(tst.Numeric != 0);
+ UNIT_ASSERT(tst.Numeric != tst.Real);
}
void* ThreadProc(void*) {
diff --git a/util/system/type_name.cpp b/util/system/type_name.cpp
index db0fe3427d..0377da4212 100644
--- a/util/system/type_name.cpp
+++ b/util/system/type_name.cpp
@@ -1,5 +1,5 @@
#include "platform.h"
-#include "demangle_impl.h"
+#include "demangle_impl.h"
#ifdef __GNUC__
#include <stdexcept>
@@ -8,23 +8,23 @@
#include "type_name.h"
-namespace {
-
-#if defined(_LIBCPP_VERSION)
- // libc++ is nested under std::__y1
- constexpr std::string_view STD_ABI_PREFIX = "std::__y1::";
-#elif defined(_linux_)
- // libstdc++ is nested under std::__cxx11
- // FIXME: is there any way to test if we are building against libstdc++?
- constexpr std::string_view STD_ABI_PREFIX = "std::__cxx11::";
-#else
- // There is no need to cutoff ABI prefix on Windows
-#endif
- constexpr std::string_view STD_PREFIX = "std::";
-
-} // anonymous namespace
-
-const char* NPrivate::TCppDemangler::Demangle(const char* name) {
+namespace {
+
+#if defined(_LIBCPP_VERSION)
+ // libc++ is nested under std::__y1
+ constexpr std::string_view STD_ABI_PREFIX = "std::__y1::";
+#elif defined(_linux_)
+ // libstdc++ is nested under std::__cxx11
+ // FIXME: is there any way to test if we are building against libstdc++?
+ constexpr std::string_view STD_ABI_PREFIX = "std::__cxx11::";
+#else
+ // There is no need to cutoff ABI prefix on Windows
+#endif
+ constexpr std::string_view STD_PREFIX = "std::";
+
+} // anonymous namespace
+
+const char* NPrivate::TCppDemangler::Demangle(const char* name) {
#ifndef __GNUC__
return name;
#else
@@ -38,23 +38,23 @@ const char* NPrivate::TCppDemangler::Demangle(const char* name) {
return TmpBuf_.Get();
#endif
}
-
-TString CppDemangle(const TString& name) {
- return NPrivate::TCppDemangler().Demangle(name.data());
-}
+
+TString CppDemangle(const TString& name) {
+ return NPrivate::TCppDemangler().Demangle(name.data());
+}
TString TypeName(const std::type_info& typeInfo) {
- TString demangled = CppDemangle(typeInfo.name()); // NOLINT(arcadia-typeid-name-restriction)
-#if defined(_linux_) || defined(_darwin_)
- SubstGlobal(demangled, STD_ABI_PREFIX, STD_PREFIX);
-#endif
- return demangled;
+ TString demangled = CppDemangle(typeInfo.name()); // NOLINT(arcadia-typeid-name-restriction)
+#if defined(_linux_) || defined(_darwin_)
+ SubstGlobal(demangled, STD_ABI_PREFIX, STD_PREFIX);
+#endif
+ return demangled;
}
TString TypeName(const std::type_index& typeIndex) {
- TString demangled = CppDemangle(typeIndex.name());
-#if defined(_linux_) || defined(_darwin_)
- SubstGlobal(demangled, STD_ABI_PREFIX, STD_PREFIX);
-#endif
- return demangled;
+ TString demangled = CppDemangle(typeIndex.name());
+#if defined(_linux_) || defined(_darwin_)
+ SubstGlobal(demangled, STD_ABI_PREFIX, STD_PREFIX);
+#endif
+ return demangled;
}
diff --git a/util/system/type_name.h b/util/system/type_name.h
index 66806ab092..b6619aba3f 100644
--- a/util/system/type_name.h
+++ b/util/system/type_name.h
@@ -1,13 +1,13 @@
#pragma once
#include <util/generic/string.h>
-#include <util/string/subst.h>
+#include <util/string/subst.h>
#include <typeindex>
#include <typeinfo>
// Consider using TypeName function family.
-TString CppDemangle(const TString& name);
+TString CppDemangle(const TString& name);
// TypeName function family return human readable type name.
diff --git a/util/system/type_name_ut.cpp b/util/system/type_name_ut.cpp
index 1d6bbc2570..86597f4232 100644
--- a/util/system/type_name_ut.cpp
+++ b/util/system/type_name_ut.cpp
@@ -67,10 +67,10 @@ Y_UNIT_TEST_SUITE(TypeName) {
UNIT_ASSERT_VALUES_EQUAL(TypeName<double>(), "double");
#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName<std::string>(), "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<std::string>(), "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >");
UNIT_ASSERT_VALUES_EQUAL(TypeName<std::runtime_error>(), "class std::runtime_error");
#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName<std::string>(), "std::basic_string<char, std::char_traits<char>, std::allocator<char> >");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<std::string>(), "std::basic_string<char, std::char_traits<char>, std::allocator<char> >");
UNIT_ASSERT_VALUES_EQUAL(TypeName<std::runtime_error>(), "std::runtime_error");
#endif
}
@@ -78,10 +78,10 @@ Y_UNIT_TEST_SUITE(TypeName) {
Y_UNIT_TEST(FromArcadiaTypes) {
#ifdef _MSC_VER
UNIT_ASSERT_VALUES_EQUAL(TypeName<yexception>(), "class yexception");
- UNIT_ASSERT_VALUES_EQUAL(TypeName<TString>(), "class TBasicString<char,struct std::char_traits<char> >");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<TString>(), "class TBasicString<char,struct std::char_traits<char> >");
#else
UNIT_ASSERT_VALUES_EQUAL(TypeName<yexception>(), "yexception");
- UNIT_ASSERT_VALUES_EQUAL(TypeName<TString>(), "TBasicString<char, std::char_traits<char> >");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName<TString>(), "TBasicString<char, std::char_traits<char> >");
#endif
}
@@ -122,10 +122,10 @@ Y_UNIT_TEST_SUITE(TypeName) {
std::string string;
std::runtime_error err("This is awful");
#ifdef _MSC_VER
- UNIT_ASSERT_VALUES_EQUAL(TypeName(string), "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(string), "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >");
UNIT_ASSERT_VALUES_EQUAL(TypeName(err), "class std::runtime_error");
#else
- UNIT_ASSERT_VALUES_EQUAL(TypeName(string), "std::basic_string<char, std::char_traits<char>, std::allocator<char> >");
+ UNIT_ASSERT_VALUES_EQUAL(TypeName(string), "std::basic_string<char, std::char_traits<char>, std::allocator<char> >");
UNIT_ASSERT_VALUES_EQUAL(TypeName(err), "std::runtime_error");
#endif
}
diff --git a/util/system/user.h b/util/system/user.h
index fc7c37c0e6..be348d1cee 100644
--- a/util/system/user.h
+++ b/util/system/user.h
@@ -1,5 +1,5 @@
#pragma once
-#include <util/generic/fwd.h>
+#include <util/generic/fwd.h>
TString GetUsername();
diff --git a/util/system/winint.h b/util/system/winint.h
index 952f32a02b..ebeaefb3d2 100644
--- a/util/system/winint.h
+++ b/util/system/winint.h
@@ -39,5 +39,5 @@
#undef TRANSPARENT
#undef CM_NONE
-
+
#endif