aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/threading/local_executor/local_executor.h
diff options
context:
space:
mode:
authorDmitry Baksheev <dbakshee@yandex.ru>2022-02-10 16:48:12 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:12 +0300
commit0e38f1d675a0b3d02016acf698e8d04c0b224047 (patch)
treeb222e5ac2e2e98872661c51ccceee5da0d291e13 /library/cpp/threading/local_executor/local_executor.h
parent17fe552c0aa936de030b2b72934d9688ab9bb1c6 (diff)
downloadydb-0e38f1d675a0b3d02016acf698e8d04c0b224047.tar.gz
Restoring authorship annotation for Dmitry Baksheev <dbakshee@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/threading/local_executor/local_executor.h')
-rw-r--r--library/cpp/threading/local_executor/local_executor.h66
1 files changed, 33 insertions, 33 deletions
diff --git a/library/cpp/threading/local_executor/local_executor.h b/library/cpp/threading/local_executor/local_executor.h
index dd75382ba1..c1c824f67c 100644
--- a/library/cpp/threading/local_executor/local_executor.h
+++ b/library/cpp/threading/local_executor/local_executor.h
@@ -21,11 +21,11 @@ namespace NPar {
virtual void LocalExec(int id) = 0;
};
- // Alternative and simpler way of describing a job for executor. Function argument has the
- // same meaning as `id` in `ILocallyExecutable::LocalExec`.
- //
- using TLocallyExecutableFunction = std::function<void(int)>;
-
+ // Alternative and simpler way of describing a job for executor. Function argument has the
+ // same meaning as `id` in `ILocallyExecutable::LocalExec`.
+ //
+ using TLocallyExecutableFunction = std::function<void(int)>;
+
class ILocalExecutor: public TNonCopyable {
public:
ILocalExecutor() = default;
@@ -157,34 +157,34 @@ namespace NPar {
ExecRange(BlockedLoopBody(params, body), 0, params.GetBlockCount(), flags);
}
- template <typename TBody>
- inline void ExecRangeBlockedWithThrow(TBody&& body, int firstId, int lastId, int batchSizeOrZeroForAutoBatchSize, int flags) {
- if (firstId >= lastId) {
- return;
- }
- const int threadCount = Max(GetThreadCount(), 1);
- const int batchSize = batchSizeOrZeroForAutoBatchSize
- ? batchSizeOrZeroForAutoBatchSize
- : (lastId - firstId + threadCount - 1) / threadCount;
- const int batchCount = (lastId - firstId + batchSize - 1) / batchSize;
- const int batchCountPerThread = (batchCount + threadCount - 1) / threadCount;
- auto states = ExecRangeWithFutures(
- [=](int threadId) {
- for (int batchIdPerThread = 0; batchIdPerThread < batchCountPerThread; ++batchIdPerThread) {
- int batchId = batchIdPerThread * threadCount + threadId;
- int begin = firstId + batchId * batchSize;
- int end = Min(begin + batchSize, lastId);
- for (int i = begin; i < end; ++i) {
- body(i);
- }
- }
- },
- 0, threadCount, flags);
- for (auto& state: states) {
- state.GetValueSync(); // Re-throw exception if any.
- }
- }
-
+ template <typename TBody>
+ inline void ExecRangeBlockedWithThrow(TBody&& body, int firstId, int lastId, int batchSizeOrZeroForAutoBatchSize, int flags) {
+ if (firstId >= lastId) {
+ return;
+ }
+ const int threadCount = Max(GetThreadCount(), 1);
+ const int batchSize = batchSizeOrZeroForAutoBatchSize
+ ? batchSizeOrZeroForAutoBatchSize
+ : (lastId - firstId + threadCount - 1) / threadCount;
+ const int batchCount = (lastId - firstId + batchSize - 1) / batchSize;
+ const int batchCountPerThread = (batchCount + threadCount - 1) / threadCount;
+ auto states = ExecRangeWithFutures(
+ [=](int threadId) {
+ for (int batchIdPerThread = 0; batchIdPerThread < batchCountPerThread; ++batchIdPerThread) {
+ int batchId = batchIdPerThread * threadCount + threadId;
+ int begin = firstId + batchId * batchSize;
+ int end = Min(begin + batchSize, lastId);
+ for (int i = begin; i < end; ++i) {
+ body(i);
+ }
+ }
+ },
+ 0, threadCount, flags);
+ for (auto& state: states) {
+ state.GetValueSync(); // Re-throw exception if any.
+ }
+ }
+
template <typename TBody>
static inline bool TryExecRangeSequentially(TBody&& body, int firstId, int lastId, int flags) {
if (lastId == firstId) {