Commit e1da80822d6e074b704ad9b71222827821edaa68
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 | 349 | QByteArray data = readArray; |
| 350 | 350 | QDataStream deserializer(data); |
| 351 | 351 | Transform *res = Transform::deserialize(deserializer); |
| 352 | + sendSignal(SignalType::OUTPUT_AVAILABLE); | |
| 352 | 353 | return res; |
| 353 | 354 | } |
| 354 | 355 | |
| ... | ... | @@ -534,6 +535,8 @@ struct ProcessData |
| 534 | 535 | class ProcessWrapperTransform : public WrapperTransform |
| 535 | 536 | { |
| 536 | 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 | 541 | QString baseKey; |
| 539 | 542 | |
| ... | ... | @@ -579,17 +582,33 @@ class ProcessWrapperTransform : public WrapperTransform |
| 579 | 582 | if (transform) { |
| 580 | 583 | QDataStream out(&serialized, QFile::WriteOnly); |
| 581 | 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 | 594 | void transmitTForm(CommunicationManager *localComm) const |
| 587 | 595 | { |
| 588 | 596 | if (serialized.isEmpty() ) |
| 589 | 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 | 604 | localComm->writeArray = serialized; |
| 605 | + if (tcount == 0) | |
| 606 | + serialized.clear(); | |
| 607 | + lock.unlock(); | |
| 608 | + | |
| 592 | 609 | emit localComm->pulseSendSerialized(); |
| 610 | + localComm->getSignal(); | |
| 611 | + counter.release(1); | |
| 593 | 612 | } |
| 594 | 613 | |
| 595 | 614 | void activateProcess(ProcessData *data) const |
| ... | ... | @@ -633,6 +652,7 @@ public: |
| 633 | 652 | bool processActive; |
| 634 | 653 | ProcessWrapperTransform() : WrapperTransform(false) { processActive = false; } |
| 635 | 654 | }; |
| 655 | +QSemaphore ProcessWrapperTransform::counter; | |
| 636 | 656 | |
| 637 | 657 | BR_REGISTER(Transform, ProcessWrapperTransform) |
| 638 | 658 | ... | ... |