pipelineevaluator.cpp 1.33 KB
Newer Older
1
#include "pipelineevaluator.h"
2
#include "tgt/qt/qtcontextmanager.h"
3
4
5

namespace TUMVis {
    PipelineEvaluator::PipelineEvaluator(AbstractPipeline* pipeline)
6
7
        : Runnable()
        , _pipeline(pipeline)
8
9
10
11
12
13
14
15
16
    {
        tgtAssert(pipeline != 0, "Pipeline must not be 0.");
        pipeline->s_PipelineInvalidated.connect(this, &PipelineEvaluator::OnPipelineInvalidated);
    }

    PipelineEvaluator::~PipelineEvaluator() {
        _pipeline->s_PipelineInvalidated.disconnect(this);
    }

17
    void PipelineEvaluator::run() {
18
        std::unique_lock<tbb::mutex> lock(_pipeline->_evaluationMutex);
19

20
        while (! _stopExecution) {
21
22
            _pipeline->execute();

23
            while (!_stopExecution && _pipeline->getInvalidationLevel().isValid())
24
25
                _evaluationCondition.wait(lock);
        }
26
27
28

        // release OpenGL context, so that other threads can access it
        CtxtMgr.releaseCurrentContext();
29
30
    }

31
    void PipelineEvaluator::stop() {
32
        // we need to execute run() one more time to ensure correct release of the OpenGL context
33
        _stopExecution = true;
34
        _evaluationCondition.notify_all();
35

36
        Runnable::stop();
37
38
39
    }

    void PipelineEvaluator::OnPipelineInvalidated() {
40
        if (!_stopExecution)
41
42
43
44
            _evaluationCondition.notify_all();
    }

}