MCPcopy Create free account
hub / github.com/cameron314/concurrentqueue / init_ap_data

Function init_ap_data

benchmarks/tbb/dynamic_link.cpp:245–329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

243 } ap_data;
244
245 static void init_ap_data() {
246 #if _WIN32
247 // Get handle of our DLL first.
248 HMODULE handle;
249 BOOL brc = GetModuleHandleExA(
250 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
251 (LPSTR)( & dynamic_link ), // any function inside the library can be used for the address
252 & handle
253 );
254 if ( !brc ) { // Error occurred.
255 int err = GetLastError();
256 DYNAMIC_LINK_WARNING( dl_sys_fail, "GetModuleHandleEx", err );
257 return;
258 }
259 // Now get path to our DLL.
260 DWORD drc = GetModuleFileNameA( handle, ap_data._path, static_cast< DWORD >( PATH_MAX ) );
261 if ( drc == 0 ) { // Error occurred.
262 int err = GetLastError();
263 DYNAMIC_LINK_WARNING( dl_sys_fail, "GetModuleFileName", err );
264 return;
265 }
266 if ( drc >= PATH_MAX ) { // Buffer too short.
267 DYNAMIC_LINK_WARNING( dl_buff_too_small );
268 return;
269 }
270 // Find the position of the last backslash.
271 char *backslash = strrchr( ap_data._path, '\\' );
272
273 if ( !backslash ) { // Backslash not found.
274 LIBRARY_ASSERT( backslash!=NULL, "Unbelievable.");
275 return;
276 }
277 LIBRARY_ASSERT( backslash >= ap_data._path, "Unbelievable.");
278 ap_data._len = (size_t)(backslash - ap_data._path) + 1;
279 *(backslash+1) = 0;
280 #else
281 // Get the library path
282 #if __TBB_WEAK_SYMBOLS_PRESENT
283 if ( !dladdr || !dlerror ) return;
284 #endif /* __TBB_WEAK_SYMBOLS_PRESENT */
285 Dl_info dlinfo;
286 int res = dladdr( (void*)&dynamic_link, &dlinfo ); // any function inside the library can be used for the address
287 if ( !res ) {
288 char const * err = dlerror();
289 DYNAMIC_LINK_WARNING( dl_sys_fail, "dladdr", err );
290 return;
291 } else {
292 LIBRARY_ASSERT( dlinfo.dli_fname!=NULL, "Unbelievable." );
293 }
294
295 char const *slash = strrchr( dlinfo.dli_fname, '/' );
296 size_t fname_len=0;
297 if ( slash ) {
298 LIBRARY_ASSERT( slash >= dlinfo.dli_fname, "Unbelievable.");
299 fname_len = (size_t)(slash - dlinfo.dli_fname) + 1;
300 }
301
302 size_t rc;

Callers 1

init_dl_dataFunction · 0.85

Calls 1

GetLastErrorFunction · 0.85

Tested by

no test coverage detected