Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

opengljobprocessor.cpp 4.79 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
4
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
schultezub's avatar
schultezub committed
11
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
12
// 
13
14
15
16
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
17
// 
18
19
20
21
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
22
23
24
25
26
// 
// ================================================================================================

#include "opengljobprocessor.h"

27
28
#include <tbb/tick_count.h>

29
#include "tgt/assert.h"
30
31
#include "tgt/logmanager.h"
#include "tgt/openglgarbagecollector.h"
32
#include "tgt/glcontextmanager.h"
33

34
namespace tgt {
35

36
37
38
    OpenGLJobProcessor::ScopedSynchronousGlJobExecution::ScopedSynchronousGlJobExecution()
        : _lock(nullptr)
    {
39
        if (! GLCtxtMgr.checkWhetherThisThreadHasAcquiredOpenGlContext()) {
40
            GLJobProc.pause();
41
            _lock = new tgt::GLContextScopedLock(GLJobProc.getContext());
42
43
44
45
46
47
48
49
50
51
52
53
        }
    }

    OpenGLJobProcessor::ScopedSynchronousGlJobExecution::~ScopedSynchronousGlJobExecution() {
        if (_lock != nullptr) {
            delete _lock;
            GLJobProc.resume();
        }
    }

// ================================================================================================
    
54
55
    OpenGLJobProcessor::OpenGLJobProcessor()
    {
56
        _pause = 0;
57
        _context= nullptr;
58
59
60
    }

    OpenGLJobProcessor::~OpenGLJobProcessor() {
61
62
63
64
        // delete all unfinished jobs
        AbstractJob* jobToDo = nullptr;
        while (_jobQueue.try_pop(jobToDo)) {
            delete jobToDo;
schultezub's avatar
schultezub committed
65
        }
66

67
        _jobQueue.clear();
68
        _jobPool.recycle();
69
70
71
72
73
    }

    void OpenGLJobProcessor::stop() {
        _stopExecution = true;
        _evaluationCondition.notify_all();
74
75

        Runnable::stop();
76
77
78
    }

    void OpenGLJobProcessor::run() {
79
80
81
        tgtAssert(_context != nullptr, "You have to set the context first before calling OpenGLJobProcessor::run()!");
        std::unique_lock<std::mutex> lock(*tgt::GlContextManager::getRef().getGlMutexForContext(_context));
        tgt::GlContextManager::getRef().acquireContext(_context, false);
82
83

        while (! _stopExecution) {
84
85
            bool hadWork = false;

86
87
            AbstractJob* jobToDo = nullptr;
            while (_pause == 0 && !_stopExecution && _jobQueue.try_pop(jobToDo)) {
88
89
                hadWork = true;

90
91
92
                // execute and delete the job
                jobToDo->execute();
                delete jobToDo;
93
            }
94

95
            while (_pause > 0) {
96
                tgt::GlContextManager::getRef().releaseContext(_context, false);
97
                _evaluationCondition.wait(lock);
98
                tgt::GlContextManager::getRef().acquireContext(_context, false);
99
100
                hadWork = true;
            }
101

102
            if (! hadWork) {
103
                tgt::GlContextManager::getRef().releaseContext(_context, false);
104
                _evaluationCondition.wait(lock);
105
                tgt::GlContextManager::getRef().acquireContext(_context, false);
106
            }
107
108
109
        }

        // release OpenGL context, so that other threads can access it
110
        tgt::GlContextManager::getRef().releaseContext(_context, false);
111
112
    }

113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
    void OpenGLJobProcessor::pause() {
        ++_pause;
    }

    void OpenGLJobProcessor::resume() {
        if (_pause == 0) {
            tgtAssert(false, "Called resume on non-paused job processor!");
            return;
        }

        --_pause;
        if (_pause == 0)
            _evaluationCondition.notify_all();
    }

128
129
    void OpenGLJobProcessor::enqueueJob(AbstractJob* job) {
        _jobQueue.push(job);
130
131
        _evaluationCondition.notify_all();
    }
132

133
134
135
    void OpenGLJobProcessor::setContext(tgt::GLCanvas* context) {
        tgtAssert(_context == nullptr, "You are trying to change an already set context, thou shalt not do that!");
        _context = context;
136
137
    }

138
    tgt::GLCanvas* OpenGLJobProcessor::getContext() {
139
        return _context;
140
141
    }

142

143
144
}