Skip to content
Snippets Groups Projects
Commit 6bd5d52b authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Use dlclose when destroying a dlopened plumed object.

Now that exceptions are translated, it is possible to dlclose an image
that is not used anymore.
parent f58158f9
No related branches found
No related tags found
No related merge requests found
...@@ -2305,9 +2305,6 @@ typedef struct { ...@@ -2305,9 +2305,6 @@ typedef struct {
/* handler to dlopened library. NULL if there was no library opened */ /* handler to dlopened library. NULL if there was no library opened */
void* dlhandle; void* dlhandle;
/* non zero if, upon destruction, the library should be dlclosed */ /* non zero if, upon destruction, the library should be dlclosed */
/* by default, we do not dlclose libraries since this might create problems if exceptions are handled after
the last plumed object has been destroyed */
/* in addition, when creating multiple plumed objects, it is more efficient to keep the library loaded */
int dlclose; int dlclose;
/* 1 if path to kernel was taken from PLUMED_KERNEL var, 0 otherwise */ /* 1 if path to kernel was taken from PLUMED_KERNEL var, 0 otherwise */
int used_plumed_kernel; int used_plumed_kernel;
...@@ -2373,12 +2370,8 @@ plumed plumed_create(void) { ...@@ -2373,12 +2370,8 @@ plumed plumed_create(void) {
pimpl->used_plumed_kernel=1; pimpl->used_plumed_kernel=1;
#endif #endif
/* note if handle should not be dlclosed */ /* note if handle should not be dlclosed */
/* Notice that PLUMED_LOAD_DLCLOSE only affects the kernel linked from PLUMED_KERNEL pimpl->dlclose=1;
and is not used in plumed_create_dlopen(). if(__PLUMED_GETENV("PLUMED_LOAD_DLCLOSE") && !__PLUMED_WRAPPER_STD strcmp(__PLUMED_GETENV("PLUMED_LOAD_DLCLOSE"),"no")) pimpl->dlclose=0;
It might make sense in combination with PLUMED_LOAD_NODEEPBIND to avoid clashes.
However, it is probably useless.
*/
pimpl->dlclose=__PLUMED_GETENV("PLUMED_LOAD_DLCLOSE")!=NULL;
/* in case of failure, return */ /* in case of failure, return */
/* the resulting object should be plumed_finalized, though you cannot use plumed_cmd */ /* the resulting object should be plumed_finalized, though you cannot use plumed_cmd */
if(!pimpl->functions.create) { if(!pimpl->functions.create) {
...@@ -2424,6 +2417,8 @@ plumed plumed_create_dlopen2(const char*path,int mode) { ...@@ -2424,6 +2417,8 @@ plumed plumed_create_dlopen2(const char*path,int mode) {
pimpl=plumed_malloc_pimpl(); pimpl=plumed_malloc_pimpl();
#ifdef __PLUMED_HAS_DLOPEN #ifdef __PLUMED_HAS_DLOPEN
if(path) pimpl->dlhandle=plumed_attempt_dlopen(path,mode); if(path) pimpl->dlhandle=plumed_attempt_dlopen(path,mode);
/* mark this library to be dlclosed when the object is finalized */
pimpl->dlclose=1;
if(pimpl->dlhandle) plumed_search_symbols(pimpl->dlhandle,&pimpl->functions,&pimpl->table); if(pimpl->dlhandle) plumed_search_symbols(pimpl->dlhandle,&pimpl->functions,&pimpl->table);
#endif #endif
if(!pimpl->functions.create) { if(!pimpl->functions.create) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment