From: Christian P. <cp...@us...> - 2005-05-07 11:55:59
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29688/include/pclasses Modified Files: Factory.h Log Message: - Added thread-safety to Factory and System::Plugin Index: Factory.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Factory.h,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- Factory.h 6 May 2005 15:16:01 -0000 1.22 +++ Factory.h 7 May 2005 11:55:47 -0000 1.23 @@ -28,6 +28,7 @@ #include <pclasses/Export.h> #include <pclasses/NonCopyable.h> #include <pclasses/SharingContext.h> +#include <pclasses/CoreMutex.h> #include <map> #include <list> @@ -42,6 +43,8 @@ will share the same Factory-instances. If we would put the instance- creation code into a template class each compilation unit will use it's own instance, leading to unwanted behaviour. + + All methods in this class are reentrant. */ class PCORE_EXPORT FactoryBase: public NonCopyable { public: @@ -113,6 +116,8 @@ Factory<InterfaceT> instantiations. ContextT is only used as a marker type, and is never instantiated by this class. Used cleverly, it can allow you quite a bit of freedom in what code has access to which factories. + + All methods in this class are reentrant. */ template <class InterfaceT, class ContextT = Sharing::FactoryContext> class Factory: FactoryBase { @@ -129,6 +134,7 @@ */ InterfaceT* create(const std::string& key) { + CoreMutex::ScopedLock lck(_mutex); std::string realKey = expandAlias(key); typename FactoryMap::const_iterator i = _factoryMap.find(realKey); @@ -166,6 +172,7 @@ P_TRACE(Factory) << "Register alias=" << aliasKey << " for key=" << isKey; + CoreMutex::ScopedLock lck(_mutex); _aliasMap.insert(std::make_pair(aliasKey, isKey)); } @@ -177,6 +184,7 @@ */ std::string expandAlias(const std::string& alias) const { + CoreMutex::ScopedLock lck(_mutex); P_TRACE(Factory) << "expandAlias("<<alias<<")"; typename AliasMap::const_iterator cit = _aliasMap.find(alias), cet = _aliasMap.end(); @@ -210,6 +218,7 @@ */ bool provides(const std::string& key) const { + CoreMutex::ScopedLock lck(_mutex); std::string realKey = expandAlias(key); typename FactoryMap::const_iterator i = _factoryMap.find(realKey); if(i == _factoryMap.end()) @@ -234,6 +243,7 @@ P_TRACE(Factory) << "registerFactory(): key=" << key << ", fc=" << typeid(fc).name(); + CoreMutex::ScopedLock lck(_mutex); _factoryMap.insert(std::make_pair(key, fc)); } @@ -269,6 +279,7 @@ FactoryMap _factoryMap; AliasMap _aliasMap; + mutable CoreMutex _mutex; }; } // !namespace P |