X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=blobdiff_plain;f=src%2Fdllmain.cpp;h=2802bdb533692b6dd4e59351e742d3ab5f102e04;hp=eff1fcc95802a909c77116344aaa0b3ff500abd7;hb=bc277979f85299cd681e5a413d63f0c7f1d67beb;hpb=40e34e6d0b104b6f5aff506ad67d43fd410e52bc diff --git a/src/dllmain.cpp b/src/dllmain.cpp index eff1fcc9..2802bdb5 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -53,6 +53,14 @@ static HINSTANCE s_DllInstance = nullptr; static unsigned int s_nProcessorCount = 1; static unsigned int s_nProcessorGroupCount = 1; +static inline void* get_proc_addr( char const* module, char const* func ) +{ + HMODULE h = GetModuleHandle( module ); + if ( !h ) + return nullptr; + return GetProcAddress( h, func ); +} + // Array of processor - cell relationship // Array size is s_nProcessorCount // s_arrProcessorCellRelationship[i] is the cell (the processor group) number for i-th processor @@ -78,7 +86,7 @@ static void discover_topology() s_nProcessorCount = 1; s_nProcessorGroupCount = 1; - glpi = (LPFN_GLPI) GetProcAddress( GetModuleHandle("kernel32"), "GetLogicalProcessorInformation" ); + glpi = (LPFN_GLPI) get_proc_addr( "kernel32", "GetLogicalProcessorInformation" ); if ( glpi == nullptr ) { return; } @@ -194,9 +202,9 @@ namespace cds { namespace OS { CDS_CXX11_INLINE_NAMESPACE namespace Win32 { static void prepare_current_processor_call() { - s_fnGetCurrentProcessorNumber = (fnGetCurrentProcessorNumber) GetProcAddress( GetModuleHandle("kernel32"), "GetCurrentProcessorNumber" ); + s_fnGetCurrentProcessorNumber = (fnGetCurrentProcessorNumber) get_proc_addr( "kernel32", "GetCurrentProcessorNumber" ); if ( s_fnGetCurrentProcessorNumber == nullptr ) - s_fnGetCurrentProcessorNumber = (fnGetCurrentProcessorNumber) GetProcAddress( GetModuleHandle("ntdll"), "NtGetCurrentProcessorNumber" ); + s_fnGetCurrentProcessorNumber = (fnGetCurrentProcessorNumber) get_proc_addr( "ntdll", "NtGetCurrentProcessorNumber" ); } namespace cds { namespace OS { CDS_CXX11_INLINE_NAMESPACE namespace Win32 {