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

[CHANGE] - no kernel class uses deprectaed WSharedAccess stuff anymore

parent 18f27e1d
......@@ -81,16 +81,14 @@ WQtConfigWidget::~WQtConfigWidget()
void WQtConfigWidget::getAvailableModuleNames()
{
WModuleFactory::PrototypeSharedContainerType::WSharedAccess pa = WModuleFactory::getModuleFactory()->getAvailablePrototypes();
m_moduleNames.clear();
// Temporarily disabled since locking causes several problems here :-/
// pa->beginRead();
// read all prototypes
WModuleFactory::PrototypeSharedContainerType::ReadTicket pa = WModuleFactory::getModuleFactory()->getPrototypes();
for ( WModuleFactory::PrototypeContainerConstIteratorType itr = pa->get().begin(); itr != pa->get().end(); ++itr )
{
m_moduleNames.push_back( ( *itr )->getName() );
}
// pa->endRead();
}
void WQtConfigWidget::updatePropertyGroups( boost::shared_ptr< WProperties > properties, std::string groupName, bool fromConfig )
......
......@@ -72,8 +72,7 @@
boost::shared_ptr< WModuleFactory > WModuleFactory::m_instance = boost::shared_ptr< WModuleFactory >();
WModuleFactory::WModuleFactory():
m_prototypes(),
m_prototypeAccess( m_prototypes.getAccessObject() )
m_prototypes()
{
// initialize members
}
......@@ -89,7 +88,7 @@ void WModuleFactory::load()
WLogger::getLogger()->addLogMessage( "Loading Modules", "ModuleFactory", LL_INFO );
// operation must be exclusive
m_prototypeAccess->beginWrite();
PrototypeSharedContainerType::WriteTicket m_prototypeAccess = m_prototypes.getWriteTicket();
// currently the prototypes are added by hand. This will be done automatically later.
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMApplyMask() ) );
......@@ -127,14 +126,15 @@ void WModuleFactory::load()
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMSplineSurface() ) );
m_prototypeAccess->get().insert( boost::shared_ptr< WModule >( new WMAtlasSurfaces() ) );
m_prototypeAccess->endWrite();
// unlock as read lock is sufficient for the further steps
m_prototypeAccess.reset();
// for this a read lock is sufficient
m_prototypeAccess->beginRead();
// for this a read lock is sufficient, gets unlocked if it looses scope
PrototypeSharedContainerType::ReadTicket l = m_prototypes.getReadTicket();
// initialize every module in the set
std::set< std::string > names; // helper to find duplicates
for( std::set< boost::shared_ptr< WModule > >::iterator listIter = m_prototypeAccess->get().begin(); listIter != m_prototypeAccess->get().end();
for( PrototypeContainerConstIteratorType listIter = l->get().begin(); listIter != l->get().end();
++listIter )
{
WLogger::getLogger()->addLogMessage( "Loading module: \"" + ( *listIter )->getName() + "\"", "ModuleFactory", LL_INFO );
......@@ -148,24 +148,23 @@ void WModuleFactory::load()
initializeModule( ( *listIter ) );
}
m_prototypeAccess->endRead();
}
boost::shared_ptr< WModule > WModuleFactory::create( boost::shared_ptr< WModule > prototype )
{
wlog::debug( "ModuleFactory" ) << "Creating new instance of prototype \"" << prototype->getName() << "\".";
// for this a read lock is sufficient
m_prototypeAccess->beginRead();
// for this a read lock is sufficient, gets unlocked if it looses scope
PrototypeSharedContainerType::ReadTicket l = m_prototypes.getReadTicket();
// ensure this one is a prototype and nothing else
if ( m_prototypeAccess->get().count( prototype ) == 0 )
if ( l->get().count( prototype ) == 0 )
{
throw WPrototypeUnknown( "Could not clone module \"" + prototype->getName() + "\" since it is no prototype." );
}
m_prototypeAccess->endRead();
// explicitly unlock
l.reset();
// call prototypes factory function
boost::shared_ptr< WModule > clone = boost::shared_ptr< WModule >( prototype->factory() );
......@@ -192,12 +191,12 @@ boost::shared_ptr< WModuleFactory > WModuleFactory::getModuleFactory()
const boost::shared_ptr< WModule > WModuleFactory::isPrototypeAvailable( std::string name )
{
// for this a read lock is sufficient
m_prototypeAccess->beginRead();
// for this a read lock is sufficient, gets unlocked if it looses scope
PrototypeSharedContainerType::ReadTicket l = m_prototypes.getReadTicket();
// find first and only prototype (ensured during load())
boost::shared_ptr< WModule > ret = boost::shared_ptr< WModule >();
for( std::set< boost::shared_ptr< WModule > >::iterator listIter = m_prototypeAccess->get().begin(); listIter != m_prototypeAccess->get().end();
for( std::set< boost::shared_ptr< WModule > >::iterator listIter = l->get().begin(); listIter != l->get().end();
++listIter )
{
if ( ( *listIter )->getName() == name )
......@@ -207,8 +206,6 @@ const boost::shared_ptr< WModule > WModuleFactory::isPrototypeAvailable( std::st
}
}
m_prototypeAccess->endRead();
return ret;
}
......@@ -230,6 +227,11 @@ const boost::shared_ptr< WModule > WModuleFactory::getPrototypeByInstance( boost
return getPrototypeByName( instance->getName() );
}
WModuleFactory::PrototypeSharedContainerType::ReadTicket WModuleFactory::getPrototypes() const
{
return m_prototypes.getReadTicket();
}
/**
* Sorting function for sorting the compatibles list. It uses the alphabetical order of the names.
*
......@@ -247,11 +249,12 @@ std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > WModuleFactory::getC
{
std::vector< boost::shared_ptr < WApplyPrototypeCombiner > > compatibles;
// for this a read lock is sufficient
m_prototypeAccess->beginRead();
// for this a read lock is sufficient, gets unlocked if it looses scope
PrototypeSharedContainerType::ReadTicket l = m_prototypes.getReadTicket();
// First, add all modules with no input connector.
for( std::set< boost::shared_ptr< WModule > >::iterator listIter = m_prototypeAccess->get().begin(); listIter != m_prototypeAccess->get().end();
for( PrototypeContainerConstIteratorType listIter = l->get().begin(); listIter != l->get().end();
++listIter )
{
// get connectors of this prototype
......@@ -288,7 +291,7 @@ std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > WModuleFactory::getC
// }
// go through every prototype
for( std::set< boost::shared_ptr< WModule > >::iterator listIter = m_prototypeAccess->get().begin(); listIter != m_prototypeAccess->get().end();
for( PrototypeContainerConstIteratorType listIter = l->get().begin(); listIter != l->get().end();
++listIter )
{
// get connectors of this prototype
......@@ -318,7 +321,8 @@ std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > WModuleFactory::getC
}
}
m_prototypeAccess->endRead();
// unlock. No locking needed for further steps.
l.reset();
// sort the compatibles
std::sort( compatibles.begin(), compatibles.end(), compatiblesSort );
......@@ -326,9 +330,3 @@ std::vector< boost::shared_ptr< WApplyPrototypeCombiner > > WModuleFactory::getC
return compatibles;
}
const WModuleFactory::PrototypeSharedContainerType::WSharedAccess WModuleFactory::getAvailablePrototypes() const
{
// TODO(ebaum): deprecated. Clean up if not needed anymore.
return m_prototypeAccess;
}
......@@ -65,11 +65,6 @@ public:
*/
typedef WSharedAssociativeContainer< PrototypeContainerType > PrototypeSharedContainerType;
/**
* Alias for the proper access object
*/
typedef PrototypeSharedContainerType::WSharedAccess PrototypeAccess;
/**
* Default constructor.
*/
......@@ -131,6 +126,13 @@ public:
*/
const boost::shared_ptr< WModule > getPrototypeByInstance( boost::shared_ptr< WModule > instance );
/**
* This method gives read access to the list of all prototypes.
*
* \return the read ticket for the prototype list
*/
PrototypeSharedContainerType::ReadTicket getPrototypes() const;
/**
* Checks whether the first instance can be casted to the second one.
*
......@@ -163,14 +165,6 @@ public:
*/
static void initializeModule( boost::shared_ptr< WModule > module );
/**
* Get access to all the prototypes.
*
* \deprecated do not use this anymore. Use \ref getPrototypes instead.
* \return the access object to thread safe iterate.
*/
const PrototypeSharedContainerType::WSharedAccess getAvailablePrototypes() const;
protected:
/**
......@@ -178,11 +172,6 @@ protected:
*/
PrototypeSharedContainerType m_prototypes;
/**
* The lock for the prototypes set.
*/
PrototypeSharedContainerType::WSharedAccess m_prototypeAccess;
private:
/**
......
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