aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/threading
diff options
context:
space:
mode:
authorishfb <ishfb@yandex-team.ru>2022-02-10 16:48:07 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:07 +0300
commit0170772a2dbf133f32e17ca137ff64790d43831f (patch)
tree68ce3ab477bcb9e09abf2b0a6e7b34287c53f0df /library/cpp/threading
parentdf6128370874866447314ec18d8e67fc7bde40b4 (diff)
downloadydb-0170772a2dbf133f32e17ca137ff64790d43831f.tar.gz
Restoring authorship annotation for <ishfb@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/threading')
-rw-r--r--library/cpp/threading/future/async.cpp2
-rw-r--r--library/cpp/threading/future/async.h38
-rw-r--r--library/cpp/threading/future/async_ut.cpp52
-rw-r--r--library/cpp/threading/future/core/future-inl.h2
-rw-r--r--library/cpp/threading/future/core/future.h2
-rw-r--r--library/cpp/threading/future/future_ut.cpp6
-rw-r--r--library/cpp/threading/future/legacy_future.h48
-rw-r--r--library/cpp/threading/future/legacy_future_ut.cpp48
-rw-r--r--library/cpp/threading/future/ut/ya.make16
-rw-r--r--library/cpp/threading/future/wait/wait-inl.h2
-rw-r--r--library/cpp/threading/future/wait/wait.cpp2
-rw-r--r--library/cpp/threading/future/wait/wait.h2
-rw-r--r--library/cpp/threading/future/ya.make8
13 files changed, 114 insertions, 114 deletions
diff --git a/library/cpp/threading/future/async.cpp b/library/cpp/threading/future/async.cpp
index ad9b21a2cf..6a0564d1cb 100644
--- a/library/cpp/threading/future/async.cpp
+++ b/library/cpp/threading/future/async.cpp
@@ -1 +1 @@
-#include "async.h"
+#include "async.h"
diff --git a/library/cpp/threading/future/async.h b/library/cpp/threading/future/async.h
index 8543fdd5c6..b2952a0548 100644
--- a/library/cpp/threading/future/async.h
+++ b/library/cpp/threading/future/async.h
@@ -1,22 +1,22 @@
-#pragma once
-
-#include "future.h"
-
+#pragma once
+
+#include "future.h"
+
#include <util/generic/function.h>
#include <util/thread/pool.h>
-
-namespace NThreading {
+
+namespace NThreading {
/**
- * @brief Asynchronously executes @arg func in @arg queue returning a future for the result.
- *
- * @arg func should be a callable object with signature T().
- * @arg queue where @arg will be executed
- * @returns For @arg func with signature T() the function returns TFuture<T> unless T is TFuture<U>.
- * In this case the function returns TFuture<U>.
- *
- * If you want to use another queue for execution just write an overload, @see ExtensionExample
- * unittest.
- */
+ * @brief Asynchronously executes @arg func in @arg queue returning a future for the result.
+ *
+ * @arg func should be a callable object with signature T().
+ * @arg queue where @arg will be executed
+ * @returns For @arg func with signature T() the function returns TFuture<T> unless T is TFuture<U>.
+ * In this case the function returns TFuture<U>.
+ *
+ * If you want to use another queue for execution just write an overload, @see ExtensionExample
+ * unittest.
+ */
template <typename Func>
TFuture<TFutureType<TFunctionResult<Func>>> Async(Func&& func, IThreadPool& queue) {
auto promise = NewPromise<TFutureType<TFunctionResult<Func>>>();
@@ -24,8 +24,8 @@ namespace NThreading {
NImpl::SetValue(promise, func);
};
queue.SafeAddFunc(std::move(lambda));
-
+
return promise.GetFuture();
}
-
-}
+
+}
diff --git a/library/cpp/threading/future/async_ut.cpp b/library/cpp/threading/future/async_ut.cpp
index a3699744e4..c2801dbd6e 100644
--- a/library/cpp/threading/future/async_ut.cpp
+++ b/library/cpp/threading/future/async_ut.cpp
@@ -1,32 +1,32 @@
-#include "async.h"
-
+#include "async.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
-#include <util/generic/ptr.h>
-#include <util/generic/vector.h>
-
-namespace {
+
+#include <util/generic/ptr.h>
+#include <util/generic/vector.h>
+
+namespace {
struct TMySuperTaskQueue {
};
-
-}
-
-namespace NThreading {
+
+}
+
+namespace NThreading {
/* Here we provide an Async overload for TMySuperTaskQueue indide NThreading namespace
- * so that we can call it in the way
- *
- * TMySuperTaskQueue queue;
- * NThreading::Async([](){}, queue);
- *
- * See also ExtensionExample unittest.
- */
+ * so that we can call it in the way
+ *
+ * TMySuperTaskQueue queue;
+ * NThreading::Async([](){}, queue);
+ *
+ * See also ExtensionExample unittest.
+ */
template <typename Func>
TFuture<TFunctionResult<Func>> Async(Func func, TMySuperTaskQueue&) {
return MakeFuture(func());
}
-
-}
-
+
+}
+
Y_UNIT_TEST_SUITE(Async) {
Y_UNIT_TEST(ExtensionExample) {
TMySuperTaskQueue queue;
@@ -34,24 +34,24 @@ Y_UNIT_TEST_SUITE(Async) {
future.Wait();
UNIT_ASSERT_VALUES_EQUAL(future.GetValue(), 5);
}
-
+
Y_UNIT_TEST(WorksWithIMtpQueue) {
auto queue = MakeHolder<TThreadPool>();
queue->Start(1);
-
+
auto future = NThreading::Async([]() { return 5; }, *queue);
future.Wait();
UNIT_ASSERT_VALUES_EQUAL(future.GetValue(), 5);
}
-
+
Y_UNIT_TEST(ProperlyDeducesFutureType) {
// Compileability test
auto queue = CreateThreadPool(1);
-
+
NThreading::TFuture<void> f1 = NThreading::Async([]() {}, *queue);
NThreading::TFuture<int> f2 = NThreading::Async([]() { return 5; }, *queue);
NThreading::TFuture<double> f3 = NThreading::Async([]() { return 5.0; }, *queue);
NThreading::TFuture<TVector<int>> f4 = NThreading::Async([]() { return TVector<int>(); }, *queue);
NThreading::TFuture<int> f5 = NThreading::Async([]() { return NThreading::MakeFuture(5); }, *queue);
}
-}
+}
diff --git a/library/cpp/threading/future/core/future-inl.h b/library/cpp/threading/future/core/future-inl.h
index 5fd4296a93..bb1aef1ed1 100644
--- a/library/cpp/threading/future/core/future-inl.h
+++ b/library/cpp/threading/future/core/future-inl.h
@@ -4,7 +4,7 @@
#error "you should never include future-inl.h directly"
#endif // INCLUDE_FUTURE_INL_H
-namespace NThreading {
+namespace NThreading {
namespace NImpl {
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/threading/future/core/future.h b/library/cpp/threading/future/core/future.h
index 2e82bb953e..3d5570ba5b 100644
--- a/library/cpp/threading/future/core/future.h
+++ b/library/cpp/threading/future/core/future.h
@@ -11,7 +11,7 @@
#include <util/system/event.h>
#include <util/system/spinlock.h>
-namespace NThreading {
+namespace NThreading {
////////////////////////////////////////////////////////////////////////////////
struct TFutureException: public yexception {};
diff --git a/library/cpp/threading/future/future_ut.cpp b/library/cpp/threading/future/future_ut.cpp
index 05950a568d..5cc51fa145 100644
--- a/library/cpp/threading/future/future_ut.cpp
+++ b/library/cpp/threading/future/future_ut.cpp
@@ -5,7 +5,7 @@
#include <list>
#include <type_traits>
-namespace NThreading {
+namespace NThreading {
namespace {
@@ -420,7 +420,7 @@ namespace {
auto promise = NewPromise<TRec>();
promise.SetValue(TRec(1));
-
+
auto future = MakeFuture(TRec(1));
const auto& rec = future.GetValue();
Y_UNUSED(rec);
@@ -637,4 +637,4 @@ namespace {
}
}
-}
+}
diff --git a/library/cpp/threading/future/legacy_future.h b/library/cpp/threading/future/legacy_future.h
index 6f1eabad73..4cb446047b 100644
--- a/library/cpp/threading/future/legacy_future.h
+++ b/library/cpp/threading/future/legacy_future.h
@@ -1,25 +1,25 @@
-#pragma once
-
+#pragma once
+
#include "fwd.h"
-#include "future.h"
-
+#include "future.h"
+
#include <util/thread/factory.h>
#include <functional>
-namespace NThreading {
+namespace NThreading {
template <typename TR, bool IgnoreException>
class TLegacyFuture: public IThreadFactory::IThreadAble, TNonCopyable {
public:
typedef TR(TFunctionSignature)();
using TFunctionObjectType = std::function<TFunctionSignature>;
using TResult = typename TFunctionObjectType::result_type;
-
+
private:
TFunctionObjectType Func_;
TPromise<TResult> Result_;
THolder<IThreadFactory::IThread> Thread_;
-
+
public:
inline TLegacyFuture(const TFunctionObjectType func, IThreadFactory* pool = SystemThreadFactory())
: Func_(func)
@@ -27,24 +27,24 @@ namespace NThreading {
, Thread_(pool->Run(this))
{
}
-
+
inline ~TLegacyFuture() override {
this->Join();
}
-
+
inline TResult Get() {
this->Join();
return Result_.GetValue();
}
-
+
private:
inline void Join() {
if (Thread_) {
Thread_->Join();
Thread_.Destroy();
}
- }
-
+ }
+
template <typename Result, bool IgnoreException_>
struct TExecutor {
static void SetPromise(TPromise<Result>& promise, const TFunctionObjectType& func) {
@@ -54,11 +54,11 @@ namespace NThreading {
} catch (...) {
}
} else {
- promise.SetValue(func());
- }
- }
+ promise.SetValue(func());
+ }
+ }
};
-
+
template <bool IgnoreException_>
struct TExecutor<void, IgnoreException_> {
static void SetPromise(TPromise<void>& promise, const TFunctionObjectType& func) {
@@ -69,15 +69,15 @@ namespace NThreading {
} catch (...) {
}
} else {
- func();
- promise.SetValue();
- }
- }
+ func();
+ promise.SetValue();
+ }
+ }
};
void DoExecute() override {
TExecutor<TResult, IgnoreException>::SetPromise(Result_, Func_);
- }
- };
-
-}
+ }
+ };
+
+}
diff --git a/library/cpp/threading/future/legacy_future_ut.cpp b/library/cpp/threading/future/legacy_future_ut.cpp
index ff63db1725..67c0ea504e 100644
--- a/library/cpp/threading/future/legacy_future_ut.cpp
+++ b/library/cpp/threading/future/legacy_future_ut.cpp
@@ -1,73 +1,73 @@
-#include "legacy_future.h"
-
+#include "legacy_future.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
-namespace NThreading {
+
+namespace NThreading {
Y_UNIT_TEST_SUITE(TLegacyFutureTest) {
int intf() {
return 17;
}
-
+
Y_UNIT_TEST(TestIntFunction) {
TLegacyFuture<int> f((&intf));
UNIT_ASSERT_VALUES_EQUAL(17, f.Get());
}
-
+
static int r;
-
+
void voidf() {
r = 18;
}
-
+
Y_UNIT_TEST(TestVoidFunction) {
r = 0;
TLegacyFuture<> f((&voidf));
f.Get();
UNIT_ASSERT_VALUES_EQUAL(18, r);
}
-
+
struct TSampleClass {
int mValue;
-
+
TSampleClass(int value)
: mValue(value)
{
}
-
+
int Calc() {
return mValue + 1;
}
};
-
+
Y_UNIT_TEST(TestMethod) {
TLegacyFuture<int> f11(std::bind(&TSampleClass::Calc, TSampleClass(3)));
UNIT_ASSERT_VALUES_EQUAL(4, f11.Get());
-
+
TLegacyFuture<int> f12(std::bind(&TSampleClass::Calc, TSampleClass(3)), SystemThreadFactory());
UNIT_ASSERT_VALUES_EQUAL(4, f12.Get());
-
+
TSampleClass c(5);
-
+
TLegacyFuture<int> f21(std::bind(&TSampleClass::Calc, std::ref(c)));
UNIT_ASSERT_VALUES_EQUAL(6, f21.Get());
-
+
TLegacyFuture<int> f22(std::bind(&TSampleClass::Calc, std::ref(c)), SystemThreadFactory());
UNIT_ASSERT_VALUES_EQUAL(6, f22.Get());
}
-
+
struct TSomeThreadPool: public IThreadFactory {};
-
+
Y_UNIT_TEST(TestFunction) {
std::function<int()> f((&intf));
-
+
UNIT_ASSERT_VALUES_EQUAL(17, TLegacyFuture<int>(f).Get());
UNIT_ASSERT_VALUES_EQUAL(17, TLegacyFuture<int>(f, SystemThreadFactory()).Get());
-
+
if (false) {
TSomeThreadPool* q = nullptr;
TLegacyFuture<int>(f, q); // just check compiles, do not start
}
- }
- }
-
-}
+ }
+ }
+
+}
diff --git a/library/cpp/threading/future/ut/ya.make b/library/cpp/threading/future/ut/ya.make
index 566b622370..b2dce89394 100644
--- a/library/cpp/threading/future/ut/ya.make
+++ b/library/cpp/threading/future/ut/ya.make
@@ -1,14 +1,14 @@
UNITTEST_FOR(library/cpp/threading/future)
-
+
OWNER(
g:rtmr
ishfb
)
-
-SRCS(
+
+SRCS(
async_ut.cpp
- future_ut.cpp
- legacy_future_ut.cpp
-)
-
-END()
+ future_ut.cpp
+ legacy_future_ut.cpp
+)
+
+END()
diff --git a/library/cpp/threading/future/wait/wait-inl.h b/library/cpp/threading/future/wait/wait-inl.h
index 2753d5446c..27f7528cd9 100644
--- a/library/cpp/threading/future/wait/wait-inl.h
+++ b/library/cpp/threading/future/wait/wait-inl.h
@@ -4,7 +4,7 @@
#error "you should never include wait-inl.h directly"
#endif // INCLUDE_FUTURE_INL_H
-namespace NThreading {
+namespace NThreading {
namespace NImpl {
template <typename TContainer>
TVector<TFuture<void>> ToVoidFutures(const TContainer& futures) {
diff --git a/library/cpp/threading/future/wait/wait.cpp b/library/cpp/threading/future/wait/wait.cpp
index a173833a7f..e538e2876f 100644
--- a/library/cpp/threading/future/wait/wait.cpp
+++ b/library/cpp/threading/future/wait/wait.cpp
@@ -3,7 +3,7 @@
#include "wait_group.h"
#include "wait_policy.h"
-namespace NThreading {
+namespace NThreading {
namespace {
template <class WaitPolicy>
TFuture<void> WaitGeneric(const TFuture<void>& f1) {
diff --git a/library/cpp/threading/future/wait/wait.h b/library/cpp/threading/future/wait/wait.h
index 6ff7d57baa..361af5c2b9 100644
--- a/library/cpp/threading/future/wait/wait.h
+++ b/library/cpp/threading/future/wait/wait.h
@@ -7,7 +7,7 @@
#include <util/generic/array_ref.h>
-namespace NThreading {
+namespace NThreading {
namespace NImpl {
template <class TContainer>
using EnableGenericWait = std::enable_if_t<
diff --git a/library/cpp/threading/future/ya.make b/library/cpp/threading/future/ya.make
index 6591031f46..aea750cb3e 100644
--- a/library/cpp/threading/future/ya.make
+++ b/library/cpp/threading/future/ya.make
@@ -2,10 +2,10 @@ OWNER(
g:rtmr
)
-LIBRARY()
-
+LIBRARY()
+
SRCS(
- async.cpp
+ async.cpp
core/future.cpp
core/fwd.cpp
fwd.cpp
@@ -15,7 +15,7 @@ SRCS(
wait/wait_policy.cpp
)
-END()
+END()
RECURSE_FOR_TESTS(
mt_ut