2 Copyright 2005-2014 Intel Corporation. All Rights Reserved.
4 This file is part of Threading Building Blocks. Threading Building Blocks is free software;
5 you can redistribute it and/or modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation. Threading Building Blocks is
7 distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
8 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9 See the GNU General Public License for more details. You should have received a copy of
10 the GNU General Public License along with Threading Building Blocks; if not, write to the
11 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13 As a special exception, you may use this file as part of a free software library without
14 restriction. Specifically, if other files instantiate templates or use macros or inline
15 functions from this file, or you compile this file and link it with other files to produce
16 an executable, this file does not by itself cause the resulting executable to be covered
17 by the GNU General Public License. This exception does not however invalidate any other
18 reasons why the executable file might be covered by the GNU General Public License.
21 #ifndef __TBB_runtime_loader_H
22 #define __TBB_runtime_loader_H
24 #if ! TBB_PREVIEW_RUNTIME_LOADER
25 #error Set TBB_PREVIEW_RUNTIME_LOADER to include runtime_loader.h
28 #include "tbb_stddef.h"
32 #if ! __TBB_NO_IMPLICIT_LINKAGE
34 #pragma comment( linker, "/nodefaultlib:tbb_debug.lib" )
35 #pragma comment( linker, "/defaultlib:tbbproxy_debug.lib" )
37 #pragma comment( linker, "/nodefaultlib:tbb.lib" )
38 #pragma comment( linker, "/defaultlib:tbbproxy.lib" )
45 namespace interface6 {
47 //! Load TBB at runtime.
55 #include "tbb/runtime_loader.h"
57 char const * path[] = { "<install dir>/lib/ia32", NULL };
58 tbb::runtime_loader loader( path );
63 Link with \c tbbproxy.lib (or \c libtbbproxy.a) instead of \c tbb.lib (\c libtbb.dylib,
66 TBB library will be loaded at runtime from \c <install dir>/lib/ia32 directory.
70 All \c runtime_loader objects (in the same module, i.e. exe or dll) share some global state.
71 The most noticeable piece of global state is loaded TBB library.
72 There are some implications:
74 - Only one TBB library can be loaded per module.
76 - If one object has already loaded TBB library, another object will not load TBB.
77 If the loaded TBB library is suitable for the second object, both will use TBB
78 cooperatively, otherwise the second object will report an error.
80 - \c runtime_loader objects will not work (correctly) in parallel due to absence of
85 class runtime_loader : tbb::internal::no_copy {
89 //! Error mode constants.
91 em_status, //!< Save status of operation and continue.
92 em_throw, //!< Throw an exception of tbb::runtime_loader::error_code type.
93 em_abort //!< Print message to \c stderr and call \c abort().
98 ec_ok, //!< No errors.
99 ec_bad_call, //!< Invalid function call (e. g. load() called when TBB is already loaded).
100 ec_bad_arg, //!< Invalid argument passed.
101 ec_bad_lib, //!< Invalid library found (e. g. \c TBB_runtime_version symbol not found).
102 ec_bad_ver, //!< TBB found but version is not suitable.
103 ec_no_lib //!< No suitable TBB library found.
106 //! Initialize object but do not load TBB.
107 runtime_loader( error_mode mode = em_abort );
109 //! Initialize object and load TBB.
111 See load() for details.
113 If error mode is \c em_status, call status() to check whether TBB was loaded or not.
116 char const * path[], //!< List of directories to search TBB in.
117 int min_ver = TBB_INTERFACE_VERSION, //!< Minimal suitable version of TBB.
118 int max_ver = INT_MAX, //!< Maximal suitable version of TBB.
119 error_mode mode = em_abort //!< Error mode for this object.
127 The method searches the directories specified in \c path[] array for the TBB library.
128 When the library is found, it is loaded and its version is checked. If the version is
129 not suitable, the library is unloaded, and the search continues.
133 For security reasons, avoid using relative directory names. For example, never load
134 TBB from current (\c "."), parent (\c "..") or any other relative directory (like
135 \c "lib" ). Use only absolute directory names (e. g. "/usr/local/lib").
137 For the same security reasons, avoid using system default directories (\c "") on
138 Windows. (See http://www.microsoft.com/technet/security/advisory/2269637.mspx for
141 Neglecting these rules may cause your program to execute 3-rd party malicious code.
144 - \c ec_bad_call - TBB already loaded by this object.
145 - \c ec_bad_arg - \p min_ver and/or \p max_ver negative or zero,
146 or \p min_ver > \p max_ver.
147 - \c ec_bad_ver - TBB of unsuitable version already loaded by another object.
148 - \c ec_no_lib - No suitable library found.
152 char const * path[], //!< List of directories to search TBB in.
153 int min_ver = TBB_INTERFACE_VERSION, //!< Minimal suitable version of TBB.
154 int max_ver = INT_MAX //!< Maximal suitable version of TBB.
161 If error mode is \c em_status, the function returns status of the last operation.
167 error_mode const my_mode;
168 error_code my_status;
171 }; // class runtime_loader
173 } // namespace interface6
175 using interface6::runtime_loader;
179 #endif /* __TBB_runtime_loader_H */