diff options
author | yazevnul <yazevnul@yandex-team.ru> | 2022-02-10 16:46:46 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:46 +0300 |
commit | 8cbc307de0221f84c80c42dcbe07d40727537e2c (patch) | |
tree | 625d5a673015d1df891e051033e9fcde5c7be4e5 /util/system | |
parent | 30d1ef3941e0dc835be7609de5ebee66958f215a (diff) | |
download | ydb-8cbc307de0221f84c80c42dcbe07d40727537e2c.tar.gz |
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/system')
101 files changed, 1437 insertions, 1437 deletions
diff --git a/util/system/atexit.cpp b/util/system/atexit.cpp index 74fb10b6b1..2ff9284f76 100644 --- a/util/system/atexit.cpp +++ b/util/system/atexit.cpp @@ -42,7 +42,7 @@ namespace { while (Items_) { auto c = Items_.top(); - Y_ASSERT(c); + Y_ASSERT(c); Items_.pop(); diff --git a/util/system/atomic_ops.h b/util/system/atomic_ops.h index 76766b4a0a..ec2e0959e2 100644 --- a/util/system/atomic_ops.h +++ b/util/system/atomic_ops.h @@ -22,7 +22,7 @@ struct TAtomicTraits { }; template <typename T, typename TT> -using TEnableIfCastable = std::enable_if_t<TAtomicTraits<T>::Castable, TT>; +using TEnableIfCastable = std::enable_if_t<TAtomicTraits<T>::Castable, TT>; template <typename T> inline TEnableIfCastable<T, T> AtomicGet(T const volatile& target) { diff --git a/util/system/backtrace.cpp b/util/system/backtrace.cpp index b77fe58fb1..b749957886 100644 --- a/util/system/backtrace.cpp +++ b/util/system/backtrace.cpp @@ -3,7 +3,7 @@ #include "platform.h" #include "backtrace.h" -#include <util/stream/output.h> +#include <util/stream/output.h> #include <util/stream/format.h> #include <util/generic/array_ref.h> #include <util/generic/string.h> @@ -233,13 +233,13 @@ TResolvedSymbol ResolveSymbol(void* sym, char*, size_t) { } #endif -void FormatBackTrace(IOutputStream* out, void* const* backtrace, size_t backtraceSize) { +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)); - *out << rs.Name << "+" << ((ptrdiff_t)backtrace[i] - (ptrdiff_t)rs.NearestSymbol) << " (" << Hex((ptrdiff_t)backtrace[i], HF_ADDX) << ')' << '\n'; + *out << rs.Name << "+" << ((ptrdiff_t)backtrace[i] - (ptrdiff_t)rs.NearestSymbol) << " (" << Hex((ptrdiff_t)backtrace[i], HF_ADDX) << ')' << '\n'; } } @@ -274,7 +274,7 @@ void TBackTrace::Capture() { Size = BackTrace(Data, CAPACITY); } -void TBackTrace::PrintTo(IOutputStream& out) const { +void TBackTrace::PrintTo(IOutputStream& out) const { FormatBackTraceFn(&out, Data, Size); } diff --git a/util/system/backtrace.h b/util/system/backtrace.h index 2fce7585c3..d19502953d 100644 --- a/util/system/backtrace.h +++ b/util/system/backtrace.h @@ -3,7 +3,7 @@ #include <util/generic/fwd.h> #include <util/system/defaults.h> -class IOutputStream; +class IOutputStream; size_t BackTrace(void** p, size_t len); @@ -14,8 +14,8 @@ struct TResolvedSymbol { TResolvedSymbol ResolveSymbol(void* sym, char* buf, size_t len); -void FormatBackTrace(IOutputStream* out, void* const* backtrace, size_t backtraceSize); -void FormatBackTrace(IOutputStream* out); +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); @@ -34,7 +34,7 @@ private: public: TBackTrace(); void Capture(); - void PrintTo(IOutputStream&) const; + void PrintTo(IOutputStream&) const; TString PrintToString() const; size_t size() const; const void* const* data() const; diff --git a/util/system/backtrace_ut.cpp b/util/system/backtrace_ut.cpp index 9b5ead71bc..a141308345 100644 --- a/util/system/backtrace_ut.cpp +++ b/util/system/backtrace_ut.cpp @@ -3,7 +3,7 @@ #include <util/generic/array_ref.h> #include <library/cpp/testing/unittest/registar.h> -#include <util/stream/output.h> +#include <util/stream/output.h> using PFunc = int (*)(void**, size_t); diff --git a/util/system/benchmark/cpu_id/main.cpp b/util/system/benchmark/cpu_id/main.cpp index 8efe539983..11f29deda8 100644 --- a/util/system/benchmark/cpu_id/main.cpp +++ b/util/system/benchmark/cpu_id/main.cpp @@ -1,51 +1,51 @@ #include <library/cpp/testing/benchmark/bench.h> - -#include <util/system/cpu_id.h> - -#include <util/generic/xrange.h> - -#define DEFINE_BENCHMARK_PAIR(name) \ - Y_CPU_BENCHMARK(Have##name, iface) { \ - for (const auto i : xrange(iface.Iterations())) { \ - Y_UNUSED(i); \ - Y_DO_NOT_OPTIMIZE_AWAY(NX86::Have##name()); \ - } \ - } \ - \ - Y_CPU_BENCHMARK(CachedHave##name, iface) { \ - for (const auto i : xrange(iface.Iterations())) { \ - Y_UNUSED(i); \ - Y_DO_NOT_OPTIMIZE_AWAY(NX86::CachedHave##name()); \ - } \ - } - -DEFINE_BENCHMARK_PAIR(SSE) -DEFINE_BENCHMARK_PAIR(SSE2) -DEFINE_BENCHMARK_PAIR(SSE3) -DEFINE_BENCHMARK_PAIR(SSSE3) -DEFINE_BENCHMARK_PAIR(SSE41) -DEFINE_BENCHMARK_PAIR(SSE42) -DEFINE_BENCHMARK_PAIR(POPCNT) -DEFINE_BENCHMARK_PAIR(BMI1) -DEFINE_BENCHMARK_PAIR(AES) -DEFINE_BENCHMARK_PAIR(AVX) -DEFINE_BENCHMARK_PAIR(AVX2) -DEFINE_BENCHMARK_PAIR(AVX512F) -DEFINE_BENCHMARK_PAIR(AVX512DQ) -DEFINE_BENCHMARK_PAIR(AVX512IFMA) -DEFINE_BENCHMARK_PAIR(AVX512PF) -DEFINE_BENCHMARK_PAIR(AVX512ER) -DEFINE_BENCHMARK_PAIR(AVX512CD) -DEFINE_BENCHMARK_PAIR(AVX512BW) -DEFINE_BENCHMARK_PAIR(AVX512VL) -DEFINE_BENCHMARK_PAIR(AVX512VBMI) -DEFINE_BENCHMARK_PAIR(PREFETCHWT1) -DEFINE_BENCHMARK_PAIR(SHA) -DEFINE_BENCHMARK_PAIR(ADX) -DEFINE_BENCHMARK_PAIR(RDRAND) -DEFINE_BENCHMARK_PAIR(RDSEED) -DEFINE_BENCHMARK_PAIR(PCOMMIT) -DEFINE_BENCHMARK_PAIR(CLFLUSHOPT) -DEFINE_BENCHMARK_PAIR(CLWB) - -#undef DEFINE_BENCHMARK_PAIR + +#include <util/system/cpu_id.h> + +#include <util/generic/xrange.h> + +#define DEFINE_BENCHMARK_PAIR(name) \ + Y_CPU_BENCHMARK(Have##name, iface) { \ + for (const auto i : xrange(iface.Iterations())) { \ + Y_UNUSED(i); \ + Y_DO_NOT_OPTIMIZE_AWAY(NX86::Have##name()); \ + } \ + } \ + \ + Y_CPU_BENCHMARK(CachedHave##name, iface) { \ + for (const auto i : xrange(iface.Iterations())) { \ + Y_UNUSED(i); \ + Y_DO_NOT_OPTIMIZE_AWAY(NX86::CachedHave##name()); \ + } \ + } + +DEFINE_BENCHMARK_PAIR(SSE) +DEFINE_BENCHMARK_PAIR(SSE2) +DEFINE_BENCHMARK_PAIR(SSE3) +DEFINE_BENCHMARK_PAIR(SSSE3) +DEFINE_BENCHMARK_PAIR(SSE41) +DEFINE_BENCHMARK_PAIR(SSE42) +DEFINE_BENCHMARK_PAIR(POPCNT) +DEFINE_BENCHMARK_PAIR(BMI1) +DEFINE_BENCHMARK_PAIR(AES) +DEFINE_BENCHMARK_PAIR(AVX) +DEFINE_BENCHMARK_PAIR(AVX2) +DEFINE_BENCHMARK_PAIR(AVX512F) +DEFINE_BENCHMARK_PAIR(AVX512DQ) +DEFINE_BENCHMARK_PAIR(AVX512IFMA) +DEFINE_BENCHMARK_PAIR(AVX512PF) +DEFINE_BENCHMARK_PAIR(AVX512ER) +DEFINE_BENCHMARK_PAIR(AVX512CD) +DEFINE_BENCHMARK_PAIR(AVX512BW) +DEFINE_BENCHMARK_PAIR(AVX512VL) +DEFINE_BENCHMARK_PAIR(AVX512VBMI) +DEFINE_BENCHMARK_PAIR(PREFETCHWT1) +DEFINE_BENCHMARK_PAIR(SHA) +DEFINE_BENCHMARK_PAIR(ADX) +DEFINE_BENCHMARK_PAIR(RDRAND) +DEFINE_BENCHMARK_PAIR(RDSEED) +DEFINE_BENCHMARK_PAIR(PCOMMIT) +DEFINE_BENCHMARK_PAIR(CLFLUSHOPT) +DEFINE_BENCHMARK_PAIR(CLWB) + +#undef DEFINE_BENCHMARK_PAIR diff --git a/util/system/benchmark/cpu_id/metrics/main.py b/util/system/benchmark/cpu_id/metrics/main.py index d9a86e825c..80ce8193b3 100644 --- a/util/system/benchmark/cpu_id/metrics/main.py +++ b/util/system/benchmark/cpu_id/metrics/main.py @@ -1,5 +1,5 @@ -import yatest.common as yc - - -def test_export_metrics(metrics): +import yatest.common as yc + + +def test_export_metrics(metrics): metrics.set_benchmark(yc.execute_benchmark('util/system/benchmark/cpu_id/cpu_id', threads=8)) diff --git a/util/system/benchmark/cpu_id/metrics/ya.make b/util/system/benchmark/cpu_id/metrics/ya.make index 8c55def99b..46f950de28 100644 --- a/util/system/benchmark/cpu_id/metrics/ya.make +++ b/util/system/benchmark/cpu_id/metrics/ya.make @@ -1,21 +1,21 @@ -OWNER( - yazevnul +OWNER( + yazevnul g:util -) +) SUBSCRIBER(g:util-subscribers) - + PY2TEST() - + SIZE(LARGE) - -TAG( + +TAG( ya:force_sandbox - sb:intel_e5_2660v1 + sb:intel_e5_2660v1 ya:fat -) - +) + TEST_SRCS(main.py) - + DEPENDS(util/system/benchmark/cpu_id) - -END() + +END() diff --git a/util/system/benchmark/cpu_id/ya.make b/util/system/benchmark/cpu_id/ya.make index 976977014f..a475d0c67f 100644 --- a/util/system/benchmark/cpu_id/ya.make +++ b/util/system/benchmark/cpu_id/ya.make @@ -1,13 +1,13 @@ -OWNER( - yazevnul +OWNER( + yazevnul g:util -) +) SUBSCRIBER(g:util-subscribers) - + Y_BENCHMARK() - -SRCS( - main.cpp -) - -END() + +SRCS( + main.cpp +) + +END() diff --git a/util/system/benchmark/create_destroy_thread/main.cpp b/util/system/benchmark/create_destroy_thread/main.cpp index 0ca2a9d96f..8f9f5c9850 100644 --- a/util/system/benchmark/create_destroy_thread/main.cpp +++ b/util/system/benchmark/create_destroy_thread/main.cpp @@ -1,26 +1,26 @@ #include <library/cpp/testing/benchmark/bench.h> - -#include <util/system/thread.h> - -static void* DoNothing(void*) noexcept { - return nullptr; -} - -Y_CPU_BENCHMARK(CreateDestroyThread, iface) { - for (size_t i = 0, iEnd = iface.Iterations(); i < iEnd; ++i) { - NBench::Clobber(); - TThread t(&DoNothing, nullptr); - Y_DO_NOT_OPTIMIZE_AWAY(t); - NBench::Clobber(); - } -} - -Y_CPU_BENCHMARK(CreateRunDestroyThread, iface) { - for (size_t i = 0, iEnd = iface.Iterations(); i < iEnd; ++i) { - NBench::Clobber(); - TThread t(&DoNothing, nullptr); - t.Start(); - NBench::Escape(t.Join()); - NBench::Clobber(); - } -} + +#include <util/system/thread.h> + +static void* DoNothing(void*) noexcept { + return nullptr; +} + +Y_CPU_BENCHMARK(CreateDestroyThread, iface) { + for (size_t i = 0, iEnd = iface.Iterations(); i < iEnd; ++i) { + NBench::Clobber(); + TThread t(&DoNothing, nullptr); + Y_DO_NOT_OPTIMIZE_AWAY(t); + NBench::Clobber(); + } +} + +Y_CPU_BENCHMARK(CreateRunDestroyThread, iface) { + for (size_t i = 0, iEnd = iface.Iterations(); i < iEnd; ++i) { + NBench::Clobber(); + TThread t(&DoNothing, nullptr); + t.Start(); + NBench::Escape(t.Join()); + NBench::Clobber(); + } +} diff --git a/util/system/benchmark/create_destroy_thread/metrics/main.py b/util/system/benchmark/create_destroy_thread/metrics/main.py index 45564cda7f..3ee8f8a2ea 100644 --- a/util/system/benchmark/create_destroy_thread/metrics/main.py +++ b/util/system/benchmark/create_destroy_thread/metrics/main.py @@ -1,7 +1,7 @@ -import yatest.common as yc - - -def test_export_metrics(metrics): +import yatest.common as yc + + +def test_export_metrics(metrics): metrics.set_benchmark( yc.execute_benchmark('util/system/benchmark/create_destroy_thread/create_destroy_thread', threads=8) ) diff --git a/util/system/benchmark/create_destroy_thread/metrics/ya.make b/util/system/benchmark/create_destroy_thread/metrics/ya.make index d526487e1a..9498e47812 100644 --- a/util/system/benchmark/create_destroy_thread/metrics/ya.make +++ b/util/system/benchmark/create_destroy_thread/metrics/ya.make @@ -1,21 +1,21 @@ -OWNER( - yazevnul +OWNER( + yazevnul g:util -) +) SUBSCRIBER(g:util-subscribers) - + PY2TEST() - + SIZE(LARGE) - -TAG( + +TAG( ya:force_sandbox - sb:intel_e5_2660v1 + sb:intel_e5_2660v1 ya:fat -) - +) + TEST_SRCS(main.py) - + DEPENDS(util/system/benchmark/create_destroy_thread) - -END() + +END() diff --git a/util/system/benchmark/create_destroy_thread/ya.make b/util/system/benchmark/create_destroy_thread/ya.make index 03eb0ec8e0..c50840aaad 100644 --- a/util/system/benchmark/create_destroy_thread/ya.make +++ b/util/system/benchmark/create_destroy_thread/ya.make @@ -1,9 +1,9 @@ OWNER(yazevnul) - + Y_BENCHMARK() - -SRCS( - main.cpp -) - -END() + +SRCS( + main.cpp +) + +END() diff --git a/util/system/benchmark/ya.make b/util/system/benchmark/ya.make index 12fa9af9d6..262bc5b090 100644 --- a/util/system/benchmark/ya.make +++ b/util/system/benchmark/ya.make @@ -1,15 +1,15 @@ -OWNER( - yazevnul +OWNER( + yazevnul g:util -) +) SUBSCRIBER(g:util-subscribers) - -RECURSE( - cpu_id - cpu_id/metrics - create_destroy_thread - create_destroy_thread/metrics -) + +RECURSE( + cpu_id + cpu_id/metrics + create_destroy_thread + create_destroy_thread/metrics +) IF (NOT OS_WINDOWS) RECURSE( diff --git a/util/system/compat_ut.cpp b/util/system/compat_ut.cpp index dbd9289c17..ead2e58865 100644 --- a/util/system/compat_ut.cpp +++ b/util/system/compat_ut.cpp @@ -5,8 +5,8 @@ #include <util/folder/dirut.h> #include <util/stream/output.h> -Y_UNIT_TEST_SUITE(TCompatTest) { - Y_UNIT_TEST(TestGetprogname) { +Y_UNIT_TEST_SUITE(TCompatTest) { + Y_UNIT_TEST(TestGetprogname) { getprogname(); // just check it links } } diff --git a/util/system/compiler.h b/util/system/compiler.h index b373edcc46..8b8373f584 100644 --- a/util/system/compiler.h +++ b/util/system/compiler.h @@ -6,36 +6,36 @@ // useful cross-platfrom definitions for compilers -/** - * @def Y_FUNC_SIGNATURE - * - * Use this macro to get pretty function name (see example). - * - * @code - * void Hi() { - * Cout << Y_FUNC_SIGNATURE << Endl; - * } - - * template <typename T> - * void Do() { - * Cout << Y_FUNC_SIGNATURE << Endl; - * } - - * int main() { - * Hi(); // void Hi() - * Do<int>(); // void Do() [T = int] +/** + * @def Y_FUNC_SIGNATURE + * + * Use this macro to get pretty function name (see example). + * + * @code + * void Hi() { + * Cout << Y_FUNC_SIGNATURE << Endl; + * } + + * template <typename T> + * void Do() { + * Cout << Y_FUNC_SIGNATURE << Endl; + * } + + * int main() { + * Hi(); // void Hi() + * Do<int>(); // void Do() [T = int] * Do<TString>(); // void Do() [T = TString] - * } - * @endcode - */ -#if defined(__GNUC__) + * } + * @endcode + */ +#if defined(__GNUC__) #define Y_FUNC_SIGNATURE __PRETTY_FUNCTION__ -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) #define Y_FUNC_SIGNATURE __FUNCSIG__ -#else +#else #define Y_FUNC_SIGNATURE "" -#endif - +#endif + #ifdef __GNUC__ #define Y_PRINTF_FORMAT(n, m) __attribute__((__format__(__printf__, n, m))) #endif @@ -53,26 +53,26 @@ #endif /** - * @def Y_DECLARE_UNUSED - * - * Macro is needed to silence compiler warning about unused entities (e.g. function or argument). - * - * @code - * Y_DECLARE_UNUSED int FunctionUsedSolelyForDebugPurposes(); - * assert(FunctionUsedSolelyForDebugPurposes() == 42); - * - * void Foo(const int argumentUsedOnlyForDebugPurposes Y_DECLARE_UNUSED) { - * assert(argumentUsedOnlyForDebugPurposes == 42); - * // however you may as well omit `Y_DECLARE_UNUSED` and use `UNUSED` macro instead - * Y_UNUSED(argumentUsedOnlyForDebugPurposes); - * } - * @endcode - */ + * @def Y_DECLARE_UNUSED + * + * Macro is needed to silence compiler warning about unused entities (e.g. function or argument). + * + * @code + * Y_DECLARE_UNUSED int FunctionUsedSolelyForDebugPurposes(); + * assert(FunctionUsedSolelyForDebugPurposes() == 42); + * + * void Foo(const int argumentUsedOnlyForDebugPurposes Y_DECLARE_UNUSED) { + * assert(argumentUsedOnlyForDebugPurposes == 42); + * // however you may as well omit `Y_DECLARE_UNUSED` and use `UNUSED` macro instead + * Y_UNUSED(argumentUsedOnlyForDebugPurposes); + * } + * @endcode + */ #ifdef __GNUC__ #define Y_DECLARE_UNUSED __attribute__((unused)) #endif -#ifndef Y_DECLARE_UNUSED +#ifndef Y_DECLARE_UNUSED #define Y_DECLARE_UNUSED #endif @@ -152,7 +152,7 @@ #define Y_PREFETCH_WRITE(Pointer, Priority) (void)(const void*)(Pointer), (void)Priority #endif -#ifndef Y_LIKELY +#ifndef Y_LIKELY #define Y_LIKELY(Cond) (Cond) #define Y_UNLIKELY(Cond) (Cond) #endif diff --git a/util/system/compiler_ut.cpp b/util/system/compiler_ut.cpp index f93b1c0850..aaeb935b16 100644 --- a/util/system/compiler_ut.cpp +++ b/util/system/compiler_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TCompilerTest) { - Y_UNIT_TEST(TestPragmaNoWshadow) { +Y_UNIT_TEST_SUITE(TCompilerTest) { + Y_UNIT_TEST(TestPragmaNoWshadow) { Y_PRAGMA_DIAGNOSTIC_PUSH Y_PRAGMA_NO_WSHADOW @@ -34,7 +34,7 @@ Y_UNIT_TEST_SUITE(TCompilerTest) { UNIT_ASSERT_EQUAL(Foo(1), 0); } - Y_UNIT_TEST(TestHaveInt128) { + Y_UNIT_TEST(TestHaveInt128) { #ifdef Y_HAVE_INT128 // will be compiled without errors unsigned __int128 a = 1; diff --git a/util/system/condvar.cpp b/util/system/condvar.cpp index 62f3d22356..2eeb720f9f 100644 --- a/util/system/condvar.cpp +++ b/util/system/condvar.cpp @@ -28,7 +28,7 @@ namespace { public: inline ~TCondVarImpl() { - Y_ASSERT(Events_.Empty()); + Y_ASSERT(Events_.Empty()); } inline void Signal() noexcept { @@ -81,25 +81,25 @@ class TCondVar::TImpl: public TCondVarImpl { class TCondVar::TImpl { public: inline TImpl() { - if (pthread_cond_init(&Cond_, nullptr)) { + if (pthread_cond_init(&Cond_, nullptr)) { ythrow yexception() << "can not create condvar(" << LastSystemErrorText() << ")"; } } inline ~TImpl() { int ret = pthread_cond_destroy(&Cond_); - Y_VERIFY(ret == 0, "pthread_cond_destroy failed: %s", LastSystemErrorText(ret)); + Y_VERIFY(ret == 0, "pthread_cond_destroy failed: %s", LastSystemErrorText(ret)); } inline void Signal() noexcept { int ret = pthread_cond_signal(&Cond_); - Y_VERIFY(ret == 0, "pthread_cond_signal failed: %s", LastSystemErrorText(ret)); + Y_VERIFY(ret == 0, "pthread_cond_signal failed: %s", LastSystemErrorText(ret)); } inline bool WaitD(TMutex& lock, TInstant deadLine) noexcept { if (deadLine == TInstant::Max()) { int ret = pthread_cond_wait(&Cond_, (pthread_mutex_t*)lock.Handle()); - Y_VERIFY(ret == 0, "pthread_cond_wait failed: %s", LastSystemErrorText(ret)); + Y_VERIFY(ret == 0, "pthread_cond_wait failed: %s", LastSystemErrorText(ret)); return true; } else { struct timespec spec; @@ -111,7 +111,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)); + Y_VERIFY(ret == 0 || ret == ETIMEDOUT, "pthread_cond_timedwait failed: %s", LastSystemErrorText(ret)); return ret == 0; } @@ -119,7 +119,7 @@ public: inline void BroadCast() noexcept { int ret = pthread_cond_broadcast(&Cond_); - Y_VERIFY(ret == 0, "pthread_cond_broadcast failed: %s", LastSystemErrorText(ret)); + Y_VERIFY(ret == 0, "pthread_cond_broadcast failed: %s", LastSystemErrorText(ret)); } private: diff --git a/util/system/condvar.h b/util/system/condvar.h index 569162717c..911ace52c6 100644 --- a/util/system/condvar.h +++ b/util/system/condvar.h @@ -6,8 +6,8 @@ #include <util/generic/noncopyable.h> #include <util/datetime/base.h> -#include <utility> - +#include <utility> + class TCondVar { public: TCondVar(); @@ -19,30 +19,30 @@ public: /* * returns false if failed by timeout */ - bool WaitD(TMutex& m, TInstant deadline) noexcept; - - template <typename P> - inline bool WaitD(TMutex& m, TInstant deadline, P pred) noexcept { - while (!pred()) { - if (!WaitD(m, deadline)) { - return pred(); - } - } - return true; - } + bool WaitD(TMutex& m, TInstant deadline) noexcept; + template <typename P> + inline bool WaitD(TMutex& m, TInstant deadline, P pred) noexcept { + while (!pred()) { + if (!WaitD(m, deadline)) { + return pred(); + } + } + return true; + } + /* * returns false if failed by timeout */ - inline bool WaitT(TMutex& m, TDuration timeout) noexcept { - return WaitD(m, timeout.ToDeadLine()); - } - - template <typename P> - inline bool WaitT(TMutex& m, TDuration timeout, P pred) noexcept { - return WaitD(m, timeout.ToDeadLine(), std::move(pred)); + inline bool WaitT(TMutex& m, TDuration timeout) noexcept { + return WaitD(m, timeout.ToDeadLine()); } + template <typename P> + inline bool WaitT(TMutex& m, TDuration timeout, P pred) noexcept { + return WaitD(m, timeout.ToDeadLine(), std::move(pred)); + } + /* * infinite wait */ @@ -50,21 +50,21 @@ public: WaitD(m, TInstant::Max()); } - template <typename P> - inline void WaitI(TMutex& m, P pred) noexcept { - WaitD(m, TInstant::Max(), std::move(pred)); - } - + template <typename P> + inline void WaitI(TMutex& m, P pred) noexcept { + WaitD(m, TInstant::Max(), std::move(pred)); + } + //deprecated inline void Wait(TMutex& m) noexcept { WaitI(m); } - template <typename P> - inline void Wait(TMutex& m, P pred) noexcept { - WaitI(m, std::move(pred)); - } - + template <typename P> + inline void Wait(TMutex& m, P pred) noexcept { + WaitI(m, std::move(pred)); + } + private: class TImpl; THolder<TImpl> Impl_; diff --git a/util/system/condvar_ut.cpp b/util/system/condvar_ut.cpp index 5130a18d32..696516c810 100644 --- a/util/system/condvar_ut.cpp +++ b/util/system/condvar_ut.cpp @@ -4,8 +4,8 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/system/atomic.h> -#include <util/system/atomic_ops.h> +#include <util/system/atomic.h> +#include <util/system/atomic_ops.h> #include <util/thread/pool.h> class TCondVarTest: public TTestBase { @@ -28,12 +28,12 @@ class TCondVarTest: public TTestBase { TCondVar condVar1; TCondVar condVar2; - TAtomic stopWaiting; + TAtomic stopWaiting; - TAtomic in; - TAtomic out; + TAtomic in; + TAtomic out; - TAtomic waited; + TAtomic waited; bool failed; }; @@ -61,36 +61,17 @@ class TCondVarTest: public TTestBase { Data_.failed = true; \ } void RunBasics() { - Y_ASSERT(TotalIds_ == 3); + Y_ASSERT(TotalIds_ == 3); if (Id_ < 2) { TGuard<TMutex> guard(Data_.mutex); - while (!AtomicGet(Data_.stopWaiting)) { + while (!AtomicGet(Data_.stopWaiting)) { bool res = Data_.condVar1.WaitT(Data_.mutex, TDuration::Seconds(1)); FAIL_ASSERT(res == true); } } else { usleep(100000); - AtomicSet(Data_.stopWaiting, true); - - TGuard<TMutex> guard(Data_.mutex); - Data_.condVar1.Signal(); - Data_.condVar1.Signal(); - } - } - - void RunBasicsWithPredicate() { - Y_ASSERT(TotalIds_ == 3); - - if (Id_ < 2) { - TGuard<TMutex> guard(Data_.mutex); - const auto res = Data_.condVar1.WaitT(Data_.mutex, TDuration::Seconds(1), [&] { - return AtomicGet(Data_.stopWaiting); - }); - FAIL_ASSERT(res == true); - } else { - usleep(100000); - AtomicSet(Data_.stopWaiting, true); + AtomicSet(Data_.stopWaiting, true); TGuard<TMutex> guard(Data_.mutex); Data_.condVar1.Signal(); @@ -98,63 +79,82 @@ class TCondVarTest: public TTestBase { } } + void RunBasicsWithPredicate() { + Y_ASSERT(TotalIds_ == 3); + + if (Id_ < 2) { + TGuard<TMutex> guard(Data_.mutex); + const auto res = Data_.condVar1.WaitT(Data_.mutex, TDuration::Seconds(1), [&] { + return AtomicGet(Data_.stopWaiting); + }); + FAIL_ASSERT(res == true); + } else { + usleep(100000); + AtomicSet(Data_.stopWaiting, true); + + TGuard<TMutex> guard(Data_.mutex); + Data_.condVar1.Signal(); + Data_.condVar1.Signal(); + } + } + void RunSyncronize() { for (size_t i = 0; i < 10; ++i) { TGuard<TMutex> guard(Data_.mutex); - AtomicIncrement(Data_.in); - if (AtomicGet(Data_.in) == TotalIds_) { - AtomicSet(Data_.out, 0); + AtomicIncrement(Data_.in); + if (AtomicGet(Data_.in) == TotalIds_) { + AtomicSet(Data_.out, 0); Data_.condVar1.BroadCast(); } else { - AtomicIncrement(Data_.waited); - while (AtomicGet(Data_.in) < TotalIds_) { + AtomicIncrement(Data_.waited); + while (AtomicGet(Data_.in) < TotalIds_) { bool res = Data_.condVar1.WaitT(Data_.mutex, TDuration::Seconds(1)); FAIL_ASSERT(res == true); } } - AtomicIncrement(Data_.out); - if (AtomicGet(Data_.out) == TotalIds_) { - AtomicSet(Data_.in, 0); + AtomicIncrement(Data_.out); + if (AtomicGet(Data_.out) == TotalIds_) { + AtomicSet(Data_.in, 0); Data_.condVar2.BroadCast(); } else { - while (AtomicGet(Data_.out) < TotalIds_) { + while (AtomicGet(Data_.out) < TotalIds_) { bool res = Data_.condVar2.WaitT(Data_.mutex, TDuration::Seconds(1)); FAIL_ASSERT(res == true); } } } - FAIL_ASSERT(AtomicGet(Data_.waited) == (TotalIds_ - 1) * 10); - } - - void RunSyncronizeWithPredicate() { - for (size_t i = 0; i < 10; ++i) { - TGuard<TMutex> guard(Data_.mutex); - AtomicIncrement(Data_.in); - if (AtomicGet(Data_.in) == TotalIds_) { - AtomicSet(Data_.out, 0); - Data_.condVar1.BroadCast(); - } else { - AtomicIncrement(Data_.waited); - const auto res = Data_.condVar1.WaitT(Data_.mutex, TDuration::Seconds(1), [&] { - return AtomicGet(Data_.in) >= TotalIds_; - }); - FAIL_ASSERT(res == true); - } - - AtomicIncrement(Data_.out); - if (AtomicGet(Data_.out) == TotalIds_) { - AtomicSet(Data_.in, 0); - Data_.condVar2.BroadCast(); - } else { - const auto res = Data_.condVar2.WaitT(Data_.mutex, TDuration::Seconds(1), [&] { - return AtomicGet(Data_.out) >= TotalIds_; - }); - FAIL_ASSERT(res == true); - } - } - + FAIL_ASSERT(AtomicGet(Data_.waited) == (TotalIds_ - 1) * 10); + } + + void RunSyncronizeWithPredicate() { + for (size_t i = 0; i < 10; ++i) { + TGuard<TMutex> guard(Data_.mutex); + AtomicIncrement(Data_.in); + if (AtomicGet(Data_.in) == TotalIds_) { + AtomicSet(Data_.out, 0); + Data_.condVar1.BroadCast(); + } else { + AtomicIncrement(Data_.waited); + const auto res = Data_.condVar1.WaitT(Data_.mutex, TDuration::Seconds(1), [&] { + return AtomicGet(Data_.in) >= TotalIds_; + }); + FAIL_ASSERT(res == true); + } + + AtomicIncrement(Data_.out); + if (AtomicGet(Data_.out) == TotalIds_) { + AtomicSet(Data_.in, 0); + Data_.condVar2.BroadCast(); + } else { + const auto res = Data_.condVar2.WaitT(Data_.mutex, TDuration::Seconds(1), [&] { + return AtomicGet(Data_.out) >= TotalIds_; + }); + FAIL_ASSERT(res == true); + } + } + FAIL_ASSERT(Data_.waited == (TotalIds_ - 1) * 10); } #undef FAIL_ASSERT @@ -162,7 +162,7 @@ class TCondVarTest: public TTestBase { private: PFunc Func_; size_t Id_; - TAtomicBase TotalIds_; + TAtomicBase TotalIds_; TSharedData& Data_; }; @@ -181,17 +181,17 @@ private: RUN_CYCLE(RunBasics, 3); } - inline void TestBasicsWithPredicate() { - RUN_CYCLE(RunBasicsWithPredicate, 3); - } - + inline void TestBasicsWithPredicate() { + RUN_CYCLE(RunBasicsWithPredicate, 3); + } + inline void TestSyncronize() { RUN_CYCLE(RunSyncronize, 6); } - - inline void TestSyncronizeWithPredicate() { - RUN_CYCLE(RunSyncronizeWithPredicate, 6); - } + + inline void TestSyncronizeWithPredicate() { + RUN_CYCLE(RunSyncronizeWithPredicate, 6); + } #undef RUN_CYCLE TSharedData Data_; TThreadPool Q_; diff --git a/util/system/context.cpp b/util/system/context.cpp index ad99309088..d108105da0 100644 --- a/util/system/context.cpp +++ b/util/system/context.cpp @@ -127,7 +127,7 @@ namespace { Y_NO_SANITIZE("address") Y_NO_SANITIZE("memory") static void ContextTrampoLine() { void** argPtr = (void**)((char*)AlignUp(&argPtr + EXTRA_PUSH_ARGS, STACK_ALIGN) + STACK_ALIGN); - Y_ASSERT(*(argPtr - 1) == *(argPtr - 2)); + Y_ASSERT(*(argPtr - 1) == *(argPtr - 2)); Run(*(argPtr - 1)); } @@ -183,7 +183,7 @@ TContMachineContext::TContMachineContext(const TContClosure& c) * fake return address */ for (size_t i = 0; i < EXTRA_PUSH_ARGS; ++i) { - stack.Push(nullptr); + stack.Push(nullptr); } #endif @@ -249,7 +249,7 @@ void TContMachineContext::SwitchTo(TContMachineContext* next) noexcept { struct TContMachineContext::TImpl { inline TImpl() - : TL(nullptr) + : TL(nullptr) , Finish(false) { } diff --git a/util/system/context_ut.cpp b/util/system/context_ut.cpp index 45cb0249f7..9fac04fc08 100644 --- a/util/system/context_ut.cpp +++ b/util/system/context_ut.cpp @@ -5,7 +5,7 @@ #include <util/generic/deque.h> #include <util/generic/yexception.h> -Y_UNIT_TEST_SUITE(TestContext) { +Y_UNIT_TEST_SUITE(TestContext) { template <class F> static TContClosure Wrap(F& f) { struct TW: public ITrampoLine { @@ -29,7 +29,7 @@ Y_UNIT_TEST_SUITE(TestContext) { return {&tw, TArrayRef(tw.Buf, sizeof(tw.Buf))}; } - Y_UNIT_TEST(TestExceptionSafety) { + Y_UNIT_TEST(TestExceptionSafety) { TExceptionSafeContext main; TExceptionSafeContext* volatile nextPtr = nullptr; diff --git a/util/system/cpu_id.cpp b/util/system/cpu_id.cpp index 598c71f4d9..37f923932a 100644 --- a/util/system/cpu_id.cpp +++ b/util/system/cpu_id.cpp @@ -4,53 +4,53 @@ #include <util/generic/singleton.h> -#if defined(_win_) +#if defined(_win_) #include <intrin.h> #include <immintrin.h> -#elif defined(_x86_) +#elif defined(_x86_) #include <cpuid.h> #endif #include <string.h> -#if defined(_x86_) && !defined(_win_) -static ui64 _xgetbv(ui32 xcr) { - ui32 eax; - ui32 edx; +#if defined(_x86_) && !defined(_win_) +static ui64 _xgetbv(ui32 xcr) { + ui32 eax; + ui32 edx; __asm__ volatile( "xgetbv" : "=a"(eax), "=d"(edx) : "c"(xcr)); - return (static_cast<ui64>(edx) << 32) | eax; -} -#endif - -bool NX86::CpuId(ui32 op, ui32 subOp, ui32* res) noexcept { -#if defined(_x86_) + return (static_cast<ui64>(edx) << 32) | eax; +} +#endif + +bool NX86::CpuId(ui32 op, ui32 subOp, ui32* res) noexcept { +#if defined(_x86_) #if defined(_MSC_VER) - static_assert(sizeof(int) == sizeof(ui32), "ups, something wrong here"); - __cpuidex((int*)res, op, subOp); + static_assert(sizeof(int) == sizeof(ui32), "ups, something wrong here"); + __cpuidex((int*)res, op, subOp); #else - __cpuid_count(op, subOp, res[0], res[1], res[2], res[3]); + __cpuid_count(op, subOp, res[0], res[1], res[2], res[3]); #endif - return true; -#else - (void)op; - (void)subOp; - - memset(res, 0, 4 * sizeof(ui32)); - - return false; -#endif -} - -bool NX86::CpuId(ui32 op, ui32* res) noexcept { + return true; +#else + (void)op; + (void)subOp; + + memset(res, 0, 4 * sizeof(ui32)); + + return false; +#endif +} + +bool NX86::CpuId(ui32 op, ui32* res) noexcept { #if defined(_x86_) #if defined(_MSC_VER) static_assert(sizeof(int) == sizeof(ui32), "ups, something wrong here"); __cpuid((int*)res, op); #else - __cpuid(op, res[0], res[1], res[2], res[3]); + __cpuid(op, res[0], res[1], res[2], res[3]); #endif return true; #else @@ -73,13 +73,13 @@ namespace { ui32 EDX; }; - inline TX86CpuInfo(ui32 op) noexcept { + inline TX86CpuInfo(ui32 op) noexcept { NX86::CpuId(op, Info); } - - inline TX86CpuInfo(ui32 op, ui32 subOp) noexcept { - NX86::CpuId(op, subOp, Info); - } + + inline TX86CpuInfo(ui32 op, ui32 subOp) noexcept { + NX86::CpuId(op, subOp, Info); + } }; static_assert(sizeof(TX86CpuInfo) == 16, "please, fix me"); @@ -90,15 +90,15 @@ bool NX86::HaveRDTSCP() noexcept { return (TX86CpuInfo(0x80000001).EDX >> 27) & 1u; } -bool NX86::HaveSSE() noexcept { +bool NX86::HaveSSE() noexcept { return (TX86CpuInfo(0x1).EDX >> 25) & 1u; } -bool NX86::HaveSSE2() noexcept { +bool NX86::HaveSSE2() noexcept { return (TX86CpuInfo(0x1).EDX >> 26) & 1u; } -bool NX86::HaveSSE3() noexcept { +bool NX86::HaveSSE3() noexcept { return TX86CpuInfo(0x1).ECX & 1u; } @@ -106,15 +106,15 @@ bool NX86::HavePCLMUL() noexcept { return (TX86CpuInfo(0x1).ECX >> 1) & 1u; } -bool NX86::HaveSSSE3() noexcept { +bool NX86::HaveSSSE3() noexcept { return (TX86CpuInfo(0x1).ECX >> 9) & 1u; } -bool NX86::HaveSSE41() noexcept { +bool NX86::HaveSSE41() noexcept { return (TX86CpuInfo(0x1).ECX >> 19) & 1u; } -bool NX86::HaveSSE42() noexcept { +bool NX86::HaveSSE42() noexcept { return (TX86CpuInfo(0x1).ECX >> 20) & 1u; } @@ -122,51 +122,51 @@ bool NX86::HaveF16C() noexcept { return (TX86CpuInfo(0x1).ECX >> 29) & 1u; } -bool NX86::HavePOPCNT() noexcept { +bool NX86::HavePOPCNT() noexcept { return (TX86CpuInfo(0x1).ECX >> 23) & 1u; } -bool NX86::HaveAES() noexcept { +bool NX86::HaveAES() noexcept { return (TX86CpuInfo(0x1).ECX >> 25) & 1u; } -bool NX86::HaveXSAVE() noexcept { - return (TX86CpuInfo(0x1).ECX >> 26) & 1u; -} - -bool NX86::HaveOSXSAVE() noexcept { - return (TX86CpuInfo(0x1).ECX >> 27) & 1u; -} - -bool NX86::HaveAVX() noexcept { +bool NX86::HaveXSAVE() noexcept { + return (TX86CpuInfo(0x1).ECX >> 26) & 1u; +} + +bool NX86::HaveOSXSAVE() noexcept { + return (TX86CpuInfo(0x1).ECX >> 27) & 1u; +} + +bool NX86::HaveAVX() noexcept { #if defined(_x86_) // http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-optimization-manual.pdf - // https://bugs.chromium.org/p/chromium/issues/detail?id=375968 + // https://bugs.chromium.org/p/chromium/issues/detail?id=375968 return HaveOSXSAVE() // implies HaveXSAVE() && (_xgetbv(0) & 6u) == 6u // XMM state and YMM state are enabled by OS && ((TX86CpuInfo(0x1).ECX >> 28) & 1u); // AVX bit -#else +#else return false; -#endif +#endif } -bool NX86::HaveFMA() noexcept { +bool NX86::HaveFMA() noexcept { return HaveAVX() && ((TX86CpuInfo(0x1).ECX >> 12) & 1u); } -bool NX86::HaveAVX2() noexcept { +bool NX86::HaveAVX2() noexcept { return HaveAVX() && ((TX86CpuInfo(0x7, 0).EBX >> 5) & 1u); -} - -bool NX86::HaveBMI1() noexcept { - return (TX86CpuInfo(0x7, 0).EBX >> 3) & 1u; -} - +} + +bool NX86::HaveBMI1() noexcept { + return (TX86CpuInfo(0x7, 0).EBX >> 3) & 1u; +} + bool NX86::HaveBMI2() noexcept { return (TX86CpuInfo(0x7, 0).EBX >> 8) & 1u; } -bool NX86::HaveAVX512F() noexcept { +bool NX86::HaveAVX512F() noexcept { #if defined(_x86_) // https://software.intel.com/en-us/articles/how-to-detect-knl-instruction-support return HaveOSXSAVE() // implies HaveXSAVE() @@ -177,73 +177,73 @@ bool NX86::HaveAVX512F() noexcept { #else return false; #endif -} - -bool NX86::HaveAVX512DQ() noexcept { +} + +bool NX86::HaveAVX512DQ() noexcept { return HaveAVX512F() && ((TX86CpuInfo(0x7, 0).EBX >> 17) & 1u); -} - -bool NX86::HaveRDSEED() noexcept { +} + +bool NX86::HaveRDSEED() noexcept { return TX86CpuInfo(0x0).EAX >= 0x7 && ((TX86CpuInfo(0x7, 0).EBX >> 18) & 1u); -} - -bool NX86::HaveADX() noexcept { +} + +bool NX86::HaveADX() noexcept { return TX86CpuInfo(0x0).EAX >= 0x7 && ((TX86CpuInfo(0x7, 0).EBX >> 19) & 1u); -} - -bool NX86::HaveAVX512IFMA() noexcept { +} + +bool NX86::HaveAVX512IFMA() noexcept { return HaveAVX512F() && ((TX86CpuInfo(0x7, 0).EBX >> 21) & 1u); -} - -bool NX86::HavePCOMMIT() noexcept { +} + +bool NX86::HavePCOMMIT() noexcept { return TX86CpuInfo(0x0).EAX >= 0x7 && ((TX86CpuInfo(0x7, 0).EBX >> 22) & 1u); -} - -bool NX86::HaveCLFLUSHOPT() noexcept { +} + +bool NX86::HaveCLFLUSHOPT() noexcept { return TX86CpuInfo(0x0).EAX >= 0x7 && ((TX86CpuInfo(0x7, 0).EBX >> 23) & 1u); -} - -bool NX86::HaveCLWB() noexcept { +} + +bool NX86::HaveCLWB() noexcept { return TX86CpuInfo(0x0).EAX >= 0x7 && ((TX86CpuInfo(0x7, 0).EBX >> 24) & 1u); -} - -bool NX86::HaveAVX512PF() noexcept { +} + +bool NX86::HaveAVX512PF() noexcept { return HaveAVX512F() && ((TX86CpuInfo(0x7, 0).EBX >> 26) & 1u); -} - -bool NX86::HaveAVX512ER() noexcept { +} + +bool NX86::HaveAVX512ER() noexcept { return HaveAVX512F() && ((TX86CpuInfo(0x7, 0).EBX >> 27) & 1u); -} - -bool NX86::HaveAVX512CD() noexcept { +} + +bool NX86::HaveAVX512CD() noexcept { return HaveAVX512F() && ((TX86CpuInfo(0x7, 0).EBX >> 28) & 1u); -} - -bool NX86::HaveSHA() noexcept { +} + +bool NX86::HaveSHA() noexcept { return TX86CpuInfo(0x0).EAX >= 0x7 && ((TX86CpuInfo(0x7, 0).EBX >> 29) & 1u); -} - -bool NX86::HaveAVX512BW() noexcept { +} + +bool NX86::HaveAVX512BW() noexcept { return HaveAVX512F() && ((TX86CpuInfo(0x7, 0).EBX >> 30) & 1u); -} - -bool NX86::HaveAVX512VL() noexcept { +} + +bool NX86::HaveAVX512VL() noexcept { return HaveAVX512F() && ((TX86CpuInfo(0x7, 0).EBX >> 31) & 1u); -} - -bool NX86::HavePREFETCHWT1() noexcept { +} + +bool NX86::HavePREFETCHWT1() noexcept { return TX86CpuInfo(0x0).EAX >= 0x7 && ((TX86CpuInfo(0x7, 0).ECX >> 0) & 1u); -} - -bool NX86::HaveAVX512VBMI() noexcept { +} + +bool NX86::HaveAVX512VBMI() noexcept { return HaveAVX512F() && ((TX86CpuInfo(0x7, 0).ECX >> 1) & 1u); -} - -bool NX86::HaveRDRAND() noexcept { +} + +bool NX86::HaveRDRAND() noexcept { return TX86CpuInfo(0x0).EAX >= 0x7 && ((TX86CpuInfo(0x1).ECX >> 30) & 1u); } -const char* CpuBrand(ui32* store) noexcept { +const char* CpuBrand(ui32* store) noexcept { memset(store, 0, 12 * sizeof(*store)); #if defined(_x86_) diff --git a/util/system/cpu_id.h b/util/system/cpu_id.h index 3c49e728a7..5f30c415c1 100644 --- a/util/system/cpu_id.h +++ b/util/system/cpu_id.h @@ -75,13 +75,13 @@ namespace NX86 { /** * returns false on non-x86 platforms */ - bool CpuId(ui32 op, ui32 res[4]) noexcept; - bool CpuId(ui32 op, ui32 subOp, ui32 res[4]) noexcept; - + bool CpuId(ui32 op, ui32 res[4]) noexcept; + bool CpuId(ui32 op, ui32 subOp, ui32 res[4]) noexcept; + #define Y_DEF_NAME(X) Y_CONST_FUNCTION bool Have##X() noexcept; Y_CPU_ID_ENUMERATE(Y_DEF_NAME) #undef Y_DEF_NAME - + #define Y_DEF_NAME(X) Y_CONST_FUNCTION bool CachedHave##X() noexcept; Y_CPU_ID_ENUMERATE_OUTLINED_CACHED_DEFINE(Y_DEF_NAME) #undef Y_DEF_NAME @@ -154,4 +154,4 @@ namespace NX86 { } -const char* CpuBrand(ui32 store[12]) noexcept; +const char* CpuBrand(ui32 store[12]) noexcept; diff --git a/util/system/cpu_id_ut.cpp b/util/system/cpu_id_ut.cpp index 68f1f8aac7..1164196479 100644 --- a/util/system/cpu_id_ut.cpp +++ b/util/system/cpu_id_ut.cpp @@ -1,51 +1,51 @@ #include "cpu_id.h" -#include "platform.h" - +#include "platform.h" + #include <library/cpp/testing/unittest/registar.h> -// There are no tests yet for instructions that use 512-bit wide registers because they are not -// supported by some compilers yet. -// Relevant review in LLVM https://reviews.llvm.org/D16757, we should wait untill it will be in our -// version of Clang. -// -// There are also no tests for PREFETCHWT1, PCOMMIT, CLFLUSHOPT and CLWB as they are not supported -// by our compilers yet (and there are no available processors yet :). - -static void ExecuteSSEInstruction(); -static void ExecuteSSE2Instruction(); -static void ExecuteSSE3Instruction(); -static void ExecuteSSSE3Instruction(); -static void ExecuteSSE41Instruction(); -static void ExecuteSSE42Instruction(); +// There are no tests yet for instructions that use 512-bit wide registers because they are not +// supported by some compilers yet. +// Relevant review in LLVM https://reviews.llvm.org/D16757, we should wait untill it will be in our +// version of Clang. +// +// There are also no tests for PREFETCHWT1, PCOMMIT, CLFLUSHOPT and CLWB as they are not supported +// by our compilers yet (and there are no available processors yet :). + +static void ExecuteSSEInstruction(); +static void ExecuteSSE2Instruction(); +static void ExecuteSSE3Instruction(); +static void ExecuteSSSE3Instruction(); +static void ExecuteSSE41Instruction(); +static void ExecuteSSE42Instruction(); static void ExecuteF16CInstruction(); -static void ExecuteAVXInstruction(); -static void ExecuteAVX2Instruction(); -static void ExecutePOPCNTInstruction(); -static void ExecuteBMI1Instruction(); +static void ExecuteAVXInstruction(); +static void ExecuteAVX2Instruction(); +static void ExecutePOPCNTInstruction(); +static void ExecuteBMI1Instruction(); static void ExecuteBMI2Instruction(); static void ExecutePCLMULInstruction(); -static void ExecuteAESInstruction(); -static void ExecuteAVXInstruction(); -static void ExecuteAVX2Instruction(); -static void ExecuteAVX512FInstruction(); -static void ExecuteAVX512DQInstruction(); -static void ExecuteAVX512IFMAInstruction(); -static void ExecuteAVX512PFInstruction(); -static void ExecuteAVX512ERInstruction(); -static void ExecuteAVX512CDInstruction(); -static void ExecuteAVX512BWInstruction(); -static void ExecuteAVX512VLInstruction(); -static void ExecuteAVX512VBMIInstruction(); -static void ExecutePREFETCHWT1Instruction(); -static void ExecuteSHAInstruction(); -static void ExecuteADXInstruction(); -static void ExecuteRDRANDInstruction(); -static void ExecuteRDSEEDInstruction(); -static void ExecutePCOMMITInstruction(); -static void ExecuteCLFLUSHOPTInstruction(); -static void ExecuteCLWBInstruction(); - +static void ExecuteAESInstruction(); +static void ExecuteAVXInstruction(); +static void ExecuteAVX2Instruction(); +static void ExecuteAVX512FInstruction(); +static void ExecuteAVX512DQInstruction(); +static void ExecuteAVX512IFMAInstruction(); +static void ExecuteAVX512PFInstruction(); +static void ExecuteAVX512ERInstruction(); +static void ExecuteAVX512CDInstruction(); +static void ExecuteAVX512BWInstruction(); +static void ExecuteAVX512VLInstruction(); +static void ExecuteAVX512VBMIInstruction(); +static void ExecutePREFETCHWT1Instruction(); +static void ExecuteSHAInstruction(); +static void ExecuteADXInstruction(); +static void ExecuteRDRANDInstruction(); +static void ExecuteRDSEEDInstruction(); +static void ExecutePCOMMITInstruction(); +static void ExecuteCLFLUSHOPTInstruction(); +static void ExecuteCLWBInstruction(); + static void ExecuteFMAInstruction() { } @@ -58,82 +58,82 @@ static void ExecuteXSAVEInstruction() { static void ExecuteOSXSAVEInstruction() { } -Y_UNIT_TEST_SUITE(TestCpuId) { -#define DECLARE_TEST_HAVE_INSTRUCTION(name) \ +Y_UNIT_TEST_SUITE(TestCpuId) { +#define DECLARE_TEST_HAVE_INSTRUCTION(name) \ Y_UNIT_TEST(Test##Have##name) { \ - if (NX86::Have##name()) { \ - Execute##name##Instruction(); \ - } \ + if (NX86::Have##name()) { \ + Execute##name##Instruction(); \ + } \ } Y_CPU_ID_ENUMERATE(DECLARE_TEST_HAVE_INSTRUCTION) -#undef DECLARE_TEST_HAVE_INSTRUCTION - - Y_UNIT_TEST(TestSSE2) { +#undef DECLARE_TEST_HAVE_INSTRUCTION + + Y_UNIT_TEST(TestSSE2) { #if defined(_x86_64_) UNIT_ASSERT(NX86::HaveSSE2()); #endif } - Y_UNIT_TEST(TestCpuBrand) { + Y_UNIT_TEST(TestCpuBrand) { ui32 store[12]; //Cout << CpuBrand(store) << Endl;; UNIT_ASSERT(strlen(CpuBrand(store)) > 0); } - - Y_UNIT_TEST(TestCachedAndNoncached) { + + Y_UNIT_TEST(TestCachedAndNoncached) { #define Y_DEF_NAME(X) UNIT_ASSERT_VALUES_EQUAL(NX86::Have##X(), NX86::CachedHave##X()); Y_CPU_ID_ENUMERATE(Y_DEF_NAME) #undef Y_DEF_NAME - } + } } - -#if defined(_x86_64_) + +#if defined(_x86_64_) #if defined(__GNUC__) -void ExecuteSSEInstruction() { +void ExecuteSSEInstruction() { __asm__ __volatile__("xorps %%xmm0, %%xmm0\n" : : : "xmm0"); -} - -void ExecuteSSE2Instruction() { +} + +void ExecuteSSE2Instruction() { __asm__ __volatile__("psrldq $0, %%xmm0\n" : : : "xmm0"); -} - -void ExecuteSSE3Instruction() { +} + +void ExecuteSSE3Instruction() { __asm__ __volatile__("addsubpd %%xmm0, %%xmm0\n" : : : "xmm0"); -} - -void ExecuteSSSE3Instruction() { +} + +void ExecuteSSSE3Instruction() { __asm__ __volatile__("psignb %%xmm0, %%xmm0\n" : : : "xmm0"); -} - -void ExecuteSSE41Instruction() { +} + +void ExecuteSSE41Instruction() { __asm__ __volatile__("pmuldq %%xmm0, %%xmm0\n" : : : "xmm0"); -} - -void ExecuteSSE42Instruction() { +} + +void ExecuteSSE42Instruction() { __asm__ __volatile__("crc32 %%eax, %%eax\n" : : : "eax"); -} - +} + void ExecuteF16CInstruction() { __asm__ __volatile__("vcvtph2ps %%xmm0, %%ymm0\n" : @@ -141,34 +141,34 @@ void ExecuteF16CInstruction() { : "xmm0"); } -void ExecuteAVXInstruction() { +void ExecuteAVXInstruction() { __asm__ __volatile__("vzeroupper\n" : : : "xmm0"); -} - -void ExecuteAVX2Instruction() { +} + +void ExecuteAVX2Instruction() { __asm__ __volatile__("vpunpcklbw %%ymm0, %%ymm0, %%ymm0\n" : : : "xmm0"); -} - -void ExecutePOPCNTInstruction() { +} + +void ExecutePOPCNTInstruction() { __asm__ __volatile__("popcnt %%eax, %%eax\n" : : : "eax"); -} - -void ExecuteBMI1Instruction() { +} + +void ExecuteBMI1Instruction() { __asm__ __volatile__("tzcnt %%eax, %%eax\n" : : : "eax"); -} - +} + void ExecuteBMI2Instruction() { __asm__ __volatile__("pdep %%rax, %%rdi, %%rax\n" : @@ -183,268 +183,268 @@ void ExecutePCLMULInstruction() { : "xmm0"); } -void ExecuteAESInstruction() { +void ExecuteAESInstruction() { __asm__ __volatile__("aesimc %%xmm0, %%xmm0\n" : : : "xmm0"); -} - -void ExecuteAVX512FInstruction() { -} - -void ExecuteAVX512DQInstruction() { -} - -void ExecuteAVX512IFMAInstruction() { -} - -void ExecuteAVX512PFInstruction() { -} - -void ExecuteAVX512ERInstruction() { -} - -void ExecuteAVX512CDInstruction() { -} - -void ExecuteAVX512BWInstruction() { -} - -void ExecuteAVX512VLInstruction() { -} - -void ExecuteAVX512VBMIInstruction() { -} - -void ExecutePREFETCHWT1Instruction() { -} - -void ExecuteSHAInstruction() { +} + +void ExecuteAVX512FInstruction() { +} + +void ExecuteAVX512DQInstruction() { +} + +void ExecuteAVX512IFMAInstruction() { +} + +void ExecuteAVX512PFInstruction() { +} + +void ExecuteAVX512ERInstruction() { +} + +void ExecuteAVX512CDInstruction() { +} + +void ExecuteAVX512BWInstruction() { +} + +void ExecuteAVX512VLInstruction() { +} + +void ExecuteAVX512VBMIInstruction() { +} + +void ExecutePREFETCHWT1Instruction() { +} + +void ExecuteSHAInstruction() { __asm__ __volatile__("sha1msg1 %%xmm0, %%xmm0\n" : : : "xmm0"); -} - -void ExecuteADXInstruction() { +} + +void ExecuteADXInstruction() { __asm__ __volatile__("adcx %%eax, %%eax\n" : : : "eax"); -} - -void ExecuteRDRANDInstruction() { +} + +void ExecuteRDRANDInstruction() { __asm__ __volatile__("rdrand %%eax" : : : "eax"); -} - -void ExecuteRDSEEDInstruction() { +} + +void ExecuteRDSEEDInstruction() { __asm__ __volatile__("rdseed %%eax" : : : "eax"); -} - -void ExecutePCOMMITInstruction() { -} - -void ExecuteCLFLUSHOPTInstruction() { -} - -void ExecuteCLWBInstruction() { -} - +} + +void ExecutePCOMMITInstruction() { +} + +void ExecuteCLFLUSHOPTInstruction() { +} + +void ExecuteCLWBInstruction() { +} + #elif defined(_MSC_VER) -void ExecuteSSEInstruction() { -} - -void ExecuteSSE2Instruction() { -} - -void ExecuteSSE3Instruction() { -} - -void ExecuteSSSE3Instruction() { -} - -void ExecuteSSE41Instruction() { -} - -void ExecuteSSE42Instruction() { -} - +void ExecuteSSEInstruction() { +} + +void ExecuteSSE2Instruction() { +} + +void ExecuteSSE3Instruction() { +} + +void ExecuteSSSE3Instruction() { +} + +void ExecuteSSE41Instruction() { +} + +void ExecuteSSE42Instruction() { +} + void ExecuteF16CInstruction() { } -void ExecuteAVXInstruction() { -} - -void ExecuteAVX2Instruction() { -} - -void ExecutePOPCNTInstruction() { -} - -void ExecuteBMI1Instruction() { -} - +void ExecuteAVXInstruction() { +} + +void ExecuteAVX2Instruction() { +} + +void ExecutePOPCNTInstruction() { +} + +void ExecuteBMI1Instruction() { +} + void ExecuteBMI2Instruction() { } void ExecutePCLMULInstruction() { } -void ExecuteAESInstruction() { -} - -void ExecuteAVX512FInstruction() { -} - -void ExecuteAVX512DQInstruction() { -} - -void ExecuteAVX512IFMAInstruction() { -} - -void ExecuteAVX512PFInstruction() { -} - -void ExecuteAVX512ERInstruction() { -} - -void ExecuteAVX512CDInstruction() { -} - -void ExecuteAVX512BWInstruction() { -} - -void ExecuteAVX512VLInstruction() { -} - -void ExecuteAVX512VBMIInstruction() { -} - -void ExecutePREFETCHWT1Instruction() { -} - -void ExecuteSHAInstruction() { -} - -void ExecuteADXInstruction() { -} - -void ExecuteRDRANDInstruction() { -} - -void ExecuteRDSEEDInstruction() { -} - -void ExecutePCOMMITInstruction() { -} - -void ExecuteCLFLUSHOPTInstruction() { -} - -void ExecuteCLWBInstruction() { -} - +void ExecuteAESInstruction() { +} + +void ExecuteAVX512FInstruction() { +} + +void ExecuteAVX512DQInstruction() { +} + +void ExecuteAVX512IFMAInstruction() { +} + +void ExecuteAVX512PFInstruction() { +} + +void ExecuteAVX512ERInstruction() { +} + +void ExecuteAVX512CDInstruction() { +} + +void ExecuteAVX512BWInstruction() { +} + +void ExecuteAVX512VLInstruction() { +} + +void ExecuteAVX512VBMIInstruction() { +} + +void ExecutePREFETCHWT1Instruction() { +} + +void ExecuteSHAInstruction() { +} + +void ExecuteADXInstruction() { +} + +void ExecuteRDRANDInstruction() { +} + +void ExecuteRDSEEDInstruction() { +} + +void ExecutePCOMMITInstruction() { +} + +void ExecuteCLFLUSHOPTInstruction() { +} + +void ExecuteCLWBInstruction() { +} + #else #error "unknown compiler" #endif -#else -void ExecuteSSEInstruction() { -} - -void ExecuteSSE2Instruction() { -} - -void ExecuteSSE3Instruction() { -} - -void ExecuteSSSE3Instruction() { -} - -void ExecuteSSE41Instruction() { -} - -void ExecuteSSE42Instruction() { -} - +#else +void ExecuteSSEInstruction() { +} + +void ExecuteSSE2Instruction() { +} + +void ExecuteSSE3Instruction() { +} + +void ExecuteSSSE3Instruction() { +} + +void ExecuteSSE41Instruction() { +} + +void ExecuteSSE42Instruction() { +} + void ExecuteF16CInstruction() { } -void ExecuteAVXInstruction() { -} - -void ExecuteAVX2Instruction() { -} - -void ExecutePOPCNTInstruction() { -} - -void ExecuteBMI1Instruction() { -} - +void ExecuteAVXInstruction() { +} + +void ExecuteAVX2Instruction() { +} + +void ExecutePOPCNTInstruction() { +} + +void ExecuteBMI1Instruction() { +} + void ExecuteBMI2Instruction() { } void ExecutePCLMULInstruction() { } -void ExecuteAESInstruction() { -} - -void ExecuteAVX512FInstruction() { -} - -void ExecuteAVX512DQInstruction() { -} - -void ExecuteAVX512IFMAInstruction() { -} - -void ExecuteAVX512PFInstruction() { -} - -void ExecuteAVX512ERInstruction() { -} - -void ExecuteAVX512CDInstruction() { -} - -void ExecuteAVX512BWInstruction() { -} - -void ExecuteAVX512VLInstruction() { -} - -void ExecuteAVX512VBMIInstruction() { -} - -void ExecutePREFETCHWT1Instruction() { -} - -void ExecuteSHAInstruction() { -} - -void ExecuteADXInstruction() { -} - -void ExecuteRDRANDInstruction() { -} - -void ExecuteRDSEEDInstruction() { -} - -void ExecutePCOMMITInstruction() { -} - -void ExecuteCLFLUSHOPTInstruction() { -} - -void ExecuteCLWBInstruction() { -} -#endif +void ExecuteAESInstruction() { +} + +void ExecuteAVX512FInstruction() { +} + +void ExecuteAVX512DQInstruction() { +} + +void ExecuteAVX512IFMAInstruction() { +} + +void ExecuteAVX512PFInstruction() { +} + +void ExecuteAVX512ERInstruction() { +} + +void ExecuteAVX512CDInstruction() { +} + +void ExecuteAVX512BWInstruction() { +} + +void ExecuteAVX512VLInstruction() { +} + +void ExecuteAVX512VBMIInstruction() { +} + +void ExecutePREFETCHWT1Instruction() { +} + +void ExecuteSHAInstruction() { +} + +void ExecuteADXInstruction() { +} + +void ExecuteRDRANDInstruction() { +} + +void ExecuteRDSEEDInstruction() { +} + +void ExecutePCOMMITInstruction() { +} + +void ExecuteCLFLUSHOPTInstruction() { +} + +void ExecuteCLWBInstruction() { +} +#endif diff --git a/util/system/datetime.cpp b/util/system/datetime.cpp index b07b50679a..5bb9716fbb 100644 --- a/util/system/datetime.cpp +++ b/util/system/datetime.cpp @@ -17,12 +17,12 @@ #define Y_HAS_CLOCK_GETTIME #endif -static ui64 ToMicroSeconds(const struct timeval& tv) { +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) { +static ui64 ToMicroSeconds(const FILETIME& ft) { return (((ui64)ft.dwHighDateTime << 32) + (ui64)ft.dwLowDateTime) / (ui64)10; } #elif defined(Y_HAS_CLOCK_GETTIME) @@ -31,9 +31,9 @@ static ui64 ToMicroSeconds(const struct timespec& ts) { } #endif -ui64 MicroSeconds() noexcept { +ui64 MicroSeconds() noexcept { struct timeval tv; - gettimeofday(&tv, nullptr); + gettimeofday(&tv, nullptr); return ToMicroSeconds(tv); } @@ -48,7 +48,7 @@ ui64 ThreadCPUUserTime() noexcept { #endif } -ui64 ThreadCPUSystemTime() noexcept { +ui64 ThreadCPUSystemTime() noexcept { #if defined(_win_) FILETIME creationTime, exitTime, kernelTime, userTime; GetThreadTimes(GetCurrentThread(), &creationTime, &exitTime, &kernelTime, &userTime); @@ -58,7 +58,7 @@ ui64 ThreadCPUSystemTime() noexcept { #endif } -ui64 ThreadCPUTime() noexcept { +ui64 ThreadCPUTime() noexcept { #if defined(_win_) FILETIME creationTime, exitTime, kernelTime, userTime; GetThreadTimes(GetCurrentThread(), &creationTime, &exitTime, &kernelTime, &userTime); @@ -72,13 +72,13 @@ ui64 ThreadCPUTime() noexcept { #endif } -ui32 Seconds() noexcept { +ui32 Seconds() noexcept { struct timeval tv; - gettimeofday(&tv, nullptr); + gettimeofday(&tv, nullptr); return tv.tv_sec; } -void NanoSleep(ui64 ns) noexcept { +void NanoSleep(ui64 ns) noexcept { #if defined(_win_) Sleep(ns / 1000000); #else @@ -88,7 +88,7 @@ void NanoSleep(ui64 ns) noexcept { req.tv_nsec = ns % NS; struct timespec left; while (nanosleep(&req, &left) < 0) { - Y_ASSERT(errno == EINTR); + Y_ASSERT(errno == EINTR); req = left; } #endif diff --git a/util/system/datetime.h b/util/system/datetime.h index aa009974e0..21f127d1d5 100644 --- a/util/system/datetime.h +++ b/util/system/datetime.h @@ -16,7 +16,7 @@ /// for handy datetime utilities include util/datetime/base.h /// Current time in microseconds since epoch -ui64 MicroSeconds() noexcept; +ui64 MicroSeconds() noexcept; /// Current time in milliseconds since epoch inline ui64 MilliSeconds() { return MicroSeconds() / ui64(1000); @@ -26,13 +26,13 @@ inline ui64 millisec() { return MilliSeconds(); } /// Current time in seconds since epoch -ui32 Seconds() noexcept; +ui32 Seconds() noexcept; ///Current thread time in microseconds -ui64 ThreadCPUUserTime() noexcept; -ui64 ThreadCPUSystemTime() noexcept; -ui64 ThreadCPUTime() noexcept; +ui64 ThreadCPUUserTime() noexcept; +ui64 ThreadCPUSystemTime() noexcept; +ui64 ThreadCPUTime() noexcept; -void NanoSleep(ui64 ns) 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 @@ -41,7 +41,7 @@ void NanoSleep(ui64 ns) noexcept; // with preceding instructions // PERFORMANCE: rdtsc - 15 cycles per call , rdtscp - 19 cycles per call // WARNING: following instruction can be executed out-of-order -Y_FORCE_INLINE ui64 GetCycleCount() noexcept { +Y_FORCE_INLINE ui64 GetCycleCount() noexcept { #if defined(_MSC_VER) // Generates the rdtscp instruction, which returns the processor time stamp. // The processor time stamp records the number of clock cycles since the last reset. diff --git a/util/system/defaults.h b/util/system/defaults.h index dcd7abea38..b2b5756b34 100644 --- a/util/system/defaults.h +++ b/util/system/defaults.h @@ -74,7 +74,7 @@ #endif #include "compiler.h" - + #ifdef _win_ #include <malloc.h> #elif defined(_sun_) @@ -93,33 +93,33 @@ constexpr bool Y_IS_DEBUG_BUILD = true; #endif #endif -/** - * @def Y_ARRAY_SIZE - * - * This macro is needed to get number of elements in a statically allocated fixed size array. The - * expression is a compile-time constant and therefore can be used in compile time computations. - * - * @code - * enum ENumbers { - * EN_ONE, - * EN_TWO, - * EN_SIZE - * } - * - * const char* NAMES[] = { - * "one", - * "two" - * } - * - * static_assert(Y_ARRAY_SIZE(NAMES) == EN_SIZE, "you should define `NAME` for each enumeration"); - * @endcode - * - * This macro also catches type errors. If you see a compiler error like "warning: division by zero - * is undefined" when using `Y_ARRAY_SIZE` then you are probably giving it a pointer. - * - * Since all of our code is expected to work on a 64 bit platform where pointers are 8 bytes we may - * falsefully accept pointers to types of sizes that are divisors of 8 (1, 2, 4 and 8). - */ +/** + * @def Y_ARRAY_SIZE + * + * This macro is needed to get number of elements in a statically allocated fixed size array. The + * expression is a compile-time constant and therefore can be used in compile time computations. + * + * @code + * enum ENumbers { + * EN_ONE, + * EN_TWO, + * EN_SIZE + * } + * + * const char* NAMES[] = { + * "one", + * "two" + * } + * + * static_assert(Y_ARRAY_SIZE(NAMES) == EN_SIZE, "you should define `NAME` for each enumeration"); + * @endcode + * + * This macro also catches type errors. If you see a compiler error like "warning: division by zero + * is undefined" when using `Y_ARRAY_SIZE` then you are probably giving it a pointer. + * + * Since all of our code is expected to work on a 64 bit platform where pointers are 8 bytes we may + * falsefully accept pointers to types of sizes that are divisors of 8 (1, 2, 4 and 8). + */ #if defined(__cplusplus) #include <util/generic/array_size.h> #else @@ -128,11 +128,11 @@ constexpr bool Y_IS_DEBUG_BUILD = true; ((sizeof(arr) / sizeof((arr)[0])) / static_cast<size_t>(!(sizeof(arr) % sizeof((arr)[0])))) #endif -#undef Y_ARRAY_BEGIN -#define Y_ARRAY_BEGIN(arr) (arr) +#undef Y_ARRAY_BEGIN +#define Y_ARRAY_BEGIN(arr) (arr) -#undef Y_ARRAY_END -#define Y_ARRAY_END(arr) ((arr) + Y_ARRAY_SIZE(arr)) +#undef Y_ARRAY_END +#define Y_ARRAY_END(arr) ((arr) + Y_ARRAY_SIZE(arr)) /** * Concatenates two symbols, even if one of them is itself a macro. @@ -148,7 +148,7 @@ constexpr bool Y_IS_DEBUG_BUILD = true; #define Y_GENERATE_UNIQUE_ID(N) Y_CAT(N, __COUNTER__) #endif -#if !defined(Y_GENERATE_UNIQUE_ID) +#if !defined(Y_GENERATE_UNIQUE_ID) #define Y_GENERATE_UNIQUE_ID(N) Y_CAT(N, __LINE__) #endif diff --git a/util/system/direct_io.cpp b/util/system/direct_io.cpp index f59c54b0cb..73a55007a0 100644 --- a/util/system/direct_io.cpp +++ b/util/system/direct_io.cpp @@ -19,7 +19,7 @@ namespace { #ifdef _linux_ utsname sysInfo; - Y_VERIFY(!uname(&sysInfo), "Error while call uname: %s", LastSystemErrorText()); + Y_VERIFY(!uname(&sysInfo), "Error while call uname: %s", LastSystemErrorText()); TStringBuf release(sysInfo.release); release = release.substr(0, release.find_first_not_of(".0123456789")); diff --git a/util/system/direct_io_ut.cpp b/util/system/direct_io_ut.cpp index 839c3de7ca..96e2de6637 100644 --- a/util/system/direct_io_ut.cpp +++ b/util/system/direct_io_ut.cpp @@ -9,8 +9,8 @@ static const char* FileName_("./test.file"); -Y_UNIT_TEST_SUITE(TDirectIoTestSuite) { - Y_UNIT_TEST(TestDirectFile) { +Y_UNIT_TEST_SUITE(TDirectIoTestSuite) { + Y_UNIT_TEST(TestDirectFile) { TDirectIOBufferedFile file(FileName_, RdWr | Direct | Seq | CreateAlways, 1 << 15); TVector<ui64> data((1 << 15) + 1); TVector<ui64> readResult(data.size()); diff --git a/util/system/dynlib.cpp b/util/system/dynlib.cpp index 9d2541c25f..3ce77e5540 100644 --- a/util/system/dynlib.cpp +++ b/util/system/dynlib.cpp @@ -33,7 +33,7 @@ inline TString DLLERR() { #ifdef _win32_ char* msg = 0; DWORD cnt = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char*)&msg, 0, nullptr); + nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char*)&msg, 0, nullptr); if (!msg) return "DLLERR() unknown error"; while (cnt && isspace(msg[cnt - 1])) @@ -80,7 +80,7 @@ public: inline void* Sym(const char* name) { void* symbol = SymOptional(name); - if (symbol == nullptr) { + if (symbol == nullptr) { ythrow yexception() << DLLERR().data(); } @@ -115,7 +115,7 @@ void TDynamicLibrary::Close() noexcept { void* TDynamicLibrary::SymOptional(const char* name) noexcept { if (!IsLoaded()) { - return nullptr; + return nullptr; } return Impl_->SymOptional(name); diff --git a/util/system/dynlib.h b/util/system/dynlib.h index 66eaf4a5c1..13ce0bf4b5 100644 --- a/util/system/dynlib.h +++ b/util/system/dynlib.h @@ -5,8 +5,8 @@ #include <util/generic/ptr.h> #include <util/generic/string.h> -#define Y_GET_FUNC(dll, name) FUNC_##name((dll).Sym(#name)) -#define Y_GET_FUNC_OPTIONAL(dll, name) FUNC_##name((dll).SymOptional(#name)) +#define Y_GET_FUNC(dll, name) FUNC_##name((dll).Sym(#name)) +#define Y_GET_FUNC_OPTIONAL(dll, name) FUNC_##name((dll).SymOptional(#name)) #ifdef _win32_ #define DEFAULT_DLLOPEN_FLAGS 0 diff --git a/util/system/env.cpp b/util/system/env.cpp index ead9b566a5..97cdd2cb31 100644 --- a/util/system/env.cpp +++ b/util/system/env.cpp @@ -11,16 +11,16 @@ #include <cstdlib> #endif -/** +/** * On Windows there may be many copies of enviroment variables, there at least two known, one is * manipulated by Win32 API, another by C runtime, so we must be consistent in the choice of - * functions used to manipulate them. - * - * Relevant links: - * - http://bugs.python.org/issue16633 + * functions used to manipulate them. + * + * Relevant links: + * - http://bugs.python.org/issue16633 * - https://a.yandex-team.ru/review/108892/details - */ - + */ + TString GetEnv(const TString& key, const TString& def) { #ifdef _win_ size_t len = GetEnvironmentVariableA(key.data(), nullptr, 0); diff --git a/util/system/env.h b/util/system/env.h index e2ccdd1e95..7f4c3cc70f 100644 --- a/util/system/env.h +++ b/util/system/env.h @@ -2,31 +2,31 @@ #include <util/generic/string.h> -/** - * Search the environment list provided by the host environment for associated variable. - * +/** + * Search the environment list provided by the host environment for associated variable. + * * @param key String identifying the name of the environmental variable to look for * @param def String that returns if environmental variable not found by key - * - * @return String that is associated with the matched environment variable or empty string if - * such variable is missing. - * + * + * @return String that is associated with the matched environment variable or empty string if + * such variable is missing. + * * @note Use it only in pair with `SetEnv` as there may be inconsistency in their behaviour - * otherwise. - * @note Calls to `GetEnv` and `SetEnv` from different threads must be synchronized. - * @see SetEnv - */ + * otherwise. + * @note Calls to `GetEnv` and `SetEnv` from different threads must be synchronized. + * @see SetEnv + */ TString GetEnv(const TString& key, const TString& def = TString()); - -/** - * Add or change environment variable provided by the host environment. - * - * @key String identifying the name of the environment variable to set or change - * @value Value to assign - + +/** + * Add or change environment variable provided by the host environment. + * + * @key String identifying the name of the environment variable to set or change + * @value Value to assign + * @note Use it only in pair with `GetEnv` as there may be inconsistency in their behaviour - * otherwise. - * @note Calls to `GetEnv` and `SetEnv` from different threads must be synchronized. - * @see GetEnv - */ + * otherwise. + * @note Calls to `GetEnv` and `SetEnv` from different threads must be synchronized. + * @see GetEnv + */ void SetEnv(const TString& key, const TString& value); diff --git a/util/system/env_ut.cpp b/util/system/env_ut.cpp index e03cc01658..865acf8e12 100644 --- a/util/system/env_ut.cpp +++ b/util/system/env_ut.cpp @@ -3,19 +3,19 @@ #include <util/generic/string.h> #include "env.h" -Y_UNIT_TEST_SUITE(EnvTest) { - Y_UNIT_TEST(GetSetEnvTest) { +Y_UNIT_TEST_SUITE(EnvTest) { + Y_UNIT_TEST(GetSetEnvTest) { TString key = "util_GETENV_TestVar"; TString value = "Some value for env var"; TString def = "Some default value for env var"; - // first of all, it should be clear + // first of all, it should be clear UNIT_ASSERT_VALUES_EQUAL(GetEnv(key), TString()); UNIT_ASSERT_VALUES_EQUAL(GetEnv(key, def), def); - SetEnv(key, value); - // set and see what value we get here - UNIT_ASSERT_VALUES_EQUAL(GetEnv(key), value); + SetEnv(key, value); + // set and see what value we get here + UNIT_ASSERT_VALUES_EQUAL(GetEnv(key), value); UNIT_ASSERT_VALUES_EQUAL(GetEnv(key, def), value); - // set empty value + // set empty value SetEnv(key, TString()); UNIT_ASSERT_VALUES_EQUAL(GetEnv(key), TString()); @@ -27,5 +27,5 @@ Y_UNIT_TEST_SUITE(EnvTest) { UNIT_ASSERT_VALUES_EQUAL(GetEnv(longKey), longValue); SetEnv(longKey, TString()); UNIT_ASSERT_VALUES_EQUAL(GetEnv(longKey), TString()); - } + } } diff --git a/util/system/error.cpp b/util/system/error.cpp index f778ec42cb..b3be00e7fe 100644 --- a/util/system/error.cpp +++ b/util/system/error.cpp @@ -1,7 +1,7 @@ #include "tls.h" #include "error.h" -#include <util/string/strip.h> +#include <util/string/strip.h> #include <util/generic/strfcpy.h> #include <cerrno> diff --git a/util/system/event.cpp b/util/system/event.cpp index 79b3cdb291..36ba4b7bcd 100644 --- a/util/system/event.cpp +++ b/util/system/event.cpp @@ -16,7 +16,7 @@ class TSystemEvent::TEvImpl: public TAtomicRefCount<TSystemEvent::TEvImpl> { public: #ifdef _win_ inline TEvImpl(ResetMode rmode) { - cond = CreateEvent(nullptr, rmode == rManual ? true : false, false, nullptr); + cond = CreateEvent(nullptr, rmode == rManual ? true : false, false, nullptr); } inline ~TEvImpl() { diff --git a/util/system/event_ut.cpp b/util/system/event_ut.cpp index 2506cb7a91..650ba4641a 100644 --- a/util/system/event_ut.cpp +++ b/util/system/event_ut.cpp @@ -82,8 +82,8 @@ namespace { } -Y_UNIT_TEST_SUITE(EventTest) { - Y_UNIT_TEST(WaitAndSignalTest) { +Y_UNIT_TEST_SUITE(EventTest) { + Y_UNIT_TEST(WaitAndSignalTest) { TSharedData data; TThreadPool queue; queue.Start(5); @@ -95,7 +95,7 @@ Y_UNIT_TEST_SUITE(EventTest) { UNIT_ASSERT(!data.failed); } - Y_UNIT_TEST(ConcurrentSignalAndWaitTest) { + Y_UNIT_TEST(ConcurrentSignalAndWaitTest) { // test for problem detected by thread-sanitizer (signal/wait race) SEARCH-2113 const size_t limit = 200; TManualEvent event[limit]; @@ -113,7 +113,7 @@ Y_UNIT_TEST_SUITE(EventTest) { } /** Test for a problem: http://nga.at.yandex-team.ru/5772 */ - Y_UNIT_TEST(DestructorBeforeSignalFinishTest) { + Y_UNIT_TEST(DestructorBeforeSignalFinishTest) { return; TVector<THolder<IObjectInQueue>> tasks; for (size_t i = 0; i < 1000; ++i) { diff --git a/util/system/execpath.cpp b/util/system/execpath.cpp index 33198af58b..10f08cea3e 100644 --- a/util/system/execpath.cpp +++ b/util/system/execpath.cpp @@ -39,7 +39,7 @@ static inline bool GoodPath(const TString& path) { static inline int FreeBSDSysCtl(int* mib, size_t mibSize, TTempBuf& res) { for (size_t i = 0; i < 2; ++i) { size_t cb = res.Size(); - if (sysctl(mib, mibSize, res.Data(), &cb, nullptr, 0) == 0) { + if (sysctl(mib, mibSize, res.Data(), &cb, nullptr, 0) == 0) { res.Proceed(cb); return 0; } else if (errno == ENOMEM) { @@ -54,7 +54,7 @@ static inline int FreeBSDSysCtl(int* mib, size_t mibSize, TTempBuf& res) { static inline TString FreeBSDGetExecPath() { int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; TTempBuf buf; - int r = FreeBSDSysCtl(mib, Y_ARRAY_SIZE(mib), buf); + int r = FreeBSDSysCtl(mib, Y_ARRAY_SIZE(mib), buf); if (r == 0) { return TString(buf.Data(), buf.Filled() - 1); } else if (r == ENOTSUP) { // older FreeBSD version @@ -73,7 +73,7 @@ static inline TString FreeBSDGetExecPath() { static inline TString FreeBSDGetArgv0() { int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_ARGS, getpid()}; TTempBuf buf; - int r = FreeBSDSysCtl(mib, Y_ARRAY_SIZE(mib), buf); + int r = FreeBSDSysCtl(mib, Y_ARRAY_SIZE(mib), buf); if (r == 0) { return TString(buf.Data()); } else if (r == ENOTSUP) { @@ -118,7 +118,7 @@ static TString GetExecPathImpl() { #elif defined(_win_) TTempBuf execNameBuf; for (;;) { - DWORD r = GetModuleFileName(nullptr, execNameBuf.Data(), execNameBuf.Size()); + DWORD r = GetModuleFileName(nullptr, execNameBuf.Data(), execNameBuf.Size()); if (r == execNameBuf.Size()) { execNameBuf = TTempBuf(execNameBuf.Size() * 2); } else if (r == 0) { diff --git a/util/system/execpath_ut.cpp b/util/system/execpath_ut.cpp index 16b01466f5..d1d23fcf72 100644 --- a/util/system/execpath_ut.cpp +++ b/util/system/execpath_ut.cpp @@ -5,8 +5,8 @@ #include "platform.h" #include <util/folder/dirut.h> -Y_UNIT_TEST_SUITE(TExecPathTest) { - Y_UNIT_TEST(TestIt) { +Y_UNIT_TEST_SUITE(TExecPathTest) { + Y_UNIT_TEST(TestIt) { TString execPath = GetExecPath(); TString persistentExecPath = GetPersistentExecPath(); diff --git a/util/system/fasttime.cpp b/util/system/fasttime.cpp index 057a814f0a..82f199e230 100644 --- a/util/system/fasttime.cpp +++ b/util/system/fasttime.cpp @@ -31,7 +31,7 @@ namespace { using TFunc = int (*)(struct timeval*, struct timezone*); inline TSymbols() - : Func(nullptr) + : Func(nullptr) { // not DEFAULT, cause library/cpp/gettimeofday Func = reinterpret_cast<TFunc>(dlsym(RTLD_NEXT, "gettimeofday")); @@ -52,7 +52,7 @@ namespace { Zero(tv); - Func(&tv, nullptr); + Func(&tv, nullptr); return (((TTime)1000000) * (TTime)tv.tv_sec) + (TTime)tv.tv_usec; } @@ -64,7 +64,7 @@ namespace { "/lib/libc.so.6", }; - for (auto& lib : libs) { + for (auto& lib : libs) { try { return MakeHolder<TDynamicLibrary>(lib); } catch (...) { diff --git a/util/system/file.cpp b/util/system/file.cpp index 4a261d020c..0ba1a89062 100644 --- a/util/system/file.cpp +++ b/util/system/file.cpp @@ -274,8 +274,8 @@ bool TFileHandle::Close() noexcept { isOk = (::CloseHandle(Fd_) != 0); } if (!isOk) { - Y_VERIFY(GetLastError() != ERROR_INVALID_HANDLE, - "must not quietly close invalid handle"); + Y_VERIFY(GetLastError() != ERROR_INVALID_HANDLE, + "must not quietly close invalid handle"); } #elif defined(_unix_) if (Fd_ != INVALID_FHANDLE) { @@ -285,7 +285,7 @@ bool TFileHandle::Close() noexcept { // Do not quietly close bad descriptor, // because often it means double close // that is disasterous - Y_VERIFY(errno != EBADF, "must not quietly close bad descriptor: fd=%d", int(Fd_)); + Y_VERIFY(errno != EBADF, "must not quietly close bad descriptor: fd=%d", int(Fd_)); } #else #error unsupported platform @@ -1288,15 +1288,15 @@ bool PosixDisableReadAhead(FHANDLE fileHandle, void* addr) noexcept { #if HAVE_POSIX_FADVISE #if defined(_linux_) - Y_UNUSED(fileHandle); + Y_UNUSED(fileHandle); ret = madvise(addr, 0, MADV_RANDOM); // according to klamm@ posix_fadvise does not work under linux, madvise does work #else - Y_UNUSED(addr); + Y_UNUSED(addr); ret = ::posix_fadvise(fileHandle, 0, 0, POSIX_FADV_RANDOM); #endif #else - Y_UNUSED(fileHandle); - Y_UNUSED(addr); + Y_UNUSED(fileHandle); + Y_UNUSED(addr); #endif return ret == 0; } diff --git a/util/system/file_ut.cpp b/util/system/file_ut.cpp index 941e6a50f3..22a2f5c625 100644 --- a/util/system/file_ut.cpp +++ b/util/system/file_ut.cpp @@ -113,7 +113,7 @@ public: const TString data = TUnbufferedFileInput(tmp.Name()).ReadAll(); UNIT_ASSERT_EQUAL(data.length(), 12); - UNIT_ASSERT(data.StartsWith("12345")); + UNIT_ASSERT(data.StartsWith("12345")); } }; @@ -202,7 +202,7 @@ void TFileTest::TestRW() { void TFileTest::TestLocale() { #ifdef _unix_ - const char* loc = setlocale(LC_CTYPE, nullptr); + const char* loc = setlocale(LC_CTYPE, nullptr); setlocale(LC_CTYPE, "ru_RU.UTF-8"); #endif TFile f("Имя.txt", CreateNew); @@ -405,8 +405,8 @@ UNIT_ASSERT_VALUES_EQUAL(file.CountCache(0, 12345), -1); #endif } -Y_UNIT_TEST_SUITE(TTestDecodeOpenMode) { - Y_UNIT_TEST(It) { +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)); diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp index 7454a4cb94..45733c7422 100644 --- a/util/system/filemap.cpp +++ b/util/system/filemap.cpp @@ -128,12 +128,12 @@ class TMemoryMap::TImpl: public TAtomicRefCount<TImpl> { public: inline void CreateMapping() { #if defined(_win_) - Mapping_ = nullptr; + Mapping_ = nullptr; if (Length_) { - Mapping_ = CreateFileMapping(File_.GetHandle(), nullptr, + Mapping_ = CreateFileMapping(File_.GetHandle(), nullptr, (Mode_ & oAccessMask) == TFileMap::oRdWr ? PAGE_READWRITE : PAGE_READONLY, - (DWORD)(Length_ >> 32), (DWORD)(Length_ & 0xFFFFFFFF), nullptr); - if (Mapping_ == nullptr) { + (DWORD)(Length_ >> 32), (DWORD)(Length_ & 0xFFFFFFFF), nullptr); + if (Mapping_ == nullptr) { ythrow yexception() << "Can't create file mapping of '" << DbgName_ << "': " << LastSystemErrorText(); } } else { @@ -147,7 +147,7 @@ public: ythrow yexception() << "Can't map " << (unsigned long)Length_ << " bytes of file '" << DbgName_ << "' at offset 0: " << LastSystemErrorText(); } } else { - PtrStart_ = nullptr; + PtrStart_ = nullptr; } #endif } @@ -209,7 +209,7 @@ public: inline bool IsOpen() const noexcept { return File_.IsOpen() #if defined(_win_) - && Mapping_ != nullptr + && Mapping_ != nullptr #endif ; } @@ -247,15 +247,15 @@ public: result.Ptr = mmap((caddr_t) nullptr, size, ModeToMmapProt(Mode_), ModeToMmapFlags(Mode_), File_.GetHandle(), base); if (result.Ptr == (char*)(-1)) { - result.Ptr = nullptr; + result.Ptr = nullptr; } #if defined(_unix_) } else { - result.Ptr = PtrStart_ ? static_cast<caddr_t>(PtrStart_) + base : nullptr; + result.Ptr = PtrStart_ ? static_cast<caddr_t>(PtrStart_) + base : nullptr; } #endif #endif - if (result.Ptr != nullptr || size == 0) { // allow map of size 0 + if (result.Ptr != nullptr || size == 0) { // allow map of size 0 result.Size = size; } else { ythrow yexception() << "Can't map " << (unsigned long)size << " bytes at offset " << offset << " of '" << DbgName_ << "': " << LastSystemErrorText(); @@ -308,7 +308,7 @@ public: #if defined(_win_) if (Mapping_) { ::CloseHandle(Mapping_); // != FALSE - Mapping_ = nullptr; + Mapping_ = nullptr; } #elif defined(_unix_) if (PtrStart_) { @@ -475,8 +475,8 @@ TFileMap::TFileMap(const TFileMap& fm) noexcept } void TFileMap::Flush(void* ptr, size_t size, bool sync) { - Y_ASSERT(ptr >= Ptr()); - Y_ASSERT(static_cast<char*>(ptr) + size <= static_cast<char*>(Ptr()) + MappedSize()); + Y_ASSERT(ptr >= Ptr()); + Y_ASSERT(static_cast<char*>(ptr) + size <= static_cast<char*>(Ptr()) + MappedSize()); if (!Region_.IsMapped()) { return; @@ -530,11 +530,11 @@ void TFileMap::Precharge(size_t pos, size_t size) const { } TMappedAllocation::TMappedAllocation(size_t size, bool shared, void* addr) - : Ptr_(nullptr) + : Ptr_(nullptr) , Size_(0) , Shared_(shared) #if defined(_win_) - , Mapping_(nullptr) + , Mapping_(nullptr) #endif { if (size != 0) { @@ -543,16 +543,16 @@ TMappedAllocation::TMappedAllocation(size_t size, bool shared, void* addr) } void* TMappedAllocation::Alloc(size_t size, void* addr) { - assert(Ptr_ == nullptr); + assert(Ptr_ == nullptr); #if defined(_win_) (void)addr; - Mapping_ = CreateFileMapping((HANDLE)-1, nullptr, PAGE_READWRITE, 0, size ? size : 1, nullptr); + Mapping_ = CreateFileMapping((HANDLE)-1, nullptr, PAGE_READWRITE, 0, size ? size : 1, nullptr); Ptr_ = MapViewOfFile(Mapping_, FILE_MAP_WRITE, 0, 0, size ? size : 1); #else Ptr_ = mmap(addr, size, PROT_READ | PROT_WRITE, (Shared_ ? MAP_SHARED : MAP_PRIVATE) | MAP_ANON, -1, 0); if (Ptr_ == (void*)MAP_FAILED) { - Ptr_ = nullptr; + Ptr_ = nullptr; } #endif if (Ptr_ != nullptr) { @@ -568,11 +568,11 @@ void TMappedAllocation::Dealloc() { #if defined(_win_) UnmapViewOfFile(Ptr_); CloseHandle(Mapping_); - Mapping_ = nullptr; + Mapping_ = nullptr; #else munmap((caddr_t)Ptr_, Size_); #endif - Ptr_ = nullptr; + Ptr_ = nullptr; Size_ = 0; } diff --git a/util/system/filemap.h b/util/system/filemap.h index 11be64bff4..262b5cd976 100644 --- a/util/system/filemap.h +++ b/util/system/filemap.h @@ -26,15 +26,15 @@ struct TMemoryMapCommon { } inline void* MappedData() const noexcept { - return Ptr ? (void*)((char*)Ptr + Head) : nullptr; + return Ptr ? (void*)((char*)Ptr + Head) : nullptr; } inline bool IsMapped() const noexcept { - return Ptr != nullptr; + return Ptr != nullptr; } inline void Reset() noexcept { - Ptr = nullptr; + Ptr = nullptr; Size = 0; Head = 0; } @@ -195,14 +195,14 @@ private: public: TFileMappedArray() - : Ptr_(nullptr) - , End_(nullptr) + : Ptr_(nullptr) + , End_(nullptr) , Size_(0) { } ~TFileMappedArray() { - Ptr_ = nullptr; - End_ = nullptr; + Ptr_ = nullptr; + End_ = nullptr; } void Init(const char* name) { DataHolder_.Reset(new TFileMap(name)); @@ -214,15 +214,15 @@ public: } void Term() { DataHolder_.Destroy(); - Ptr_ = nullptr; + Ptr_ = nullptr; Size_ = 0; - End_ = nullptr; + End_ = nullptr; } void Precharge() { DataHolder_->Precharge(); } const T& operator[](size_t pos) const { - Y_ASSERT(pos < size()); + Y_ASSERT(pos < size()); return Ptr_[pos]; } /// for STL compatibility only, Size() usage is recommended @@ -289,7 +289,7 @@ private: class TMappedAllocation: TMoveOnly { public: - TMappedAllocation(size_t size = 0, bool shared = false, void* addr = nullptr); + TMappedAllocation(size_t size = 0, bool shared = false, void* addr = nullptr); ~TMappedAllocation() { Dealloc(); } @@ -300,13 +300,13 @@ public: this->swap(other); return *this; } - void* Alloc(size_t size, void* addr = nullptr); + void* Alloc(size_t size, void* addr = nullptr); void Dealloc(); void* Ptr() const { return Ptr_; } char* Data(ui32 pos = 0) const { - return (char*)(Ptr_ ? ((char*)Ptr_ + pos) : nullptr); + return (char*)(Ptr_ ? ((char*)Ptr_ + pos) : nullptr); } char* Begin() const noexcept { return (char*)Ptr(); @@ -341,11 +341,11 @@ public: Destroy(); } T* Create(size_t siz) { - Y_ASSERT(MappedSize() == 0 && Ptr() == nullptr); + Y_ASSERT(MappedSize() == 0 && Ptr() == nullptr); T* arr = (T*)Alloc((sizeof(T) * siz)); if (!arr) - return nullptr; - Y_ASSERT(MappedSize() == sizeof(T) * siz); + return nullptr; + Y_ASSERT(MappedSize() == sizeof(T) * siz); for (size_t n = 0; n < siz; n++) new (&arr[n]) T(); return arr; @@ -359,11 +359,11 @@ public: } } T& operator[](size_t pos) { - Y_ASSERT(pos < size()); + Y_ASSERT(pos < size()); return ((T*)Ptr())[pos]; } const T& operator[](size_t pos) const { - Y_ASSERT(pos < size()); + Y_ASSERT(pos < size()); return ((T*)Ptr())[pos]; } T* begin() { diff --git a/util/system/filemap_ut.cpp b/util/system/filemap_ut.cpp index 73f109dc88..a0ec229681 100644 --- a/util/system/filemap_ut.cpp +++ b/util/system/filemap_ut.cpp @@ -11,7 +11,7 @@ #include <cstring> #include <cstdio> -Y_UNIT_TEST_SUITE(TFileMapTest) { +Y_UNIT_TEST_SUITE(TFileMapTest) { static const char* FileName_("./mappped_file"); void BasicTest(TMemoryMapCommon::EOpenMode mode) { @@ -59,7 +59,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { BasicTest(TMemoryMapCommon::oRdWr | TMemoryMapCommon::oPopulate); } - Y_UNIT_TEST(TestFileRemap) { + Y_UNIT_TEST(TestFileRemap) { const char data1[] = "01234"; const char data2[] = "abcdefg"; const char data3[] = "COPY"; @@ -104,7 +104,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { NFs::Remove(FileName_); } - Y_UNIT_TEST(TestFileMapDbgName) { + Y_UNIT_TEST(TestFileMapDbgName) { // This test checks that dbgName passed to the TFileMap constructor is saved inside the object and appears // in subsequent error messages. const char* const dbgName = "THIS_IS_A_TEST"; @@ -131,7 +131,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { #elif defined(_cygwin_) //cygwin is not real unix :( #else - Y_UNIT_TEST(TestNotGreedy) { + Y_UNIT_TEST(TestNotGreedy) { unsigned page[4096 / sizeof(unsigned)]; #if defined(_unix_) @@ -211,7 +211,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { } #endif - Y_UNIT_TEST(TestFileMappedArray) { + Y_UNIT_TEST(TestFileMappedArray) { { TFileMappedArray<ui32> mappedArray; ui32 data[] = {123, 456, 789, 10}; @@ -268,13 +268,13 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { NFs::Remove(FileName_); } - Y_UNIT_TEST(TestMappedArray) { + Y_UNIT_TEST(TestMappedArray) { ui32 sz = 10; TMappedArray<ui32> mappedArray; ui32* ptr = mappedArray.Create(sz); - UNIT_ASSERT(ptr != nullptr); + UNIT_ASSERT(ptr != nullptr); UNIT_ASSERT(mappedArray.size() == sz); UNIT_ASSERT(mappedArray.begin() + sz == mappedArray.end()); @@ -290,12 +290,12 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { UNIT_ASSERT(mappedArray.size() == 1000 && mappedArray2.size() == sz); } - Y_UNIT_TEST(TestMemoryMap) { + Y_UNIT_TEST(TestMemoryMap) { TFile file(FileName_, CreateAlways | WrOnly); file.Close(); FILE* f = fopen(FileName_, "rb"); - UNIT_ASSERT(f != nullptr); + UNIT_ASSERT(f != nullptr); try { TMemoryMap mappedMem(f); mappedMem.Map(mappedMem.Length() / 2, mappedMem.Length() + 100); // overflow @@ -318,7 +318,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { NFs::Remove(FileName_); } - Y_UNIT_TEST(TestMemoryMapIsWritable) { + Y_UNIT_TEST(TestMemoryMapIsWritable) { TFile file(FileName_, CreateAlways | WrOnly); file.Close(); @@ -333,7 +333,7 @@ Y_UNIT_TEST_SUITE(TFileMapTest) { NFs::Remove(FileName_); } - Y_UNIT_TEST(TestFileMapIsWritable) { + Y_UNIT_TEST(TestFileMapIsWritable) { TFile file(FileName_, CreateAlways | WrOnly); file.Close(); { diff --git a/util/system/flock_ut.cpp b/util/system/flock_ut.cpp index b5f6cb5328..6a1caec83e 100644 --- a/util/system/flock_ut.cpp +++ b/util/system/flock_ut.cpp @@ -5,15 +5,15 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TFileLockTest) { - Y_UNIT_TEST(TestFlock) { +Y_UNIT_TEST_SUITE(TFileLockTest) { + Y_UNIT_TEST(TestFlock) { TTempFileHandle tmp("./file"); UNIT_ASSERT_EQUAL(Flock(tmp.GetHandle(), LOCK_EX), 0); UNIT_ASSERT_EQUAL(Flock(tmp.GetHandle(), LOCK_UN), 0); } - Y_UNIT_TEST(TestFileLocker) { + Y_UNIT_TEST(TestFileLocker) { TTempFileHandle tmp("./file.locker"); TFileLock fileLockExclusive1("./file.locker"); TFileLock fileLockExclusive2("./file.locker"); diff --git a/util/system/fs.cpp b/util/system/fs.cpp index d2611a8ccc..c95e77e4df 100644 --- a/util/system/fs.cpp +++ b/util/system/fs.cpp @@ -43,7 +43,7 @@ void NFs::RemoveRecursive(const TString& path) { switch (it->fts_info) { case FTS_DOT: case FTS_D: - break; + break; default: if (!NFs::Remove(it->fts_path)) { ythrow TSystemError() << errStr << it->fts_path << " with cwd (" << NFs::CurrentWorkingDirectory() << ")"; @@ -55,7 +55,7 @@ void NFs::RemoveRecursive(const TString& path) { bool NFs::MakeDirectory(const TString& path, EFilePermissions mode) { #if defined(_win_) - Y_UNUSED(mode); + Y_UNUSED(mode); return NFsPrivate::WinMakeDirectory(path); #else return mkdir(path.data(), mode) == 0; @@ -65,8 +65,8 @@ bool NFs::MakeDirectory(const TString& path, EFilePermissions mode) { bool NFs::MakeDirectoryRecursive(const TString& path, EFilePermissions mode, bool alwaysCreate) { if (NFs::Exists(path) && TFileStat(path).IsDir()) { if (alwaysCreate) { - ythrow TIoException() << "path " << path << " already exists" - << " with cwd (" << NFs::CurrentWorkingDirectory() << ")"; + ythrow TIoException() << "path " << path << " already exists" + << " with cwd (" << NFs::CurrentWorkingDirectory() << ")"; } return true; } else { diff --git a/util/system/fs.h b/util/system/fs.h index 237daf2d2d..344adccc4c 100644 --- a/util/system/fs.h +++ b/util/system/fs.h @@ -6,18 +6,18 @@ namespace NFs { enum EFilePermission { - FP_ALL_EXEC = 01, - FP_ALL_WRITE = 02, - FP_ALL_READ = 04, - FP_GROUP_READ = 040, - FP_GROUP_WRITE = 020, - FP_GROUP_EXEC = 010, - FP_OWNER_READ = 0400, - FP_OWNER_WRITE = 0200, - FP_OWNER_EXEC = 0100, - - FP_COMMON_FILE = 0777, - FP_SECRET_FILE = 0700, + FP_ALL_EXEC = 01, + FP_ALL_WRITE = 02, + FP_ALL_READ = 04, + FP_GROUP_READ = 040, + FP_GROUP_WRITE = 020, + FP_GROUP_EXEC = 010, + FP_OWNER_READ = 0400, + FP_OWNER_WRITE = 0200, + FP_OWNER_EXEC = 0100, + + FP_COMMON_FILE = 0777, + FP_SECRET_FILE = 0700, FP_NONSECRET_FILE = 0744, }; @@ -148,7 +148,7 @@ namespace NFs { /// @param[in] path Path to check /// @returns input argument inline const TString& EnsureExists(const TString& path) { - Y_ENSURE_EX(Exists(path), TFileError{} << "Path " << path << " does not exists (checked from cwd:" << NFs::CurrentWorkingDirectory() << ")"); + Y_ENSURE_EX(Exists(path), TFileError{} << "Path " << path << " does not exists (checked from cwd:" << NFs::CurrentWorkingDirectory() << ")"); return path; } } diff --git a/util/system/fs_ut.cpp b/util/system/fs_ut.cpp index de071ebf55..02a0c8d9ae 100644 --- a/util/system/fs_ut.cpp +++ b/util/system/fs_ut.cpp @@ -313,8 +313,8 @@ void TFsTest::TestEnsureExists() { TStringBuilder expected; TString got; try { - NFs::EnsureExists(nonExists); - expected << __LOCATION__; + NFs::EnsureExists(nonExists); + expected << __LOCATION__; } catch (const TFileError& err) { got = err.what(); } diff --git a/util/system/fs_win.cpp b/util/system/fs_win.cpp index a410ccac06..04adf6b3c1 100644 --- a/util/system/fs_win.cpp +++ b/util/system/fs_win.cpp @@ -13,7 +13,7 @@ namespace NFsPrivate { wstr.resize(str.size()); size_t written = 0; if (!UTF8ToWide(str.data(), str.size(), wstr.begin(), written)) - return nullptr; + return nullptr; wstr.erase(written); static_assert(sizeof(WCHAR) == sizeof(wchar16), "expect sizeof(WCHAR) == sizeof(wchar16)"); return (const WCHAR*)wstr.data(); @@ -25,7 +25,7 @@ namespace NFsPrivate { return WideToUTF8((wchar16*)wstr, len); } - HANDLE CreateFileWithUtf8Name(const TStringBuf fName, ui32 accessMode, ui32 shareMode, ui32 createMode, ui32 attributes, bool inheritHandle) { + HANDLE CreateFileWithUtf8Name(const TStringBuf fName, ui32 accessMode, ui32 shareMode, ui32 createMode, ui32 attributes, bool inheritHandle) { TUtf16String wstr; LPCWSTR wname = UTF8ToWCHAR(fName, wstr); if (!wname) { @@ -34,9 +34,9 @@ namespace NFsPrivate { } SECURITY_ATTRIBUTES secAttrs; secAttrs.bInheritHandle = inheritHandle ? TRUE : FALSE; - secAttrs.lpSecurityDescriptor = nullptr; + secAttrs.lpSecurityDescriptor = nullptr; secAttrs.nLength = sizeof(secAttrs); - return ::CreateFileW(wname, accessMode, shareMode, &secAttrs, createMode, attributes, nullptr); + return ::CreateFileW(wname, accessMode, shareMode, &secAttrs, createMode, attributes, nullptr); } bool WinRename(const TString& oldPath, const TString& newPath) { @@ -110,7 +110,7 @@ namespace NFsPrivate { return false; } - return (CreateHardLinkW(npPtr, epPtr, nullptr) != 0); + return (CreateHardLinkW(npPtr, epPtr, nullptr) != 0); } bool WinExists(const TString& path) { @@ -186,7 +186,7 @@ namespace NFsPrivate { TTempBuf buf; while (true) { DWORD bytesReturned = 0; - BOOL res = DeviceIoControl(h, FSCTL_GET_REPARSE_POINT, nullptr, 0, buf.Data(), buf.Size(), &bytesReturned, nullptr); + BOOL res = DeviceIoControl(h, FSCTL_GET_REPARSE_POINT, nullptr, 0, buf.Data(), buf.Size(), &bytesReturned, nullptr); if (res) { REPARSE_DATA_BUFFER* rdb = (REPARSE_DATA_BUFFER*)buf.Data(); if (rdb->ReparseTag == IO_REPARSE_TAG_SYMLINK) { @@ -219,8 +219,8 @@ bool GetObjectId(const char* path, GUID* id) { if (h.IsOpen()) { FILE_OBJECTID_BUFFER fob; DWORD resSize = 0; - if (DeviceIoControl(h, FSCTL_CREATE_OR_GET_OBJECT_ID, nullptr, 0, &fob, sizeof(fob), &resSize, nullptr)) { - Y_ASSERT(resSize == sizeof(fob)); + if (DeviceIoControl(h, FSCTL_CREATE_OR_GET_OBJECT_ID, nullptr, 0, &fob, sizeof(fob), &resSize, nullptr)) { + Y_ASSERT(resSize == sizeof(fob)); memcpy(id, &fob.ObjectId, sizeof(GUID)); return true; } diff --git a/util/system/fs_win.h b/util/system/fs_win.h index 8086129828..a3deaef660 100644 --- a/util/system/fs_win.h +++ b/util/system/fs_win.h @@ -15,7 +15,7 @@ namespace NFsPrivate { TString WinReadLink(const TString& path); - HANDLE CreateFileWithUtf8Name(const TStringBuf fName, ui32 accessMode, ui32 shareMode, ui32 createMode, ui32 attributes, bool inheritHandle); + HANDLE CreateFileWithUtf8Name(const TStringBuf fName, ui32 accessMode, ui32 shareMode, ui32 createMode, ui32 attributes, bool inheritHandle); bool WinRemove(const TString& path); diff --git a/util/system/fstat.cpp b/util/system/fstat.cpp index 81e98cbc6b..d25651621a 100644 --- a/util/system/fstat.cpp +++ b/util/system/fstat.cpp @@ -132,23 +132,23 @@ TFileStat::TFileStat(const char* fileName, bool nofollow) { MakeFromFileName(fileName, nofollow); } -bool TFileStat::IsNull() const noexcept { +bool TFileStat::IsNull() const noexcept { return *this == TFileStat(); } -bool TFileStat::IsFile() const noexcept { +bool TFileStat::IsFile() const noexcept { return S_ISREG(Mode); } -bool TFileStat::IsDir() const noexcept { +bool TFileStat::IsDir() const noexcept { return S_ISDIR(Mode); } -bool TFileStat::IsSymlink() const noexcept { +bool TFileStat::IsSymlink() const noexcept { return S_ISLNK(Mode); } -bool operator==(const TFileStat& l, const TFileStat& r) noexcept { +bool operator==(const TFileStat& l, const TFileStat& r) noexcept { return l.Mode == r.Mode && l.Uid == r.Uid && l.Gid == r.Gid && @@ -159,7 +159,7 @@ bool operator==(const TFileStat& l, const TFileStat& r) noexcept { l.CTime == r.CTime; } -bool operator!=(const TFileStat& l, const TFileStat& r) noexcept { +bool operator!=(const TFileStat& l, const TFileStat& r) noexcept { return !(l == r); } diff --git a/util/system/fstat.h b/util/system/fstat.h index 64e79e1b55..46d3db8a05 100644 --- a/util/system/fstat.h +++ b/util/system/fstat.h @@ -23,11 +23,11 @@ struct TFileStat { public: TFileStat(); - bool IsNull() const noexcept; + bool IsNull() const noexcept; - bool IsFile() const noexcept; - bool IsDir() const noexcept; - bool IsSymlink() const noexcept; + bool IsFile() const noexcept; + bool IsDir() const noexcept; + bool IsSymlink() const noexcept; explicit TFileStat(const TFile& f); explicit TFileStat(FHANDLE f); @@ -35,8 +35,8 @@ public: TFileStat(const TString& fileName, bool nofollow = false); TFileStat(const char* fileName, bool nofollow = false); - friend bool operator==(const TFileStat& l, const TFileStat& r) noexcept; - friend bool operator!=(const TFileStat& l, const TFileStat& r) noexcept; + friend bool operator==(const TFileStat& l, const TFileStat& r) noexcept; + friend bool operator!=(const TFileStat& l, const TFileStat& r) noexcept; private: void MakeFromFileName(const char* fileName, bool nofollow); diff --git a/util/system/fstat_ut.cpp b/util/system/fstat_ut.cpp index 160ecd936e..c7f0f27f15 100644 --- a/util/system/fstat_ut.cpp +++ b/util/system/fstat_ut.cpp @@ -6,10 +6,10 @@ #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/testing/unittest/tests_data.h> -#include <util/folder/path.h> - -Y_UNIT_TEST_SUITE(TestFileStat) { - Y_UNIT_TEST(FileTest) { +#include <util/folder/path.h> + +Y_UNIT_TEST_SUITE(TestFileStat) { + Y_UNIT_TEST(FileTest) { TString fileName = "f1.txt"; TFileStat oFs; { @@ -46,7 +46,7 @@ Y_UNIT_TEST_SUITE(TestFileStat) { UNIT_ASSERT(unlink(fileName.data()) == 0); } - Y_UNIT_TEST(DirTest) { + Y_UNIT_TEST(DirTest) { Mkdir("tmpd", MODE0777); TFileStat fs("tmpd"); UNIT_ASSERT(!fs.IsFile()); @@ -62,77 +62,77 @@ Y_UNIT_TEST_SUITE(TestFileStat) { UNIT_ASSERT(fs.CTime == 0); } - Y_UNIT_TEST(SymlinkToExistingFileTest) { - const auto path = GetOutputPath() / "file_1"; - const auto link = GetOutputPath() / "symlink_1"; - TFile(path, EOpenModeFlag::CreateNew | EOpenModeFlag::RdWr); - UNIT_ASSERT(NFs::SymLink(path, link)); - - const TFileStat statNoFollow(link, false); - UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsNull(), ToString(statNoFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(true, statNoFollow.IsFile(), ToString(statNoFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsSymlink(), ToString(statNoFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsDir(), ToString(statNoFollow.Mode)); - - const TFileStat statFollow(link, true); - UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsNull(), ToString(statFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsSymlink(), ToString(statFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); - } - - Y_UNIT_TEST(SymlinkToNonExistingFileTest) { - const auto path = GetOutputPath() / "file_2"; - const auto link = GetOutputPath() / "symlink_2"; - UNIT_ASSERT(NFs::SymLink(path, link)); - - const TFileStat statNoFollow(link, false); - UNIT_ASSERT_VALUES_EQUAL_C(true, statNoFollow.IsNull(), ToString(statNoFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsFile(), ToString(statNoFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsSymlink(), ToString(statNoFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsDir(), ToString(statNoFollow.Mode)); - - const TFileStat statFollow(link, true); - UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsNull(), ToString(statFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsSymlink(), ToString(statFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); - } - - Y_UNIT_TEST(SymlinkToFileThatCantExistTest) { - const auto path = TFsPath("/path") / "that" / "does" / "not" / "exists"; - const auto link = GetOutputPath() / "symlink_3"; - UNIT_ASSERT(NFs::SymLink(path, link)); - - const TFileStat statNoFollow(link, false); - UNIT_ASSERT_VALUES_EQUAL_C(true, statNoFollow.IsNull(), ToString(statNoFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsFile(), ToString(statNoFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsSymlink(), ToString(statNoFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsDir(), ToString(statNoFollow.Mode)); - - const TFileStat statFollow(link, true); - UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsNull(), ToString(statFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsSymlink(), ToString(statFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); - } - - Y_UNIT_TEST(FileDoesNotExistTest) { - const auto path = TFsPath("/path") / "that" / "does" / "not" / "exists"; - - const TFileStat statNoFollow(path, false); - UNIT_ASSERT_VALUES_EQUAL_C(true, statNoFollow.IsNull(), ToString(statNoFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsFile(), ToString(statNoFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsSymlink(), ToString(statNoFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsDir(), ToString(statNoFollow.Mode)); - - const TFileStat statFollow(path, true); - UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsNull(), ToString(statFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsSymlink(), ToString(statFollow.Mode)); - UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); - } - + Y_UNIT_TEST(SymlinkToExistingFileTest) { + const auto path = GetOutputPath() / "file_1"; + const auto link = GetOutputPath() / "symlink_1"; + TFile(path, EOpenModeFlag::CreateNew | EOpenModeFlag::RdWr); + UNIT_ASSERT(NFs::SymLink(path, link)); + + const TFileStat statNoFollow(link, false); + UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsNull(), ToString(statNoFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(true, statNoFollow.IsFile(), ToString(statNoFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsSymlink(), ToString(statNoFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsDir(), ToString(statNoFollow.Mode)); + + const TFileStat statFollow(link, true); + UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsNull(), ToString(statFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsSymlink(), ToString(statFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); + } + + Y_UNIT_TEST(SymlinkToNonExistingFileTest) { + const auto path = GetOutputPath() / "file_2"; + const auto link = GetOutputPath() / "symlink_2"; + UNIT_ASSERT(NFs::SymLink(path, link)); + + const TFileStat statNoFollow(link, false); + UNIT_ASSERT_VALUES_EQUAL_C(true, statNoFollow.IsNull(), ToString(statNoFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsFile(), ToString(statNoFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsSymlink(), ToString(statNoFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsDir(), ToString(statNoFollow.Mode)); + + const TFileStat statFollow(link, true); + UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsNull(), ToString(statFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsSymlink(), ToString(statFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); + } + + Y_UNIT_TEST(SymlinkToFileThatCantExistTest) { + const auto path = TFsPath("/path") / "that" / "does" / "not" / "exists"; + const auto link = GetOutputPath() / "symlink_3"; + UNIT_ASSERT(NFs::SymLink(path, link)); + + const TFileStat statNoFollow(link, false); + UNIT_ASSERT_VALUES_EQUAL_C(true, statNoFollow.IsNull(), ToString(statNoFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsFile(), ToString(statNoFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsSymlink(), ToString(statNoFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsDir(), ToString(statNoFollow.Mode)); + + const TFileStat statFollow(link, true); + UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsNull(), ToString(statFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsSymlink(), ToString(statFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); + } + + Y_UNIT_TEST(FileDoesNotExistTest) { + const auto path = TFsPath("/path") / "that" / "does" / "not" / "exists"; + + const TFileStat statNoFollow(path, false); + UNIT_ASSERT_VALUES_EQUAL_C(true, statNoFollow.IsNull(), ToString(statNoFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsFile(), ToString(statNoFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsSymlink(), ToString(statNoFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statNoFollow.IsDir(), ToString(statNoFollow.Mode)); + + const TFileStat statFollow(path, true); + UNIT_ASSERT_VALUES_EQUAL_C(true, statFollow.IsNull(), ToString(statFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsFile(), ToString(statFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsSymlink(), ToString(statFollow.Mode)); + UNIT_ASSERT_VALUES_EQUAL_C(false, statFollow.IsDir(), ToString(statFollow.Mode)); + } + Y_UNIT_TEST(ChmodTest) { const TString fileName = "m.txt"; TFile file(fileName.c_str(), OpenAlways | WrOnly); diff --git a/util/system/guard.h b/util/system/guard.h index efc091d5f8..49d7a4b335 100644 --- a/util/system/guard.h +++ b/util/system/guard.h @@ -48,7 +48,7 @@ public: inline TGuard(TGuard&& g) noexcept : T_(g.T_) { - g.T_ = nullptr; + g.T_ = nullptr; } inline ~TGuard() { @@ -58,7 +58,7 @@ public: inline void Release() noexcept { if (WasAcquired()) { TOps::Release(T_); - T_ = nullptr; + T_ = nullptr; } } @@ -67,7 +67,7 @@ public: } inline bool WasAcquired() const noexcept { - return T_ != nullptr; + return T_ != nullptr; } inline T* GetMutex() const noexcept { @@ -150,12 +150,12 @@ public: inline void Release() noexcept { if (WasAcquired()) { TOps::Release(T_); - T_ = nullptr; + T_ = nullptr; } } inline bool WasAcquired() const noexcept { - return T_ != nullptr; + return T_ != nullptr; } explicit inline operator bool() const noexcept { @@ -164,7 +164,7 @@ public: private: inline void Init(const T* t) noexcept { - T_ = nullptr; + T_ = nullptr; T* tMutable = const_cast<T*>(t); if (TOps::TryAcquire(tMutable)) { T_ = tMutable; diff --git a/util/system/hostname.cpp b/util/system/hostname.cpp index 386f646d6b..2003c6d4d3 100644 --- a/util/system/hostname.cpp +++ b/util/system/hostname.cpp @@ -82,7 +82,7 @@ const char* GetFQDNHostName() { bool IsFQDN(const TString& name) { TString absName = name; - if (!absName.EndsWith('.')) { + if (!absName.EndsWith('.')) { absName.append("."); } diff --git a/util/system/hp_timer.cpp b/util/system/hp_timer.cpp index e4c3f21e6b..310db999e6 100644 --- a/util/system/hp_timer.cpp +++ b/util/system/hp_timer.cpp @@ -66,8 +66,8 @@ namespace { double vec[N_VEC]; - for (auto& i : vec) { - i = EstimateCPUClock(); + for (auto& i : vec) { + i = EstimateCPUClock(); } Sort(vec, vec + N_VEC); @@ -93,23 +93,23 @@ namespace { }; } -double NHPTimer::GetSeconds(const STime& a) noexcept { +double NHPTimer::GetSeconds(const STime& a) noexcept { return TFreq::Instance().GetSeconds(a); } -double NHPTimer::GetClockRate() noexcept { +double NHPTimer::GetClockRate() noexcept { return TFreq::Instance().GetClockRate(); } -ui64 NHPTimer::GetCyclesPerSecond() noexcept { +ui64 NHPTimer::GetCyclesPerSecond() noexcept { return TFreq::Instance().GetCyclesPerSecond(); } -void NHPTimer::GetTime(STime* pTime) noexcept { +void NHPTimer::GetTime(STime* pTime) noexcept { *pTime = GetCycleCount(); } -double NHPTimer::GetTimePassed(STime* pTime) noexcept { +double NHPTimer::GetTimePassed(STime* pTime) noexcept { STime old(*pTime); *pTime = GetCycleCount(); diff --git a/util/system/hp_timer.h b/util/system/hp_timer.h index 0a4c252ec2..ea02b660ed 100644 --- a/util/system/hp_timer.h +++ b/util/system/hp_timer.h @@ -5,29 +5,29 @@ namespace NHPTimer { using STime = i64; // May delay for ~50ms to compute frequency - double GetSeconds(const STime& a) noexcept; + double GetSeconds(const STime& a) noexcept; // Returns the current time - void GetTime(STime* pTime) noexcept; + void GetTime(STime* pTime) noexcept; // Returns the time passed since *pTime, and writes the current time into *pTime. - double GetTimePassed(STime* pTime) noexcept; + double GetTimePassed(STime* pTime) noexcept; // Get TSC frequency, may delay for ~50ms to compute frequency - double GetClockRate() noexcept; - // same as GetClockRate, but in integer - ui64 GetCyclesPerSecond() noexcept; + double GetClockRate() noexcept; + // same as GetClockRate, but in integer + ui64 GetCyclesPerSecond() noexcept; } struct THPTimer { THPTimer() noexcept { Reset(); } - void Reset() noexcept { + void Reset() noexcept { NHPTimer::GetTime(&Start); } - double Passed() const noexcept { + double Passed() const noexcept { NHPTimer::STime tmp = Start; return NHPTimer::GetTimePassed(&tmp); } - double PassedReset() noexcept { + double PassedReset() noexcept { return NHPTimer::GetTimePassed(&Start); } diff --git a/util/system/info.cpp b/util/system/info.cpp index cf6681e89a..78db83cd61 100644 --- a/util/system/info.cpp +++ b/util/system/info.cpp @@ -134,7 +134,7 @@ size_t NSystemInfo::NumberOfCpus() { mib[0] = CTL_HW; mib[1] = HW_NCPU; len = sizeof(ncpus); - if (sysctl(mib, 2, &ncpus, &len, nullptr, 0) == -1) { + if (sysctl(mib, 2, &ncpus, &len, nullptr, 0) == -1) { abort(); } diff --git a/util/system/mem_info.cpp b/util/system/mem_info.cpp index aa51ae3b16..e5f60b49be 100644 --- a/util/system/mem_info.cpp +++ b/util/system/mem_info.cpp @@ -134,7 +134,7 @@ namespace NMemInfo { Zero(proc); errno = 0; - if (sysctl((int*)mib, 4, &proc, &size, nullptr, 0) == -1) { + if (sysctl((int*)mib, 4, &proc, &size, nullptr, 0) == -1) { int err = errno; TString errtxt = LastSystemErrorText(err); ythrow yexception() << "sysctl({CTL_KERN,KERN_PROC,KERN_PROC_PID,pid},4,proc,&size,NULL,0) returned -1, errno: " << err << " (" << errtxt << ")" << Endl; diff --git a/util/system/mutex.cpp b/util/system/mutex.cpp index 4041402db9..b4513615a2 100644 --- a/util/system/mutex.cpp +++ b/util/system/mutex.cpp @@ -35,7 +35,7 @@ public: inline ~T() { int result = pthread_mutexattr_destroy(&Attr); - Y_VERIFY(result == 0, "mutexattr destroy(%s)", LastSystemErrorText(result)); + Y_VERIFY(result == 0, "mutexattr destroy(%s)", LastSystemErrorText(result)); } } pma; @@ -51,7 +51,7 @@ public: DeleteCriticalSection(&Obj); #else int result = pthread_mutex_destroy(&Obj); - Y_VERIFY(result == 0, "mutex destroy failure (%s)", LastSystemErrorText(result)); + Y_VERIFY(result == 0, "mutex destroy failure (%s)", LastSystemErrorText(result)); #endif } @@ -60,7 +60,7 @@ public: EnterCriticalSection(&Obj); #else int result = pthread_mutex_lock(&Obj); - Y_VERIFY(result == 0, "mutex lock failure (%s)", LastSystemErrorText(result)); + Y_VERIFY(result == 0, "mutex lock failure (%s)", LastSystemErrorText(result)); #endif } @@ -95,7 +95,7 @@ public: if (result == 0 || result == EBUSY) { return result == 0; } - Y_FAIL("mutex trylock failure (%s)", LastSystemErrorText(result)); + Y_FAIL("mutex trylock failure (%s)", LastSystemErrorText(result)); #endif } @@ -104,7 +104,7 @@ public: LeaveCriticalSection(&Obj); #else int result = pthread_mutex_unlock(&Obj); - Y_VERIFY(result == 0, "mutex unlock failure (%s)", LastSystemErrorText(result)); + Y_VERIFY(result == 0, "mutex unlock failure (%s)", LastSystemErrorText(result)); #endif } diff --git a/util/system/nice_ut.cpp b/util/system/nice_ut.cpp index ae0051f285..bc8d942da8 100644 --- a/util/system/nice_ut.cpp +++ b/util/system/nice_ut.cpp @@ -12,13 +12,13 @@ static int GetPriority() { } #endif -Y_UNIT_TEST_SUITE(NiceTest) { - Y_UNIT_TEST(TestNiceZero) { +Y_UNIT_TEST_SUITE(NiceTest) { + Y_UNIT_TEST(TestNiceZero) { UNIT_ASSERT(Nice(0)); UNIT_ASSERT(Nice(0)); } #ifdef _unix_ - Y_UNIT_TEST(TestNice) { + Y_UNIT_TEST(TestNice) { int prio = GetPriority(); if (prio >= 10) { diff --git a/util/system/pipe.cpp b/util/system/pipe.cpp index a543bd7472..6bb915513b 100644 --- a/util/system/pipe.cpp +++ b/util/system/pipe.cpp @@ -1,6 +1,6 @@ #include "pipe.h" -#include <util/stream/output.h> +#include <util/stream/output.h> #include <util/generic/yexception.h> ssize_t TPipeHandle::Read(void* buffer, size_t byteCount) const noexcept { diff --git a/util/system/pipe_ut.cpp b/util/system/pipe_ut.cpp index 6d53432de8..d120804e4b 100644 --- a/util/system/pipe_ut.cpp +++ b/util/system/pipe_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TPipeTest) { - Y_UNIT_TEST(TestPipe) { +Y_UNIT_TEST_SUITE(TPipeTest) { + Y_UNIT_TEST(TestPipe) { TPipe r; TPipe w; TPipe::Pipe(r, w); diff --git a/util/system/progname.cpp b/util/system/progname.cpp index 2c29119320..9ed924ad4c 100644 --- a/util/system/progname.cpp +++ b/util/system/progname.cpp @@ -18,7 +18,7 @@ namespace { } const TString& GetProgramName() { - return Singleton<TProgramNameHolder>()->ProgName; + return Singleton<TProgramNameHolder>()->ProgName; } void SetProgramName(const char* argv0) { diff --git a/util/system/progname_ut.cpp b/util/system/progname_ut.cpp index 11f3d9308b..6c2709e26e 100644 --- a/util/system/progname_ut.cpp +++ b/util/system/progname_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TProgramNameTest) { - Y_UNIT_TEST(TestIt) { +Y_UNIT_TEST_SUITE(TProgramNameTest) { + Y_UNIT_TEST(TestIt) { TString progName = GetProgramName(); try { diff --git a/util/system/rusage_ut.cpp b/util/system/rusage_ut.cpp index 0d4e0fe54b..dcb771be71 100644 --- a/util/system/rusage_ut.cpp +++ b/util/system/rusage_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TRusageTest) { - Y_UNIT_TEST(TestRusage) { +Y_UNIT_TEST_SUITE(TRusageTest) { + Y_UNIT_TEST(TestRusage) { TRusage r; // just check it returns something r.Fill(); diff --git a/util/system/rwlock.cpp b/util/system/rwlock.cpp index bb3dcbf188..067cbd5140 100644 --- a/util/system/rwlock.cpp +++ b/util/system/rwlock.cpp @@ -164,7 +164,7 @@ private: }; TRWMutex::TImpl::TImpl() { - int result = pthread_rwlock_init(&Lock_, nullptr); + int result = pthread_rwlock_init(&Lock_, nullptr); if (result != 0) { ythrow yexception() << "rwlock init failed (" << LastSystemErrorText(result) << ")"; } @@ -172,44 +172,44 @@ TRWMutex::TImpl::TImpl() { TRWMutex::TImpl::~TImpl() { const int result = pthread_rwlock_destroy(&Lock_); - Y_VERIFY(result == 0, "rwlock destroy failed (%s)", LastSystemErrorText(result)); + Y_VERIFY(result == 0, "rwlock destroy failed (%s)", LastSystemErrorText(result)); } void TRWMutex::TImpl::AcquireRead() noexcept { const int result = pthread_rwlock_rdlock(&Lock_); - Y_VERIFY(result == 0, "rwlock rdlock failed (%s)", LastSystemErrorText(result)); + Y_VERIFY(result == 0, "rwlock rdlock failed (%s)", LastSystemErrorText(result)); } bool TRWMutex::TImpl::TryAcquireRead() noexcept { const int result = pthread_rwlock_tryrdlock(&Lock_); - Y_VERIFY(result == 0 || result == EBUSY, "rwlock tryrdlock failed (%s)", LastSystemErrorText(result)); + Y_VERIFY(result == 0 || result == EBUSY, "rwlock tryrdlock failed (%s)", LastSystemErrorText(result)); return result == 0; } void TRWMutex::TImpl::ReleaseRead() noexcept { const int result = pthread_rwlock_unlock(&Lock_); - Y_VERIFY(result == 0, "rwlock (read) unlock failed (%s)", LastSystemErrorText(result)); + Y_VERIFY(result == 0, "rwlock (read) unlock failed (%s)", LastSystemErrorText(result)); } void TRWMutex::TImpl::AcquireWrite() noexcept { const int result = pthread_rwlock_wrlock(&Lock_); - Y_VERIFY(result == 0, "rwlock wrlock failed (%s)", LastSystemErrorText(result)); + Y_VERIFY(result == 0, "rwlock wrlock failed (%s)", LastSystemErrorText(result)); } bool TRWMutex::TImpl::TryAcquireWrite() noexcept { const int result = pthread_rwlock_trywrlock(&Lock_); - Y_VERIFY(result == 0 || result == EBUSY, "rwlock trywrlock failed (%s)", LastSystemErrorText(result)); + Y_VERIFY(result == 0 || result == EBUSY, "rwlock trywrlock failed (%s)", LastSystemErrorText(result)); return result == 0; } void TRWMutex::TImpl::ReleaseWrite() noexcept { const int result = pthread_rwlock_unlock(&Lock_); - Y_VERIFY(result == 0, "rwlock (write) unlock failed (%s)", LastSystemErrorText(result)); + Y_VERIFY(result == 0, "rwlock (write) unlock failed (%s)", LastSystemErrorText(result)); } void TRWMutex::TImpl::Release() noexcept { const int result = pthread_rwlock_unlock(&Lock_); - Y_VERIFY(result == 0, "rwlock unlock failed (%s)", LastSystemErrorText(result)); + Y_VERIFY(result == 0, "rwlock unlock failed (%s)", LastSystemErrorText(result)); } #endif diff --git a/util/system/sanitizers_ut.cpp b/util/system/sanitizers_ut.cpp index 5de096e14b..99480202a6 100644 --- a/util/system/sanitizers_ut.cpp +++ b/util/system/sanitizers_ut.cpp @@ -3,8 +3,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(Sanitizers) { - Y_UNIT_TEST(MarkAsIntentionallyLeaked) { +Y_UNIT_TEST_SUITE(Sanitizers) { + Y_UNIT_TEST(MarkAsIntentionallyLeaked) { auto* p1 = new i32[100]; NSan::MarkAsIntentionallyLeaked(p1); @@ -12,4 +12,4 @@ Y_UNIT_TEST_SUITE(Sanitizers) { NSan::MarkAsIntentionallyLeaked(p2); } -} // Y_UNIT_TEST_SUITE(Sanitizers) +} // Y_UNIT_TEST_SUITE(Sanitizers) diff --git a/util/system/sem.cpp b/util/system/sem.cpp index 4a93b903b5..8263992de4 100644 --- a/util/system/sem.cpp +++ b/util/system/sem.cpp @@ -129,7 +129,7 @@ namespace { #else int ret = sem_post(Handle); #endif - Y_VERIFY(ret == 0, "can not release semaphore"); + Y_VERIFY(ret == 0, "can not release semaphore"); #endif } @@ -137,7 +137,7 @@ namespace { //hence to maintain consistancy, for win32 case we use INFINITE or 0 timeout. inline void Acquire() noexcept { #ifdef _win_ - Y_VERIFY(::WaitForSingleObject(Handle, INFINITE) == WAIT_OBJECT_0, "can not acquire semaphore"); + Y_VERIFY(::WaitForSingleObject(Handle, INFINITE) == WAIT_OBJECT_0, "can not acquire semaphore"); #else #ifdef USE_SYSV_SEMAPHORES struct sembuf ops[] = {{0, -1, SEM_UNDO}}; @@ -145,7 +145,7 @@ namespace { #else int ret = sem_wait(Handle); #endif - Y_VERIFY(ret == 0, "can not acquire semaphore"); + Y_VERIFY(ret == 0, "can not acquire semaphore"); #endif } @@ -183,20 +183,20 @@ namespace { } inline ~TPosixSemaphore() { - Y_VERIFY(sem_destroy(&S_) == 0, "semaphore destroy failed"); + Y_VERIFY(sem_destroy(&S_) == 0, "semaphore destroy failed"); } inline void Acquire() noexcept { - Y_VERIFY(sem_wait(&S_) == 0, "semaphore acquire failed"); + Y_VERIFY(sem_wait(&S_) == 0, "semaphore acquire failed"); } inline void Release() noexcept { - Y_VERIFY(sem_post(&S_) == 0, "semaphore release failed"); + Y_VERIFY(sem_post(&S_) == 0, "semaphore release failed"); } inline bool TryAcquire() noexcept { if (sem_trywait(&S_)) { - Y_VERIFY(errno == EAGAIN, "semaphore try wait failed"); + Y_VERIFY(errno == EAGAIN, "semaphore try wait failed"); return false; } diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp index b1989b5c8c..7ba438be12 100644 --- a/util/system/shellcommand.cpp +++ b/util/system/shellcommand.cpp @@ -2,16 +2,16 @@ #include "user.h" #include "nice.h" #include "sigset.h" -#include "atomic.h" - +#include "atomic.h" + #include <util/folder/dirut.h> -#include <util/generic/algorithm.h> -#include <util/generic/buffer.h> -#include <util/generic/vector.h> -#include <util/generic/yexception.h> -#include <util/memory/tempbuf.h> +#include <util/generic/algorithm.h> +#include <util/generic/buffer.h> +#include <util/generic/vector.h> +#include <util/generic/yexception.h> +#include <util/memory/tempbuf.h> #include <util/network/socket.h> -#include <util/stream/pipe.h> +#include <util/stream/pipe.h> #include <util/stream/str.h> #include <util/string/cast.h> #include <util/system/info.h> @@ -157,13 +157,13 @@ public: ssize_t Read(void* buffer, size_t byteCount) const noexcept { DWORD doneBytes; - if (!ReadFile(Fd_, buffer, byteCount, &doneBytes, nullptr)) + if (!ReadFile(Fd_, buffer, byteCount, &doneBytes, nullptr)) return -1; return doneBytes; } ssize_t Write(const void* buffer, size_t byteCount) const noexcept { DWORD doneBytes; - if (!WriteFile(Fd_, buffer, byteCount, &doneBytes, nullptr)) + if (!WriteFile(Fd_, buffer, byteCount, &doneBytes, nullptr)) return -1; return doneBytes; } @@ -196,9 +196,9 @@ private: TString WorkDir; TAtomic ExecutionStatus; // TShellCommand::ECommandStatus TMaybe<int> ExitCode; - IInputStream* InputStream; - IOutputStream* OutputStream; - IOutputStream* ErrorStream; + IInputStream* InputStream; + IOutputStream* OutputStream; + IOutputStream* ErrorStream; TString CollectedOutput; TString CollectedError; TString InternalError; @@ -289,7 +289,7 @@ public: , InputStream(options.InputStream) , OutputStream(options.OutputStream) , ErrorStream(options.ErrorStream) - , WatchThread(nullptr) + , WatchThread(nullptr) , TerminateFlag(false) , ClearSignalMask(options.ClearSignalMask) , CloseAllFdsOnExec(options.CloseAllFdsOnExec) @@ -330,36 +330,36 @@ public: #endif } - inline void AppendArgument(const TStringBuf argument) { - if (AtomicGet(ExecutionStatus) == SHELL_RUNNING) { + inline void AppendArgument(const TStringBuf argument) { + if (AtomicGet(ExecutionStatus) == SHELL_RUNNING) { ythrow yexception() << "You cannot change command parameters while process is running"; } Arguments.push_back(ToString(argument)); } inline const TString& GetOutput() const { - if (AtomicGet(ExecutionStatus) == SHELL_RUNNING) { + if (AtomicGet(ExecutionStatus) == SHELL_RUNNING) { ythrow yexception() << "You cannot retrieve output while process is running."; } return CollectedOutput; } inline const TString& GetError() const { - if (AtomicGet(ExecutionStatus) == SHELL_RUNNING) { + if (AtomicGet(ExecutionStatus) == SHELL_RUNNING) { ythrow yexception() << "You cannot retrieve output while process is running."; } return CollectedError; } inline const TString& GetInternalError() const { - if (AtomicGet(ExecutionStatus) != SHELL_INTERNAL_ERROR) { + if (AtomicGet(ExecutionStatus) != SHELL_INTERNAL_ERROR) { ythrow yexception() << "Internal error hasn't occured so can't be retrieved."; } return InternalError; } inline ECommandStatus GetStatus() const { - return static_cast<ECommandStatus>(AtomicGet(ExecutionStatus)); + return static_cast<ECommandStatus>(AtomicGet(ExecutionStatus)); } inline TMaybe<int> GetExitCode() const { @@ -390,7 +390,7 @@ public: void Run(); inline void Terminate() { - if (!!Pid && (AtomicGet(ExecutionStatus) == SHELL_RUNNING)) { + if (!!Pid && (AtomicGet(ExecutionStatus) == SHELL_RUNNING)) { bool ok = #if defined(_unix_) kill(DetachSession ? -1 * Pid : Pid, SIGTERM) == 0; @@ -446,7 +446,7 @@ public: inline static void* WatchProcess(void* data) { TProcessInfo* pi = reinterpret_cast<TProcessInfo*>(data); Communicate(pi); - return nullptr; + return nullptr; } inline static void* ReadStream(void* data) noexcept { @@ -573,7 +573,7 @@ void TShellCommand::TImpl::StartProcess(TShellCommand::TImpl::TPipes& pipes) { cwd = cwdBuff.c_str(); } - void* lpEnvironment = nullptr; + void* lpEnvironment = nullptr; TString env; if (!Environment.empty()) { for (auto e = Environment.begin(); e != Environment.end(); ++e) { @@ -590,7 +590,7 @@ void TShellCommand::TImpl::StartProcess(TShellCommand::TImpl::TPipes& pipes) { BOOL res = 0; if (User.Name.empty() || GetUsername() == User.Name) { res = CreateProcessW( - nullptr, // image name + nullptr, // image name cmdcopy.Data(), nullptr, // process security attributes nullptr, // thread security attributes @@ -603,7 +603,7 @@ void TShellCommand::TImpl::StartProcess(TShellCommand::TImpl::TPipes& pipes) { } else { res = CreateProcessWithLogonW( GetWString(User.Name.data()).c_str(), - nullptr, // domain (if this parameter is NULL, the user name must be specified in UPN format) + nullptr, // domain (if this parameter is NULL, the user name must be specified in UPN format) GetWString(User.Password.data()).c_str(), 0, // logon flags NULL, // image name @@ -616,7 +616,7 @@ void TShellCommand::TImpl::StartProcess(TShellCommand::TImpl::TPipes& pipes) { } if (!res) { - AtomicSet(ExecutionStatus, SHELL_ERROR); + AtomicSet(ExecutionStatus, SHELL_ERROR); /// @todo: write to error stream if set TStringOutput out(CollectedError); out << "Process was not created: " << LastSystemErrorText() << " command text was: '" << GetAString(cmdcopy.Data()) << "'"; @@ -653,12 +653,12 @@ bool ArgNeedsQuotes(TStringBuf arg) noexcept { TString TShellCommand::TImpl::GetQuotedCommand() const { TString quoted = Command; /// @todo command itself should be quoted too - for (const auto& argument : Arguments) { + for (const auto& argument : Arguments) { // Don't add unnecessary quotes. It's especially important for the windows with a 32k command line length limit. if (QuoteArguments && ArgNeedsQuotes(argument)) { - ::ShellQuoteArgSp(quoted, argument); + ::ShellQuoteArgSp(quoted, argument); } else { - quoted.append(" ").append(argument); + quoted.append(" ").append(argument); } } return quoted; @@ -678,13 +678,13 @@ void TShellCommand::TImpl::OnFork(TPipes& pipes, sigset_t oldmask, char* const* SigEmptySet(&sa.sa_mask); for (int i = 0; i < NSIG; ++i) { // some signals cannot be caught, so just ignore return value - sigaction(i, &sa, nullptr); + sigaction(i, &sa, nullptr); } if (ClearSignalMask) { SigEmptySet(&oldmask); } // clear / restore signal mask - if (SigProcMask(SIG_SETMASK, &oldmask, nullptr) != 0) { + if (SigProcMask(SIG_SETMASK, &oldmask, nullptr) != 0) { ythrow TSystemError() << "Cannot " << (ClearSignalMask ? "clear" : "restore") << " signal mask in child"; } @@ -772,7 +772,7 @@ void TShellCommand::TImpl::Run() { TRealPipeHandle::Pipe(pipes.InputPipeFd[0], pipes.InputPipeFd[1], CloseOnExec); } - AtomicSet(ExecutionStatus, SHELL_RUNNING); + AtomicSet(ExecutionStatus, SHELL_RUNNING); #if defined(_unix_) // block all signals to avoid signal handler race after fork() @@ -819,7 +819,7 @@ void TShellCommand::TImpl::Run() { pid_t pid = fork(); if (pid == -1) { - AtomicSet(ExecutionStatus, SHELL_ERROR); + AtomicSet(ExecutionStatus, SHELL_ERROR); /// @todo check if pipes are still open ythrow TSystemError() << "Cannot fork"; } else if (pid == 0) { // child @@ -830,7 +830,7 @@ void TShellCommand::TImpl::Run() { } } else { // parent // restore signal mask - if (SigProcMask(SIG_SETMASK, &oldmask, nullptr) != 0) { + if (SigProcMask(SIG_SETMASK, &oldmask, nullptr) != 0) { ythrow TSystemError() << "Cannot restore signal mask in parent"; } } @@ -873,19 +873,19 @@ void TShellCommand::TImpl::Run() { } void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { - THolder<IOutputStream> outputHolder; - IOutputStream* output = pi->Parent->OutputStream; + THolder<IOutputStream> outputHolder; + IOutputStream* output = pi->Parent->OutputStream; if (!output) { outputHolder.Reset(output = new TStringOutput(pi->Parent->CollectedOutput)); } - THolder<IOutputStream> errorHolder; - IOutputStream* error = pi->Parent->ErrorStream; + THolder<IOutputStream> errorHolder; + IOutputStream* error = pi->Parent->ErrorStream; if (!error) { errorHolder.Reset(error = new TStringOutput(pi->Parent->CollectedError)); } - IInputStream*& input = pi->Parent->InputStream; + IInputStream*& input = pi->Parent->InputStream; #if defined(_unix_) // not really needed, io is done via poll @@ -922,7 +922,7 @@ void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { TBuffer inputBuffer(DATA_BUFFER_SIZE); int bytes; int bytesToWrite = 0; - char* bufPos = nullptr; + char* bufPos = nullptr; #endif TWaitResult waitPidResult; TExitStatus status = 0; @@ -940,7 +940,7 @@ void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { waitpid(pi->Parent->Pid, &status, WNOHANG); #else WaitForSingleObject(pi->Parent->Pid /* process_info.hProcess */, pi->Parent->PollDelayMs /* ms */); - Y_UNUSED(status); + Y_UNUSED(status); #endif // DBG(Cerr << "wait result: " << waitPidResult << Endl); if (waitPidResult != WAIT_PROCEED) { @@ -999,13 +999,13 @@ void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { if ((fds[1].revents & POLLIN) == POLLIN) { haveOut = true; } else if (fds[1].revents & (POLLERR | POLLHUP)) { - output = nullptr; + output = nullptr; } if ((fds[2].revents & POLLIN) == POLLIN) { haveErr = true; } else if (fds[2].revents & (POLLERR | POLLHUP)) { - error = nullptr; + error = nullptr; } if (input && ((fds[0].revents & POLLOUT) == POLLOUT)) { @@ -1018,7 +1018,7 @@ void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { if (bytes > 0) { output->Write(buffer.Data(), bytes); } else { - output = nullptr; + output = nullptr; } } if (haveErr) { @@ -1027,7 +1027,7 @@ void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { if (bytes > 0) { error->Write(buffer.Data(), bytes); } else { - error = nullptr; + error = nullptr; } } @@ -1048,7 +1048,7 @@ void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { bytesToWrite -= bytes; bufPos += bytes; } else { - input = nullptr; + input = nullptr; } DBG(Cerr << "transferred " << bytes << " bytes of input" << Endl); @@ -1084,9 +1084,9 @@ void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { #endif pi->Parent->ExitCode = processExitCode; if (cleanExit) { - AtomicSet(pi->Parent->ExecutionStatus, SHELL_FINISHED); + AtomicSet(pi->Parent->ExecutionStatus, SHELL_FINISHED); } else { - AtomicSet(pi->Parent->ExecutionStatus, SHELL_ERROR); + AtomicSet(pi->Parent->ExecutionStatus, SHELL_ERROR); } #if defined(_win_) @@ -1109,7 +1109,7 @@ void TShellCommand::TImpl::Communicate(TProcessInfo* pi) { #endif } catch (const yexception& e) { // Some error in watch occured, set result to error - AtomicSet(pi->Parent->ExecutionStatus, SHELL_INTERNAL_ERROR); + AtomicSet(pi->Parent->ExecutionStatus, SHELL_INTERNAL_ERROR); pi->Parent->InternalError = e.what(); if (input) { pi->InputFd.Close(); @@ -1134,7 +1134,7 @@ TShellCommand::TShellCommand(const TStringBuf cmd, const TShellCommandOptions& o TShellCommand::~TShellCommand() = default; -TShellCommand& TShellCommand::operator<<(const TStringBuf argument) { +TShellCommand& TShellCommand::operator<<(const TStringBuf argument) { Impl->AppendArgument(argument); return *this; } diff --git a/util/system/shellcommand.h b/util/system/shellcommand.h index 8730627fe5..6141b8ae0e 100644 --- a/util/system/shellcommand.h +++ b/util/system/shellcommand.h @@ -129,7 +129,7 @@ public: * * @return self */ - inline TShellCommandOptions& SetInputStream(IInputStream* stream) { + inline TShellCommandOptions& SetInputStream(IInputStream* stream) { InputStream = stream; if (InputStream == nullptr) { InputMode = HANDLE_INHERIT; @@ -148,7 +148,7 @@ public: * * @return self */ - inline TShellCommandOptions& SetOutputStream(IOutputStream* stream) { + inline TShellCommandOptions& SetOutputStream(IOutputStream* stream) { OutputStream = stream; return *this; } @@ -162,7 +162,7 @@ public: * * @return self */ - inline TShellCommandOptions& SetErrorStream(IOutputStream* stream) { + inline TShellCommandOptions& SetErrorStream(IOutputStream* stream) { ErrorStream = stream; return *this; } @@ -313,10 +313,10 @@ public: // bool SearchPath // search exe name in $PATH // bool UnicodeConsole // bool EmulateConsole // provide isatty == true - /// @todo command's stdin should be exposet as IOutputStream to support dialogue - IInputStream* InputStream; - IOutputStream* OutputStream; - IOutputStream* ErrorStream; + /// @todo command's stdin should be exposet as IOutputStream to support dialogue + IInputStream* InputStream; + IOutputStream* OutputStream; + IOutputStream* ErrorStream; TUserOptions User; THashMap<TString, TString> Environment; int Nice = 0; @@ -364,7 +364,7 @@ public: * * @return self */ - TShellCommand& operator<<(const TStringBuf argument); + TShellCommand& operator<<(const TStringBuf argument); /** * @brief return the collected output from the command. diff --git a/util/system/shellcommand_ut.cpp b/util/system/shellcommand_ut.cpp index 9d849279d2..5546c41dd3 100644 --- a/util/system/shellcommand_ut.cpp +++ b/util/system/shellcommand_ut.cpp @@ -27,7 +27,7 @@ const char catCommand[] = "/bin/cat"; const size_t textSize = 20000; #endif -class TGuardedStringStream: public IInputStream, public IOutputStream { +class TGuardedStringStream: public IInputStream, public IOutputStream { public: TGuardedStringStream() { Stream_.Reserve(100); @@ -59,8 +59,8 @@ private: TStringStream Stream_; }; -Y_UNIT_TEST_SUITE(TShellQuoteTest) { - Y_UNIT_TEST(TestQuoteArg) { +Y_UNIT_TEST_SUITE(TShellQuoteTest) { + Y_UNIT_TEST(TestQuoteArg) { TString cmd; ShellQuoteArg(cmd, "/pr f/krev/prev.exe"); ShellQuoteArgSp(cmd, "-DVal=\"W Quotes\""); @@ -70,8 +70,8 @@ Y_UNIT_TEST_SUITE(TShellQuoteTest) { } } -Y_UNIT_TEST_SUITE(TShellCommandTest) { - Y_UNIT_TEST(TestNoQuotes) { +Y_UNIT_TEST_SUITE(TShellCommandTest) { + Y_UNIT_TEST(TestNoQuotes) { TShellCommandOptions options; options.SetQuoteArguments(false); TShellCommand cmd("echo hello"); @@ -97,7 +97,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); } - Y_UNIT_TEST(TestRun) { + Y_UNIT_TEST(TestRun) { TShellCommand cmd("echo"); cmd << "hello"; cmd.Run(); @@ -112,7 +112,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { } // running with no shell is not implemented for win // there should be no problem with it as long as SearchPath is on - Y_UNIT_TEST(TestNoShell) { + Y_UNIT_TEST(TestNoShell) { #if defined(_win_) const char dir[] = "dir"; #else @@ -143,7 +143,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); } } - Y_UNIT_TEST(TestAsyncRun) { + Y_UNIT_TEST(TestAsyncRun) { TShellCommandOptions options; options.SetAsync(true); #if defined(_win_) @@ -168,7 +168,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); #endif } - Y_UNIT_TEST(TestQuotes) { + Y_UNIT_TEST(TestQuotes) { TShellCommandOptions options; TString input = TString("a\"a a"); TString output; @@ -185,14 +185,14 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { #endif UNIT_ASSERT_VALUES_EQUAL(cmd.GetError().size(), 0u); } - Y_UNIT_TEST(TestRunNonexistent) { + Y_UNIT_TEST(TestRunNonexistent) { TShellCommand cmd("iwerognweiofnewio"); // some nonexistent command name cmd.Run().Wait(); UNIT_ASSERT(TShellCommand::SHELL_ERROR == cmd.GetStatus()); UNIT_ASSERT_VALUES_UNEQUAL(cmd.GetError().size(), 0u); UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 != cmd.GetExitCode()); } - Y_UNIT_TEST(TestExitCode) { + Y_UNIT_TEST(TestExitCode) { TShellCommand cmd("grep qwerty qwerty"); // some nonexistent file name cmd.Run().Wait(); UNIT_ASSERT(TShellCommand::SHELL_ERROR == cmd.GetStatus()); @@ -200,7 +200,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT(cmd.GetExitCode().Defined() && 2 == cmd.GetExitCode()); } // 'type con' and 'copy con con' want real console, not stdin, use sort - Y_UNIT_TEST(TestInput) { + Y_UNIT_TEST(TestInput) { TShellCommandOptions options; TString input = (TString("a") * 2000).append(NL) * textSize; TStringInput inputStream(input); @@ -210,7 +210,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT_VALUES_EQUAL(input, cmd.GetOutput()); UNIT_ASSERT_VALUES_EQUAL(cmd.GetError().size(), 0u); } - Y_UNIT_TEST(TestOutput) { + Y_UNIT_TEST(TestOutput) { TShellCommandOptions options; TString input = (TString("a") * 2000).append(NL) * textSize; TStringInput inputStream(input); @@ -223,7 +223,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT_VALUES_EQUAL(input, output); UNIT_ASSERT_VALUES_EQUAL(cmd.GetError().size(), 0u); } - Y_UNIT_TEST(TestIO) { + Y_UNIT_TEST(TestIO) { // descriptive test: use all options TShellCommandOptions options; options.SetAsync(true); @@ -260,12 +260,12 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT_VALUES_EQUAL(read.Str(), "alpha" NL "omega" NL "zeta" NL); UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); } - Y_UNIT_TEST(TestStreamClose) { - struct TStream: public IOutputStream { + Y_UNIT_TEST(TestStreamClose) { + struct TStream: public IOutputStream { size_t NumCloses = 0; void DoWrite(const void* buf, size_t len) override { - Y_UNUSED(buf); - Y_UNUSED(len); + Y_UNUSED(buf); + Y_UNUSED(len); } void DoFinish() override { ++NumCloses; @@ -280,7 +280,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { TShellCommand("echo hello", options).Run().Wait(); UNIT_ASSERT_VALUES_EQUAL(stream.NumCloses, 2); } - Y_UNIT_TEST(TestInterruptSimple) { + Y_UNIT_TEST(TestInterruptSimple) { TShellCommandOptions options; options.SetAsync(true); options.SetCloseInput(false); @@ -296,7 +296,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { } #if !defined(_win_) // this ut is unix-only, port to win using %TEMP% - Y_UNIT_TEST(TestInterrupt) { + Y_UNIT_TEST(TestInterrupt) { TString tmpfile = TString("shellcommand_ut.interrupt.") + ToString(RandomNumber<ui32>()); TShellCommandOptions options; @@ -318,7 +318,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT(!NFs::Exists(tmpfile)); } // this ut is unix-only (win has no signal mask) - Y_UNIT_TEST(TestSignalMask) { + Y_UNIT_TEST(TestSignalMask) { // block SIGTERM int rc; sigset_t newmask, oldmask; @@ -365,7 +365,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT(!NFs::Exists(tmpfile)); // restore signal mask - rc = SigProcMask(SIG_SETMASK, &oldmask, nullptr); + rc = SigProcMask(SIG_SETMASK, &oldmask, nullptr); UNIT_ASSERT(rc == 0); } #else @@ -380,10 +380,10 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { UNIT_ASSERT(cmd.GetExitCode().Defined() && 0 == cmd.GetExitCode()); } #endif - Y_UNIT_TEST(TestInternalError) { + Y_UNIT_TEST(TestInternalError) { TString input = (TString("a") * 2000).append("\n"); TStringInput inputStream(input); - TMemoryOutput outputStream(nullptr, 0); + TMemoryOutput outputStream(nullptr, 0); TShellCommandOptions options; options.SetInputStream(&inputStream); options.SetOutputStream(&outputStream); diff --git a/util/system/shmat.cpp b/util/system/shmat.cpp index 07ff0d6caa..663e63bc12 100644 --- a/util/system/shmat.cpp +++ b/util/system/shmat.cpp @@ -91,7 +91,7 @@ namespace { TSharedMemory::TSharedMemory() : Handle(INVALID_FHANDLE) - , Data(nullptr) + , Data(nullptr) , Size(0) { } @@ -102,7 +102,7 @@ static void FormatName(char* buf, const TGUID& id) { } bool TSharedMemory::Open(const TGUID& id, int size) { - //Y_ASSERT(Data == 0); + //Y_ASSERT(Data == 0); Id = id; Size = size; @@ -117,7 +117,7 @@ bool TSharedMemory::Open(const TGUID& id, int size) { Data = MapViewOfFile(Handle, FILE_MAP_ALL_ACCESS, 0, 0, size); if (Data == 0) { - //Y_ASSERT(0); + //Y_ASSERT(0); CloseHandle(Handle); Handle = INVALID_OS_HANDLE; @@ -128,7 +128,7 @@ bool TSharedMemory::Open(const TGUID& id, int size) { } bool TSharedMemory::Create(int size) { - //Y_ASSERT(Data == 0); + //Y_ASSERT(Data == 0); Size = size; CreateGuid(&Id); @@ -138,14 +138,14 @@ bool TSharedMemory::Create(int size) { Handle = CreateFileMappingA(INVALID_OS_HANDLE, nullptr, PAGE_READWRITE, 0, size, name); if (Handle == 0) { - //Y_ASSERT(0); + //Y_ASSERT(0); return false; } Data = MapViewOfFile(Handle, FILE_MAP_ALL_ACCESS, 0, 0, size); if (Data == 0) { - //Y_ASSERT(0); + //Y_ASSERT(0); CloseHandle(Handle); Handle = INVALID_OS_HANDLE; @@ -172,7 +172,7 @@ static key_t GetKey(const TGUID& id) { bool TSharedMemory::Open(const TGUID& id, int size) { Y_VERIFY(id, "invalid shared memory guid: %s", GetGuidAsString(id).data()); - //Y_ASSERT(Data == 0); + //Y_ASSERT(Data == 0); Size = size; key_t k = GetKey(id); @@ -182,10 +182,10 @@ bool TSharedMemory::Open(const TGUID& id, int size) { return false; } - Data = shmat(shmId, nullptr, 0); + Data = shmat(shmId, nullptr, 0); - if (Data == nullptr) { - //Y_ASSERT(0); + if (Data == nullptr) { + //Y_ASSERT(0); return false; } @@ -193,7 +193,7 @@ bool TSharedMemory::Open(const TGUID& id, int size) { } bool TSharedMemory::Create(int size) { - //Y_ASSERT(Data == 0); + //Y_ASSERT(Data == 0); Size = size; CreateGuid(&Id); @@ -202,14 +202,14 @@ bool TSharedMemory::Create(int size) { Handle = shmget(k, Size, IPC_CREAT | IPC_EXCL | 0777); if (Handle < 0) { - //Y_ASSERT(0); + //Y_ASSERT(0); return false; } Data = shmat(Handle, nullptr, 0); if (Data == (void*)-1) { - //Y_ASSERT(0); + //Y_ASSERT(0); shmctl(Handle, IPC_RMID, nullptr); Handle = -1; diff --git a/util/system/shmat_ut.cpp b/util/system/shmat_ut.cpp index 9d92243ae7..45921aaa88 100644 --- a/util/system/shmat_ut.cpp +++ b/util/system/shmat_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TTestSharedMemory) { - Y_UNIT_TEST(TestInProc) { +Y_UNIT_TEST_SUITE(TTestSharedMemory) { + Y_UNIT_TEST(TestInProc) { TSharedMemory m1; TSharedMemory m2; diff --git a/util/system/sigset.h b/util/system/sigset.h index 8dd02fd817..ed6f768e02 100644 --- a/util/system/sigset.h +++ b/util/system/sigset.h @@ -22,7 +22,7 @@ inline int SigEmptySet(sigset_t* set) { #if defined _unix_ return sigemptyset(set); #else - Y_UNUSED(set); + Y_UNUSED(set); return 0; #endif } @@ -31,7 +31,7 @@ inline int SigFillSet(sigset_t* set) { #if defined _unix_ return sigfillset(set); #else - Y_UNUSED(set); + Y_UNUSED(set); return 0; #endif } @@ -40,8 +40,8 @@ inline int SigAddSet(sigset_t* set, int signo) { #if defined _unix_ return sigaddset(set, signo); #else - Y_UNUSED(set); - Y_UNUSED(signo); + Y_UNUSED(set); + Y_UNUSED(signo); return 0; #endif } @@ -50,8 +50,8 @@ inline int SigDelSet(sigset_t* set, int signo) { #if defined _unix_ return sigdelset(set, signo); #else - Y_UNUSED(set); - Y_UNUSED(signo); + Y_UNUSED(set); + Y_UNUSED(signo); return 0; #endif } @@ -60,8 +60,8 @@ inline int SigIsMember(const sigset_t* set, int signo) { #if defined _unix_ return sigismember(const_cast<sigset_t*>(set), signo); #else - Y_UNUSED(set); - Y_UNUSED(signo); + Y_UNUSED(set); + Y_UNUSED(signo); return 0; #endif } @@ -70,9 +70,9 @@ inline int SigProcMask(int how, const sigset_t* set, sigset_t* oset) { #if defined _unix_ return pthread_sigmask(how, set, oset); #else - Y_UNUSED(set); - Y_UNUSED(oset); - Y_UNUSED(how); + Y_UNUSED(set); + Y_UNUSED(oset); + Y_UNUSED(how); return 0; #endif } diff --git a/util/system/spinlock_ut.cpp b/util/system/spinlock_ut.cpp index e8639a6404..384aafab0b 100644 --- a/util/system/spinlock_ut.cpp +++ b/util/system/spinlock_ut.cpp @@ -2,7 +2,7 @@ #include "spinlock.h" -Y_UNIT_TEST_SUITE(TSpinLock) { +Y_UNIT_TEST_SUITE(TSpinLock) { template <typename TLock> void TestLock() { TLock lock; @@ -27,11 +27,11 @@ Y_UNIT_TEST_SUITE(TSpinLock) { UNIT_ASSERT(!lock.IsLocked()); } - Y_UNIT_TEST(TSpinLock_IsLocked) { + Y_UNIT_TEST(TSpinLock_IsLocked) { TestLock<TSpinLock>(); } - Y_UNIT_TEST(TAdaptiveLock_IsLocked) { + Y_UNIT_TEST(TAdaptiveLock_IsLocked) { TestLock<TAdaptiveLock>(); } } diff --git a/util/system/src_location.cpp b/util/system/src_location.cpp index 13ff1f24b3..5d9ce4fd13 100644 --- a/util/system/src_location.cpp +++ b/util/system/src_location.cpp @@ -5,7 +5,7 @@ #include <algorithm> template <> -void Out<TSourceLocation>(IOutputStream& o, const TSourceLocation& t) { +void Out<TSourceLocation>(IOutputStream& o, const TSourceLocation& t) { #if defined(_win_) TString file(t.File); std::replace(file.begin(), file.vend(), '\\', '/'); diff --git a/util/system/src_location.h b/util/system/src_location.h index 12ba6e063e..ed911e0169 100644 --- a/util/system/src_location.h +++ b/util/system/src_location.h @@ -5,7 +5,7 @@ #include <util/generic/strbuf.h> struct TSourceLocation { - constexpr TSourceLocation(const TStringBuf f, int l) noexcept + constexpr TSourceLocation(const TStringBuf f, int l) noexcept : File(f) , Line(l) { diff --git a/util/system/src_location_ut.cpp b/util/system/src_location_ut.cpp index 5b86cb86ef..400bf6d8d3 100644 --- a/util/system/src_location_ut.cpp +++ b/util/system/src_location_ut.cpp @@ -8,8 +8,8 @@ static inline TString GenLoc() { return TStringBuilder() << __LOCATION__; } -Y_UNIT_TEST_SUITE(TestLocation) { - Y_UNIT_TEST(Test1) { +Y_UNIT_TEST_SUITE(TestLocation) { + Y_UNIT_TEST(Test1) { UNIT_ASSERT_VALUES_EQUAL(GenLoc(), "util/system/src_location_ut.cpp:8"); static constexpr TSourceLocation location = __LOCATION__; diff --git a/util/system/src_root.h b/util/system/src_root.h index 4f2d9f5ee6..25f380f723 100644 --- a/util/system/src_root.h +++ b/util/system/src_root.h @@ -7,19 +7,19 @@ namespace NPrivate { struct TStaticBuf { - constexpr TStaticBuf(const char* data, unsigned len) noexcept + constexpr TStaticBuf(const char* data, unsigned len) noexcept : Data(data) , Len(len) { } template <class T> - constexpr T As() const noexcept { + constexpr T As() const noexcept { return T(Data, Len); } template <class T> - constexpr operator T() const noexcept { + constexpr operator T() const noexcept { return this->As<T>(); } diff --git a/util/system/src_root_ut.cpp b/util/system/src_root_ut.cpp index e9a675eb9a..57255786d4 100644 --- a/util/system/src_root_ut.cpp +++ b/util/system/src_root_ut.cpp @@ -3,8 +3,8 @@ #include <util/folder/pathsplit.h> #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TestSourceRoot) { - Y_UNIT_TEST(TestStrip) { +Y_UNIT_TEST_SUITE(TestSourceRoot) { + Y_UNIT_TEST(TestStrip) { // Reconstruct() converts "\" -> "/" on Windows const TString path = TPathSplit(__SOURCE_FILE_IMPL__.As<TStringBuf>()).Reconstruct(); UNIT_ASSERT_EQUAL(path, "util" LOCSLASH_S "system" LOCSLASH_S "src_root_ut.cpp"); diff --git a/util/system/sys_alloc.h b/util/system/sys_alloc.h index 4221a28f8c..0a4516bc53 100644 --- a/util/system/sys_alloc.h +++ b/util/system/sys_alloc.h @@ -1,14 +1,14 @@ #pragma once -#include <util/system/compiler.h> - +#include <util/system/compiler.h> + #include <cstdlib> #include <new> inline void* y_allocate(size_t n) { void* r = malloc(n); - if (r == nullptr) { + if (r == nullptr) { throw std::bad_alloc(); } @@ -35,7 +35,7 @@ inline void* y_reallocate(void* p, size_t new_sz) { void* r = realloc(p, new_sz); - if (r == nullptr) { + if (r == nullptr) { throw std::bad_alloc(); } diff --git a/util/system/tempfile_ut.cpp b/util/system/tempfile_ut.cpp index e4a0923d0b..f8e2bb5e5b 100644 --- a/util/system/tempfile_ut.cpp +++ b/util/system/tempfile_ut.cpp @@ -8,8 +8,8 @@ #include <algorithm> -Y_UNIT_TEST_SUITE(TTempFileHandle) { - Y_UNIT_TEST(Create) { +Y_UNIT_TEST_SUITE(TTempFileHandle) { + Y_UNIT_TEST(Create) { TString path; { TTempFileHandle tmp; diff --git a/util/system/thread.cpp b/util/system/thread.cpp index 6236746c2d..f51bc31d1d 100644 --- a/util/system/thread.cpp +++ b/util/system/thread.cpp @@ -128,9 +128,9 @@ namespace { //do not do this, kids, at home P_->Ref(); #if _WIN32_WINNT < 0x0502 - Handle = reinterpret_cast<HANDLE>(::_beginthreadex(nullptr, (unsigned)StackSize(*P_), Proxy, (void*)P_.Get(), 0, &ThreadId)); + Handle = reinterpret_cast<HANDLE>(::_beginthreadex(nullptr, (unsigned)StackSize(*P_), Proxy, (void*)P_.Get(), 0, &ThreadId)); #else - Handle = reinterpret_cast<HANDLE>(::_beginthreadex(nullptr, (unsigned)StackSize(*P_), Proxy, (void*)P_.Get(), 0, nullptr)); + Handle = reinterpret_cast<HANDLE>(::_beginthreadex(nullptr, (unsigned)StackSize(*P_), Proxy, (void*)P_.Get(), 0, nullptr)); #endif if (!Handle) { @@ -163,7 +163,7 @@ namespace { public: inline TPosixThread(const TParams& params) : P_(new TParams(params)) - , H_() + , H_() { static_assert(sizeof(H_) == sizeof(TId), "expect sizeof(H_) == sizeof(TId)"); } @@ -173,7 +173,7 @@ namespace { } inline void* Join() { - void* tec = nullptr; + void* tec = nullptr; PCHECK(pthread_join(H_, &tec), "can not join thread"); return tec; @@ -188,7 +188,7 @@ namespace { } inline void Start() { - pthread_attr_t* pattrs = nullptr; + pthread_attr_t* pattrs = nullptr; pthread_attr_t attrs; if (P_->StackSize > 0) { @@ -302,7 +302,7 @@ void* TThread::Join() { return ret; } - return nullptr; + return nullptr; } void TThread::Detach() { @@ -363,8 +363,8 @@ namespace { } } -ISimpleThread::ISimpleThread(size_t stackSize) - : TThread(TParams(ThreadProcWrapper<ISimpleThread>, reinterpret_cast<void*>(this), stackSize)) +ISimpleThread::ISimpleThread(size_t stackSize) + : TThread(TParams(ThreadProcWrapper<ISimpleThread>, reinterpret_cast<void*>(this), stackSize)) { } @@ -470,36 +470,36 @@ void TThread::SetCurrentThreadName(const char* name) { } TString TThread::CurrentThreadName() { -#if defined(_freebsd_) +#if defined(_freebsd_) // 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. - // via `man prctl` - char name[16]; - memset(name, 0, sizeof(name)); - Y_VERIFY(prctl(PR_GET_NAME, name, 0, 0, 0) == 0, "pctl failed: %s", strerror(errno)); - return name; -#elif defined(_darwin_) - // available on Mac OS 10.6+ - const auto thread = pthread_self(); - char name[256]; - 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(_linux_) + // > The buffer should allow space for up to 16 bytes; the returned string will be + // > null-terminated. + // via `man prctl` + char name[16]; + memset(name, 0, sizeof(name)); + Y_VERIFY(prctl(PR_GET_NAME, name, 0, 0, 0) == 0, "pctl failed: %s", strerror(errno)); + return name; +#elif defined(_darwin_) + // available on Mac OS 10.6+ + const auto thread = pthread_self(); + char name[256]; + 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 {}; -#else +#else // no idea -#endif // OS - - return {}; -} - +#endif // OS + + return {}; +} + bool TThread::CanGetCurrentThreadName() { #if defined(_linux_) || defined(_darwin_) return true; diff --git a/util/system/thread.h b/util/system/thread.h index a6e8abdb5b..1db7af6adb 100644 --- a/util/system/thread.h +++ b/util/system/thread.h @@ -8,7 +8,7 @@ #include <util/generic/string.h> #include "defaults.h" -#include "progname.h" +#include "progname.h" bool SetHighestThreadPriority(); @@ -27,11 +27,11 @@ public: size_t StackSize; void* StackPointer; // See comments for `SetCurrentThreadName` - TString Name = GetProgramName(); + TString Name = GetProgramName(); inline TParams() - : Proc(nullptr) - , Data(nullptr) + : Proc(nullptr) + , Data(nullptr) , StackSize(0) , StackPointer(nullptr) { @@ -103,24 +103,24 @@ 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; - // NOTE: Content of `name` will be copied. - // - // NOTE: On Linux thread name is limited to 15 symbols which is probably the smallest one among + // 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 // `CurrentThreadName` to return the same name as `name` make sure it's not longer than 15 - // symbols. + // symbols. static void SetCurrentThreadName(const char* name); // 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(); @@ -157,11 +157,11 @@ private: THolder<TImpl> Impl_; }; -class ISimpleThread: public TThread { +class ISimpleThread: public TThread { public: - ISimpleThread(size_t stackSize = 0); + ISimpleThread(size_t stackSize = 0); - virtual ~ISimpleThread() = default; + virtual ~ISimpleThread() = default; virtual void* ThreadProc() = 0; }; diff --git a/util/system/thread_ut.cpp b/util/system/thread_ut.cpp index d820898fd5..d47c409765 100644 --- a/util/system/thread_ut.cpp +++ b/util/system/thread_ut.cpp @@ -4,10 +4,10 @@ #include <atomic> -Y_UNIT_TEST_SUITE(TSysThreadTest) { +Y_UNIT_TEST_SUITE(TSysThreadTest) { struct TIdTester { inline TIdTester() - : Thr(nullptr) + : Thr(nullptr) , Cur(0) , Real(0) { @@ -16,7 +16,7 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) { static inline void* DoRun(void* ptr) { ((TIdTester*)ptr)->Run(); - return nullptr; + return nullptr; } inline void Run() { @@ -31,7 +31,7 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) { TThread::TId Numeric; }; - Y_UNIT_TEST(TestThreadId) { + Y_UNIT_TEST(TestThreadId) { TIdTester tst; TThread thr(tst.DoRun, &tst); @@ -48,131 +48,131 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) { void* ThreadProc(void*) { TThread::SetCurrentThreadName("CurrentThreadSetNameTest"); - return nullptr; + return nullptr; } void* ThreadProc2(void*) { - return nullptr; + return nullptr; } - void* ThreadProc3(void*) { + void* ThreadProc3(void*) { const auto name = TThread::CurrentThreadName(); - Y_FAKE_READ(name); - return nullptr; - } - - void* ThreadProc4(void*) { - const TString setName = "ThreadName"; + Y_FAKE_READ(name); + return nullptr; + } + + void* ThreadProc4(void*) { + const TString setName = "ThreadName"; TThread::SetCurrentThreadName(setName.data()); - + const auto getName = TThread::CurrentThreadName(); if (TThread::CanGetCurrentThreadName()) { UNIT_ASSERT_VALUES_EQUAL(setName, getName); } else { UNIT_ASSERT_VALUES_EQUAL("", getName); } - return nullptr; - } - - void* ThreadProcChild(void*) { + return nullptr; + } + + void* ThreadProcChild(void*) { const auto name = TThread::CurrentThreadName(); - const auto defaultName = GetProgramName(); - - (void)name; - (void)defaultName; - -#if defined(_darwin_) || defined(_linux_) - UNIT_ASSERT_VALUES_EQUAL(name, defaultName); -#endif - return nullptr; - } - - void* ThreadProcParent(void*) { - const TString setName = "Parent"; + const auto defaultName = GetProgramName(); + + (void)name; + (void)defaultName; + +#if defined(_darwin_) || defined(_linux_) + UNIT_ASSERT_VALUES_EQUAL(name, defaultName); +#endif + return nullptr; + } + + void* ThreadProcParent(void*) { + const TString setName = "Parent"; TThread::SetCurrentThreadName(setName.data()); - - TThread thread(&ThreadProcChild, nullptr); - - thread.Start(); - thread.Join(); - + + TThread thread(&ThreadProcChild, nullptr); + + thread.Start(); + thread.Join(); + const auto getName = TThread::CurrentThreadName(); if (TThread::CanGetCurrentThreadName()) { UNIT_ASSERT_VALUES_EQUAL(setName, getName); } else { UNIT_ASSERT_VALUES_EQUAL("", getName); } - return nullptr; - } - - Y_UNIT_TEST(TestSetThreadName) { - TThread thread(&ThreadProc, nullptr); + return nullptr; + } + + Y_UNIT_TEST(TestSetThreadName) { + TThread thread(&ThreadProc, nullptr); // just check it doesn't crash thread.Start(); thread.Join(); } - Y_UNIT_TEST(TestSetThreadName2) { - TThread thread(TThread::TParams(&ThreadProc, nullptr, 0).SetName("XXX")); - - thread.Start(); - thread.Join(); - } - - Y_UNIT_TEST(TestGetThreadName) { - TThread thread(&ThreadProc3, nullptr); - thread.Start(); - thread.Join(); - } - - Y_UNIT_TEST(TestSetGetThreadName) { - TThread thread(&ThreadProc4, nullptr); - thread.Start(); - thread.Join(); - } + Y_UNIT_TEST(TestSetThreadName2) { + TThread thread(TThread::TParams(&ThreadProc, nullptr, 0).SetName("XXX")); - Y_UNIT_TEST(TestSetGetThreadNameInChildThread) { - TThread thread(&ThreadProcParent, nullptr); thread.Start(); thread.Join(); } - Y_UNIT_TEST(TestDoubleJoin) { - TThread thread(&ThreadProc, nullptr); + Y_UNIT_TEST(TestGetThreadName) { + TThread thread(&ThreadProc3, nullptr); + thread.Start(); + thread.Join(); + } + + Y_UNIT_TEST(TestSetGetThreadName) { + TThread thread(&ThreadProc4, nullptr); + thread.Start(); + thread.Join(); + } + + Y_UNIT_TEST(TestSetGetThreadNameInChildThread) { + TThread thread(&ThreadProcParent, nullptr); + thread.Start(); + thread.Join(); + } + + Y_UNIT_TEST(TestDoubleJoin) { + TThread thread(&ThreadProc, nullptr); thread.Start(); thread.Join(); - UNIT_ASSERT_EQUAL(thread.Join(), nullptr); + UNIT_ASSERT_EQUAL(thread.Join(), nullptr); } - Y_UNIT_TEST(TestDoubleStart) { - TThread thread(&ThreadProc, nullptr); + Y_UNIT_TEST(TestDoubleStart) { + TThread thread(&ThreadProc, nullptr); thread.Start(); UNIT_ASSERT_EXCEPTION(thread.Start(), yexception); thread.Join(); } - Y_UNIT_TEST(TestNoStart) { - TThread thread(&ThreadProc, nullptr); + Y_UNIT_TEST(TestNoStart) { + TThread thread(&ThreadProc, nullptr); } - Y_UNIT_TEST(TestNoStartJoin) { - TThread thread(&ThreadProc, nullptr); + Y_UNIT_TEST(TestNoStartJoin) { + TThread thread(&ThreadProc, nullptr); - UNIT_ASSERT_EQUAL(thread.Join(), nullptr); + UNIT_ASSERT_EQUAL(thread.Join(), nullptr); } - Y_UNIT_TEST(TestStackPointer) { + Y_UNIT_TEST(TestStackPointer) { TArrayHolder<char> buf(new char[64000]); - TThread thr(TThread::TParams(ThreadProc2, nullptr).SetStackPointer(buf.Get()).SetStackSize(64000)); + TThread thr(TThread::TParams(ThreadProc2, nullptr).SetStackPointer(buf.Get()).SetStackSize(64000)); thr.Start(); UNIT_ASSERT_VALUES_EQUAL(thr.Join(), nullptr); } - Y_UNIT_TEST(TestStackLimits) { + Y_UNIT_TEST(TestStackLimits) { TCurrentThreadLimits sl; UNIT_ASSERT(sl.StackBegin); diff --git a/util/system/tls.cpp b/util/system/tls.cpp index c2f1a04a14..74400efea2 100644 --- a/util/system/tls.cpp +++ b/util/system/tls.cpp @@ -41,7 +41,7 @@ namespace { class TStoredValue: public TIntrusiveListItem<TStoredValue> { public: inline TStoredValue(const TKey* key) - : Data_(nullptr) + : Data_(nullptr) , Dtor_(key->Dtor) { } @@ -98,7 +98,7 @@ namespace { }; inline TPerThreadStorage* MyStorage() { -#if defined(Y_HAVE_FAST_POD_TLS) +#if defined(Y_HAVE_FAST_POD_TLS) Y_POD_STATIC_THREAD(TPerThreadStorage*) my(nullptr); @@ -123,14 +123,14 @@ namespace { class TMasterTls: public TGenericTlsBase { public: inline TMasterTls() { - Y_VERIFY(!pthread_key_create(&Key_, Dtor), "pthread_key_create failed"); + Y_VERIFY(!pthread_key_create(&Key_, Dtor), "pthread_key_create failed"); } inline ~TMasterTls() override { //explicitly call dtor for main thread Dtor(pthread_getspecific(Key_)); - Y_VERIFY(!pthread_key_delete(Key_), "pthread_key_delete failed"); + Y_VERIFY(!pthread_key_delete(Key_), "pthread_key_delete failed"); } static inline TMasterTls* Instance() { @@ -144,7 +144,7 @@ namespace { if (!ret) { ret = new TPerThreadStorage(); - Y_VERIFY(!pthread_setspecific(Key_, ret), "pthread_setspecific failed"); + Y_VERIFY(!pthread_setspecific(Key_, ret), "pthread_setspecific failed"); } return (TPerThreadStorage*)ret; diff --git a/util/system/tls.h b/util/system/tls.h index 3c4f56dbeb..3cc297b8ae 100644 --- a/util/system/tls.h +++ b/util/system/tls.h @@ -20,7 +20,7 @@ #endif /** - @def Y_THREAD(TType) + @def Y_THREAD(TType) A thread-local wrapper for a given class. Suitable for POD and classes with a constructor with a single argument. @@ -46,7 +46,7 @@ Example: @code //the field declaration in header - Y_THREAD(TBuffer) TmpBuffer; + Y_THREAD(TBuffer) TmpBuffer; //...later somewhere in cpp... TmpBuffer.Clear(); for (size_t i = 0; i < sz && TrieCursor[i].second.IsFork(); ++i) { @@ -57,10 +57,10 @@ Example: @code //the field decalrataion in header - Y_THREAD(TMyWriter*) ThreadLocalWriter; + Y_THREAD(TMyWriter*) ThreadLocalWriter; //...later somewhere in cpp... TMyWriter*& writerRef = ThreadLocalWriter.Get(); - if (writerRef == nullptr) { + if (writerRef == nullptr) { THolder<TMyWriter> threadLocalWriter( new TMyWriter( *Session, MinLogError, @@ -84,7 +84,7 @@ Example: @code - Y_THREAD(TScoreCalcer*) ScoreCalcerPtr; + Y_THREAD(TScoreCalcer*) ScoreCalcerPtr; static TScoreCalcer* GetScoreCalcer(yint maxElemCount) { if (ScoreCalcerPtr == 0) { ScoreCalcerPtr = new TScoreCalcer(); @@ -98,35 +98,35 @@ **/ /** - @def Y_STATIC_THREAD(TType) + @def Y_STATIC_THREAD(TType) - Equivalent to "static Y_THREAD(TType)" + Equivalent to "static Y_THREAD(TType)" - @see Y_THREAD(TType) + @see Y_THREAD(TType) **/ /** - @def Y_POD_THREAD(TType) + @def Y_POD_THREAD(TType) - Same interface as Y_THREAD(TType), but TType must be a POD. - Implemented (based on the compiler) as Y_THREAD(TType) or as native tls. + Same interface as Y_THREAD(TType), but TType must be a POD. + Implemented (based on the compiler) as Y_THREAD(TType) or as native tls. - @see Y_THREAD(TType) + @see Y_THREAD(TType) **/ /** @def STATIC_POD_THREAD(TType) - Equivalent to "static Y_POD_THREAD(TType)" + Equivalent to "static Y_POD_THREAD(TType)" - @see Y_POD_THREAD(TType) + @see Y_POD_THREAD(TType) **/ -#define Y_THREAD(T) ::NTls::TValue<T> -#define Y_STATIC_THREAD(T) static Y_THREAD(T) +#define Y_THREAD(T) ::NTls::TValue<T> +#define Y_STATIC_THREAD(T) static Y_THREAD(T) // gcc and msvc support automatic tls for POD types -#if defined(Y_DISABLE_THRKEY_OPTIMIZATION) +#if defined(Y_DISABLE_THRKEY_OPTIMIZATION) // nothing to do #elif defined(__clang__) #define Y_POD_THREAD(T) thread_local T @@ -140,7 +140,7 @@ #define Y_POD_STATIC_THREAD(T) __declspec(thread) static T #endif -#if !defined(Y_POD_THREAD) || !defined(Y_POD_STATIC_THREAD) +#if !defined(Y_POD_THREAD) || !defined(Y_POD_STATIC_THREAD) #define Y_POD_THREAD(T) Y_THREAD(T) #define Y_POD_STATIC_THREAD(T) Y_STATIC_THREAD(T) #else diff --git a/util/system/tls_ut.cpp b/util/system/tls_ut.cpp index e84d34b42a..586919b781 100644 --- a/util/system/tls_ut.cpp +++ b/util/system/tls_ut.cpp @@ -3,7 +3,7 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TTestTLS) { +Y_UNIT_TEST_SUITE(TTestTLS) { struct X { inline X() : V(0) @@ -22,10 +22,10 @@ Y_UNIT_TEST_SUITE(TTestTLS) { V; }; - Y_UNIT_TEST(TestHugeSetup) { + Y_UNIT_TEST(TestHugeSetup) { TArrayHolder<X> x(new X[100000]); - struct TThr: public ISimpleThread { + struct TThr: public ISimpleThread { inline TThr(X* ptr) : P(ptr) { diff --git a/util/system/type_name.cpp b/util/system/type_name.cpp index 0377da4212..811b90b85f 100644 --- a/util/system/type_name.cpp +++ b/util/system/type_name.cpp @@ -29,7 +29,7 @@ const char* NPrivate::TCppDemangler::Demangle(const char* name) { return name; #else int status; - TmpBuf_.Reset(__cxxabiv1::__cxa_demangle(name, nullptr, nullptr, &status)); + TmpBuf_.Reset(__cxxabiv1::__cxa_demangle(name, nullptr, nullptr, &status)); if (!TmpBuf_) { return name; diff --git a/util/system/type_name_ut.cpp b/util/system/type_name_ut.cpp index 86597f4232..518b257965 100644 --- a/util/system/type_name_ut.cpp +++ b/util/system/type_name_ut.cpp @@ -8,8 +8,8 @@ #include <stdexcept> #include <string> -Y_UNIT_TEST_SUITE(TDemangleTest) { - Y_UNIT_TEST(SimpleTest) { +Y_UNIT_TEST_SUITE(TDemangleTest) { + Y_UNIT_TEST(SimpleTest) { // just check it does not crash or leak CppDemangle("hello"); CppDemangle(""); diff --git a/util/system/types_ut.cpp b/util/system/types_ut.cpp index 19e40cef46..4a7c96cfa7 100644 --- a/util/system/types_ut.cpp +++ b/util/system/types_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TestTypes) { - Y_UNIT_TEST(TestScanf) { +Y_UNIT_TEST_SUITE(TestTypes) { + Y_UNIT_TEST(TestScanf) { i32 val32 = 0; sscanf("-123", "%" SCNi32, &val32); UNIT_ASSERT(val32 == -123); diff --git a/util/system/unaligned_mem.h b/util/system/unaligned_mem.h index 4b84686f2f..6985270d9e 100644 --- a/util/system/unaligned_mem.h +++ b/util/system/unaligned_mem.h @@ -1,7 +1,7 @@ #pragma once #include "defaults.h" -#include "yassert.h" +#include "yassert.h" #include <string.h> #include <type_traits> @@ -23,45 +23,45 @@ template <class T> inline void WriteUnaligned(void* to, const std::remove_reference_t<T>& t) noexcept { memcpy(to, &t, sizeof(T)); } - -template <class T, unsigned Align = sizeof(T)> -class TUnalignedMemoryIterator { -public: - inline TUnalignedMemoryIterator(const void* buf, size_t len) - : C_((const unsigned char*)buf) - , E_(C_ + len) - , L_(E_ - (len % Align)) - { - Y_FAKE_READ(buf); - } - - inline bool AtEnd() const noexcept { - return C_ == L_; - } - - inline T Cur() const noexcept { + +template <class T, unsigned Align = sizeof(T)> +class TUnalignedMemoryIterator { +public: + inline TUnalignedMemoryIterator(const void* buf, size_t len) + : C_((const unsigned char*)buf) + , E_(C_ + len) + , L_(E_ - (len % Align)) + { + Y_FAKE_READ(buf); + } + + inline bool AtEnd() const noexcept { + return C_ == L_; + } + + inline T Cur() const noexcept { Y_ASSERT(C_ < L_ || sizeof(T) < Align); - return ::ReadUnaligned<T>(C_); - } - - inline T Next() noexcept { - T ret(Cur()); - - C_ += sizeof(T); - - return ret; - } - - inline const unsigned char* Last() const noexcept { - return C_; - } - - inline size_t Left() const noexcept { - return E_ - C_; - } - -private: - const unsigned char* C_; - const unsigned char* E_; - const unsigned char* L_; -}; + return ::ReadUnaligned<T>(C_); + } + + inline T Next() noexcept { + T ret(Cur()); + + C_ += sizeof(T); + + return ret; + } + + inline const unsigned char* Last() const noexcept { + return C_; + } + + inline size_t Left() const noexcept { + return E_ - C_; + } + +private: + const unsigned char* C_; + const unsigned char* E_; + const unsigned char* L_; +}; diff --git a/util/system/unaligned_mem_ut.cpp b/util/system/unaligned_mem_ut.cpp index 9de3f3e931..fddf98f8de 100644 --- a/util/system/unaligned_mem_ut.cpp +++ b/util/system/unaligned_mem_ut.cpp @@ -29,8 +29,8 @@ namespace { } #endif -Y_UNIT_TEST_SUITE(UnalignedMem) { - Y_UNIT_TEST(TestReadWrite) { +Y_UNIT_TEST_SUITE(UnalignedMem) { + Y_UNIT_TEST(TestReadWrite) { alignas(ui64) char buf[100]; WriteUnaligned<ui16>(buf + 1, (ui16)1); @@ -42,7 +42,7 @@ Y_UNIT_TEST_SUITE(UnalignedMem) { UNIT_ASSERT_VALUES_EQUAL(ReadUnaligned<ui64>(buf + 1 + 2 + 4), 3); } - Y_UNIT_TEST(TestReadWriteRuntime) { + Y_UNIT_TEST(TestReadWriteRuntime) { // Unlike the test above, this test avoids compile-time execution by a smart compiler. // It is required to catch the SIGSEGV in case compiler emits an alignment-sensitive instruction. @@ -69,14 +69,14 @@ Y_UNIT_TEST_SUITE(UnalignedMem) { UNIT_ASSERT_VALUES_EQUAL(val3, 3); } #ifdef Y_HAVE_INT128 - Y_UNIT_TEST(TestReadWrite128) { + Y_UNIT_TEST(TestReadWrite128) { alignas(TUInt128) char buf[100] = {0}; WriteUnaligned<TUInt128>(buf + 1, TUInt128::Max()); auto val = ReadUnaligned<TUInt128>(buf + 1); UNIT_ASSERT(val == TUInt128::Max()); } - Y_UNIT_TEST(TestReadWriteRuntime128) { + Y_UNIT_TEST(TestReadWriteRuntime128) { // Unlike the test above, this test avoids compile-time execution by a smart compiler. // It is required to catch the SIGSEGV in case compiler emits an alignment-sensitive instruction. diff --git a/util/system/user_ut.cpp b/util/system/user_ut.cpp index 4f8a5ce2ef..49ed264475 100644 --- a/util/system/user_ut.cpp +++ b/util/system/user_ut.cpp @@ -2,8 +2,8 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(TestUser) { - Y_UNIT_TEST(TestNotEmpty) { +Y_UNIT_TEST_SUITE(TestUser) { + Y_UNIT_TEST(TestNotEmpty) { UNIT_ASSERT(GetUsername()); } } diff --git a/util/system/utime.cpp b/util/system/utime.cpp index c7bfc4bf3d..347467f28f 100644 --- a/util/system/utime.cpp +++ b/util/system/utime.cpp @@ -9,7 +9,7 @@ #endif int TouchFile(const char* filePath) { - return utime(filePath, nullptr); + return utime(filePath, nullptr); } int SetModTime(const char* filePath, time_t modtime, time_t actime) { diff --git a/util/system/yassert.cpp b/util/system/yassert.cpp index 0f586648b7..cf53876f49 100644 --- a/util/system/yassert.cpp +++ b/util/system/yassert.cpp @@ -1,21 +1,21 @@ #include "yassert.h" -#include "backtrace.h" +#include "backtrace.h" #include "guard.h" #include "spinlock.h" -#include "src_root.h" - +#include "src_root.h" + #include <util/datetime/base.h> -#include <util/generic/singleton.h> +#include <util/generic/singleton.h> #include <util/generic/strbuf.h> #include <util/generic/string.h> -#include <util/stream/output.h> -#include <util/stream/str.h> -#include <util/string/printf.h> +#include <util/stream/output.h> +#include <util/stream/str.h> +#include <util/string/printf.h> -#include <cstdlib> -#include <stdarg.h> -#include <stdio.h> +#include <cstdlib> +#include <stdarg.h> +#include <stdio.h> #ifdef CLANG_COVERAGE extern "C" { diff --git a/util/system/yassert.h b/util/system/yassert.h index 529823440c..530a82174c 100644 --- a/util/system/yassert.h +++ b/util/system/yassert.h @@ -54,7 +54,7 @@ inline void YaDebugBreak() { __debugbreak(); } -#undef Y_ASSERT +#undef Y_ASSERT #if !defined(NDEBUG) && !defined(__GCCXML__) #define Y_ASSERT(a) \ @@ -95,16 +95,16 @@ namespace NPrivate { } /// Assert that does not depend on NDEBUG macro and outputs message like printf -#define Y_VERIFY(expr, ...) \ +#define Y_VERIFY(expr, ...) \ do { \ if (Y_UNLIKELY(!(expr))) { \ ::NPrivate::Panic(__SOURCE_FILE_IMPL__, __LINE__, __FUNCTION__, #expr, " " __VA_ARGS__); \ } \ } while (false) -#define Y_FAIL(...) \ - do { \ - ::NPrivate::Panic(__SOURCE_FILE_IMPL__, __LINE__, __FUNCTION__, nullptr, " " __VA_ARGS__); \ +#define Y_FAIL(...) \ + do { \ + ::NPrivate::Panic(__SOURCE_FILE_IMPL__, __LINE__, __FUNCTION__, nullptr, " " __VA_ARGS__); \ } while (false) #ifndef NDEBUG diff --git a/util/system/yassert_ut.cpp b/util/system/yassert_ut.cpp index ddd392666c..56d6122d0f 100644 --- a/util/system/yassert_ut.cpp +++ b/util/system/yassert_ut.cpp @@ -4,32 +4,32 @@ #include <library/cpp/testing/unittest/registar.h> -Y_UNIT_TEST_SUITE(YassertTest) { - Y_UNIT_TEST(TestAcsLikeFunctionCall) { +Y_UNIT_TEST_SUITE(YassertTest) { + Y_UNIT_TEST(TestAcsLikeFunctionCall) { if (true) { - Y_ASSERT(true); // this cannot be compiled if Y_ASSERT is "if (!cond) { ... }" + Y_ASSERT(true); // this cannot be compiled if Y_ASSERT is "if (!cond) { ... }" } else { - Y_ASSERT(false); + Y_ASSERT(false); } bool var = false; if (false) { - Y_ASSERT(false); + Y_ASSERT(false); } else { - var = true; // this is unreachable if Y_ASSERT is "if (!cond) { ... }" + var = true; // this is unreachable if Y_ASSERT is "if (!cond) { ... }" } UNIT_ASSERT(var); } - Y_UNIT_TEST(TestFailCompiles) { + Y_UNIT_TEST(TestFailCompiles) { if (false) { - Y_FAIL("%d is a lucky number", 7); - Y_FAIL(); + Y_FAIL("%d is a lucky number", 7); + Y_FAIL(); } } - Y_UNIT_TEST(TestVerify) { - Y_VERIFY(true, "hi %s", "there"); - Y_VERIFY(true); + Y_UNIT_TEST(TestVerify) { + Y_VERIFY(true, "hi %s", "there"); + Y_VERIFY(true); } } |