aboutsummaryrefslogtreecommitdiffstats
path: root/util/system
diff options
context:
space:
mode:
authormelkov <melkov@yandex-team.ru>2022-02-10 16:48:14 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:14 +0300
commit2c532b38e6aeb4fd88531027c7335690fd34c4e5 (patch)
treeb222e5ac2e2e98872661c51ccceee5da0d291e13 /util/system
parent438546c8737d5c1fdeb31157dcf999717d930eec (diff)
downloadydb-2c532b38e6aeb4fd88531027c7335690fd34c4e5.tar.gz
Restoring authorship annotation for <melkov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system')
-rw-r--r--util/system/align.h6
-rw-r--r--util/system/atomic.h6
-rw-r--r--util/system/atomic_gcc.h4
-rw-r--r--util/system/atomic_win.h10
-rw-r--r--util/system/compat.h2
-rw-r--r--util/system/err.cpp44
-rw-r--r--util/system/file.cpp64
-rw-r--r--util/system/file.h2
-rw-r--r--util/system/filemap.cpp10
-rw-r--r--util/system/filemap.h38
-rw-r--r--util/system/fs_win.cpp2
-rw-r--r--util/system/guard.h2
-rw-r--r--util/system/mktemp.cpp2
-rw-r--r--util/system/mutex.h2
-rw-r--r--util/system/shellcommand.cpp22
-rw-r--r--util/system/shellcommand.h8
-rw-r--r--util/system/shellcommand_ut.cpp16
-rw-r--r--util/system/spin_wait.h2
-rw-r--r--util/system/spinlock.h2
-rw-r--r--util/system/thread.cpp132
-rw-r--r--util/system/thread.h20
-rw-r--r--util/system/thread.i2
-rw-r--r--util/system/thread_ut.cpp20
-rw-r--r--util/system/type_name.cpp4
-rw-r--r--util/system/unaligned_mem.h2
-rw-r--r--util/system/yassert.cpp2
26 files changed, 213 insertions, 213 deletions
diff --git a/util/system/align.h b/util/system/align.h
index e5e8a217f8..ea0bbc5b46 100644
--- a/util/system/align.h
+++ b/util/system/align.h
@@ -21,9 +21,9 @@ template <class T>
static inline T AlignUpSpace(T len, T align) noexcept {
Y_ASSERT(IsPowerOf2(align)); // align should be power of 2
return ((T)0 - len) & (align - 1); // AlignUp(len, align) - len;
-}
-
-template <class T>
+}
+
+template <class T>
static inline T* AlignUp(T* ptr, size_t align) noexcept {
return (T*)AlignUp((uintptr_t)ptr, align);
}
diff --git a/util/system/atomic.h b/util/system/atomic.h
index 676fa3fb91..80265babfd 100644
--- a/util/system/atomic.h
+++ b/util/system/atomic.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "defaults.h"
using TAtomicBase = intptr_t;
@@ -11,8 +11,8 @@ using TAtomic = volatile TAtomicBase;
#include "atomic_win.h"
#else
#error unsupported platform
-#endif
-
+#endif
+
#if !defined(ATOMIC_COMPILER_BARRIER)
#define ATOMIC_COMPILER_BARRIER()
#endif
diff --git a/util/system/atomic_gcc.h b/util/system/atomic_gcc.h
index 8838e3919c..ed8dc2bdc5 100644
--- a/util/system/atomic_gcc.h
+++ b/util/system/atomic_gcc.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#define ATOMIC_COMPILER_BARRIER() __asm__ __volatile__("" \
: \
: \
@@ -61,7 +61,7 @@ static inline intptr_t AtomicSwap(TAtomic* p, intptr_t v) {
__atomic_exchange(p, &v, &ret, __ATOMIC_SEQ_CST);
return ret;
}
-
+
static inline bool AtomicCas(TAtomic* a, intptr_t exchange, intptr_t compare) {
(void)a; // disable strange 'parameter set but not used' warning on gcc
return __atomic_compare_exchange(a, &compare, &exchange, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
diff --git a/util/system/atomic_win.h b/util/system/atomic_win.h
index 084c4c8859..65c290e6cc 100644
--- a/util/system/atomic_win.h
+++ b/util/system/atomic_win.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include <intrin.h>
#define USE_GENERIC_SETGET
@@ -14,7 +14,7 @@
static inline intptr_t AtomicIncrement(TAtomic& a) {
return _InterlockedIncrement((volatile long*)&a);
-}
+}
static inline intptr_t AtomicGetAndIncrement(TAtomic& a) {
return _InterlockedIncrement((volatile long*)&a) - 1;
@@ -22,7 +22,7 @@ static inline intptr_t AtomicGetAndIncrement(TAtomic& a) {
static inline intptr_t AtomicDecrement(TAtomic& a) {
return _InterlockedDecrement((volatile long*)&a);
-}
+}
static inline intptr_t AtomicGetAndDecrement(TAtomic& a) {
return _InterlockedDecrement((volatile long*)&a) + 1;
@@ -30,7 +30,7 @@ static inline intptr_t AtomicGetAndDecrement(TAtomic& a) {
static inline intptr_t AtomicAdd(TAtomic& a, intptr_t b) {
return _InterlockedExchangeAdd((volatile long*)&a, b) + b;
-}
+}
static inline intptr_t AtomicGetAndAdd(TAtomic& a, intptr_t b) {
return _InterlockedExchangeAdd((volatile long*)&a, b);
@@ -39,7 +39,7 @@ static inline intptr_t AtomicGetAndAdd(TAtomic& a, intptr_t b) {
static inline intptr_t AtomicSwap(TAtomic* a, intptr_t b) {
return _InterlockedExchange((volatile long*)a, b);
}
-
+
static inline bool AtomicCas(TAtomic* a, intptr_t exchange, intptr_t compare) {
return _InterlockedCompareExchange((volatile long*)a, exchange, compare) == compare;
}
diff --git a/util/system/compat.h b/util/system/compat.h
index b85591b0d1..c53dbcca17 100644
--- a/util/system/compat.h
+++ b/util/system/compat.h
@@ -44,7 +44,7 @@ extern "C" {
void vwarnx(const char* format, va_list ap);
void vwarn(const char* format, va_list ap);
void verrx(int status, const char* format, va_list ap);
-#else
+#else
#include <err.h>
#endif
}
diff --git a/util/system/err.cpp b/util/system/err.cpp
index 891d7c0cb6..5573ea1ee9 100644
--- a/util/system/err.cpp
+++ b/util/system/err.cpp
@@ -4,20 +4,20 @@
#include "error.h"
#include <util/generic/scope.h>
-
+
#include <util/stream/printf.h>
#include <util/stream/output.h>
-
+
void vwarnx(const char* fmt, va_list args) {
Cerr << GetProgramName() << ": ";
-
+
if (fmt) {
Printf(Cerr, fmt, args);
}
-
+
Cerr << '\n';
}
-
+
void vwarn(const char* fmt, va_list args) {
int curErrNo = errno;
auto curErrText = LastSystemErrorText();
@@ -25,55 +25,55 @@ void vwarn(const char* fmt, va_list args) {
Y_DEFER {
errno = curErrNo;
};
-
+
Cerr << GetProgramName() << ": ";
-
+
if (fmt) {
Printf(Cerr, fmt, args);
Cerr << ": ";
}
Cerr << curErrText << '\n';
-}
-
+}
+
void warn(const char* fmt, ...) {
va_list args;
-
+
va_start(args, fmt);
vwarn(fmt, args);
va_end(args);
-}
-
+}
+
void warnx(const char* fmt, ...) {
va_list args;
-
+
va_start(args, fmt);
vwarnx(fmt, args);
va_end(args);
-}
-
+}
+
void verr(int status, const char* fmt, va_list args) {
vwarn(fmt, args);
exit(status);
-}
-
+}
+
void err(int status, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
verr(status, fmt, args);
va_end(args);
-}
-
+}
+
void verrx(int status, const char* fmt, va_list args) {
vwarnx(fmt, args);
exit(status);
-}
-
+}
+
void errx(int status, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
verrx(status, fmt, args);
va_end(args);
-}
+}
diff --git a/util/system/file.cpp b/util/system/file.cpp
index ec7cc69272..4a261d020c 100644
--- a/util/system/file.cpp
+++ b/util/system/file.cpp
@@ -49,7 +49,7 @@
#include <sys/sendfile.h>
#define HAVE_POSIX_FADVISE 1
#define HAVE_SYNC_FILE_RANGE 1
-#elif defined(__FreeBSD__) && !defined(WITH_VALGRIND)
+#elif defined(__FreeBSD__) && !defined(WITH_VALGRIND)
#include <sys/param.h>
#define HAVE_POSIX_FADVISE (__FreeBSD_version >= 900501)
#define HAVE_SYNC_FILE_RANGE 0
@@ -565,38 +565,38 @@ FHANDLE TFileHandle::Duplicate() const noexcept {
#endif
}
-int TFileHandle::Duplicate2Posix(int dstHandle) const noexcept {
- if (!IsOpen()) {
- return -1;
- }
-#if defined(_win_)
- FHANDLE dupHandle = Duplicate();
- if (dupHandle == INVALID_FHANDLE) {
- _set_errno(EMFILE);
- return -1;
- }
- int posixHandle = _open_osfhandle((intptr_t)dupHandle, 0);
- if (posixHandle == -1) {
- CloseHandle(dupHandle);
- return -1;
- }
- if (dup2(posixHandle, dstHandle) == -1) {
- dstHandle = -1;
- }
- _close(posixHandle);
- return dstHandle;
-#elif defined(_unix_)
- while (dup2(Fd_, dstHandle) == -1) {
- if (errno != EINTR) {
- return -1;
- }
- }
- return dstHandle;
-#else
+int TFileHandle::Duplicate2Posix(int dstHandle) const noexcept {
+ if (!IsOpen()) {
+ return -1;
+ }
+#if defined(_win_)
+ FHANDLE dupHandle = Duplicate();
+ if (dupHandle == INVALID_FHANDLE) {
+ _set_errno(EMFILE);
+ return -1;
+ }
+ int posixHandle = _open_osfhandle((intptr_t)dupHandle, 0);
+ if (posixHandle == -1) {
+ CloseHandle(dupHandle);
+ return -1;
+ }
+ if (dup2(posixHandle, dstHandle) == -1) {
+ dstHandle = -1;
+ }
+ _close(posixHandle);
+ return dstHandle;
+#elif defined(_unix_)
+ while (dup2(Fd_, dstHandle) == -1) {
+ if (errno != EINTR) {
+ return -1;
+ }
+ }
+ return dstHandle;
+#else
#error unsupported platform
-#endif
-}
-
+#endif
+}
+
bool TFileHandle::LinkTo(const TFileHandle& fh) const noexcept {
#if defined(_unix_)
while (dup2(fh.Fd_, Fd_) == -1) {
diff --git a/util/system/file.h b/util/system/file.h
index caec596d9e..9502e159b6 100644
--- a/util/system/file.h
+++ b/util/system/file.h
@@ -120,7 +120,7 @@ public:
int Flock(int op) noexcept;
FHANDLE Duplicate() const noexcept;
- int Duplicate2Posix(int dstHandle) const noexcept;
+ int Duplicate2Posix(int dstHandle) const noexcept;
//dup2 - like semantics, return true on success
bool LinkTo(const TFileHandle& fh) const noexcept;
diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp
index a0864cc980..7454a4cb94 100644
--- a/util/system/filemap.cpp
+++ b/util/system/filemap.cpp
@@ -60,7 +60,7 @@ namespace {
return sysInfo.dwAllocationGranularity;
#else
return NSystemInfo::GetPageSize();
-#endif
+#endif
}
const size_t GRANULARITY_;
@@ -188,7 +188,7 @@ public:
, Mode_(om)
{
CheckFile();
-
+
if (File_.GetLength() < Length_) {
File_.Resize(Length_);
}
@@ -220,15 +220,15 @@ public:
inline TMapResult Map(i64 offset, size_t size) {
assert(File_.IsOpen());
-
+
if (offset > Length_) {
ythrow yexception() << "Can't map something at offset " << offset << " of '" << DbgName_ << "' with length " << Length_;
}
-
+
if (offset + (i64)size > Length_) {
ythrow yexception() << "Can't map " << (unsigned long)size << " bytes at offset " << offset << " of '" << DbgName_ << "' with length " << Length_;
}
-
+
TMapResult result;
i64 base = DownToGranularity(offset);
diff --git a/util/system/filemap.h b/util/system/filemap.h
index 014b46c41d..11be64bff4 100644
--- a/util/system/filemap.h
+++ b/util/system/filemap.h
@@ -52,7 +52,7 @@ struct TMemoryMapCommon {
oRdOnly = 1,
oRdWr = 2,
oCopyOnWr = 4,
-
+
oAccessMask = 7,
oNotGreedy = 8,
oPrecharge = 16,
@@ -77,12 +77,12 @@ public:
TMemoryMap(FILE* f, EOpenMode om, TString dbgName = UnknownFileName());
TMemoryMap(const TFile& file, TString dbgName = UnknownFileName());
TMemoryMap(const TFile& file, EOpenMode om, TString dbgName = UnknownFileName());
-
+
~TMemoryMap();
-
+
TMapResult Map(i64 offset, size_t size);
bool Unmap(TMapResult region);
-
+
void ResizeAndReset(i64 size);
TMapResult ResizeAndRemap(i64 offset, size_t size);
@@ -91,7 +91,7 @@ public:
bool IsWritable() const noexcept;
EOpenMode GetMode() const noexcept;
TFile GetFile() const noexcept;
-
+
void SetSequential();
void Evict(void* ptr, size_t len);
void Evict();
@@ -100,7 +100,7 @@ public:
* deprecated
*/
bool Unmap(void* ptr, size_t size);
-
+
private:
class TImpl;
TSimpleIntrusivePtr<TImpl> Impl_;
@@ -165,7 +165,7 @@ public:
TFile GetFile() const noexcept {
return Map_.GetFile();
}
-
+
void Precharge(size_t pos = 0, size_t size = (size_t)-1) const;
void SetSequential() {
@@ -203,11 +203,11 @@ public:
~TFileMappedArray() {
Ptr_ = nullptr;
End_ = nullptr;
- }
+ }
void Init(const char* name) {
DataHolder_.Reset(new TFileMap(name));
DoInit(name);
- }
+ }
void Init(const TFileMap& fileMap) {
DataHolder_.Reset(new TFileMap(fileMap));
DoInit(fileMap.GetFile().GetName());
@@ -217,18 +217,18 @@ public:
Ptr_ = nullptr;
Size_ = 0;
End_ = nullptr;
- }
+ }
void Precharge() {
DataHolder_->Precharge();
}
const T& operator[](size_t pos) const {
Y_ASSERT(pos < size());
return Ptr_[pos];
- }
+ }
/// for STL compatibility only, Size() usage is recommended
- size_t size() const {
+ size_t size() const {
return Size_;
- }
+ }
size_t Size() const {
return Size_;
}
@@ -236,11 +236,11 @@ public:
if (pos < Size_)
return Ptr_[pos];
return Dummy();
- }
+ }
void SetDummy(const T& n_Dummy) {
Dummy_.Destroy();
Dummy_.Reset(new (DummyData()) T(n_Dummy));
- }
+ }
inline char* DummyData() const noexcept {
return AlignUp((char*)DummyData_);
}
@@ -285,8 +285,8 @@ private:
Size_ = DataHolder_->Length() / sizeof(T);
End_ = Ptr_ + Size_;
}
-};
-
+};
+
class TMappedAllocation: TMoveOnly {
public:
TMappedAllocation(size_t size = 0, bool shared = false, void* addr = nullptr);
@@ -343,12 +343,12 @@ public:
T* Create(size_t siz) {
Y_ASSERT(MappedSize() == 0 && Ptr() == nullptr);
T* arr = (T*)Alloc((sizeof(T) * siz));
- if (!arr)
+ if (!arr)
return nullptr;
Y_ASSERT(MappedSize() == sizeof(T) * siz);
for (size_t n = 0; n < siz; n++)
new (&arr[n]) T();
- return arr;
+ return arr;
}
void Destroy() {
T* arr = (T*)Ptr();
diff --git a/util/system/fs_win.cpp b/util/system/fs_win.cpp
index 52ecf3ed7f..a410ccac06 100644
--- a/util/system/fs_win.cpp
+++ b/util/system/fs_win.cpp
@@ -6,7 +6,7 @@
#include <util/charset/wide.h>
#include "file.h"
-#include <winioctl.h>
+#include <winioctl.h>
namespace NFsPrivate {
static LPCWSTR UTF8ToWCHAR(const TStringBuf str, TUtf16String& wstr) {
diff --git a/util/system/guard.h b/util/system/guard.h
index fa8da37f27..efc091d5f8 100644
--- a/util/system/guard.h
+++ b/util/system/guard.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include <util/generic/noncopyable.h>
template <class T>
diff --git a/util/system/mktemp.cpp b/util/system/mktemp.cpp
index 4b332255af..505b7b4a4b 100644
--- a/util/system/mktemp.cpp
+++ b/util/system/mktemp.cpp
@@ -10,7 +10,7 @@
#ifdef _win32_
#include "winint.h"
#include <io.h>
-#else
+#else
#include <unistd.h>
#include <stdlib.h>
#endif
diff --git a/util/system/mutex.h b/util/system/mutex.h
index 2187380e65..032630d134 100644
--- a/util/system/mutex.h
+++ b/util/system/mutex.h
@@ -17,7 +17,7 @@ public:
inline void Release() noexcept {
}
-
+
inline void lock() noexcept {
Acquire();
}
diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp
index 4200491e2e..b1989b5c8c 100644
--- a/util/system/shellcommand.cpp
+++ b/util/system/shellcommand.cpp
@@ -628,22 +628,22 @@ void TShellCommand::TImpl::StartProcess(TShellCommand::TImpl::TPipes& pipes) {
#endif
void ShellQuoteArg(TString& dst, TStringBuf argument) {
- dst.append("\"");
- TStringBuf l, r;
+ dst.append("\"");
+ TStringBuf l, r;
while (argument.TrySplit('"', l, r)) {
- dst.append(l);
- dst.append("\\\"");
+ dst.append(l);
+ dst.append("\\\"");
argument = r;
- }
+ }
dst.append(argument);
- dst.append("\"");
-}
-
+ dst.append("\"");
+}
+
void ShellQuoteArgSp(TString& dst, TStringBuf argument) {
- dst.append(' ');
+ dst.append(' ');
ShellQuoteArg(dst, argument);
-}
-
+}
+
bool ArgNeedsQuotes(TStringBuf arg) noexcept {
if (arg.empty()) {
return true;
diff --git a/util/system/shellcommand.h b/util/system/shellcommand.h
index d3d1488d3a..8730627fe5 100644
--- a/util/system/shellcommand.h
+++ b/util/system/shellcommand.h
@@ -474,11 +474,11 @@ private:
using TImplRef = TSimpleIntrusivePtr<TImpl>;
TImplRef Impl;
};
-
-/// Appends to dst: quoted arg
+
+/// Appends to dst: quoted arg
void ShellQuoteArg(TString& dst, TStringBuf arg);
-
-/// Appends to dst: space, quoted arg
+
+/// Appends to dst: space, quoted arg
void ShellQuoteArgSp(TString& dst, TStringBuf arg);
/// Returns true if arg should be quoted
diff --git a/util/system/shellcommand_ut.cpp b/util/system/shellcommand_ut.cpp
index ffd7fd738d..9d849279d2 100644
--- a/util/system/shellcommand_ut.cpp
+++ b/util/system/shellcommand_ut.cpp
@@ -62,14 +62,14 @@ private:
Y_UNIT_TEST_SUITE(TShellQuoteTest) {
Y_UNIT_TEST(TestQuoteArg) {
TString cmd;
- ShellQuoteArg(cmd, "/pr f/krev/prev.exe");
- ShellQuoteArgSp(cmd, "-DVal=\"W Quotes\"");
- ShellQuoteArgSp(cmd, "-DVal=W Space");
- ShellQuoteArgSp(cmd, "-DVal=Blah");
- UNIT_ASSERT_STRINGS_EQUAL(cmd, "\"/pr f/krev/prev.exe\" \"-DVal=\\\"W Quotes\\\"\" \"-DVal=W Space\" \"-DVal=Blah\"");
- }
-}
-
+ ShellQuoteArg(cmd, "/pr f/krev/prev.exe");
+ ShellQuoteArgSp(cmd, "-DVal=\"W Quotes\"");
+ ShellQuoteArgSp(cmd, "-DVal=W Space");
+ ShellQuoteArgSp(cmd, "-DVal=Blah");
+ UNIT_ASSERT_STRINGS_EQUAL(cmd, "\"/pr f/krev/prev.exe\" \"-DVal=\\\"W Quotes\\\"\" \"-DVal=W Space\" \"-DVal=Blah\"");
+ }
+}
+
Y_UNIT_TEST_SUITE(TShellCommandTest) {
Y_UNIT_TEST(TestNoQuotes) {
TShellCommandOptions options;
diff --git a/util/system/spin_wait.h b/util/system/spin_wait.h
index c13559bce6..91dd423e33 100644
--- a/util/system/spin_wait.h
+++ b/util/system/spin_wait.h
@@ -1,5 +1,5 @@
#pragma once
-
+
struct TSpinWait {
TSpinWait() noexcept;
diff --git a/util/system/spinlock.h b/util/system/spinlock.h
index a560d83821..af2630890a 100644
--- a/util/system/spinlock.h
+++ b/util/system/spinlock.h
@@ -1,5 +1,5 @@
#pragma once
-
+
#include "atomic.h"
#include "spin_wait.h"
diff --git a/util/system/thread.cpp b/util/system/thread.cpp
index f1fe4a24b4..6236746c2d 100644
--- a/util/system/thread.cpp
+++ b/util/system/thread.cpp
@@ -8,7 +8,7 @@
#include <util/generic/yexception.h>
#include "yassert.h"
#include <utility>
-
+
#if defined(_glibc_)
#if !__GLIBC_PREREQ(2, 30)
#include <sys/syscall.h>
@@ -82,7 +82,7 @@ namespace {
#endif
{
}
-
+
inline bool Running() const noexcept {
return Handle != 0;
}
@@ -231,7 +231,7 @@ namespace {
#undef PCHECK
using TThreadBase = TPosixThread;
-#endif
+#endif
template <class T>
static inline typename T::TValueType* Impl(T& t, const char* op, bool check = true) {
@@ -403,48 +403,48 @@ static void WindowsCurrentSetThreadName(DWORD dwThreadID, const char* threadName
}
#endif
-#if defined(_win_)
-namespace {
- struct TWinThreadDescrAPI {
- TWinThreadDescrAPI()
+#if defined(_win_)
+namespace {
+ struct TWinThreadDescrAPI {
+ TWinThreadDescrAPI()
: Kernel32Dll("kernel32.dll")
- , SetThreadDescription((TSetThreadDescription)Kernel32Dll.SymOptional("SetThreadDescription"))
- , GetThreadDescription((TGetThreadDescription)Kernel32Dll.SymOptional("GetThreadDescription"))
- {
- }
-
- // This API is for Windows 10+ only:
- // https://msdn.microsoft.com/en-us/library/windows/desktop/mt774972(v=vs.85).aspx
- bool HasAPI() noexcept {
- return SetThreadDescription && GetThreadDescription;
- }
-
- // Should always succeed, unless something very strange is passed in `descr'
- void SetDescr(const char* descr) {
- auto hr = SetThreadDescription(GetCurrentThread(), (const WCHAR*)UTF8ToWide(descr).data());
- Y_VERIFY(SUCCEEDED(hr), "SetThreadDescription failed");
- }
-
- TString GetDescr() {
- PWSTR wideName;
- auto hr = GetThreadDescription(GetCurrentThread(), &wideName);
- Y_VERIFY(SUCCEEDED(hr), "GetThreadDescription failed");
- Y_DEFER {
- LocalFree(wideName);
- };
- return WideToUTF8((const wchar16*)wideName);
- }
-
+ , SetThreadDescription((TSetThreadDescription)Kernel32Dll.SymOptional("SetThreadDescription"))
+ , GetThreadDescription((TGetThreadDescription)Kernel32Dll.SymOptional("GetThreadDescription"))
+ {
+ }
+
+ // This API is for Windows 10+ only:
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/mt774972(v=vs.85).aspx
+ bool HasAPI() noexcept {
+ return SetThreadDescription && GetThreadDescription;
+ }
+
+ // Should always succeed, unless something very strange is passed in `descr'
+ void SetDescr(const char* descr) {
+ auto hr = SetThreadDescription(GetCurrentThread(), (const WCHAR*)UTF8ToWide(descr).data());
+ Y_VERIFY(SUCCEEDED(hr), "SetThreadDescription failed");
+ }
+
+ TString GetDescr() {
+ PWSTR wideName;
+ auto hr = GetThreadDescription(GetCurrentThread(), &wideName);
+ Y_VERIFY(SUCCEEDED(hr), "GetThreadDescription failed");
+ Y_DEFER {
+ LocalFree(wideName);
+ };
+ return WideToUTF8((const wchar16*)wideName);
+ }
+
typedef HRESULT(__cdecl* TSetThreadDescription)(HANDLE hThread, PCWSTR lpThreadDescription);
typedef HRESULT(__cdecl* TGetThreadDescription)(HANDLE hThread, PWSTR* ppszThreadDescription);
-
- TDynamicLibrary Kernel32Dll;
- TSetThreadDescription SetThreadDescription;
- TGetThreadDescription GetThreadDescription;
- };
-}
-#endif // _win_
-
+
+ TDynamicLibrary Kernel32Dll;
+ TSetThreadDescription SetThreadDescription;
+ TGetThreadDescription GetThreadDescription;
+ };
+}
+#endif // _win_
+
void TThread::SetCurrentThreadName(const char* name) {
(void)name;
@@ -455,15 +455,15 @@ void TThread::SetCurrentThreadName(const char* name) {
prctl(PR_SET_NAME, name, 0, 0, 0);
#elif defined(_darwin_)
pthread_setname_np(name);
-#elif defined(_win_)
- auto api = Singleton<TWinThreadDescrAPI>();
- if (api->HasAPI()) {
- api->SetDescr(name);
- } else {
+#elif defined(_win_)
+ auto api = Singleton<TWinThreadDescrAPI>();
+ if (api->HasAPI()) {
+ api->SetDescr(name);
+ } else {
#if defined(_MSC_VER)
- WindowsCurrentSetThreadName(DWORD(-1), name);
+ WindowsCurrentSetThreadName(DWORD(-1), name);
#endif
- }
+ }
#else
// no idea
#endif // OS
@@ -471,7 +471,7 @@ void TThread::SetCurrentThreadName(const char* name) {
TString TThread::CurrentThreadName() {
#if defined(_freebsd_)
-// TODO: check pthread_get_name_np API availability
+// TODO: check pthread_get_name_np API availability
#elif defined(_linux_)
// > The buffer should allow space for up to 16 bytes; the returned string will be
// > null-terminated.
@@ -487,12 +487,12 @@ TString TThread::CurrentThreadName() {
memset(name, 0, sizeof(name));
Y_VERIFY(pthread_getname_np(thread, name, sizeof(name)) == 0, "pthread_getname_np failed: %s", strerror(errno));
return name;
-#elif defined(_win_)
- auto api = Singleton<TWinThreadDescrAPI>();
- if (api->HasAPI()) {
- return api->GetDescr();
- }
- return {};
+#elif defined(_win_)
+ auto api = Singleton<TWinThreadDescrAPI>();
+ if (api->HasAPI()) {
+ return api->GetDescr();
+ }
+ return {};
#else
// no idea
#endif // OS
@@ -500,16 +500,16 @@ TString TThread::CurrentThreadName() {
return {};
}
-bool TThread::CanGetCurrentThreadName() {
-#if defined(_linux_) || defined(_darwin_)
- return true;
-#elif defined(_win_)
- return Singleton<TWinThreadDescrAPI>()->HasAPI();
-#else
- return false;
-#endif // OS
-}
-
+bool TThread::CanGetCurrentThreadName() {
+#if defined(_linux_) || defined(_darwin_)
+ return true;
+#elif defined(_win_)
+ return Singleton<TWinThreadDescrAPI>()->HasAPI();
+#else
+ return false;
+#endif // OS
+}
+
TCurrentThreadLimits::TCurrentThreadLimits() noexcept
: StackBegin(nullptr)
, StackLength(0)
diff --git a/util/system/thread.h b/util/system/thread.h
index 8ce6ab3016..a6e8abdb5b 100644
--- a/util/system/thread.h
+++ b/util/system/thread.h
@@ -1,5 +1,5 @@
#pragma once
-
+
/// This code should not be used directly unless you really understand what you do.
/// If you need threads, use thread pool functionality in <util/thread/factory.h>
/// @see SystemThreadFactory()
@@ -9,7 +9,7 @@
#include "defaults.h"
#include "progname.h"
-
+
bool SetHighestThreadPriority();
class TThread {
@@ -71,7 +71,7 @@ public:
return *this;
}
};
-
+
TThread(const TParams& params);
TThread(TThreadProc threadProc, void* param);
@@ -113,18 +113,18 @@ public:
// NOTE: Content of `name` will be copied.
//
// NOTE: On Linux thread name is limited to 15 symbols which is probably the smallest one among
- // all platforms. If you provide a name longer than 15 symbols it will be cut. So if you expect
+ // all platforms. If you provide a name longer than 15 symbols it will be cut. So if you expect
// `CurrentThreadName` to return the same name as `name` make sure it's not longer than 15
// symbols.
static void SetCurrentThreadName(const char* name);
- // NOTE: Will return empty string where CanGetCurrentThreadName() returns false.
+ // NOTE: Will return empty string where CanGetCurrentThreadName() returns false.
static TString CurrentThreadName();
- // NOTE: Depends on a platform version.
- // Will return true for Darwin, Linux or fresh Windows 10.
- static bool CanGetCurrentThreadName();
-
+ // NOTE: Depends on a platform version.
+ // Will return true for Darwin, Linux or fresh Windows 10.
+ static bool CanGetCurrentThreadName();
+
private:
struct TCallableBase {
virtual ~TCallableBase() = default;
@@ -155,7 +155,7 @@ private:
private:
class TImpl;
THolder<TImpl> Impl_;
-};
+};
class ISimpleThread: public TThread {
public:
diff --git a/util/system/thread.i b/util/system/thread.i
index ee18b5efee..8cba505473 100644
--- a/util/system/thread.i
+++ b/util/system/thread.i
@@ -23,7 +23,7 @@
#endif
#include <util/digest/numeric.h>
-
+
static inline size_t SystemCurrentThreadIdImpl() noexcept {
#if defined(_unix_)
return (size_t)pthread_self();
diff --git a/util/system/thread_ut.cpp b/util/system/thread_ut.cpp
index 8d0b023da0..d820898fd5 100644
--- a/util/system/thread_ut.cpp
+++ b/util/system/thread_ut.cpp
@@ -66,11 +66,11 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) {
TThread::SetCurrentThreadName(setName.data());
const auto getName = TThread::CurrentThreadName();
- if (TThread::CanGetCurrentThreadName()) {
- UNIT_ASSERT_VALUES_EQUAL(setName, getName);
- } else {
- UNIT_ASSERT_VALUES_EQUAL("", getName);
- }
+ if (TThread::CanGetCurrentThreadName()) {
+ UNIT_ASSERT_VALUES_EQUAL(setName, getName);
+ } else {
+ UNIT_ASSERT_VALUES_EQUAL("", getName);
+ }
return nullptr;
}
@@ -97,11 +97,11 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) {
thread.Join();
const auto getName = TThread::CurrentThreadName();
- if (TThread::CanGetCurrentThreadName()) {
- UNIT_ASSERT_VALUES_EQUAL(setName, getName);
- } else {
- UNIT_ASSERT_VALUES_EQUAL("", getName);
- }
+ if (TThread::CanGetCurrentThreadName()) {
+ UNIT_ASSERT_VALUES_EQUAL(setName, getName);
+ } else {
+ UNIT_ASSERT_VALUES_EQUAL("", getName);
+ }
return nullptr;
}
diff --git a/util/system/type_name.cpp b/util/system/type_name.cpp
index 16efdbe353..0377da4212 100644
--- a/util/system/type_name.cpp
+++ b/util/system/type_name.cpp
@@ -1,7 +1,7 @@
#include "platform.h"
#include "demangle_impl.h"
-#ifdef __GNUC__
+#ifdef __GNUC__
#include <stdexcept>
#include <cxxabi.h>
#endif
@@ -25,7 +25,7 @@ namespace {
} // anonymous namespace
const char* NPrivate::TCppDemangler::Demangle(const char* name) {
-#ifndef __GNUC__
+#ifndef __GNUC__
return name;
#else
int status;
diff --git a/util/system/unaligned_mem.h b/util/system/unaligned_mem.h
index 4af20371f2..4b84686f2f 100644
--- a/util/system/unaligned_mem.h
+++ b/util/system/unaligned_mem.h
@@ -40,7 +40,7 @@ public:
}
inline T Cur() const noexcept {
- Y_ASSERT(C_ < L_ || sizeof(T) < Align);
+ Y_ASSERT(C_ < L_ || sizeof(T) < Align);
return ::ReadUnaligned<T>(C_);
}
diff --git a/util/system/yassert.cpp b/util/system/yassert.cpp
index 816e9e8448..0f586648b7 100644
--- a/util/system/yassert.cpp
+++ b/util/system/yassert.cpp
@@ -78,7 +78,7 @@ namespace NPrivate {
} else {
o << " " << function << "() failed" << Endl;
}
- Cerr << r << Flush;
+ Cerr << r << Flush;
#ifndef WITH_VALGRIND
PrintBackTrace();
#endif