@@ -188,40 +188,41 @@ unsigned acl_convert_mmd_capabilities(unsigned mmd_capabilities);
188
188
const static size_t MIN_SOF_SIZE = 1 ;
189
189
const static size_t MIN_PLL_CONFIG_SIZE = 1 ;
190
190
191
- // Helper function needed for dl libraries wrapper
192
- void *my_dlopen (const char *library_name, char **error_msg);
193
- void *my_dlsym (void *library, const char *function_name, char **error_msg);
194
-
195
191
// Wrapper for dl libraries
196
192
struct dl_wrapper_t {
197
- void *mmd_lib;
198
- dl_wrapper_t (const char *library_name, char **error_msg) {
199
- this ->mmd_lib = my_dlopen (library_name, error_msg);
200
- }
193
+ std::vector<void *> mmd_libs;
194
+ dl_wrapper_t (){;}
201
195
~dl_wrapper_t () {
202
- if (this ->mmd_lib ) {
196
+ for (void * mmd_lib : this ->mmd_libs ){
197
+ if (mmd_lib) {
203
198
#ifdef _WIN32
204
- FreeLibrary ((HMODULE)this -> mmd_lib );
199
+ FreeLibrary ((HMODULE)mmd_lib);
205
200
#else
206
- dlclose (this -> mmd_lib );
201
+ dlclose (mmd_lib);
207
202
#endif
203
+ }
208
204
}
209
205
}
206
+
207
+ // destroy last element of mmd_libs
208
+ void pop_back (){
209
+ if (this ->mmd_libs .back ()){
210
+ #ifdef _WIN32
211
+ FreeLibrary ((HMODULE)this ->mmd_libs .back ());
212
+ #else
213
+ dlclose (this ->mmd_libs .back ());
214
+ #endif
215
+ }
216
+ this ->mmd_libs .pop_back ();
217
+ }
218
+
210
219
// prohibit copying to avoid double-close of handle
211
220
dl_wrapper_t (const dl_wrapper_t &) = delete ;
212
221
dl_wrapper_t &operator =(const dl_wrapper_t &) = delete ;
213
-
214
- // enable move for vector operations
215
- dl_wrapper_t (dl_wrapper_t &&) noexcept {};
216
-
217
- // return symbol
218
- void *sym (const char *function_name, char **error_msg) {
219
- return my_dlsym (this ->mmd_lib , function_name, error_msg);
220
- }
221
222
};
222
223
223
224
std::vector<acl_mmd_dispatch_t > internal_mmd_dispatch;
224
- std::vector< dl_wrapper_t > dl_wrapper_list ;
225
+ static dl_wrapper_t dl_wrapper ;
225
226
226
227
// Dynamically load board mmd & symbols
227
228
static size_t num_board_pkgs;
@@ -601,9 +602,9 @@ cl_bool l_load_single_board_library(const char *library_name,
601
602
return CL_FALSE;
602
603
}
603
604
#endif
604
- dl_wrapper_list. emplace_back ( library_name, &error_msg);
605
- if (!dl_wrapper_list. back (). mmd_lib ) {
606
- dl_wrapper_list .pop_back ();
605
+ dl_wrapper. mmd_libs . push_back ( my_dlopen ( library_name, &error_msg) );
606
+ if (!dl_wrapper. mmd_libs . back ()) {
607
+ dl_wrapper .pop_back ();
607
608
std::cout << " Error: Could not load board library " << library_name;
608
609
if (error_msg && error_msg[0 ] != ' \0 ' ) {
609
610
std::cout << " (error_msg: " << error_msg << " )" ;
@@ -613,18 +614,18 @@ cl_bool l_load_single_board_library(const char *library_name,
613
614
}
614
615
615
616
auto *test_symbol =
616
- dl_wrapper_list. back (). sym ( " aocl_mmd_get_offline_info" , &error_msg);
617
+ my_dlsym (dl_wrapper. mmd_libs . back (), " aocl_mmd_get_offline_info" , &error_msg);
617
618
if (!test_symbol) {
618
619
// On Linux, for custom libraries close the library (which was opened
619
620
// locally) and then reopen globally. For Windows, there is no option (i.e.
620
621
// it is always global)
621
622
#ifdef __linux__
622
- my_dlclose (dl_wrapper_list. back (). mmd_lib );
623
+ my_dlclose (dl_wrapper. mmd_libs . back ());
623
624
ACL_HAL_DEBUG_MSG_VERBOSE (
624
625
1 , " This library is a custom library. Opening globally.\n " );
625
- dl_wrapper_list. back (). mmd_lib = my_dlopen_global (library_name, &error_msg);
626
- if (!dl_wrapper_list. back (). mmd_lib ) {
627
- dl_wrapper_list .pop_back ();
626
+ dl_wrapper. mmd_libs . back () = my_dlopen_global (library_name, &error_msg);
627
+ if (!dl_wrapper. mmd_libs . back ()) {
628
+ dl_wrapper .pop_back ();
628
629
std::cout << " Error: Could not load custom library " << library_name;
629
630
if (error_msg && error_msg[0 ] != ' \0 ' ) {
630
631
std::cout << " (error_msg: " << error_msg << " )" ;
@@ -637,7 +638,7 @@ cl_bool l_load_single_board_library(const char *library_name,
637
638
if (load_libraries) {
638
639
auto result = l_load_board_functions (
639
640
&(internal_mmd_dispatch[num_boards_found]), library_name,
640
- dl_wrapper_list. back (). mmd_lib , error_msg);
641
+ dl_wrapper. mmd_libs . back (), error_msg);
641
642
if (result == CL_FALSE) {
642
643
std::cout << " Error: Could not load board library " << library_name
643
644
<< " due to failure to load symbols\n " ;
@@ -1190,10 +1191,10 @@ static acl_mmd_dispatch_t *get_msim_mmd_layer() {
1190
1191
ipa_simulator ? mmd_lib_name_ipa : mmd_lib_name_aoc;
1191
1192
1192
1193
char *error_msg = nullptr ;
1193
- dl_wrapper_list. emplace_back ( mmd_lib_name, &error_msg);
1194
+ dl_wrapper. mmd_libs . push_back ( my_dlopen ( mmd_lib_name, &error_msg) );
1194
1195
typedef acl_mmd_dispatch_t *(*fcn_type)();
1195
- if (!dl_wrapper_list. back (). mmd_lib ) {
1196
- dl_wrapper_list .pop_back ();
1196
+ if (!dl_wrapper. mmd_libs . back ()) {
1197
+ dl_wrapper .pop_back ();
1197
1198
std::cout << " Error: Could not load simulation MMD library "
1198
1199
<< mmd_lib_name;
1199
1200
if (error_msg && error_msg[0 ] != ' \0 ' ) {
@@ -1202,9 +1203,9 @@ static acl_mmd_dispatch_t *get_msim_mmd_layer() {
1202
1203
std::cout << " \n " ;
1203
1204
return nullptr ;
1204
1205
}
1205
- auto *sym = dl_wrapper_list. back (). sym ( sym_name, &error_msg);
1206
+ auto *sym = my_dlsym (dl_wrapper. mmd_libs . back (), sym_name, &error_msg);
1206
1207
if (!sym) {
1207
- dl_wrapper_list .pop_back ();
1208
+ dl_wrapper .pop_back ();
1208
1209
std::cout << " Error: Symbol " << sym_name
1209
1210
<< " not found in simulation MMD library " ;
1210
1211
if (error_msg && error_msg[0 ] != ' \0 ' ) {
0 commit comments