Commit 796ecc7b authored by schultezub's avatar schultezub
Browse files

introducing locked state for processors

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@446 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 99b5c682
......@@ -98,18 +98,25 @@ namespace campvis {
void AbstractPipeline::executeProcessor(AbstractProcessor* processor) {
tgtAssert(processor != 0, "Processor must not be 0.");
if (processor->getEnabled() && !processor->getInvalidationLevel().isValid()) {
processor->lockProperties();
processor->setEnabled(false); // TODO: dirty hack to avoid multiple execution of the same processor -> introduce s.th. like _processor.isLocked()
if (processor->getEnabled() && !processor->isLocked() && !processor->getInvalidationLevel().isValid()) {
processor->lockProcessor();
#ifdef CAMPVIS_DEBUG
clock_t startTime = clock();
#endif
processor->process(_data);
try {
processor->process(_data);
}
catch (std::exception& e) {
LERROR("Caught unhandled exception while executing processor " << processor->getName() << ": " << e.what());
}
catch (...) {
LERROR("Caught unhandled exception while executing processor " << processor->getName() << ": unknown exception");
}
#ifdef CAMPVIS_DEBUG
clock_t endTime = clock();
#endif
processor->setEnabled(true);
processor->unlockProperties();
processor->unlockProcessor();
#ifdef CAMPVIS_DEBUG
LDEBUG("Executed processor " << processor->getName() << " duration: " << (endTime - startTime));
......
......@@ -27,6 +27,7 @@
//
// ================================================================================================
#include "tgt/assert.h"
#include "abstractprocessor.h"
namespace campvis {
......@@ -36,8 +37,9 @@ namespace campvis {
AbstractProcessor::AbstractProcessor()
: HasPropertyCollection()
, _enabled(true)
{
_enabled = true;
_locked = 0;
}
AbstractProcessor::~AbstractProcessor() {
......@@ -66,12 +68,20 @@ namespace campvis {
}
void AbstractProcessor::lockProperties() {
void AbstractProcessor::lockProcessor() {
while (_locked.compare_and_swap(true, false) == true); // TODO: busy waiting us fu**ing ugly...
_locked = true;
lockAllProperties();
}
void AbstractProcessor::unlockProperties() {
void AbstractProcessor::unlockProcessor() {
tgtAssert(_locked == true, "Called AbstractProcessor::unlockProcessor() on unlocked processor!");
unlockAllProperties();
_locked = false;
}
bool AbstractProcessor::isLocked() {
return _locked != 0;
}
void AbstractProcessor::onPropertyChanged(const AbstractProperty* prop) {
......
......@@ -31,6 +31,7 @@
#define PROCESSOR_H__
#include "sigslot/sigslot.h"
#include "tbb/include/tbb/atomic.h"
#include "tgt/logmanager.h"
#include "core/datastructures/datacontainer.h"
#include "core/tools/invalidationlevel.h"
......@@ -138,17 +139,24 @@ namespace campvis {
void setEnabled(bool enabled);
/**
*
* Locks all properties in the processor's PropertyCollection and marks them as "in use".
* \sa AbstractProcessor::unlock
* \sa AbstractProcessor::unlockProcessor
*/
void lockProperties();
void lockProcessor();
/**
* Unlocks all properties in the processor's PropertyCollection and marks them as "not in use".
* \sa AbstractProcessor::lock
* \sa AbstractProcessor::lockProcessor
*/
void unlockProperties();
void unlockProcessor();
/**
* Returns the current lockProcessor status of this processor.
* If a processor is locked, all of its properties are locked and its process method must not be called.
* \return _locked != 0
*/
bool isLocked();
/// Signal emitted when the processor has been invalidated.
sigslot::signal1<AbstractProcessor*> s_invalidated;
......@@ -162,7 +170,11 @@ namespace campvis {
protected:
InvalidationLevel _invalidationLevel; ///< current invalidation level of this processor
bool _enabled; ///< flag whether this processor is currently enabled
tbb::atomic<bool> _enabled; ///< flag whether this processor is currently enabled
/// Flag whether this processor is currently locked
/// (This implies, that all properties are locked and it is not valid to call process())
tbb::atomic<bool> _locked;
static const std::string loggerCat_;
};
......
......@@ -177,6 +177,11 @@ namespace campvis {
_effectiveRenderTargetSize.s_changed.connect<AdvancedUsVis>(this, &AdvancedUsVis::onRenderTargetSizeChanged);
}
void AdvancedUsVis::deinit() {
_effectiveRenderTargetSize.s_changed.disconnect(this);
VisualizationPipeline::deinit();
}
void AdvancedUsVis::execute() {
{
tbb::spin_mutex::scoped_lock lock(_localMutex);
......
......@@ -61,6 +61,9 @@ namespace campvis {
/// \see VisualizationPipeline::init()
virtual void init();
/// \see VisualizationPipeline::deinit()
virtual void deinit();
/// \see AbstractPipeline::getName()
virtual const std::string getName() const;
......
......@@ -143,6 +143,11 @@ namespace campvis {
_effectiveRenderTargetSize.s_changed.connect<DVRVis>(this, &DVRVis::onRenderTargetSizeChanged);
}
void DVRVis::deinit() {
_effectiveRenderTargetSize.s_changed.disconnect(this);
VisualizationPipeline::deinit();
}
void DVRVis::execute() {
{
tbb::spin_mutex::scoped_lock lock(_localMutex);
......
......@@ -60,6 +60,9 @@ namespace campvis {
/// \see VisualizationPipeline::init()
virtual void init();
/// \see VisualizationPipeline::deinit()
virtual void deinit();
/// \see AbstractPipeline::getName()
virtual const std::string getName() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment