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