1 | /* |
2 | Copyright (c) 2005-2019 Intel Corporation |
3 | |
4 | Licensed under the Apache License, Version 2.0 (the "License"); |
5 | you may not use this file except in compliance with the License. |
6 | You may obtain a copy of the License at |
7 | |
8 | http://www.apache.org/licenses/LICENSE-2.0 |
9 | |
10 | Unless required by applicable law or agreed to in writing, software |
11 | distributed under the License is distributed on an "AS IS" BASIS, |
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | See the License for the specific language governing permissions and |
14 | limitations under the License. |
15 | */ |
16 | |
17 | // No ifndef guard because this file is not a normal include file. |
18 | |
19 | #if TBB_USE_DEBUG |
20 | #define DEBUG_SUFFIX "_debug" |
21 | #else |
22 | #define DEBUG_SUFFIX |
23 | #endif /* TBB_USE_DEBUG */ |
24 | |
25 | // RML_SERVER_NAME is the name of the RML server library. |
26 | #if _WIN32||_WIN64 |
27 | #define RML_SERVER_NAME "irml" DEBUG_SUFFIX ".dll" |
28 | #elif __APPLE__ |
29 | #define RML_SERVER_NAME "libirml" DEBUG_SUFFIX ".dylib" |
30 | #elif __linux__ |
31 | #define RML_SERVER_NAME "libirml" DEBUG_SUFFIX ".so.1" |
32 | #elif __FreeBSD__ || __NetBSD__ || __OpenBSD__ || __sun || _AIX |
33 | #define RML_SERVER_NAME "libirml" DEBUG_SUFFIX ".so" |
34 | #else |
35 | #error Unknown OS |
36 | #endif |
37 | |
38 | const ::rml::versioned_object::version_type CLIENT_VERSION = 2; |
39 | |
40 | #if __TBB_WEAK_SYMBOLS_PRESENT |
41 | #pragma weak __RML_open_factory |
42 | #pragma weak __RML_close_factory |
43 | extern "C" { |
44 | ::rml::factory::status_type __RML_open_factory ( ::rml::factory&, ::rml::versioned_object::version_type&, ::rml::versioned_object::version_type ); |
45 | void __RML_close_factory( ::rml::factory& f ); |
46 | } |
47 | #endif /* __TBB_WEAK_SYMBOLS_PRESENT */ |
48 | |
49 | ::rml::factory::status_type FACTORY::open() { |
50 | // Failure of following assertion indicates that factory is already open, or not zero-inited. |
51 | LIBRARY_ASSERT( !library_handle, NULL ); |
52 | status_type (*open_factory_routine)( factory&, version_type&, version_type ); |
53 | dynamic_link_descriptor server_link_table[4] = { |
54 | DLD(__RML_open_factory,open_factory_routine), |
55 | MAKE_SERVER(my_make_server_routine), |
56 | DLD(__RML_close_factory,my_wait_to_close_routine), |
57 | GET_INFO(my_call_with_server_info_routine), |
58 | }; |
59 | status_type result; |
60 | if( dynamic_link( RML_SERVER_NAME, server_link_table, 4, &library_handle ) ) { |
61 | version_type server_version; |
62 | result = (*open_factory_routine)( *this, server_version, CLIENT_VERSION ); |
63 | // server_version can be checked here for incompatibility if necessary. |
64 | } else { |
65 | library_handle = NULL; |
66 | result = st_not_found; |
67 | } |
68 | return result; |
69 | } |
70 | |
71 | void FACTORY::close() { |
72 | if( library_handle ) |
73 | (*my_wait_to_close_routine)(*this); |
74 | if( (size_t)library_handle>FACTORY::c_dont_unload ) { |
75 | dynamic_unlink(library_handle); |
76 | library_handle = NULL; |
77 | } |
78 | } |
79 | |
80 | ::rml::factory::status_type FACTORY::make_server( SERVER*& s, CLIENT& c) { |
81 | // Failure of following assertion means that factory was not successfully opened. |
82 | LIBRARY_ASSERT( my_make_server_routine, NULL ); |
83 | return (*my_make_server_routine)(*this,s,c); |
84 | } |
85 | |
86 | void FACTORY::call_with_server_info( ::rml::server_info_callback_t cb, void* arg ) const { |
87 | // Failure of following assertion means that factory was not successfully opened. |
88 | LIBRARY_ASSERT( my_call_with_server_info_routine, NULL ); |
89 | (*my_call_with_server_info_routine)( cb, arg ); |
90 | } |
91 | |