diff options
author | rzhikharevich <rzhikharevich@yandex-team.ru> | 2022-02-10 16:51:00 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:51:00 +0300 |
commit | 3fd404e3c028261bd5c6720cd67d4b755740d161 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 | |
parent | 724861a587a9d8ecec238aec4c37154e3f2409bb (diff) | |
download | ydb-3fd404e3c028261bd5c6720cd67d4b755740d161.tar.gz |
Restoring authorship annotation for <rzhikharevich@yandex-team.ru>. Commit 2 of 2.
-rw-r--r-- | library/cpp/threading/future/core/future-inl.h | 8 | ||||
-rw-r--r-- | library/cpp/threading/future/future_ut.cpp | 158 | ||||
-rw-r--r-- | util/system/datetime.cpp | 28 |
3 files changed, 97 insertions, 97 deletions
diff --git a/library/cpp/threading/future/core/future-inl.h b/library/cpp/threading/future/core/future-inl.h index e0ddd4295ec..5fd4296a93c 100644 --- a/library/cpp/threading/future/core/future-inl.h +++ b/library/cpp/threading/future/core/future-inl.h @@ -621,8 +621,8 @@ namespace NThreading { template <typename F> inline TFuture<TFutureType<TFutureCallResult<F, T>>> TFuture<T>::Apply(F&& func) const { auto promise = NewPromise<TFutureType<TFutureCallResult<F, T>>>(); - Subscribe([promise, func = std::forward<F>(func)](const TFuture<T>& future) mutable { - NImpl::SetValue(promise, [&]() { return func(future); }); + Subscribe([promise, func = std::forward<F>(func)](const TFuture<T>& future) mutable { + NImpl::SetValue(promise, [&]() { return func(future); }); }); return promise; } @@ -720,8 +720,8 @@ namespace NThreading { template <typename F> inline TFuture<TFutureType<TFutureCallResult<F, void>>> TFuture<void>::Apply(F&& func) const { auto promise = NewPromise<TFutureType<TFutureCallResult<F, void>>>(); - Subscribe([promise, func = std::forward<F>(func)](const TFuture<void>& future) mutable { - NImpl::SetValue(promise, [&]() { return func(future); }); + Subscribe([promise, func = std::forward<F>(func)](const TFuture<void>& future) mutable { + NImpl::SetValue(promise, [&]() { return func(future); }); }); return promise; } diff --git a/library/cpp/threading/future/future_ut.cpp b/library/cpp/threading/future/future_ut.cpp index ccc214372df..05950a568d4 100644 --- a/library/cpp/threading/future/future_ut.cpp +++ b/library/cpp/threading/future/future_ut.cpp @@ -9,32 +9,32 @@ namespace NThreading { namespace { - class TCopyCounter { - public: - TCopyCounter(size_t* numCopies) - : NumCopies(numCopies) - {} - - TCopyCounter(const TCopyCounter& that) - : NumCopies(that.NumCopies) - { - ++*NumCopies; - } - - TCopyCounter& operator=(const TCopyCounter& that) { - NumCopies = that.NumCopies; - ++*NumCopies; - return *this; - } - - TCopyCounter(TCopyCounter&& that) = default; - - TCopyCounter& operator=(TCopyCounter&& that) = default; - - private: - size_t* NumCopies = nullptr; - }; - + class TCopyCounter { + public: + TCopyCounter(size_t* numCopies) + : NumCopies(numCopies) + {} + + TCopyCounter(const TCopyCounter& that) + : NumCopies(that.NumCopies) + { + ++*NumCopies; + } + + TCopyCounter& operator=(const TCopyCounter& that) { + NumCopies = that.NumCopies; + ++*NumCopies; + return *this; + } + + TCopyCounter(TCopyCounter&& that) = default; + + TCopyCounter& operator=(TCopyCounter&& that) = default; + + private: + size_t* NumCopies = nullptr; + }; + template <typename T> auto MakePromise() { if constexpr (std::is_same_v<T, void>) { @@ -582,59 +582,59 @@ namespace { TestFutureStateId<void>(); TestFutureStateId<int>(); } - - template <typename T> - void TestApplyNoRvalueCopyImpl() { - size_t numCopies = 0; - TCopyCounter copyCounter(&numCopies); - - auto promise = MakePromise<T>(); - - const auto future = promise.GetFuture().Apply( - [copyCounter = std::move(copyCounter)] (const auto&) {} - ); - - if constexpr (std::is_same_v<T, void>) { - promise.SetValue(); - } else { - promise.SetValue(T()); - } - - future.GetValueSync(); - - UNIT_ASSERT_VALUES_EQUAL(numCopies, 0); - } - - Y_UNIT_TEST(ApplyNoRvalueCopy) { - TestApplyNoRvalueCopyImpl<void>(); - TestApplyNoRvalueCopyImpl<int>(); - } - - template <typename T> - void TestApplyLvalueCopyImpl() { - size_t numCopies = 0; - TCopyCounter copyCounter(&numCopies); - - auto promise = MakePromise<T>(); - - auto func = [copyCounter = std::move(copyCounter)] (const auto&) {}; - const auto future = promise.GetFuture().Apply(func); - - if constexpr (std::is_same_v<T, void>) { - promise.SetValue(); - } else { - promise.SetValue(T()); - } - - future.GetValueSync(); - - UNIT_ASSERT_VALUES_EQUAL(numCopies, 1); - } - - Y_UNIT_TEST(ApplyLvalueCopy) { - TestApplyLvalueCopyImpl<void>(); - TestApplyLvalueCopyImpl<int>(); - } + + template <typename T> + void TestApplyNoRvalueCopyImpl() { + size_t numCopies = 0; + TCopyCounter copyCounter(&numCopies); + + auto promise = MakePromise<T>(); + + const auto future = promise.GetFuture().Apply( + [copyCounter = std::move(copyCounter)] (const auto&) {} + ); + + if constexpr (std::is_same_v<T, void>) { + promise.SetValue(); + } else { + promise.SetValue(T()); + } + + future.GetValueSync(); + + UNIT_ASSERT_VALUES_EQUAL(numCopies, 0); + } + + Y_UNIT_TEST(ApplyNoRvalueCopy) { + TestApplyNoRvalueCopyImpl<void>(); + TestApplyNoRvalueCopyImpl<int>(); + } + + template <typename T> + void TestApplyLvalueCopyImpl() { + size_t numCopies = 0; + TCopyCounter copyCounter(&numCopies); + + auto promise = MakePromise<T>(); + + auto func = [copyCounter = std::move(copyCounter)] (const auto&) {}; + const auto future = promise.GetFuture().Apply(func); + + if constexpr (std::is_same_v<T, void>) { + promise.SetValue(); + } else { + promise.SetValue(T()); + } + + future.GetValueSync(); + + UNIT_ASSERT_VALUES_EQUAL(numCopies, 1); + } + + Y_UNIT_TEST(ApplyLvalueCopy) { + TestApplyLvalueCopyImpl<void>(); + TestApplyLvalueCopyImpl<int>(); + } } } diff --git a/util/system/datetime.cpp b/util/system/datetime.cpp index ad2c8c376fd..b07b50679a6 100644 --- a/util/system/datetime.cpp +++ b/util/system/datetime.cpp @@ -8,15 +8,15 @@ #include <ctime> #include <cerrno> -#ifdef _darwin_ +#ifdef _darwin_ #include <AvailabilityMacros.h> #if defined(MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12 #define Y_HAS_CLOCK_GETTIME #endif -#elif defined(_linux_) || defined(_freebsd_) || defined(_cygwin_) +#elif defined(_linux_) || defined(_freebsd_) || defined(_cygwin_) #define Y_HAS_CLOCK_GETTIME -#endif - +#endif + static ui64 ToMicroSeconds(const struct timeval& tv) { return (ui64)tv.tv_sec * 1000000 + (ui64)tv.tv_usec; } @@ -25,10 +25,10 @@ static ui64 ToMicroSeconds(const struct timeval& tv) { static ui64 ToMicroSeconds(const FILETIME& ft) { return (((ui64)ft.dwHighDateTime << 32) + (ui64)ft.dwLowDateTime) / (ui64)10; } -#elif defined(Y_HAS_CLOCK_GETTIME) -static ui64 ToMicroSeconds(const struct timespec& ts) { - return (ui64)ts.tv_sec * 1000000 + (ui64)ts.tv_nsec / 1000; -} +#elif defined(Y_HAS_CLOCK_GETTIME) +static ui64 ToMicroSeconds(const struct timespec& ts) { + return (ui64)ts.tv_sec * 1000000 + (ui64)ts.tv_nsec / 1000; +} #endif ui64 MicroSeconds() noexcept { @@ -63,12 +63,12 @@ ui64 ThreadCPUTime() noexcept { FILETIME creationTime, exitTime, kernelTime, userTime; GetThreadTimes(GetCurrentThread(), &creationTime, &exitTime, &kernelTime, &userTime); return ToMicroSeconds(userTime) + ToMicroSeconds(kernelTime); -#elif defined(Y_HAS_CLOCK_GETTIME) +#elif defined(Y_HAS_CLOCK_GETTIME) struct timespec ts; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); return ToMicroSeconds(ts); -#else - return 0; +#else + return 0; #endif } @@ -97,7 +97,7 @@ void NanoSleep(ui64 ns) noexcept { #if defined(_x86_) extern const bool HaveRdtscp = NX86::HaveRDTSCP(); #endif - -#ifdef Y_HAS_CLOCK_GETTIME + +#ifdef Y_HAS_CLOCK_GETTIME #undef Y_HAS_CLOCK_GETTIME -#endif +#endif |