dynamic_link.h
Go to the documentation of this file.
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __TBB_dynamic_link
#define __TBB_dynamic_link
// Support for dynamic loading entry points from other shared libraries.
#include "tbb/tbb_stddef.h"
#ifdef LIBRARY_ASSERT
#undef __TBB_ASSERT
#define __TBB_ASSERT(x,y) LIBRARY_ASSERT(x,y)
#else
#define LIBRARY_ASSERT(x,y) __TBB_ASSERT_EX(x,y)
#endif /* !LIBRARY_ASSERT */
#ifndef OPEN_INTERNAL_NAMESPACE
#define OPEN_INTERNAL_NAMESPACE namespace tbb { namespace internal {
#define CLOSE_INTERNAL_NAMESPACE }}
#endif /* OPEN_INTERNAL_NAMESPACE */
#include <stddef.h>
#if _WIN32
#include "tbb/machine/windows_api.h"
#endif /* _WIN32 */
OPEN_INTERNAL_NAMESPACE
typedef void (*pointer_to_handler)();
// Double cast through the void* in DLD macro is necessary to
// prevent warnings from some compilers (g++ 4.1)
#if __TBB_WEAK_SYMBOLS_PRESENT
#define DLD(s,h) {#s, (pointer_to_handler*)(void*)(&h), (pointer_to_handler)&s}
#define DLD_NOWEAK(s,h) {#s, (pointer_to_handler*)(void*)(&h), NULL}
#else
#define DLD(s,h) {#s, (pointer_to_handler*)(void*)(&h)}
#define DLD_NOWEAK(s,h) DLD(s,h)
#endif /* __TBB_WEAK_SYMBOLS_PRESENT */
struct dynamic_link_descriptor {
const char* name;
pointer_to_handler* handler;
#if __TBB_WEAK_SYMBOLS_PRESENT
pointer_to_handler ptr;
#endif
};
#if _WIN32
typedef HMODULE dynamic_link_handle;
#else
typedef void* dynamic_link_handle;
#endif /* _WIN32 */
const int DYNAMIC_LINK_GLOBAL = 0x01;
const int DYNAMIC_LINK_LOAD = 0x02;
const int DYNAMIC_LINK_WEAK = 0x04;
const int DYNAMIC_LINK_ALL = DYNAMIC_LINK_GLOBAL | DYNAMIC_LINK_LOAD | DYNAMIC_LINK_WEAK;
bool dynamic_link( const char* library,
const dynamic_link_descriptor descriptors[],
size_t required,
dynamic_link_handle* handle = 0,
int flags = DYNAMIC_LINK_ALL );
void dynamic_unlink( dynamic_link_handle handle );
void dynamic_unlink_all();
enum dynamic_link_error_t {
dl_success = 0,
dl_lib_not_found, // char const * lib, dlerr_t err
dl_sym_not_found, // char const * sym, dlerr_t err
// Note: dlerr_t depends on OS: it is char const * on Linux* and macOS*, int on Windows*.
dl_sys_fail, // char const * func, int err
dl_buff_too_small // none
}; // dynamic_link_error_t
CLOSE_INTERNAL_NAMESPACE
#endif /* __TBB_dynamic_link */
windows_api.h
tbb_stddef.h
pointer_to_handler
OPEN_INTERNAL_NAMESPACE typedef void(* pointer_to_handler)()
Type definition for a pointer to a void somefunc(void)
Definition: dynamic_link.h:47
DYNAMIC_LINK_LOAD
const int DYNAMIC_LINK_LOAD
Definition: dynamic_link.h:78
dynamic_link_handle
void * dynamic_link_handle
Definition: dynamic_link.h:74
DYNAMIC_LINK_ALL
const int DYNAMIC_LINK_ALL
Definition: dynamic_link.h:80
CLOSE_INTERNAL_NAMESPACE
#define CLOSE_INTERNAL_NAMESPACE
Definition: dynamic_link.h:36
DYNAMIC_LINK_GLOBAL
const int DYNAMIC_LINK_GLOBAL
Definition: dynamic_link.h:77
dynamic_unlink
void dynamic_unlink(dynamic_link_handle handle)
Definition: dynamic_link.cpp:569
dynamic_link_error_t
dynamic_link_error_t
Definition: dynamic_link.h:108
dl_lib_not_found
@ dl_lib_not_found
Definition: dynamic_link.h:110
dl_sys_fail
@ dl_sys_fail
Definition: dynamic_link.h:113
dl_success
@ dl_success
Definition: dynamic_link.h:109
dl_sym_not_found
@ dl_sym_not_found
Definition: dynamic_link.h:111
dl_buff_too_small
@ dl_buff_too_small
Definition: dynamic_link.h:114
dynamic_link
bool dynamic_link(const char *library, const dynamic_link_descriptor descriptors[], size_t required, dynamic_link_handle *handle=0, int flags=DYNAMIC_LINK_ALL)
Fill in dynamically linked handlers.
OPEN_INTERNAL_NAMESPACE
#define OPEN_INTERNAL_NAMESPACE
Definition: dynamic_link.h:35
DYNAMIC_LINK_WEAK
const int DYNAMIC_LINK_WEAK
Definition: dynamic_link.h:79
dynamic_unlink_all
void dynamic_unlink_all()
Definition: dynamic_link.cpp:570
void
void
Definition: ittnotify_static.h:91
dynamic_link_descriptor
Association between a handler name and location of pointer to it.
Definition: dynamic_link.h:60
dynamic_link_descriptor::handler
pointer_to_handler * handler
Pointer to the handler.
Definition: dynamic_link.h:64
dynamic_link_descriptor::name
const char * name
Name of the handler.
Definition: dynamic_link.h:62

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.