aboutsummaryrefslogtreecommitdiffstats
path: root/util/system
diff options
context:
space:
mode:
authornga <nga@yandex-team.ru>2022-02-10 16:48:09 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:09 +0300
commit1f553f46fb4f3c5eec631352cdd900a0709016af (patch)
treea231fba2c03b440becaea6c86a2702d0bfb0336e /util/system
parentc4de7efdedc25b49cbea74bd589eecb61b55b60a (diff)
downloadydb-1f553f46fb4f3c5eec631352cdd900a0709016af.tar.gz
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/system')
-rw-r--r--util/system/backtrace.cpp32
-rw-r--r--util/system/backtrace.h18
-rw-r--r--util/system/byteorder_ut.cpp10
-rw-r--r--util/system/compat.cpp2
-rw-r--r--util/system/compat.h6
-rw-r--r--util/system/compat_ut.cpp14
-rw-r--r--util/system/condvar.cpp2
-rw-r--r--util/system/condvar.h2
-rw-r--r--util/system/context.cpp4
-rw-r--r--util/system/datetime.cpp46
-rw-r--r--util/system/datetime.h26
-rw-r--r--util/system/datetime_ut.cpp2
-rw-r--r--util/system/defaults.h2
-rw-r--r--util/system/error_ut.cpp2
-rw-r--r--util/system/event.h2
-rw-r--r--util/system/execpath.cpp34
-rw-r--r--util/system/execpath.h4
-rw-r--r--util/system/execpath_ut.cpp8
-rw-r--r--util/system/fasttime.cpp4
-rw-r--r--util/system/file.cpp100
-rw-r--r--util/system/file.h6
-rw-r--r--util/system/file_ut.cpp10
-rw-r--r--util/system/filemap.cpp2
-rw-r--r--util/system/info.cpp8
-rw-r--r--util/system/info_ut.cpp2
-rw-r--r--util/system/pipe.cpp138
-rw-r--r--util/system/pipe.h78
-rw-r--r--util/system/pipe_ut.cpp20
-rw-r--r--util/system/rusage.cpp116
-rw-r--r--util/system/rusage.h38
-rw-r--r--util/system/rusage_ut.cpp12
-rw-r--r--util/system/spin_wait.h4
-rw-r--r--util/system/spinlock.h12
-rw-r--r--util/system/spinlock_ut.cpp52
-rw-r--r--util/system/thread.cpp4
-rw-r--r--util/system/thread.h4
-rw-r--r--util/system/type_name.cpp20
-rw-r--r--util/system/type_name.h4
-rw-r--r--util/system/type_name_ut.cpp14
-rw-r--r--util/system/yassert.cpp30
-rw-r--r--util/system/yassert.h14
-rw-r--r--util/system/yassert_ut.cpp32
42 files changed, 470 insertions, 470 deletions
diff --git a/util/system/backtrace.cpp b/util/system/backtrace.cpp
index b77fe58fb1..1bc57de75d 100644
--- a/util/system/backtrace.cpp
+++ b/util/system/backtrace.cpp
@@ -236,15 +236,15 @@ TResolvedSymbol ResolveSymbol(void* sym, char*, size_t) {
void FormatBackTrace(IOutputStream* out, void* const* backtrace, size_t backtraceSize) {
char tmpBuf[1024];
- for (size_t i = 0; i < backtraceSize; ++i) {
- TResolvedSymbol rs = ResolveSymbol(backtrace[i], tmpBuf, sizeof(tmpBuf));
+ for (size_t i = 0; i < backtraceSize; ++i) {
+ TResolvedSymbol rs = ResolveSymbol(backtrace[i], tmpBuf, sizeof(tmpBuf));
*out << rs.Name << "+" << ((ptrdiff_t)backtrace[i] - (ptrdiff_t)rs.NearestSymbol) << " (" << Hex((ptrdiff_t)backtrace[i], HF_ADDX) << ')' << '\n';
}
}
TFormatBackTraceFn FormatBackTraceFn = FormatBackTrace;
-
+
TFormatBackTraceFn SetFormatBackTraceFn(TFormatBackTraceFn f) {
TFormatBackTraceFn prevFn = FormatBackTraceFn;
FormatBackTraceFn = f;
@@ -264,25 +264,25 @@ TFormatBackTraceFn GetFormatBackTraceFn() {
void PrintBackTrace() {
FormatBackTrace(&Cerr);
}
-
-TBackTrace::TBackTrace()
- : Size(0)
+
+TBackTrace::TBackTrace()
+ : Size(0)
{
}
-
-void TBackTrace::Capture() {
- Size = BackTrace(Data, CAPACITY);
-}
-
+
+void TBackTrace::Capture() {
+ Size = BackTrace(Data, CAPACITY);
+}
+
void TBackTrace::PrintTo(IOutputStream& out) const {
FormatBackTraceFn(&out, Data, Size);
-}
-
+}
+
TString TBackTrace::PrintToString() const {
- TStringStream ss;
- PrintTo(ss);
+ TStringStream ss;
+ PrintTo(ss);
return ss.Str();
-}
+}
size_t TBackTrace::size() const {
return Size;
diff --git a/util/system/backtrace.h b/util/system/backtrace.h
index 2fce7585c3..71b3c8f528 100644
--- a/util/system/backtrace.h
+++ b/util/system/backtrace.h
@@ -17,7 +17,7 @@ TResolvedSymbol ResolveSymbol(void* sym, char* buf, size_t len);
void FormatBackTrace(IOutputStream* out, void* const* backtrace, size_t backtraceSize);
void FormatBackTrace(IOutputStream* out);
void PrintBackTrace();
-
+
using TFormatBackTraceFn = void (*)(IOutputStream*, void* const* backtrace, size_t backtraceSize);
TFormatBackTraceFn SetFormatBackTraceFn(TFormatBackTraceFn f);
@@ -25,15 +25,15 @@ TFormatBackTraceFn GetFormatBackTraceFn();
using TBackTraceView = TArrayRef<void* const>;
-class TBackTrace {
-private:
+class TBackTrace {
+private:
static constexpr size_t CAPACITY = 300;
- void* Data[CAPACITY];
- size_t Size;
+ void* Data[CAPACITY];
+ size_t Size;
-public:
- TBackTrace();
- void Capture();
+public:
+ TBackTrace();
+ void Capture();
void PrintTo(IOutputStream&) const;
TString PrintToString() const;
size_t size() const;
@@ -41,4 +41,4 @@ public:
operator TBackTraceView() const;
static TBackTrace FromCurrentException();
-};
+};
diff --git a/util/system/byteorder_ut.cpp b/util/system/byteorder_ut.cpp
index 39b8603d3f..b728f86915 100644
--- a/util/system/byteorder_ut.cpp
+++ b/util/system/byteorder_ut.cpp
@@ -1,8 +1,8 @@
#include "byteorder.h"
#include <library/cpp/testing/unittest/registar.h>
-
-class TByteOrderTest: public TTestBase {
+
+class TByteOrderTest: public TTestBase {
UNIT_TEST_SUITE(TByteOrderTest);
UNIT_TEST(TestSwap16)
UNIT_TEST(TestSwap32)
@@ -21,6 +21,6 @@ private:
inline void TestSwap64() {
UNIT_ASSERT_EQUAL(0x1234567890abcdefULL, SwapBytes((ui64)ULL(0xefcdab9078563412)));
}
-};
-
-UNIT_TEST_SUITE_REGISTRATION(TByteOrderTest);
+};
+
+UNIT_TEST_SUITE_REGISTRATION(TByteOrderTest);
diff --git a/util/system/compat.cpp b/util/system/compat.cpp
index 18fbfa296a..edeb78e8e3 100644
--- a/util/system/compat.cpp
+++ b/util/system/compat.cpp
@@ -16,7 +16,7 @@
#include <io.h>
#endif
-#ifndef HAVE_NATIVE_GETPROGNAME
+#ifndef HAVE_NATIVE_GETPROGNAME
const char* getprogname() {
return GetProgramName().data();
}
diff --git a/util/system/compat.h b/util/system/compat.h
index c53dbcca17..6aef2761f9 100644
--- a/util/system/compat.h
+++ b/util/system/compat.h
@@ -30,9 +30,9 @@ extern "C" {
#if defined(__FreeBSD__) || defined(_darwin_)
#define HAVE_NATIVE_GETPROGNAME
-#endif
-
-#ifndef HAVE_NATIVE_GETPROGNAME
+#endif
+
+#ifndef HAVE_NATIVE_GETPROGNAME
const char* getprogname();
#endif
diff --git a/util/system/compat_ut.cpp b/util/system/compat_ut.cpp
index dbd9289c17..a46b41a4ce 100644
--- a/util/system/compat_ut.cpp
+++ b/util/system/compat_ut.cpp
@@ -1,12 +1,12 @@
#include "compat.h"
#include <library/cpp/testing/unittest/registar.h>
-
-#include <util/folder/dirut.h>
-#include <util/stream/output.h>
-
+
+#include <util/folder/dirut.h>
+#include <util/stream/output.h>
+
Y_UNIT_TEST_SUITE(TCompatTest) {
Y_UNIT_TEST(TestGetprogname) {
- getprogname(); // just check it links
- }
-}
+ getprogname(); // just check it links
+ }
+}
diff --git a/util/system/condvar.cpp b/util/system/condvar.cpp
index 62f3d22356..48addfb210 100644
--- a/util/system/condvar.cpp
+++ b/util/system/condvar.cpp
@@ -112,7 +112,7 @@ public:
int ret = pthread_cond_timedwait(&Cond_, (pthread_mutex_t*)lock.Handle(), &spec);
Y_VERIFY(ret == 0 || ret == ETIMEDOUT, "pthread_cond_timedwait failed: %s", LastSystemErrorText(ret));
-
+
return ret == 0;
}
}
diff --git a/util/system/condvar.h b/util/system/condvar.h
index 569162717c..2fa33a1107 100644
--- a/util/system/condvar.h
+++ b/util/system/condvar.h
@@ -4,7 +4,7 @@
#include <util/generic/ptr.h>
#include <util/generic/noncopyable.h>
-#include <util/datetime/base.h>
+#include <util/datetime/base.h>
#include <utility>
diff --git a/util/system/context.cpp b/util/system/context.cpp
index ad99309088..0c8f3069ff 100644
--- a/util/system/context.cpp
+++ b/util/system/context.cpp
@@ -24,7 +24,7 @@ namespace __cxxabiv1 {
#endif
#endif
-#include <util/stream/output.h>
+#include <util/stream/output.h>
#include <util/generic/yexception.h>
#define FROM_CONTEXT_IMPL
@@ -37,7 +37,7 @@ void ITrampoLine::DoRunNaked() {
try {
DoRun();
} catch (...) {
- Cerr << "Uncaught exception in coroutine: " << CurrentExceptionMessage() << "\n";
+ Cerr << "Uncaught exception in coroutine: " << CurrentExceptionMessage() << "\n";
}
abort();
diff --git a/util/system/datetime.cpp b/util/system/datetime.cpp
index b07b50679a..4c5488a24c 100644
--- a/util/system/datetime.cpp
+++ b/util/system/datetime.cpp
@@ -7,7 +7,7 @@
#include <ctime>
#include <cerrno>
-
+
#ifdef _darwin_
#include <AvailabilityMacros.h>
#if defined(MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
@@ -19,8 +19,8 @@
static ui64 ToMicroSeconds(const struct timeval& tv) {
return (ui64)tv.tv_sec * 1000000 + (ui64)tv.tv_usec;
-}
-
+}
+
#if defined(_win_)
static ui64 ToMicroSeconds(const FILETIME& ft) {
return (((ui64)ft.dwHighDateTime << 32) + (ui64)ft.dwLowDateTime) / (ui64)10;
@@ -32,12 +32,12 @@ static ui64 ToMicroSeconds(const struct timespec& ts) {
#endif
ui64 MicroSeconds() noexcept {
- struct timeval tv;
+ struct timeval tv;
gettimeofday(&tv, nullptr);
-
+
return ToMicroSeconds(tv);
-}
-
+}
+
ui64 ThreadCPUUserTime() noexcept {
#if defined(_win_)
FILETIME creationTime, exitTime, kernelTime, userTime;
@@ -73,26 +73,26 @@ ui64 ThreadCPUTime() noexcept {
}
ui32 Seconds() noexcept {
- struct timeval tv;
+ struct timeval tv;
gettimeofday(&tv, nullptr);
- return tv.tv_sec;
-}
-
+ return tv.tv_sec;
+}
+
void NanoSleep(ui64 ns) noexcept {
#if defined(_win_)
- Sleep(ns / 1000000);
-#else
- const ui64 NS = 1000 * 1000 * 1000;
- struct timespec req;
- req.tv_sec = ns / NS;
- req.tv_nsec = ns % NS;
- struct timespec left;
- while (nanosleep(&req, &left) < 0) {
+ Sleep(ns / 1000000);
+#else
+ const ui64 NS = 1000 * 1000 * 1000;
+ struct timespec req;
+ req.tv_sec = ns / NS;
+ req.tv_nsec = ns % NS;
+ struct timespec left;
+ while (nanosleep(&req, &left) < 0) {
Y_ASSERT(errno == EINTR);
- req = left;
- }
-#endif
-}
+ req = left;
+ }
+#endif
+}
#if defined(_x86_)
extern const bool HaveRdtscp = NX86::HaveRDTSCP();
diff --git a/util/system/datetime.h b/util/system/datetime.h
index aa009974e0..92aacdc31f 100644
--- a/util/system/datetime.h
+++ b/util/system/datetime.h
@@ -1,21 +1,21 @@
#pragma once
-
+
#include "defaults.h"
#include "platform.h"
-
+
#if defined(_win_)
#include <intrin.h>
#pragma intrinsic(__rdtsc)
#endif // _win_
-
+
#if defined(_darwin_) && !defined(_x86_)
#include <mach/mach_time.h>
#endif
-/// util/system/datetime.h contains only system time providers
-/// for handy datetime utilities include util/datetime/base.h
-
-/// Current time in microseconds since epoch
+/// util/system/datetime.h contains only system time providers
+/// for handy datetime utilities include util/datetime/base.h
+
+/// Current time in microseconds since epoch
ui64 MicroSeconds() noexcept;
/// Current time in milliseconds since epoch
inline ui64 MilliSeconds() {
@@ -25,17 +25,17 @@ inline ui64 MilliSeconds() {
inline ui64 millisec() {
return MilliSeconds();
}
-/// Current time in seconds since epoch
+/// Current time in seconds since epoch
ui32 Seconds() noexcept;
///Current thread time in microseconds
ui64 ThreadCPUUserTime() noexcept;
ui64 ThreadCPUSystemTime() noexcept;
ui64 ThreadCPUTime() noexcept;
-
+
void NanoSleep(ui64 ns) noexcept;
-
-// GetCycleCount guarantees to return synchronous values on different cores
-// and provide constant rate only on modern Intel and AMD processors
+
+// GetCycleCount guarantees to return synchronous values on different cores
+// and provide constant rate only on modern Intel and AMD processors
// NOTE: rdtscp is used to prevent out of order execution
// rdtsc can be reordered, while rdtscp cannot be reordered
// with preceding instructions
@@ -95,4 +95,4 @@ Y_FORCE_INLINE ui64 GetCycleCount() noexcept {
#else
#error "unsupported arch"
#endif
-}
+}
diff --git a/util/system/datetime_ut.cpp b/util/system/datetime_ut.cpp
index a865a888ca..bddf9df35d 100644
--- a/util/system/datetime_ut.cpp
+++ b/util/system/datetime_ut.cpp
@@ -1 +1 @@
-#include "datetime.h"
+#include "datetime.h"
diff --git a/util/system/defaults.h b/util/system/defaults.h
index dcd7abea38..2d95db149b 100644
--- a/util/system/defaults.h
+++ b/util/system/defaults.h
@@ -142,7 +142,7 @@ constexpr bool Y_IS_DEBUG_BUILD = true;
#define Y_CAT_II(X, Y) X##Y
#define Y_STRINGIZE(X) UTIL_PRIVATE_STRINGIZE_AUX(X)
-#define UTIL_PRIVATE_STRINGIZE_AUX(X) #X
+#define UTIL_PRIVATE_STRINGIZE_AUX(X) #X
#if defined(__COUNTER__)
#define Y_GENERATE_UNIQUE_ID(N) Y_CAT(N, __COUNTER__)
diff --git a/util/system/error_ut.cpp b/util/system/error_ut.cpp
index 763b0dddb7..8403dfa180 100644
--- a/util/system/error_ut.cpp
+++ b/util/system/error_ut.cpp
@@ -6,7 +6,7 @@
#ifdef _win_
#include "winint.h"
-#else
+#else
#include <fcntl.h>
#endif
diff --git a/util/system/event.h b/util/system/event.h
index cab2fc478a..a63498a72e 100644
--- a/util/system/event.h
+++ b/util/system/event.h
@@ -1,7 +1,7 @@
#pragma once
#include <util/generic/ptr.h>
-#include <util/datetime/base.h>
+#include <util/datetime/base.h>
struct TEventResetType {
enum ResetMode {
diff --git a/util/system/execpath.cpp b/util/system/execpath.cpp
index 33198af58b..836edeb76d 100644
--- a/util/system/execpath.cpp
+++ b/util/system/execpath.cpp
@@ -2,11 +2,11 @@
#include <stdlib.h>
-#if defined(_solaris_)
+#if defined(_solaris_)
#include <stdlib.h>
-#elif defined(_darwin_)
+#elif defined(_darwin_)
#include <mach-o/dyld.h>
-#elif defined(_win_)
+#elif defined(_win_)
#include "winint.h"
#include <io.h>
#elif defined(_linux_)
@@ -16,13 +16,13 @@
#include <sys/types.h> // for u_int not defined in sysctl.h
#include <sys/sysctl.h>
#include <unistd.h>
-#endif
-
+#endif
+
#include <util/folder/dirut.h>
#include <util/generic/singleton.h>
#include <util/generic/function.h>
#include <util/generic/yexception.h>
-#include <util/memory/tempbuf.h>
+#include <util/memory/tempbuf.h>
#include <util/stream/file.h>
#include <util/stream/pipe.h>
#include <util/string/cast.h>
@@ -30,7 +30,7 @@
#include "filemap.h"
#include "execpath.h"
#include "fs.h"
-
+
#if defined(_freebsd_)
static inline bool GoodPath(const TString& path) {
return path.find('/') != TString::npos;
@@ -101,9 +101,9 @@ static inline bool FreeBSDGuessExecBasePath(const TString& guessBasePath, TStrin
#endif
static TString GetExecPathImpl() {
-#if defined(_solaris_)
+#if defined(_solaris_)
return execname();
-#elif defined(_darwin_)
+#elif defined(_darwin_)
TTempBuf execNameBuf;
for (size_t i = 0; i < 2; ++i) {
std::remove_pointer_t<TFunctionArg<decltype(_NSGetExecutablePath), 1>> bufsize = execNameBuf.Size();
@@ -112,10 +112,10 @@ static TString GetExecPathImpl() {
return execNameBuf.Data();
} else if (r == -1) {
execNameBuf = TTempBuf(bufsize);
- }
+ }
}
ythrow yexception() << "GetExecPathImpl() failed";
-#elif defined(_win_)
+#elif defined(_win_)
TTempBuf execNameBuf;
for (;;) {
DWORD r = GetModuleFileName(nullptr, execNameBuf.Data(), execNameBuf.Size());
@@ -125,13 +125,13 @@ static TString GetExecPathImpl() {
ythrow yexception() << "GetExecPathImpl() failed: " << LastSystemErrorText();
} else {
return execNameBuf.Data();
- }
+ }
}
#elif defined(_linux_) || defined(_cygwin_)
TString path("/proc/self/exe");
return NFs::ReadLink(path);
// TODO(yoda): check if the filename ends with " (deleted)"
-#elif defined(_freebsd_)
+#elif defined(_freebsd_)
TString execPath = FreeBSDGetExecPath();
if (GoodPath(execPath)) {
return execPath;
@@ -150,9 +150,9 @@ static TString GetExecPathImpl() {
}
ythrow yexception() << "can not resolve exec path";
-#else
+#else
#error dont know how to implement GetExecPath on this platform
-#endif
+#endif
}
static bool GetPersistentExecPathImpl(TString& to) {
@@ -189,10 +189,10 @@ namespace {
TString PersistentExecPath;
};
}
-
+
const TString& GetExecPath() {
return TExecPathsHolder::Instance()->ExecPath;
-}
+}
const TString& GetPersistentExecPath() {
return TExecPathsHolder::Instance()->PersistentExecPath;
diff --git a/util/system/execpath.h b/util/system/execpath.h
index 4b914b8e85..7f1cd5a14b 100644
--- a/util/system/execpath.h
+++ b/util/system/execpath.h
@@ -1,7 +1,7 @@
#pragma once
-
+
#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/execpath_ut.cpp b/util/system/execpath_ut.cpp
index 16b01466f5..ebccec6791 100644
--- a/util/system/execpath_ut.cpp
+++ b/util/system/execpath_ut.cpp
@@ -3,8 +3,8 @@
#include <library/cpp/testing/unittest/registar.h>
#include "platform.h"
-#include <util/folder/dirut.h>
-
+#include <util/folder/dirut.h>
+
Y_UNIT_TEST_SUITE(TExecPathTest) {
Y_UNIT_TEST(TestIt) {
TString execPath = GetExecPath();
@@ -18,5 +18,5 @@ Y_UNIT_TEST_SUITE(TExecPathTest) {
throw;
}
- }
-}
+ }
+}
diff --git a/util/system/fasttime.cpp b/util/system/fasttime.cpp
index 057a814f0a..3a32bd4019 100644
--- a/util/system/fasttime.cpp
+++ b/util/system/fasttime.cpp
@@ -5,7 +5,7 @@
#include <util/generic/yexception.h>
#include <utility>
-#include <util/thread/singleton.h>
+#include <util/thread/singleton.h>
#if defined(_win_) || defined(_arm32_) || defined(_cygwin_)
ui64 InterpolatedMicroSeconds() {
@@ -236,7 +236,7 @@ namespace {
}
ui64 InterpolatedMicroSeconds() {
- return FastTlsSingleton<TTimePredictor>()->Get();
+ return FastTlsSingleton<TTimePredictor>()->Get();
}
#endif
diff --git a/util/system/file.cpp b/util/system/file.cpp
index 4a261d020c..5fd4ae8d2f 100644
--- a/util/system/file.cpp
+++ b/util/system/file.cpp
@@ -22,7 +22,7 @@
#include <util/generic/yexception.h>
#include <util/datetime/base.h>
-
+
#include <errno.h>
#if defined(_unix_)
@@ -140,7 +140,7 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept {
::SetFilePointer(Fd_, 0, 0, FILE_END);
}
-#elif defined(_unix_)
+#elif defined(_unix_)
switch (createMode) {
case OpenExisting:
@@ -262,7 +262,7 @@ TFileHandle::TFileHandle(const TString& fName, EOpenMode oMode) noexcept {
if (Fd_ >= 0 && (oMode & Transient)) {
unlink(fName.data());
}
-#else
+#else
#error unsupported platform
#endif
}
@@ -277,9 +277,9 @@ bool TFileHandle::Close() noexcept {
Y_VERIFY(GetLastError() != ERROR_INVALID_HANDLE,
"must not quietly close invalid handle");
}
-#elif defined(_unix_)
+#elif defined(_unix_)
if (Fd_ != INVALID_FHANDLE) {
- isOk = (::close(Fd_) == 0 || errno == EINTR);
+ isOk = (::close(Fd_) == 0 || errno == EINTR);
}
if (!isOk) {
// Do not quietly close bad descriptor,
@@ -307,7 +307,7 @@ static inline i64 DoSeek(FHANDLE h, i64 offset, SeekDir origin) noexcept {
pos.QuadPart = -1;
}
return pos.QuadPart;
-#elif defined(_unix_)
+#elif defined(_unix_)
static int dir[] = {SEEK_SET, SEEK_CUR, SEEK_END};
#if defined(_sun_)
return ::llseek(h, (offset_t)offset, dir[origin]);
@@ -328,9 +328,9 @@ i64 TFileHandle::Seek(i64 offset, SeekDir origin) noexcept {
}
i64 TFileHandle::GetLength() const noexcept {
- // XXX: returns error code, but does not set errno
+ // XXX: returns error code, but does not set errno
if (!IsOpen()) {
- return -1L;
+ return -1L;
}
return GetFileLength(Fd_);
}
@@ -424,7 +424,7 @@ bool TFileHandle::Flush() noexcept {
* The function returns FALSE, and GetLastError returns ERROR_INVALID_HANDLE.
*/
return ok || GetLastError() == ERROR_INVALID_HANDLE;
-#elif defined(_unix_)
+#elif defined(_unix_)
int ret = ::fsync(Fd_);
/*
@@ -469,13 +469,13 @@ i32 TFileHandle::Read(void* buffer, ui32 byteCount) noexcept {
return bytesRead;
}
return -1;
-#elif defined(_unix_)
+#elif defined(_unix_)
i32 ret;
do {
ret = ::read(Fd_, buffer, byteCount);
} while (ret == -1 && errno == EINTR);
return ret;
-#else
+#else
#error unsupported platform
#endif
}
@@ -490,13 +490,13 @@ i32 TFileHandle::Write(const void* buffer, ui32 byteCount) noexcept {
return bytesWritten;
}
return -1;
-#elif defined(_unix_)
+#elif defined(_unix_)
i32 ret;
do {
ret = ::write(Fd_, buffer, byteCount);
} while (ret == -1 && errno == EINTR);
return ret;
-#else
+#else
#error unsupported platform
#endif
}
@@ -515,13 +515,13 @@ i32 TFileHandle::Pread(void* buffer, ui32 byteCount, i64 offset) const noexcept
return 0;
}
return -1;
-#elif defined(_unix_)
+#elif defined(_unix_)
i32 ret;
do {
ret = ::pread(Fd_, buffer, byteCount, offset);
} while (ret == -1 && errno == EINTR);
return ret;
-#else
+#else
#error unsupported platform
#endif
}
@@ -537,13 +537,13 @@ i32 TFileHandle::Pwrite(const void* buffer, ui32 byteCount, i64 offset) const no
return bytesWritten;
}
return -1;
-#elif defined(_unix_)
+#elif defined(_unix_)
i32 ret;
do {
ret = ::pwrite(Fd_, buffer, byteCount, offset);
} while (ret == -1 && errno == EINTR);
return ret;
-#else
+#else
#error unsupported platform
#endif
}
@@ -558,9 +558,9 @@ FHANDLE TFileHandle::Duplicate() const noexcept {
return INVALID_FHANDLE;
}
return dupHandle;
-#elif defined(_unix_)
+#elif defined(_unix_)
return ::dup(Fd_);
-#else
+#else
#error unsupported platform
#endif
}
@@ -776,10 +776,10 @@ bool TFileHandle::FlushCache(i64 offset, i64 length, bool wait) noexcept {
}
TString DecodeOpenMode(ui32 mode0) {
- ui32 mode = mode0;
-
+ ui32 mode = mode0;
+
TStringBuilder r;
-
+
#define F(flag) \
if ((mode & flag) == flag) { \
mode &= ~flag; \
@@ -787,14 +787,14 @@ TString DecodeOpenMode(ui32 mode0) {
r << TStringBuf("|"); \
} \
r << TStringBuf(#flag); \
- }
-
- F(RdWr)
+ }
+
+ F(RdWr)
F(RdOnly)
F(WrOnly)
F(CreateAlways)
- F(CreateNew)
+ F(CreateNew)
F(OpenAlways)
F(TruncExisting)
F(ForAppend)
@@ -809,38 +809,38 @@ TString DecodeOpenMode(ui32 mode0) {
F(NoReuse)
F(NoReadAhead)
- F(AX)
- F(AR)
- F(AW)
- F(ARW)
-
- F(AXOther)
- F(AWOther)
- F(AROther)
- F(AXGroup)
- F(AWGroup)
- F(ARGroup)
- F(AXUser)
- F(AWUser)
- F(ARUser)
-
-#undef F
-
- if (mode != 0) {
+ F(AX)
+ F(AR)
+ F(AW)
+ F(ARW)
+
+ F(AXOther)
+ F(AWOther)
+ F(AROther)
+ F(AXGroup)
+ F(AWGroup)
+ F(ARGroup)
+ F(AXUser)
+ F(AWUser)
+ F(ARUser)
+
+#undef F
+
+ if (mode != 0) {
if (r) {
r << TStringBuf("|");
}
r << Hex(mode);
- }
-
+ }
+
if (!r) {
return "0";
}
-
- return r;
+
+ return r;
}
-
+
class TFile::TImpl: public TAtomicRefCount<TImpl> {
public:
inline TImpl(FHANDLE fd, const TString& fname = TString())
@@ -1277,7 +1277,7 @@ TFile Duplicate(int fd) {
return TFile(dupHandle);
#elif defined(_unix_)
- return TFile(::dup(fd));
+ return TFile(::dup(fd));
#else
#error unsupported platform
#endif
diff --git a/util/system/file.h b/util/system/file.h
index 9502e159b6..27f711aff6 100644
--- a/util/system/file.h
+++ b/util/system/file.h
@@ -53,7 +53,7 @@ Y_DECLARE_FLAGS(EOpenMode, EOpenModeFlag)
Y_DECLARE_OPERATORS_FOR_FLAGS(EOpenMode)
TString DecodeOpenMode(ui32 openMode);
-
+
enum SeekDir {
sSet = 0,
sCur = 1,
@@ -64,7 +64,7 @@ class TFileHandle: public TNonCopyable {
public:
constexpr TFileHandle() = default;
- /// Warning: takes ownership of fd, so closes it in destructor.
+ /// Warning: takes ownership of fd, so closes it in destructor.
inline TFileHandle(FHANDLE fd) noexcept
: Fd_(fd)
{
@@ -147,7 +147,7 @@ private:
class TFile {
public:
TFile();
- /// Takes ownership of handle, so closes it when the last holder of descriptor dies.
+ /// Takes ownership of handle, so closes it when the last holder of descriptor dies.
explicit TFile(FHANDLE fd);
TFile(FHANDLE fd, const TString& fname);
TFile(const TString& fName, EOpenMode oMode);
diff --git a/util/system/file_ut.cpp b/util/system/file_ut.cpp
index 941e6a50f3..bb97a6e5d4 100644
--- a/util/system/file_ut.cpp
+++ b/util/system/file_ut.cpp
@@ -408,9 +408,9 @@ UNIT_ASSERT_VALUES_EQUAL(file.CountCache(0, 12345), -1);
Y_UNIT_TEST_SUITE(TTestDecodeOpenMode) {
Y_UNIT_TEST(It) {
UNIT_ASSERT_VALUES_EQUAL("0", DecodeOpenMode(0));
- UNIT_ASSERT_VALUES_EQUAL("RdOnly", DecodeOpenMode(RdOnly));
- UNIT_ASSERT_VALUES_EQUAL("RdWr", DecodeOpenMode(RdWr));
- UNIT_ASSERT_VALUES_EQUAL("WrOnly|ForAppend", DecodeOpenMode(WrOnly | ForAppend));
+ UNIT_ASSERT_VALUES_EQUAL("RdOnly", DecodeOpenMode(RdOnly));
+ UNIT_ASSERT_VALUES_EQUAL("RdWr", DecodeOpenMode(RdWr));
+ UNIT_ASSERT_VALUES_EQUAL("WrOnly|ForAppend", DecodeOpenMode(WrOnly | ForAppend));
UNIT_ASSERT_VALUES_EQUAL("RdWr|CreateAlways|CreateNew|ForAppend|Transient|CloseOnExec|Temp|Sync|Direct|DirectAligned|Seq|NoReuse|NoReadAhead|AX|AR|AW|AWOther|0xF8888000", DecodeOpenMode(0xFFFFFFFF));
- }
-}
+ }
+}
diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp
index 7454a4cb94..992acdf724 100644
--- a/util/system/filemap.cpp
+++ b/util/system/filemap.cpp
@@ -2,7 +2,7 @@
#include "madvise.h"
#include "defaults.h"
#include "hi_lo.h"
-
+
#include <util/generic/buffer.h>
#include <util/generic/yexception.h>
#include <util/generic/singleton.h>
diff --git a/util/system/info.cpp b/util/system/info.cpp
index cf6681e89a..9175c664b3 100644
--- a/util/system/info.cpp
+++ b/util/system/info.cpp
@@ -12,7 +12,7 @@
#if defined(_win_)
#include "winint.h"
#include <stdio.h>
-#else
+#else
#include <unistd.h>
#endif
@@ -175,17 +175,17 @@ size_t NSystemInfo::CachedNumberOfCpus() {
return NCpus;
}
-
+
size_t NSystemInfo::GetPageSize() noexcept {
#if defined(_win_)
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
-
+
return sysInfo.dwPageSize;
#else
return sysconf(_SC_PAGESIZE);
#endif
-}
+}
size_t NSystemInfo::TotalMemorySize() {
#if defined(_linux_) && defined(_64_)
diff --git a/util/system/info_ut.cpp b/util/system/info_ut.cpp
index ad7449f8f4..6923c63005 100644
--- a/util/system/info_ut.cpp
+++ b/util/system/info_ut.cpp
@@ -7,7 +7,7 @@ class TSysInfoTest: public TTestBase {
UNIT_TEST(TestNumberOfCpus)
UNIT_TEST(TestGetPageSize)
UNIT_TEST_SUITE_END();
-
+
private:
inline void TestNumberOfCpus() {
UNIT_ASSERT(NSystemInfo::NumberOfCpus() > 0);
diff --git a/util/system/pipe.cpp b/util/system/pipe.cpp
index a543bd7472..f1d80a363b 100644
--- a/util/system/pipe.cpp
+++ b/util/system/pipe.cpp
@@ -2,36 +2,36 @@
#include <util/stream/output.h>
#include <util/generic/yexception.h>
-
+
ssize_t TPipeHandle::Read(void* buffer, size_t byteCount) const noexcept {
-#ifdef _win_
+#ifdef _win_
return recv(Fd_, (char*)buffer, byteCount, 0);
-#else
+#else
return read(Fd_, buffer, byteCount);
-#endif
-}
-
+#endif
+}
+
ssize_t TPipeHandle::Write(const void* buffer, size_t byteCount) const noexcept {
-#ifdef _win_
+#ifdef _win_
return send(Fd_, (const char*)buffer, byteCount, 0);
-#else
+#else
return write(Fd_, buffer, byteCount);
-#endif
-}
-
+#endif
+}
+
bool TPipeHandle::Close() noexcept {
- bool ok = true;
+ bool ok = true;
if (Fd_ != INVALID_PIPEHANDLE) {
-#ifdef _win_
+#ifdef _win_
ok = closesocket(Fd_) == 0;
-#else
+#else
ok = close(Fd_) == 0;
-#endif
- }
+#endif
+ }
Fd_ = INVALID_PIPEHANDLE;
- return ok;
-}
-
+ return ok;
+}
+
void TPipeHandle::Pipe(TPipeHandle& reader, TPipeHandle& writer, EOpenMode mode) {
PIPEHANDLE fds[2];
#ifdef _win_
@@ -66,90 +66,90 @@ void TPipeHandle::Pipe(TPipeHandle& reader, TPipeHandle& writer, EOpenMode mode)
}
class TPipe::TImpl: public TAtomicRefCount<TImpl> {
-public:
- TImpl()
+public:
+ TImpl()
: Handle_(INVALID_PIPEHANDLE)
- {
- }
+ {
+ }
- TImpl(PIPEHANDLE fd)
+ TImpl(PIPEHANDLE fd)
: Handle_(fd)
- {
- }
-
- inline ~TImpl() {
- Close();
- }
-
- bool IsOpen() {
+ {
+ }
+
+ inline ~TImpl() {
+ Close();
+ }
+
+ bool IsOpen() {
return Handle_.IsOpen();
- }
-
- inline void Close() {
+ }
+
+ inline void Close() {
if (!Handle_.IsOpen()) {
- return;
+ return;
}
if (!Handle_.Close()) {
ythrow TFileError() << "failed to close pipe";
}
- }
-
+ }
+
TPipeHandle& GetHandle() noexcept {
return Handle_;
- }
-
+ }
+
size_t Read(void* buffer, size_t count) const {
ssize_t r = Handle_.Read(buffer, count);
if (r < 0) {
ythrow TFileError() << "failed to read from pipe";
}
- return r;
- }
-
+ return r;
+ }
+
size_t Write(const void* buffer, size_t count) const {
ssize_t r = Handle_.Write(buffer, count);
if (r < 0) {
ythrow TFileError() << "failed to write to pipe";
}
- return r;
- }
+ return r;
+ }
-private:
+private:
TPipeHandle Handle_;
-};
-
-TPipe::TPipe()
+};
+
+TPipe::TPipe()
: Impl_(new TImpl)
-{
-}
-
-TPipe::TPipe(PIPEHANDLE fd)
+{
+}
+
+TPipe::TPipe(PIPEHANDLE fd)
: Impl_(new TImpl(fd))
-{
-}
-
+{
+}
+
TPipe::~TPipe() = default;
-
-void TPipe::Close() {
+
+void TPipe::Close() {
Impl_->Close();
-}
-
+}
+
PIPEHANDLE TPipe::GetHandle() const noexcept {
return Impl_->GetHandle();
-}
-
+}
+
bool TPipe::IsOpen() const noexcept {
return Impl_->IsOpen();
-}
-
+}
+
size_t TPipe::Read(void* buf, size_t len) const {
return Impl_->Read(buf, len);
-}
-
+}
+
size_t TPipe::Write(const void* buf, size_t len) const {
return Impl_->Write(buf, len);
-}
-
+}
+
void TPipe::Pipe(TPipe& reader, TPipe& writer, EOpenMode mode) {
TImplRef r(new TImpl());
TImplRef w(new TImpl());
@@ -158,4 +158,4 @@ void TPipe::Pipe(TPipe& reader, TPipe& writer, EOpenMode mode) {
r.Swap(reader.Impl_);
w.Swap(writer.Impl_);
-}
+}
diff --git a/util/system/pipe.h b/util/system/pipe.h
index 75d0360049..b8cd9bd2ac 100644
--- a/util/system/pipe.h
+++ b/util/system/pipe.h
@@ -4,19 +4,19 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds" //need because of bug in gcc4.9.2
#endif
-
+
#include "defaults.h"
#include "file.h"
-#include <util/generic/ptr.h>
+#include <util/generic/ptr.h>
#include <util/network/pair.h>
#include <util/generic/noncopyable.h>
-
+
using PIPEHANDLE = SOCKET;
#define INVALID_PIPEHANDLE INVALID_SOCKET
-/// Pipe-like object: pipe on POSIX and socket on windows
+/// Pipe-like object: pipe on POSIX and socket on windows
class TPipeHandle: public TNonCopyable {
-public:
+public:
inline TPipeHandle() noexcept
: Fd_(INVALID_PIPEHANDLE)
{
@@ -24,66 +24,66 @@ public:
inline TPipeHandle(PIPEHANDLE fd) noexcept
: Fd_(fd)
- {
- }
-
+ {
+ }
+
inline ~TPipeHandle() {
- Close();
- }
-
+ Close();
+ }
+
bool Close() noexcept;
-
+
inline PIPEHANDLE Release() noexcept {
PIPEHANDLE ret = Fd_;
Fd_ = INVALID_PIPEHANDLE;
- return ret;
- }
-
+ return ret;
+ }
+
inline void Swap(TPipeHandle& r) noexcept {
DoSwap(Fd_, r.Fd_);
- }
-
+ }
+
inline operator PIPEHANDLE() const noexcept {
return Fd_;
- }
-
+ }
+
inline bool IsOpen() const noexcept {
return Fd_ != INVALID_PIPEHANDLE;
- }
-
+ }
+
ssize_t Read(void* buffer, size_t byteCount) const noexcept;
ssize_t Write(const void* buffer, size_t byteCount) const noexcept;
-
+
// Only CloseOnExec is supported
static void Pipe(TPipeHandle& reader, TPipeHandle& writer, EOpenMode mode = 0);
-private:
+private:
PIPEHANDLE Fd_;
-};
-
-class TPipe {
-public:
- TPipe();
- /// Takes ownership of handle, so closes it when the last holder of descriptor dies.
- explicit TPipe(PIPEHANDLE fd);
+};
+
+class TPipe {
+public:
+ TPipe();
+ /// Takes ownership of handle, so closes it when the last holder of descriptor dies.
+ explicit TPipe(PIPEHANDLE fd);
~TPipe();
-
- void Close();
-
+
+ void Close();
+
bool IsOpen() const noexcept;
PIPEHANDLE GetHandle() const noexcept;
-
+
size_t Read(void* buf, size_t len) const;
size_t Write(const void* buf, size_t len) const;
-
+
// Only CloseOnExec is supported
static void Pipe(TPipe& reader, TPipe& writer, EOpenMode mode = 0);
-
-private:
- class TImpl;
+
+private:
+ class TImpl;
using TImplRef = TSimpleIntrusivePtr<TImpl>;
TImplRef Impl_;
-};
+};
#ifdef __GNUC__
#pragma GCC diagnostic pop
diff --git a/util/system/pipe_ut.cpp b/util/system/pipe_ut.cpp
index 6d53432de8..67cc0eb5f0 100644
--- a/util/system/pipe_ut.cpp
+++ b/util/system/pipe_ut.cpp
@@ -1,15 +1,15 @@
#include "pipe.h"
#include <library/cpp/testing/unittest/registar.h>
-
+
Y_UNIT_TEST_SUITE(TPipeTest) {
Y_UNIT_TEST(TestPipe) {
- TPipe r;
- TPipe w;
- TPipe::Pipe(r, w);
- char c = 'a';
- UNIT_ASSERT(1 == w.Write(&c, 1));
- UNIT_ASSERT(1 == r.Read(&c, 1));
- UNIT_ASSERT_VALUES_EQUAL('a', c);
- }
-}
+ TPipe r;
+ TPipe w;
+ TPipe::Pipe(r, w);
+ char c = 'a';
+ UNIT_ASSERT(1 == w.Write(&c, 1));
+ UNIT_ASSERT(1 == r.Read(&c, 1));
+ UNIT_ASSERT_VALUES_EQUAL('a', c);
+ }
+}
diff --git a/util/system/rusage.cpp b/util/system/rusage.cpp
index 2befeca875..918169ebdf 100644
--- a/util/system/rusage.cpp
+++ b/util/system/rusage.cpp
@@ -1,40 +1,40 @@
#include "platform.h"
-
+
#if defined(__APPLE__) && defined(__MACH__)
#include <mach/mach.h>
#endif
-#ifdef _win_
-
+#ifdef _win_
+
#include "winint.h"
#include <psapi.h>
-
-#else
-
+
+#else
+
#include <sys/time.h>
#include <sys/resource.h>
-
-#endif
-
-#include <util/generic/yexception.h>
-
-#include "info.h"
-
-#include "rusage.h"
-
-#ifdef _win_
-TDuration FiletimeToDuration(const FILETIME& ft) {
+
+#endif
+
+#include <util/generic/yexception.h>
+
+#include "info.h"
+
+#include "rusage.h"
+
+#ifdef _win_
+TDuration FiletimeToDuration(const FILETIME& ft) {
union {
ui64 ft_scalar;
FILETIME ft_struct;
} nt_time;
- nt_time.ft_struct = ft;
- return TDuration::MicroSeconds(nt_time.ft_scalar / 10);
-}
-#endif
-
+ nt_time.ft_struct = ft;
+ return TDuration::MicroSeconds(nt_time.ft_scalar / 10);
+}
+#endif
+
size_t TRusage::GetCurrentRSS() {
/*
* Author: David Robert Nadeau
@@ -74,40 +74,40 @@ size_t TRusage::GetCurrentRSS() {
#endif
}
-void TRusage::Fill() {
- *this = TRusage();
-
-#ifdef _win_
- // copy-paste from PostgreSQL getrusage.c
-
- FILETIME starttime;
- FILETIME exittime;
- FILETIME kerneltime;
- FILETIME usertime;
-
- if (GetProcessTimes(GetCurrentProcess(), &starttime, &exittime, &kerneltime, &usertime) == 0) {
- ythrow TSystemError() << "GetProcessTimes failed";
- }
-
- Utime = FiletimeToDuration(usertime);
- Stime = FiletimeToDuration(kerneltime);
-
- PROCESS_MEMORY_COUNTERS pmc;
-
- if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)) == 0) {
- ythrow TSystemError() << "GetProcessMemoryInfo failed";
- }
-
+void TRusage::Fill() {
+ *this = TRusage();
+
+#ifdef _win_
+ // copy-paste from PostgreSQL getrusage.c
+
+ FILETIME starttime;
+ FILETIME exittime;
+ FILETIME kerneltime;
+ FILETIME usertime;
+
+ if (GetProcessTimes(GetCurrentProcess(), &starttime, &exittime, &kerneltime, &usertime) == 0) {
+ ythrow TSystemError() << "GetProcessTimes failed";
+ }
+
+ Utime = FiletimeToDuration(usertime);
+ Stime = FiletimeToDuration(kerneltime);
+
+ PROCESS_MEMORY_COUNTERS pmc;
+
+ if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)) == 0) {
+ ythrow TSystemError() << "GetProcessMemoryInfo failed";
+ }
+
MaxRss = pmc.PeakWorkingSetSize;
MajorPageFaults = pmc.PageFaultCount;
-
-#else
- struct rusage ru;
- int r = getrusage(RUSAGE_SELF, &ru);
- if (r < 0) {
- ythrow TSystemError() << "rusage failed";
- }
-
+
+#else
+ struct rusage ru;
+ int r = getrusage(RUSAGE_SELF, &ru);
+ if (r < 0) {
+ ythrow TSystemError() << "rusage failed";
+ }
+
#if defined(_darwin_)
// see https://lists.apple.com/archives/darwin-kernel/2009/Mar/msg00005.html
MaxRss = ru.ru_maxrss;
@@ -115,7 +115,7 @@ void TRusage::Fill() {
MaxRss = ru.ru_maxrss * 1024LL;
#endif
MajorPageFaults = ru.ru_majflt;
- Utime = ru.ru_utime;
- Stime = ru.ru_stime;
-#endif
-}
+ Utime = ru.ru_utime;
+ Stime = ru.ru_stime;
+#endif
+}
diff --git a/util/system/rusage.h b/util/system/rusage.h
index 61aeca83f2..3964df1116 100644
--- a/util/system/rusage.h
+++ b/util/system/rusage.h
@@ -1,26 +1,26 @@
#pragma once
-
+
#include "defaults.h"
-#include <util/generic/utility.h>
-#include <util/datetime/base.h>
-
-/// portable getrusage
-
-struct TRusage {
- // some fields may be zero if unsupported
-
+#include <util/generic/utility.h>
+#include <util/datetime/base.h>
+
+/// portable getrusage
+
+struct TRusage {
+ // some fields may be zero if unsupported
+
ui64 MaxRss = 0;
ui64 MajorPageFaults = 0;
- TDuration Utime;
- TDuration Stime;
-
- void Fill();
+ TDuration Utime;
+ TDuration Stime;
+
+ void Fill();
static size_t GetCurrentRSS();
- static TRusage Get() {
- TRusage r;
- r.Fill();
- return r;
- }
-};
+ static TRusage Get() {
+ TRusage r;
+ r.Fill();
+ return r;
+ }
+};
diff --git a/util/system/rusage_ut.cpp b/util/system/rusage_ut.cpp
index 0d4e0fe54b..a5c6a80e62 100644
--- a/util/system/rusage_ut.cpp
+++ b/util/system/rusage_ut.cpp
@@ -1,11 +1,11 @@
#include "rusage.h"
#include <library/cpp/testing/unittest/registar.h>
-
+
Y_UNIT_TEST_SUITE(TRusageTest) {
Y_UNIT_TEST(TestRusage) {
- TRusage r;
- // just check it returns something
- r.Fill();
- }
-}
+ TRusage r;
+ // just check it returns something
+ r.Fill();
+ }
+}
diff --git a/util/system/spin_wait.h b/util/system/spin_wait.h
index 91dd423e33..e52f413e6d 100644
--- a/util/system/spin_wait.h
+++ b/util/system/spin_wait.h
@@ -4,7 +4,7 @@ struct TSpinWait {
TSpinWait() noexcept;
void Sleep() noexcept;
-
+
unsigned T;
unsigned C;
-};
+};
diff --git a/util/system/spinlock.h b/util/system/spinlock.h
index af2630890a..9d1480130b 100644
--- a/util/system/spinlock.h
+++ b/util/system/spinlock.h
@@ -3,29 +3,29 @@
#include "atomic.h"
#include "spin_wait.h"
-class TSpinLockBase {
+class TSpinLockBase {
protected:
inline TSpinLockBase() noexcept {
AtomicSet(Val_, 0);
}
-
+
public:
inline bool IsLocked() const noexcept {
return AtomicGet(Val_);
}
-
+
inline bool TryAcquire() noexcept {
return AtomicTryLock(&Val_);
}
-
+
inline bool try_lock() noexcept {
return TryAcquire();
}
protected:
TAtomic Val_;
-};
-
+};
+
static inline void SpinLockPause() {
#if defined(__GNUC__)
#if defined(_i386_) || defined(_x86_64_)
diff --git a/util/system/spinlock_ut.cpp b/util/system/spinlock_ut.cpp
index e8639a6404..f2793fd95f 100644
--- a/util/system/spinlock_ut.cpp
+++ b/util/system/spinlock_ut.cpp
@@ -1,23 +1,23 @@
#include <library/cpp/testing/unittest/registar.h>
-
-#include "spinlock.h"
-
+
+#include "spinlock.h"
+
Y_UNIT_TEST_SUITE(TSpinLock) {
- template <typename TLock>
- void TestLock() {
- TLock lock;
- UNIT_ASSERT(!lock.IsLocked());
- lock.Acquire();
- UNIT_ASSERT(lock.IsLocked());
- lock.Release();
- UNIT_ASSERT(!lock.IsLocked());
-
- UNIT_ASSERT(lock.TryAcquire());
- UNIT_ASSERT(lock.IsLocked());
- UNIT_ASSERT(!lock.TryAcquire());
- UNIT_ASSERT(lock.IsLocked());
- lock.Release();
- UNIT_ASSERT(!lock.IsLocked());
+ template <typename TLock>
+ void TestLock() {
+ TLock lock;
+ UNIT_ASSERT(!lock.IsLocked());
+ lock.Acquire();
+ UNIT_ASSERT(lock.IsLocked());
+ lock.Release();
+ UNIT_ASSERT(!lock.IsLocked());
+
+ UNIT_ASSERT(lock.TryAcquire());
+ UNIT_ASSERT(lock.IsLocked());
+ UNIT_ASSERT(!lock.TryAcquire());
+ UNIT_ASSERT(lock.IsLocked());
+ lock.Release();
+ UNIT_ASSERT(!lock.IsLocked());
// Lockable requirements
lock.lock();
@@ -25,13 +25,13 @@ Y_UNIT_TEST_SUITE(TSpinLock) {
UNIT_ASSERT(!lock.try_lock());
lock.unlock();
UNIT_ASSERT(!lock.IsLocked());
- }
-
+ }
+
Y_UNIT_TEST(TSpinLock_IsLocked) {
- TestLock<TSpinLock>();
- }
-
+ TestLock<TSpinLock>();
+ }
+
Y_UNIT_TEST(TAdaptiveLock_IsLocked) {
- TestLock<TAdaptiveLock>();
- }
-}
+ TestLock<TAdaptiveLock>();
+ }
+}
diff --git a/util/system/thread.cpp b/util/system/thread.cpp
index 6236746c2d..0aad030bcf 100644
--- a/util/system/thread.cpp
+++ b/util/system/thread.cpp
@@ -5,7 +5,7 @@
#include <util/generic/ptr.h>
#include <util/generic/ymath.h>
#include <util/generic/ylimits.h>
-#include <util/generic/yexception.h>
+#include <util/generic/yexception.h>
#include "yassert.h"
#include <utility>
@@ -289,7 +289,7 @@ TThread::~TThread() {
Join();
}
-void TThread::Start() {
+void TThread::Start() {
Impl(Impl_, "start", false)->Start();
}
diff --git a/util/system/thread.h b/util/system/thread.h
index a6e8abdb5b..541ecccbef 100644
--- a/util/system/thread.h
+++ b/util/system/thread.h
@@ -1,9 +1,9 @@
#pragma once
-/// This code should not be used directly unless you really understand what you do.
+/// 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()
-
+
#include <util/generic/ptr.h>
#include <util/generic/string.h>
diff --git a/util/system/type_name.cpp b/util/system/type_name.cpp
index 0377da4212..411b98774c 100644
--- a/util/system/type_name.cpp
+++ b/util/system/type_name.cpp
@@ -1,13 +1,13 @@
#include "platform.h"
#include "demangle_impl.h"
-
+
#ifdef __GNUC__
#include <stdexcept>
#include <cxxabi.h>
-#endif
-
+#endif
+
#include "type_name.h"
-
+
namespace {
#if defined(_LIBCPP_VERSION)
@@ -26,18 +26,18 @@ namespace {
const char* NPrivate::TCppDemangler::Demangle(const char* name) {
#ifndef __GNUC__
- return name;
-#else
- int status;
+ return name;
+#else
+ int status;
TmpBuf_.Reset(__cxxabiv1::__cxa_demangle(name, nullptr, nullptr, &status));
if (!TmpBuf_) {
- return name;
+ return name;
}
return TmpBuf_.Get();
-#endif
-}
+#endif
+}
TString CppDemangle(const TString& name) {
return NPrivate::TCppDemangler().Demangle(name.data());
diff --git a/util/system/type_name.h b/util/system/type_name.h
index b6619aba3f..6561519bc1 100644
--- a/util/system/type_name.h
+++ b/util/system/type_name.h
@@ -1,8 +1,8 @@
#pragma once
-
+
#include <util/generic/string.h>
#include <util/string/subst.h>
-
+
#include <typeindex>
#include <typeinfo>
diff --git a/util/system/type_name_ut.cpp b/util/system/type_name_ut.cpp
index 86597f4232..7af6838814 100644
--- a/util/system/type_name_ut.cpp
+++ b/util/system/type_name_ut.cpp
@@ -1,7 +1,7 @@
#include "type_name.h"
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <util/generic/yexception.h>
#include <util/generic/fwd.h>
@@ -10,12 +10,12 @@
Y_UNIT_TEST_SUITE(TDemangleTest) {
Y_UNIT_TEST(SimpleTest) {
- // just check it does not crash or leak
- CppDemangle("hello");
- CppDemangle("");
- CppDemangle("Sfsdf$dfsdfTTSFSDF23234::SDFS:FSDFSDF#$%");
- }
-}
+ // just check it does not crash or leak
+ CppDemangle("hello");
+ CppDemangle("");
+ CppDemangle("Sfsdf$dfsdfTTSFSDF23234::SDFS:FSDFSDF#$%");
+ }
+}
namespace NUtil::NTypeNameTest {
diff --git a/util/system/yassert.cpp b/util/system/yassert.cpp
index 0f586648b7..d356f11300 100644
--- a/util/system/yassert.cpp
+++ b/util/system/yassert.cpp
@@ -12,7 +12,7 @@
#include <util/stream/output.h>
#include <util/stream/str.h>
#include <util/string/printf.h>
-
+
#include <cstdlib>
#include <stdarg.h>
#include <stdio.h>
@@ -37,20 +37,20 @@ namespace {
namespace NPrivate {
[[noreturn]] Y_NO_INLINE void InternalPanicImpl(int line, const char* function, const char* expr, int, int, int, const TStringBuf file, const char* errorMessage, size_t errorMessageSize) noexcept;
}
-
+
void ::NPrivate::Panic(const TStaticBuf& file, int line, const char* function, const char* expr, const char* format, ...) noexcept {
try {
// We care of panic of first failed thread only
// Otherwise stderr could contain multiple messages and stack traces shuffled
auto guard = Guard(*Singleton<TPanicLockHolder>());
-
+
TString errorMsg;
va_list args;
va_start(args, format);
- // format has " " prefix to mute GCC warning on empty format
- vsprintf(errorMsg, format[0] == ' ' ? format + 1 : format, args);
+ // format has " " prefix to mute GCC warning on empty format
+ vsprintf(errorMsg, format[0] == ' ' ? format + 1 : format, args);
va_end(args);
-
+
constexpr int abiPlaceholder = 0;
::NPrivate::InternalPanicImpl(line, function, expr, abiPlaceholder, abiPlaceholder, abiPlaceholder, file.As<TStringBuf>(), errorMsg.c_str(), errorMsg.size());
} catch (...) {
@@ -69,19 +69,19 @@ namespace NPrivate {
TStringOutput o(r);
if (expr) {
o << "VERIFY failed (" << now << "): " << errorMsg << Endl;
- } else {
+ } else {
o << "FAIL (" << now << "): " << errorMsg << Endl;
- }
+ }
o << " " << file << ":" << line << Endl;
if (expr) {
- o << " " << function << "(): requirement " << expr << " failed" << Endl;
- } else {
- o << " " << function << "() failed" << Endl;
- }
+ o << " " << function << "(): requirement " << expr << " failed" << Endl;
+ } else {
+ o << " " << function << "() failed" << Endl;
+ }
Cerr << r << Flush;
-#ifndef WITH_VALGRIND
+#ifndef WITH_VALGRIND
PrintBackTrace();
-#endif
+#endif
#ifdef CLANG_COVERAGE
if (__llvm_profile_write_file()) {
Cerr << "Failed to dump clang coverage" << Endl;
@@ -91,4 +91,4 @@ namespace NPrivate {
} catch (...) {
abort();
}
-}
+}
diff --git a/util/system/yassert.h b/util/system/yassert.h
index 529823440c..a94b47d3f4 100644
--- a/util/system/yassert.h
+++ b/util/system/yassert.h
@@ -3,7 +3,7 @@
#include "defaults.h"
#include "src_root.h"
#include "backtrace.h"
-
+
#if defined(_MSC_VER)
#include <new>
#if defined(_DEBUG)
@@ -89,12 +89,12 @@ inline void YaDebugBreak() {
} while (false)
#endif
-namespace NPrivate {
- /// method should not be used directly
+namespace NPrivate {
+ /// method should not be used directly
[[noreturn]] void Panic(const TStaticBuf& file, int line, const char* function, const char* expr, const char* format, ...) noexcept Y_PRINTF_FORMAT(5, 6);
-}
-
-/// Assert that does not depend on NDEBUG macro and outputs message like printf
+}
+
+/// Assert that does not depend on NDEBUG macro and outputs message like printf
#define Y_VERIFY(expr, ...) \
do { \
if (Y_UNLIKELY(!(expr))) { \
@@ -106,7 +106,7 @@ namespace NPrivate {
do { \
::NPrivate::Panic(__SOURCE_FILE_IMPL__, __LINE__, __FUNCTION__, nullptr, " " __VA_ARGS__); \
} while (false)
-
+
#ifndef NDEBUG
/// Assert that depend on NDEBUG macro and outputs message like printf
#define Y_VERIFY_DEBUG(expr, ...) \
diff --git a/util/system/yassert_ut.cpp b/util/system/yassert_ut.cpp
index ddd392666c..c3f8cce999 100644
--- a/util/system/yassert_ut.cpp
+++ b/util/system/yassert_ut.cpp
@@ -1,9 +1,9 @@
-#undef NDEBUG
-// yassert.h must be included before all headers
-#include "yassert.h"
-
+#undef NDEBUG
+// yassert.h must be included before all headers
+#include "yassert.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
+
Y_UNIT_TEST_SUITE(YassertTest) {
Y_UNIT_TEST(TestAcsLikeFunctionCall) {
if (true) {
@@ -11,25 +11,25 @@ Y_UNIT_TEST_SUITE(YassertTest) {
} else {
Y_ASSERT(false);
}
-
- bool var = false;
+
+ bool var = false;
if (false) {
Y_ASSERT(false);
} else {
var = true; // this is unreachable if Y_ASSERT is "if (!cond) { ... }"
}
- UNIT_ASSERT(var);
- }
-
+ UNIT_ASSERT(var);
+ }
+
Y_UNIT_TEST(TestFailCompiles) {
- if (false) {
+ if (false) {
Y_FAIL("%d is a lucky number", 7);
Y_FAIL();
- }
- }
-
+ }
+ }
+
Y_UNIT_TEST(TestVerify) {
Y_VERIFY(true, "hi %s", "there");
Y_VERIFY(true);
- }
-}
+ }
+}