From: Christian P. <cp...@us...> - 2005-01-24 01:21:42
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8326/src/System Modified Files: SharedLib.win32.cpp Log Message: Compile fixes for win32. Index: SharedLib.win32.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/SharedLib.win32.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- SharedLib.win32.cpp 26 Dec 2004 14:38:09 -0000 1.7 +++ SharedLib.win32.cpp 24 Jan 2005 01:21:32 -0000 1.8 @@ -42,26 +42,35 @@ SharedLib::SharedLib(const Unicode::String& name, BindMode mode) throw(SystemError) { -// Unicode::String realName = name; -// realName.append(".dll"); + Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); + CriticalSection::ScopedLock lck(cache.mutex); - _handle = (unsigned long)LoadLibrary(name); - if(!_handle) - throw SystemError(GetLastError(), "Could not load shared library", P_SOURCEINFO); + // se if we can get it from the handle cache ... + Cache::iterator i = cache.lookup(name.utf8()); + if(i == cache.end()) + { + //@fixme .. use win32 Unicode API !!! + _handle = (unsigned long)LoadLibrary(name.utf8().c_str()); + if(!_handle) + throw SystemError(GetLastError(), "Could not load shared library", P_SOURCEINFO); + + // add the handle to the cache + cache.add(name.utf8(), _handle); + } + else + { + _handle = i->second; + } } SharedLib::SharedLib(const std::string& name, BindMode mode) throw(SystemError) { -// std::ostringstream realName; -// realName << name; -// realName << ".dll"; - Cache& cache = shared_lib_cache<unsigned long, SharedLibCloser>(); CriticalSection::ScopedLock lck(cache.mutex); // se if we can get it from the handle cache ... - unsigned long handle = cache.lookup(name); - if(handle == Cache::InvalidHandle) + Cache::iterator i = cache.lookup(name); + if(i == cache.end()) { _handle = (unsigned long)LoadLibrary(name.c_str()); if(!_handle) @@ -72,7 +81,7 @@ } else { - _handle = handle; + _handle = i->second; } } |