71 lines
2.0 KiB
C++
71 lines
2.0 KiB
C++
/*! \file pithreadpoolloop.h
|
|
* \ingroup Thread
|
|
* \~\brief
|
|
* \~english Thread pool loop
|
|
* \~russian Пул потоков
|
|
*/
|
|
/*
|
|
PIP - Platform Independent Primitives
|
|
Thread pool loop
|
|
Ivan Pelipenko peri4ko@yandex.ru
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef PITHREADPOOLLOOP_H
|
|
#define PITHREADPOOLLOOP_H
|
|
|
|
#include "pivector.h"
|
|
|
|
class PIThread;
|
|
|
|
class PIP_EXPORT PIThreadPoolLoop {
|
|
public:
|
|
|
|
//! Contructs thread pool with threads count "thread_cnt".
|
|
//! If "thread_cnt" = -1 then system processors count used
|
|
PIThreadPoolLoop(int thread_cnt = -1);
|
|
|
|
virtual ~PIThreadPoolLoop();
|
|
|
|
//! Set threads function to "f" with format [](int){...}
|
|
void setFunction(std::function<void(int)> f);
|
|
|
|
//! Wait for all threads stop
|
|
void wait();
|
|
|
|
//! Start functions execution with integer argument range
|
|
//! from "index_start" to "index_start + index_count - 1"
|
|
void start(int index_start, int index_count);
|
|
|
|
//! Start functions execution with integer argument range
|
|
//! from "index_start" to "index_start + index_count - 1"
|
|
//! and wait for finish
|
|
void exec(int index_start, int index_count);
|
|
|
|
//! Start functions "f" execution with integer argument range
|
|
//! from "index_start" to "index_start + index_count - 1"
|
|
//! and wait for finish
|
|
void exec(int index_start, int index_count, std::function<void(int)> f);
|
|
|
|
private:
|
|
PIVector<PIThread * > threads;
|
|
std::function<void(int)> func;
|
|
std::atomic_int counter;
|
|
|
|
};
|
|
|
|
|
|
#endif
|