Skip to content

Commit 0d318d7

Browse files
author
Tyler Zhao
committed
Using destructor to close MMD libraries
1 parent 7f40d69 commit 0d318d7

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/acl_hal_mmd.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,25 @@ static void my_dlclose(void *library) {
455455
#endif
456456
}
457457

458+
static void my_dlclose_no_assert(void *library) {
459+
#ifdef _WIN32
460+
FreeLibrary((HMODULE)library);
461+
#else
462+
dlclose(library);
463+
#endif
464+
}
465+
466+
typedef struct my_dl_wrapper {
467+
void* handle;
468+
my_dl_wrapper(void* handle) {
469+
this->handle = handle;
470+
}
471+
~my_dl_wrapper() {
472+
my_dlclose_no_assert(this->handle);
473+
}
474+
} my_dl_wrapper;
475+
std::vector<std::unique_ptr<my_dl_wrapper>> mmd_libs;
476+
458477
cl_bool l_load_board_functions(acl_mmd_dispatch_t *mmd_dispatch,
459478
const char *library_name, void *mmd_library,
460479
char *error_msg) {
@@ -630,7 +649,7 @@ cl_bool l_load_single_board_library(const char *library_name,
630649
++num_boards_found;
631650
}
632651

633-
my_dlclose(mmd_library);
652+
mmd_libs.push_back(std::make_unique<my_dl_wrapper>(mmd_library));
634653
return CL_TRUE;
635654
}
636655

0 commit comments

Comments
 (0)