Commit e306d5b2 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - WSubject now uses read/write tickets too

[DOC]
[STYLE]
parent 989b9942
......@@ -141,20 +141,6 @@ public:
boost::shared_ptr< WCondition > m_objectChangeCondition;
};
/**
* Use a shared_ptr since the shared and unique locks from boost are non-copyable.
*/
typedef boost::shared_ptr< WSharedObjectAccess > WSharedAccess;
/**
* This method distributes access objects. These objects are able to read/write lock the object and grant access to it, in
* a thread-safe manner.
*
* \deprecated do not use this anymore. Use \ref getReadTicket and \ref getWriteTicket instead
* \return the access object which allows thread safe access to the object.
*/
WSharedAccess getAccessObject();
/**
* Type for read tickets.
*/
......@@ -181,6 +167,20 @@ public:
*/
WriteTicket getWriteTicket( bool suppressNotify = false ) const;
/**
* Use a shared_ptr since the shared and unique locks from boost are non-copyable.
*/
typedef boost::shared_ptr< WSharedObjectAccess > WSharedAccess;
/**
* This method distributes access objects. These objects are able to read/write lock the object and grant access to it, in
* a thread-safe manner.
*
* \deprecated do not use this anymore. Use getReadTicket and getWriteTicket instead
* \return the access object which allows thread safe access to the object.
*/
WSharedAccess getAccessObject();
/**
* This condition fires whenever the encapsulated object changed. This is fired automatically by endWrite().
*
......
......@@ -37,7 +37,6 @@
WSubject::WSubject():
m_datasets(),
m_datasetAccess( m_datasets.getAccessObject() ),
m_changeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
m_listChangeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
m_personalInfo( WPersonalInformation::createDummyInformation() )
......@@ -46,7 +45,6 @@ WSubject::WSubject():
WSubject::WSubject( WPersonalInformation personInfo ):
m_datasets(),
m_datasetAccess( m_datasets.getAccessObject() ),
m_changeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
m_listChangeCondition( boost::shared_ptr< WConditionSet >( new WConditionSet() ) ),
m_personalInfo( personInfo )
......@@ -85,11 +83,11 @@ void WSubject::addDataSet( boost::shared_ptr< WDataSet > dataset )
void WSubject::removeDataSet( boost::shared_ptr< WDataSet > dataset )
{
m_datasetAccess->beginWrite();
DatasetSharedContainerType::WriteTicket l = m_datasets.getWriteTicket();
// iterate and find, remove
DatasetContainerType::iterator fIt = std::find( m_datasetAccess->get().begin(), m_datasetAccess->get().end(), dataset );
m_datasetAccess->get().erase( fIt );
DatasetIterator fIt = std::find( l->get().begin(), l->get().end(), dataset );
l->get().erase( fIt );
// also deregister condition
boost::shared_ptr< WCondition > c = dataset->getChangeCondition();
......@@ -97,7 +95,9 @@ void WSubject::removeDataSet( boost::shared_ptr< WDataSet > dataset )
{
m_changeCondition->remove( c );
}
m_datasetAccess->endWrite();
// unlock if some callback notified below wants to access the list
l.reset();
m_changeCondition->notify();
m_listChangeCondition->notify();
......@@ -105,33 +105,40 @@ void WSubject::removeDataSet( boost::shared_ptr< WDataSet > dataset )
void WSubject::clear()
{
m_datasetAccess->beginWrite();
DatasetSharedContainerType::WriteTicket l = m_datasets.getWriteTicket();
// iterate and find, remove
for ( DatasetContainerType::iterator iter = m_datasetAccess->get().begin(); iter != m_datasetAccess->get().end(); ++iter )
for ( DatasetIterator iter = l->get().begin(); iter != l->get().end(); ++iter )
{
// also deregister condition
// also de-register condition
boost::shared_ptr< WCondition > c = ( *iter )->getChangeCondition();
if ( c.get() )
{
m_changeCondition->remove( c );
}
}
m_datasetAccess->get().clear();
l->get().clear();
m_datasetAccess->endWrite();
// unlock if some callback notified below wants to access the list
l.reset();
m_listChangeCondition->notify();
}
WSubject::DatasetSharedContainerType::ReadTicket WSubject::getDatasets() const
{
return m_datasets.getReadTicket();
}
std::vector< boost::shared_ptr< WDataTexture3D > > WSubject::getDataTextures( bool onlyActive )
{
std::vector< boost::shared_ptr< WDataTexture3D > > tex;
// iterate the list and find all textures
m_datasetAccess->beginRead();
// Read lock the list, the lock is freed upon destruction of the ticket (if it goes out of scope for example).
DatasetSharedContainerType::ReadTicket l = m_datasets.getReadTicket();
for ( DatasetContainerType::iterator iter = m_datasetAccess->get().begin(); iter != m_datasetAccess->get().end(); ++iter )
// iterate the list and find all textures
for ( DatasetConstIterator iter = l->get().begin(); iter != l->get().end(); ++iter )
{
// is it a texture?
if ( ( *iter )->isTexture() && ( !onlyActive || ( *iter )->getTexture()->isGloballyActive() ) )
......@@ -140,12 +147,12 @@ std::vector< boost::shared_ptr< WDataTexture3D > > WSubject::getDataTextures( bo
}
}
m_datasetAccess->endRead();
return tex;
}
WSubject::DatasetAccess WSubject::getAccessObject()
{
// TODO(ebaum): clean up if it is not used anymore
return m_datasets.getAccessObject();
}
......
......@@ -69,6 +69,16 @@ public:
*/
typedef WSharedSequenceContainer< boost::shared_ptr< WDataSet >, DatasetContainerType > DatasetSharedContainerType;
/**
* The dataset iterator.
*/
typedef DatasetContainerType::iterator DatasetIterator;
/**
* The dataset const iterator.
*/
typedef DatasetContainerType::const_iterator DatasetConstIterator;
/**
* Alias for the proper access object
*/
......@@ -124,6 +134,13 @@ public:
*/
void clear();
/**
* Returns read-access to the dataset list. As long as the returned ticket exists, the list of datasets can't be changed by others.
*
* \return the read ticket.
*/
DatasetSharedContainerType::ReadTicket getDatasets() const;
/**
* This gives a list of data textures from all supporting datasets in this subject.
*
......@@ -135,6 +152,7 @@ public:
/**
* Gets an access object which allows thread save iteration over the datasets.
*
* \deprecated do not use this anymore. Use getDatasets instead.
* \return the access object.
*/
DatasetAccess getAccessObject();
......@@ -160,11 +178,6 @@ protected:
*/
DatasetSharedContainerType m_datasets;
/**
* The access object used for thread safe access.
*/
DatasetSharedContainerType::WSharedAccess m_datasetAccess;
/**
* This condition set fires whenever one dataset gets dirty or the list of datasets changes.
*/
......
......@@ -88,20 +88,18 @@ public:
dummyDataSet->setFileName( fileName );
WSubject dummySubject;
WSubject::DatasetAccess a = dummySubject.getAccessObject();
dummySubject.addDataSet( dummyDataSet );
TS_ASSERT_EQUALS( 1, dummySubject.m_datasets.size() );
// iterate the list and find all textures
a->beginRead();
WSubject::DatasetSharedContainerType::ReadTicket a = dummySubject.getDatasets();
int count = 0;
for ( WSubject::DatasetContainerType::iterator iter = a->get().begin(); iter != a->get().end(); ++iter )
for ( WSubject::DatasetConstIterator iter = a->get().begin(); iter != a->get().end(); ++iter )
{
count++;
TS_ASSERT_EQUALS( fileName, ( *iter )->getFileName() );
TS_ASSERT_EQUALS( dummyDataSet, ( *iter ) );
}
a->endRead();
TS_ASSERT( count == 1 );
}
......
......@@ -78,7 +78,7 @@ public:
* defines are a better choice when compared with a lot of branches (if-statements).
*
* \param key The name of the define
* \param value The value of the define. If this is not specified, the define can be used as simple #ifdef switch.
* \param value The value of the define. If this is not specified, the define can be used as simple ifdef switch.
*/
void setDefine( std::string key, float value = 1.0 );
......
......@@ -139,13 +139,17 @@ private:
*/
WPropInt m_alpha;
/**
* Types of shading supported.
*/
enum
{
Cortex = 0,
Depth,
Phong,
PhongDepth
} SHADING_ALGORITHMS;
}
SHADING_ALGORITHMS;
/**
* The available shading algorithms.
......
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