diff options
author | gulin <gulin@yandex-team.ru> | 2022-02-10 16:47:32 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:32 +0300 |
commit | 7199613d295246a07c2f7b331fbb3128936039dc (patch) | |
tree | c0748b5dcbade83af788c0abfa89c0383d6b779c /library/cpp/threading/local_executor | |
parent | c807aae441c17fc7f577c35757a4b6e0bd909802 (diff) | |
download | ydb-7199613d295246a07c2f7b331fbb3128936039dc.tar.gz |
Restoring authorship annotation for <gulin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/threading/local_executor')
-rw-r--r-- | library/cpp/threading/local_executor/local_executor.cpp | 36 | ||||
-rw-r--r-- | library/cpp/threading/local_executor/local_executor.h | 14 |
2 files changed, 25 insertions, 25 deletions
diff --git a/library/cpp/threading/local_executor/local_executor.cpp b/library/cpp/threading/local_executor/local_executor.cpp index 271e763498..1d3fbb4bf4 100644 --- a/library/cpp/threading/local_executor/local_executor.cpp +++ b/library/cpp/threading/local_executor/local_executor.cpp @@ -5,24 +5,24 @@ #include <util/generic/utility.h> #include <util/system/atomic.h> #include <util/system/event.h> -#include <util/system/thread.h> +#include <util/system/thread.h> #include <util/system/tls.h> -#include <util/system/yield.h> +#include <util/system/yield.h> #include <util/thread/lfqueue.h> - + #include <utility> -#ifdef _win_ +#ifdef _win_ static void RegularYield() { -} -#else -// unix actually has cooperative multitasking! :) -// without this function program runs slower and system lags for some magic reason +} +#else +// unix actually has cooperative multitasking! :) +// without this function program runs slower and system lags for some magic reason static void RegularYield() { - SchedYield(); -} -#endif - + SchedYield(); +} +#endif + namespace { struct TFunctionWrapper : NPar::ILocallyExecutable { NPar::TLocallyExecutableFunction Exec; @@ -79,15 +79,15 @@ namespace { : Exec(std::move(exec)) , Id(id) { - } + } }; - + class TLocalRangeExecutor: public NPar::ILocallyExecutable { TIntrusivePtr<NPar::ILocallyExecutable> Exec; alignas(64) TAtomic Counter; alignas(64) TAtomic WorkerCount; int LastId; - + void LocalExec(int) override { AtomicAdd(WorkerCount, 1); for (;;) { @@ -96,7 +96,7 @@ namespace { } AtomicAdd(WorkerCount, -1); } - + public: TLocalRangeExecutor(TIntrusivePtr<ILocallyExecutable> exec, int firstId, int lastId) : Exec(std::move(exec)) @@ -121,8 +121,8 @@ namespace { return Max<int>(LastId - Counter, 0); } }; - -} + +} ////////////////////////////////////////////////////////////////////////// class NPar::TLocalExecutor::TImpl { diff --git a/library/cpp/threading/local_executor/local_executor.h b/library/cpp/threading/local_executor/local_executor.h index 0fdd20454b..c1c824f67c 100644 --- a/library/cpp/threading/local_executor/local_executor.h +++ b/library/cpp/threading/local_executor/local_executor.h @@ -1,5 +1,5 @@ -#pragma once - +#pragma once + #include <library/cpp/threading/future/future.h> #include <util/generic/cast.h> @@ -10,7 +10,7 @@ #include <util/generic/ymath.h> #include <functional> - + namespace NPar { struct ILocallyExecutable : virtual public TThrRefBase { // Must be implemented by the end user to define job that will be processed by one of @@ -20,7 +20,7 @@ namespace NPar { // some dummy value, e.g. `0`. 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`. // @@ -196,8 +196,8 @@ namespace NPar { } return false; } - }; - + }; + // `TLocalExecutor` provides facilities for easy parallelization of existing code and cycles. // // Examples: @@ -291,4 +291,4 @@ namespace NPar { params.SetBlockCountToThreadCount(); LocalExecutor().ExecRange(std::forward<TBody>(body), params, 0); } -} +} |