Commit e1da80822d6e074b704ad9b71222827821edaa68

Authored by Charles Otto
1 parent 14ce2fa6

Reduce memory use during ProcessWrapper initialization

Showing 1 changed file with 21 additions and 1 deletions
openbr/plugins/process.cpp
@@ -349,6 +349,7 @@ public: @@ -349,6 +349,7 @@ public:
349 QByteArray data = readArray; 349 QByteArray data = readArray;
350 QDataStream deserializer(data); 350 QDataStream deserializer(data);
351 Transform *res = Transform::deserialize(deserializer); 351 Transform *res = Transform::deserialize(deserializer);
  352 + sendSignal(SignalType::OUTPUT_AVAILABLE);
352 return res; 353 return res;
353 } 354 }
354 355
@@ -534,6 +535,8 @@ struct ProcessData @@ -534,6 +535,8 @@ struct ProcessData
534 class ProcessWrapperTransform : public WrapperTransform 535 class ProcessWrapperTransform : public WrapperTransform
535 { 536 {
536 Q_OBJECT 537 Q_OBJECT
  538 + Q_PROPERTY(int concurrentCount READ get_concurrentCount WRITE set_concurrentCount RESET reset_concurrentCount STORED false)
  539 + BR_PROPERTY(int, concurrentCount, 2)
537 540
538 QString baseKey; 541 QString baseKey;
539 542
@@ -579,17 +582,33 @@ class ProcessWrapperTransform : public WrapperTransform @@ -579,17 +582,33 @@ class ProcessWrapperTransform : public WrapperTransform
579 if (transform) { 582 if (transform) {
580 QDataStream out(&serialized, QFile::WriteOnly); 583 QDataStream out(&serialized, QFile::WriteOnly);
581 transform->serialize(out); 584 transform->serialize(out);
  585 + tcount = Globals->parallelism;
  586 + counter.acquire(counter.available());
  587 + counter.release(this->concurrentCount);
582 } 588 }
583 } 589 }
584 590
585 - QByteArray serialized; 591 + static QSemaphore counter;
  592 + mutable int tcount;
  593 + mutable QByteArray serialized;
586 void transmitTForm(CommunicationManager *localComm) const 594 void transmitTForm(CommunicationManager *localComm) const
587 { 595 {
588 if (serialized.isEmpty() ) 596 if (serialized.isEmpty() )
589 qFatal("Trying to transmit empty transform!"); 597 qFatal("Trying to transmit empty transform!");
590 598
  599 + counter.acquire(1);
  600 + static QMutex transmission;
  601 + QMutexLocker lock(&transmission);
  602 + tcount--;
  603 +
591 localComm->writeArray = serialized; 604 localComm->writeArray = serialized;
  605 + if (tcount == 0)
  606 + serialized.clear();
  607 + lock.unlock();
  608 +
592 emit localComm->pulseSendSerialized(); 609 emit localComm->pulseSendSerialized();
  610 + localComm->getSignal();
  611 + counter.release(1);
593 } 612 }
594 613
595 void activateProcess(ProcessData *data) const 614 void activateProcess(ProcessData *data) const
@@ -633,6 +652,7 @@ public: @@ -633,6 +652,7 @@ public:
633 bool processActive; 652 bool processActive;
634 ProcessWrapperTransform() : WrapperTransform(false) { processActive = false; } 653 ProcessWrapperTransform() : WrapperTransform(false) { processActive = false; }
635 }; 654 };
  655 +QSemaphore ProcessWrapperTransform::counter;
636 656
637 BR_REGISTER(Transform, ProcessWrapperTransform) 657 BR_REGISTER(Transform, ProcessWrapperTransform)
638 658