code format

This commit is contained in:
2022-12-14 14:13:52 +03:00
parent 430a41fefc
commit c2b8a8d6da
297 changed files with 27331 additions and 24162 deletions

View File

@@ -1,23 +1,24 @@
/*
PIP - Platform Independent Primitives
Thread pool loop
Ivan Pelipenko peri4ko@yandex.ru
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 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.
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/>.
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/>.
*/
#include "pithreadpoolloop.h"
#include "pisysteminfo.h"
#include "pithread.h"
@@ -102,27 +103,25 @@
PIThreadPoolLoop::PIThreadPoolLoop(int thread_cnt) {
if (thread_cnt <= 0)
thread_cnt = piMaxi(1, PISystemInfo::instance()->processorsCount);
piForTimes (thread_cnt) {
if (thread_cnt <= 0) thread_cnt = piMaxi(1, PISystemInfo::instance()->processorsCount);
piForTimes(thread_cnt) {
auto * t = new PIThread();
threads << t;
}
//piCout << "PIThreadPoolLoop" << proc_cnt << "threads";
// piCout << "PIThreadPoolLoop" << proc_cnt << "threads";
}
PIThreadPoolLoop::~PIThreadPoolLoop() {
for (auto * t: threads) {
t->stop();
if (!t->waitForFinish(100))
t->terminate();
if (!t->waitForFinish(100)) t->terminate();
delete t;
}
}
void PIThreadPoolLoop::setFunction(std::function<void (int)> f) {
void PIThreadPoolLoop::setFunction(std::function<void(int)> f) {
func = f;
}
@@ -131,7 +130,7 @@ void PIThreadPoolLoop::start(int index_start, int index_count) {
counter = index_start;
int end = index_start + index_count;
for (auto * t: threads)
t->start([this,end,t](){
t->start([this, end, t]() {
while (1) {
int cc = counter.fetch_add(1);
if (cc >= end) {
@@ -150,7 +149,7 @@ void PIThreadPoolLoop::exec(int index_start, int index_count) {
}
void PIThreadPoolLoop::exec(int index_start, int index_count, std::function<void (int)> f) {
void PIThreadPoolLoop::exec(int index_start, int index_count, std::function<void(int)> f) {
setFunction(f);
exec(index_start, index_count);
}