|
From: Frank V. C. <fr...@us...> - 2000-11-24 13:45:11
|
Update of /cvsroot/corelinux/clfll/src/clfll In directory slayer.i.sourceforge.net:/tmp/cvs-serv30620/src/clfll Modified Files: FunctionLibraryInstance.cpp FunctionLoader.cpp Log Message: 112702 Function Library Loader Index: FunctionLibraryInstance.cpp =================================================================== RCS file: /cvsroot/corelinux/clfll/src/clfll/FunctionLibraryInstance.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** FunctionLibraryInstance.cpp 2000/11/21 16:26:04 1.2 --- FunctionLibraryInstance.cpp 2000/11/24 13:45:07 1.3 *************** *** 61,65 **** : LibraryInstance( aName ), ! theLibraryHandle( aLibHandle ) { ; // do nothing --- 61,66 ---- : LibraryInstance( aName ), ! theLibraryHandle( aLibHandle ), ! theReferenceCount( 1 ) { ; // do nothing *************** *** 71,75 **** : LibraryInstance(), ! theLibraryHandle( NULLPTR ) { ; // do nothing --- 72,77 ---- : LibraryInstance(), ! theLibraryHandle( NULLPTR ), ! theReferenceCount( 1 ) { ; // do nothing *************** *** 84,88 **** : LibraryInstance( aCref ), ! theLibraryHandle( NULLPTR ) { ; // do nothing --- 86,91 ---- : LibraryInstance( aCref ), ! theLibraryHandle( NULLPTR ), ! theReferenceCount( 1 ) { ; // do nothing *************** *** 93,97 **** FunctionLibraryInstance::~FunctionLibraryInstance( void ) { ! theLibraryHandle = NULLPTR ; } --- 96,101 ---- FunctionLibraryInstance::~FunctionLibraryInstance( void ) { ! LibraryObjectRegistry::dropAllObjects( this ); ! theLibraryHandle = NULLPTR; } *************** *** 235,238 **** --- 239,269 ---- } + // Get the reference counter value + + Count FunctionLibraryInstance::getReferenceCount( void ) const + { + return theReferenceCount; + } + + // Get the library handle + + Handle FunctionLibraryInstance::getLibraryHandle( void ) const + { + return theLibraryHandle; + } + + // Increase and return + + Count FunctionLibraryInstance::increaseReferenceCount( void ) + { + return ( ++theReferenceCount ); + } + + // Decrease and return + + Count FunctionLibraryInstance::decreaseReferenceCount( void ) + { + return ( --theReferenceCount ); + } } Index: FunctionLoader.cpp =================================================================== RCS file: /cvsroot/corelinux/clfll/src/clfll/FunctionLoader.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** FunctionLoader.cpp 2000/11/20 05:26:35 1.2 --- FunctionLoader.cpp 2000/11/24 13:45:07 1.3 *************** *** 104,117 **** InstanceMapIterator aFItr(FunctionLoader::theInstances.find(aLibName)); if( aFItr != FunctionLoader::theInstances.end() ) { ! aPtr = (*aFItr).second; } else { Handle libHandle( dlopen( aLibName, RTLD_NOW ) ); if( libHandle != NULLPTR ) { aPtr = new FunctionLibraryInstance( aLibName, libHandle ); } else --- 104,129 ---- InstanceMapIterator aFItr(FunctionLoader::theInstances.find(aLibName)); + // If we find we have it, just increment the reference count + if( aFItr != FunctionLoader::theInstances.end() ) { ! FunctionLibraryInstancePtr aFPtr ! ( ! dynamic_cast<FunctionLibraryInstancePtr>((*aFItr).second) ! ); ! aPtr = aFPtr; ! aFPtr->increaseReferenceCount(); } else { + // We create a instance that automatically has a reference + // count of one (1) + Handle libHandle( dlopen( aLibName, RTLD_NOW ) ); + if( libHandle != NULLPTR ) { aPtr = new FunctionLibraryInstance( aLibName, libHandle ); + FunctionLoader::theInstances[aLibName] = aPtr; } else *************** *** 123,126 **** --- 135,187 ---- } + // + // Make sure we have a function library instance and then + // validate it's references before dropping it. + // + + void FunctionLoader::unLoad( LibraryInstancePtr aLibInst ) + throw ( LoadException ) + { + InstanceMapIterator aFItr + ( + FunctionLoader::theInstances.find + ( + aLibInst->getLibraryName() + ) + ); + + if( aFItr != FunctionLoader::theInstances.end() ) + { + FunctionLibraryInstancePtr aFPtr + ( + dynamic_cast<FunctionLibraryInstancePtr>(aLibInst) + ); + if( aFPtr != NULLPTR ) + { + // If this is the last, get the library handle and + // close this puppy before deleting + + if( aFPtr->decreaseReferenceCount() == 0 ) + { + dlclose( aFPtr->getLibraryHandle() ); + delete aFPtr; + } + else + { + ; // do nothing, still references + } + } + else + { + + } + } + else + { + + } + + } + // version FunctionLoader for the MetaType *************** *** 158,162 **** --- 219,242 ---- CLOSE_DISPATCH_FUNCTION; + // Define dispatch function that handles unloading a library + // instance + + DISPATCH_STATIC_FUNCTION( FunctionLoader, unloadInstance ) + ret=ret; + LibraryInstancePtr myPtr = (LibraryInstancePtr ) args ; + if( myPtr != NULLPTR ) + { + FunctionLoader aLoader; + aLoader.unLoad( myPtr ); + } + else + { + ; // do nothing + } + + CLOSE_DISPATCH_FUNCTION; + DEFINE_DISPATCH_DESCRIPTOR( FunctionLoader, loadInstance, loadInstance ); + DEFINE_DISPATCH_DESCRIPTOR( FunctionLoader, unloadInstance, unloadInstance ); // Create the function dispatch table *************** *** 164,167 **** --- 244,248 ---- OPEN_DISPATCH_TABLE( FunctionLoader ) DEFINE_DISPATCH_ENTRY( FunctionLoader, loadInstance ) + DEFINE_DISPATCH_ENTRY( FunctionLoader, unloadInstance ) CLOSE_DISPATCH_TABLE; |