diff options
author | dobrokot <dobrokot@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
commit | 25d83bf841d8b3ce3886525078f1964ac3c293c5 (patch) | |
tree | bd52fa16c8dd727890b2ef9d87d1a402bd0d3a9a /util/thread/pool.h | |
parent | 1d2e8a8e9976488ea69a7e4763aa749244f82612 (diff) | |
download | ydb-25d83bf841d8b3ce3886525078f1964ac3c293c5.tar.gz |
Restoring authorship annotation for <dobrokot@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/thread/pool.h')
-rw-r--r-- | util/thread/pool.h | 126 |
1 files changed, 63 insertions, 63 deletions
diff --git a/util/thread/pool.h b/util/thread/pool.h index d1ea3a67cb..ad0f447cc4 100644 --- a/util/thread/pool.h +++ b/util/thread/pool.h @@ -15,22 +15,22 @@ class TDuration; struct IObjectInQueue { virtual ~IObjectInQueue() = default; - /** - * Supposed to be implemented by user, to define jobs processed - * in multiple threads. - * - * @param threadSpecificResource is nullptr by default. But if you override + /** + * Supposed to be implemented by user, to define jobs processed + * in multiple threads. + * + * @param threadSpecificResource is nullptr by default. But if you override * IThreadPool::CreateThreadSpecificResource, then result of * IThreadPool::CreateThreadSpecificResource is passed as threadSpecificResource - * parameter. - */ - virtual void Process(void* threadSpecificResource) = 0; + * parameter. + */ + virtual void Process(void* threadSpecificResource) = 0; }; -/** - * Mighty class to add 'Pool' method to derived classes. - * Useful only for creators of new queue classes. - */ +/** + * Mighty class to add 'Pool' method to derived classes. + * Useful only for creators of new queue classes. + */ class TThreadFactoryHolder { public: TThreadFactoryHolder() noexcept; @@ -133,20 +133,20 @@ struct TThreadPoolParams { } }; -/** +/** * A queue processed simultaneously by several threads - */ + */ class IThreadPool: public IThreadFactory, public TNonCopyable { public: using TParams = TThreadPoolParams; ~IThreadPool() override = default; - - /** - * Safe versions of Add*() functions. Behave exactly like as non-safe - * version of Add*(), but use exceptions instead returning false - */ - void SafeAdd(IObjectInQueue* obj); + + /** + * Safe versions of Add*() functions. Behave exactly like as non-safe + * version of Add*(), but use exceptions instead returning false + */ + void SafeAdd(IObjectInQueue* obj); template <class T> void SafeAddFunc(T&& func) { @@ -154,13 +154,13 @@ public: } void SafeAddAndOwn(THolder<IObjectInQueue> obj); - - /** - * Add object to queue, run ojb->Proccess in other threads. - * Obj is not deleted after execution - * @return true of obj is successfully added to queue - * @return false if queue is full or shutting down - */ + + /** + * Add object to queue, run ojb->Proccess in other threads. + * Obj is not deleted after execution + * @return true of obj is successfully added to queue + * @return false if queue is full or shutting down + */ virtual bool Add(IObjectInQueue* obj) Y_WARN_UNUSED_RESULT = 0; template <class T> @@ -174,17 +174,17 @@ public: } bool AddAndOwn(THolder<IObjectInQueue> obj) Y_WARN_UNUSED_RESULT; - virtual void Start(size_t threadCount, size_t queueSizeLimit = 0) = 0; + virtual void Start(size_t threadCount, size_t queueSizeLimit = 0) = 0; /** Wait for completion of all scheduled objects, and then exit */ virtual void Stop() noexcept = 0; - /** Number of tasks currently in queue */ + /** Number of tasks currently in queue */ virtual size_t Size() const noexcept = 0; - -public: - /** - * RAII wrapper for Create/DestroyThreadSpecificResource. + +public: + /** + * RAII wrapper for Create/DestroyThreadSpecificResource. * Useful only for implementers of new IThreadPool queues. - */ + */ class TTsr { public: inline TTsr(IThreadPool* q) @@ -210,12 +210,12 @@ public: void* Data_; }; - /** - * CreateThreadSpecificResource and DestroyThreadSpecificResource + /** + * CreateThreadSpecificResource and DestroyThreadSpecificResource * called from internals of (TAdaptiveThreadPool, TThreadPool, ...) implementation, * not by user of IThreadPool interface. - * Created resource is passed to IObjectInQueue::Proccess function. - */ + * Created resource is passed to IObjectInQueue::Proccess function. + */ virtual void* CreateThreadSpecificResource() { return nullptr; } @@ -230,11 +230,11 @@ private: IThread* DoCreate() override; }; -/** +/** * Single-threaded implementation of IThreadPool, process tasks in same thread when - * added. - * Can be used to remove multithreading. - */ + * added. + * Can be used to remove multithreading. + */ class TFakeThreadPool: public IThreadPool { public: bool Add(IObjectInQueue* pObj) override Y_WARN_UNUSED_RESULT { @@ -263,17 +263,17 @@ protected: TParams Params; }; -/** queue processed by fixed size thread pool */ +/** queue processed by fixed size thread pool */ class TThreadPool: public TThreadPoolBase { public: TThreadPool(const TParams& params = {}); ~TThreadPool() override; bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; - /** - * @param queueSizeLimit means "unlimited" when = 0 - * @param threadCount means "single thread" when = 0 - */ + /** + * @param queueSizeLimit means "unlimited" when = 0 + * @param threadCount means "single thread" when = 0 + */ void Start(size_t threadCount, size_t queueSizeLimit = 0) override; void Stop() noexcept override; size_t Size() const noexcept override; @@ -286,24 +286,24 @@ private: THolder<TImpl> Impl_; }; -/** - * Always create new thread for new task, when all existing threads are busy. - * Maybe dangerous, number of threads is not limited. - */ +/** + * Always create new thread for new task, when all existing threads are busy. + * Maybe dangerous, number of threads is not limited. + */ class TAdaptiveThreadPool: public TThreadPoolBase { public: TAdaptiveThreadPool(const TParams& params = {}); ~TAdaptiveThreadPool() override; - /** - * If working thread waits task too long (more then interval parameter), - * then the thread would be killed. Default value - infinity, all created threads - * waits for new task forever, before Stop. - */ + /** + * If working thread waits task too long (more then interval parameter), + * then the thread would be killed. Default value - infinity, all created threads + * waits for new task forever, before Stop. + */ void SetMaxIdleTime(TDuration interval); bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; - /** @param thrnum, @param maxque are ignored */ + /** @param thrnum, @param maxque are ignored */ void Start(size_t thrnum = 0, size_t maxque = 0) override; void Stop() noexcept override; size_t Size() const noexcept override; @@ -320,10 +320,10 @@ public: ~TSimpleThreadPool() override; bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; - /** + /** * @parameter thrnum. If thrnum is 0, use TAdaptiveThreadPool with small * SetMaxIdleTime interval parameter. if thrnum is not 0, use non-blocking TThreadPool - */ + */ void Start(size_t thrnum, size_t maxque = 0) override; void Stop() noexcept override; size_t Size() const noexcept override; @@ -332,11 +332,11 @@ private: THolder<IThreadPool> Slave_; }; -/** - * Helper to override virtual functions Create/DestroyThreadSpecificResource +/** + * Helper to override virtual functions Create/DestroyThreadSpecificResource * from IThreadPool and implement them using functions with same name from - * pointer to TSlave. - */ + * pointer to TSlave. + */ template <class TQueueType, class TSlave> class TThreadPoolBinder: public TQueueType { public: |