aboutsummaryrefslogtreecommitdiffstats
path: root/util/thread/factory.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /util/thread/factory.cpp
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'util/thread/factory.cpp')
-rw-r--r--util/thread/factory.cpp128
1 files changed, 64 insertions, 64 deletions
diff --git a/util/thread/factory.cpp b/util/thread/factory.cpp
index 0de161f007..48e898f32d 100644
--- a/util/thread/factory.cpp
+++ b/util/thread/factory.cpp
@@ -1,71 +1,71 @@
#include "factory.h"
-
-#include <util/system/thread.h>
-#include <util/generic/singleton.h>
-
+
+#include <util/system/thread.h>
+#include <util/generic/singleton.h>
+
using IThread = IThreadFactory::IThread;
-
-namespace {
+
+namespace {
class TSystemThreadFactory: public IThreadFactory {
- public:
- class TPoolThread: public IThread {
- public:
+ public:
+ class TPoolThread: public IThread {
+ public:
~TPoolThread() override {
- if (Thr_) {
- Thr_->Detach();
- }
- }
-
+ if (Thr_) {
+ Thr_->Detach();
+ }
+ }
+
void DoRun(IThreadAble* func) override {
- Thr_.Reset(new TThread(ThreadProc, func));
-
- Thr_->Start();
- }
-
+ Thr_.Reset(new TThread(ThreadProc, func));
+
+ Thr_->Start();
+ }
+
void DoJoin() noexcept override {
- if (!Thr_) {
- return;
- }
-
- Thr_->Join();
- Thr_.Destroy();
- }
-
- private:
- static void* ThreadProc(void* func) {
- ((IThreadAble*)(func))->Execute();
-
+ if (!Thr_) {
+ return;
+ }
+
+ Thr_->Join();
+ Thr_.Destroy();
+ }
+
+ private:
+ static void* ThreadProc(void* func) {
+ ((IThreadAble*)(func))->Execute();
+
return nullptr;
- }
-
- private:
- THolder<TThread> Thr_;
- };
-
+ }
+
+ private:
+ THolder<TThread> Thr_;
+ };
+
inline TSystemThreadFactory() noexcept {
- }
-
+ }
+
IThread* DoCreate() override {
- return new TPoolThread;
- }
- };
+ return new TPoolThread;
+ }
+ };
class TThreadFactoryFuncObj: public IThreadFactory::IThreadAble {
- public:
+ public:
TThreadFactoryFuncObj(const std::function<void()>& func)
- : Func(func)
- {
- }
+ : Func(func)
+ {
+ }
void DoExecute() override {
THolder<TThreadFactoryFuncObj> self(this);
- Func();
- }
-
- private:
+ Func();
+ }
+
+ private:
std::function<void()> Func;
};
-}
-
+}
+
THolder<IThread> IThreadFactory::Run(std::function<void()> func) {
THolder<IThread> ret(DoCreate());
@@ -76,18 +76,18 @@ THolder<IThread> IThreadFactory::Run(std::function<void()> func) {
static IThreadFactory* SystemThreadPoolImpl() {
return Singleton<TSystemThreadFactory>();
-}
-
+}
+
static IThreadFactory* systemPool = nullptr;
-
+
IThreadFactory* SystemThreadFactory() {
- if (systemPool) {
- return systemPool;
- }
-
- return SystemThreadPoolImpl();
-}
-
+ if (systemPool) {
+ return systemPool;
+ }
+
+ return SystemThreadPoolImpl();
+}
+
void SetSystemThreadFactory(IThreadFactory* pool) {
- systemPool = pool;
-}
+ systemPool = pool;
+}