]> git.sesse.net Git - casparcg/blob - dependencies64/tbb/include/tbb/runtime_loader.h
Updated some libraries to newer versions and/or versions compiled for vc12 (freeimage...
[casparcg] / dependencies64 / tbb / include / tbb / runtime_loader.h
1 /*
2     Copyright 2005-2014 Intel Corporation.  All Rights Reserved.
3
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
12
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.
19 */
20
21 #ifndef __TBB_runtime_loader_H
22 #define __TBB_runtime_loader_H
23
24 #if ! TBB_PREVIEW_RUNTIME_LOADER
25     #error Set TBB_PREVIEW_RUNTIME_LOADER to include runtime_loader.h
26 #endif
27
28 #include "tbb_stddef.h"
29 #include <climits>
30
31 #if _MSC_VER
32     #if ! __TBB_NO_IMPLICIT_LINKAGE
33         #ifdef _DEBUG
34             #pragma comment( linker, "/nodefaultlib:tbb_debug.lib" )
35             #pragma comment( linker, "/defaultlib:tbbproxy_debug.lib" )
36         #else
37             #pragma comment( linker, "/nodefaultlib:tbb.lib" )
38             #pragma comment( linker, "/defaultlib:tbbproxy.lib" )
39         #endif
40     #endif
41 #endif
42
43 namespace tbb {
44
45 namespace interface6 {
46
47 //! Load TBB at runtime.
48 /*!
49
50 \b Usage:
51
52 In source code:
53
54 \code
55 #include "tbb/runtime_loader.h"
56
57 char const * path[] = { "<install dir>/lib/ia32", NULL };
58 tbb::runtime_loader loader( path );
59
60 // Now use TBB.
61 \endcode
62
63 Link with \c tbbproxy.lib (or \c libtbbproxy.a) instead of \c tbb.lib (\c libtbb.dylib,
64 \c libtbb.so).
65
66 TBB library will be loaded at runtime from \c <install dir>/lib/ia32 directory.
67
68 \b Attention:
69
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:
73
74     -   Only one TBB library can be loaded per module.
75
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.
79
80     -   \c runtime_loader objects will not work (correctly) in parallel due to absence of
81         synchronization.
82
83 */
84
85 class runtime_loader : tbb::internal::no_copy {
86
87     public:
88
89         //! Error mode constants.
90         enum error_mode {
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().
94         }; // error_mode
95
96         //! Error codes.
97         enum error_code {
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.
104         }; // error_code
105
106         //! Initialize object but do not load TBB.
107         runtime_loader( error_mode mode = em_abort );
108
109         //! Initialize object and load TBB.
110         /*!
111             See load() for details.
112
113             If error mode is \c em_status, call status() to check whether TBB was loaded or not.
114         */
115         runtime_loader(
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.
120         );
121
122         //! Destroy object.
123         ~runtime_loader();
124
125         //! Load TBB.
126         /*!
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.
130
131             \b Note:
132
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").
136
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
139             details.)
140
141             Neglecting these rules may cause your program to execute 3-rd party malicious code.
142
143             \b Errors:
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.
149         */
150         error_code
151         load(
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.
155
156         );
157
158
159         //! Report status.
160         /*!
161             If error mode is \c em_status, the function returns status of the last operation.
162         */
163         error_code status();
164
165     private:
166
167         error_mode const my_mode;
168         error_code       my_status;
169         bool             my_loaded;
170
171 }; // class runtime_loader
172
173 } // namespace interface6
174
175 using interface6::runtime_loader;
176
177 } // namespace tbb
178
179 #endif /* __TBB_runtime_loader_H */
180