mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-15 07:59:50 +00:00
Windows: Use GetModuleHandleEx instead of LoadLibrary
We were using an anti-pattern of: - LoadLibrary - GetProcAddress - FreeLibrary This is problematic because of several reasons: - We are holding on to pointers into a library we just unloaded. - Calling LoadLibrary results in an increase in the reference count of the library in question and any libraries that it depends on and so-on and so-forth. This is none too quick. Instead, use GetModuleHandleEx with GET_MODULE_HANDLE_EX_FLAG_PIN. This is done because because we didn't bring the reference for the library into existence and therefor shouldn't count on it being around later. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192550 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
833a29c296
commit
00f31bac0b
@ -48,7 +48,8 @@ static bool loadSRW() {
|
||||
if (!sChecked) {
|
||||
sChecked = true;
|
||||
|
||||
HMODULE hLib = ::LoadLibraryW(L"Kernel32.dll");
|
||||
HMODULE hLib;
|
||||
::GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN, L"Kernel32.dll", &hLib);
|
||||
if (hLib) {
|
||||
fpInitializeSRWLock =
|
||||
(VOID (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib,
|
||||
@ -65,7 +66,6 @@ static bool loadSRW() {
|
||||
fpReleaseSRWLockShared =
|
||||
(VOID (WINAPI *)(PSRWLOCK))::GetProcAddress(hLib,
|
||||
"ReleaseSRWLockShared");
|
||||
::FreeLibrary(hLib);
|
||||
|
||||
if (fpInitializeSRWLock != NULL) {
|
||||
sHasSRW = true;
|
||||
|
Loading…
Reference in New Issue
Block a user