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

@@ -5,40 +5,40 @@
* \~russian Класс для создания многопоточного конвейера
*/
/*
PIP - Platform Independent Primitives
Class for create multihread pipeline
Andrey Bychkov work.a.b@yandex.ru
PIP - Platform Independent Primitives
Class for create multihread pipeline
Andrey Bychkov work.a.b@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/>.
*/
#ifndef PIPIPELINETHREAD_H
#define PIPIPELINETHREAD_H
#include "pithread.h"
#include "piqueue.h"
#include "piconditionvar.h"
#include "piqueue.h"
#include "pithread.h"
template <typename Tin, typename Tout>
class PIPipelineThread : public PIThread
{
template<typename Tin, typename Tout>
class PIPipelineThread: public PIThread {
PIOBJECT_SUBCLASS(PIPipelineThread, PIThread);
public:
PIPipelineThread() {
cnt = 0;
max_size = 0;
cnt = 0;
max_size = 0;
wait_next_pipe = false;
}
~PIPipelineThread() {
@@ -49,17 +49,18 @@ public:
terminate();
}
}
template <typename T>
template<typename T>
void connectTo(PIPipelineThread<Tout, T> * next) {
CONNECT3(void, Tout, bool, bool *, this, calculated, next, enqueue);
}
EVENT3(calculated, const Tout &, v, bool, wait, bool *, overload);
EVENT_HANDLER3(void, enqueue, const Tin &, v, bool, wait, bool *, overload) {
mutex.lock();
//piCoutObj << "enque" << overload;
// piCoutObj << "enque" << overload;
if (wait && max_size != 0) {
mutex_wait.lock();
while (in.size() >= max_size) cv_wait.wait(mutex_wait);
while (in.size() >= max_size)
cv_wait.wait(mutex_wait);
mutex_wait.unlock();
}
if (max_size == 0 || in.size() < max_size) {
@@ -71,9 +72,9 @@ public:
}
mutex.unlock();
}
void enqueue(const Tin &v, bool wait = false) {enqueue(v, wait, nullptr);}
const ullong * counterPtr() const {return &cnt;}
ullong counter() const {return cnt;}
void enqueue(const Tin & v, bool wait = false) { enqueue(v, wait, nullptr); }
const ullong * counterPtr() const { return &cnt; }
ullong counter() const { return cnt; }
bool isEmpty() {
bool ret;
mutex.lock();
@@ -115,9 +116,7 @@ public:
return ret;
}
uint maxQueSize() {
return max_size;
}
uint maxQueSize() { return max_size; }
void setMaxQueSize(uint count) {
mutex.lock();
@@ -126,16 +125,16 @@ public:
mutex.unlock();
}
bool isWaitNextPipe() {return wait_next_pipe;}
void setWaitNextPipe(bool wait) {wait_next_pipe = wait;}
bool isWaitNextPipe() { return wait_next_pipe; }
void setWaitNextPipe(bool wait) { wait_next_pipe = wait; }
protected:
virtual Tout calc(Tin &v, bool &ok) = 0;
virtual Tout calc(Tin & v, bool & ok) = 0;
uint max_size;
private:
void begin() override {cnt = 0;}
void begin() override { cnt = 0; }
void run() override {
mutex.lock();
while (in.isEmpty()) {
@@ -151,16 +150,16 @@ private:
cv_wait.notifyAll();
mutex_wait.unlock();
bool ok = true;
Tout r = calc(t, ok);
Tout r = calc(t, ok);
if (ok) {
mutex_last.lock();
last = r;
mutex_last.unlock();
cnt++;
//piCoutObj << "calc ok";
// piCoutObj << "calc ok";
calculated(r, wait_next_pipe);
}
//piCoutObj << "run ok";
// piCoutObj << "run ok";
}
PIMutex mutex, mutex_wait;
PIConditionVariable cv, cv_wait;