Skip to content

Commit

Permalink
Add yogrt_[init|fini]()
Browse files Browse the repository at this point in the history
  • Loading branch information
morrone committed Apr 26, 2022
1 parent ae7ea1d commit f27c495
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/yogrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ static inline int load_backend(void)
return 1;
}

static void unload_backend(void)
{
if (backend_handle != NULL) {
dlclose(backend_handle);
backend_handle = NULL;
memset(&backend, 0, sizeof(backend));
}
}

static int init_yogrt(void)
{
int rc = 1;
Expand All @@ -318,6 +327,14 @@ static int init_yogrt(void)
return rc;
}

static void fini_yogrt(void)
{
if (initialized == 1) {
unload_backend();
initialized = 0;
}
}

/*
* Returns 1 if update is needed, 0 otherwise.
*/
Expand Down Expand Up @@ -498,6 +515,20 @@ int yogrt_get_debug(void)
return verbosity;
}

int yogrt_init(void)
{
int rc;

rc = init_yogrt();

return rc;
}

void yogrt_fini(void)
{
fini_yogrt();
}

/**********************************************************************
* Fortran wrappers (single underscore version)
**********************************************************************/
Expand Down Expand Up @@ -567,6 +598,16 @@ int iyogrt_get_debug_(void)
return yogrt_get_debug();
}

int iyogrt_init_(void)
{
return yogrt_init();
}

void iyogrt_fini_(void)
{
yogrt_fini();
}

/**********************************************************************
* Fortran wrappers (double underscore version)
**********************************************************************/
Expand Down Expand Up @@ -635,3 +676,14 @@ int iyogrt_get_debug__(void)
{
return yogrt_get_debug();
}

int iyogrt_init__(void)
{
return yogrt_init();
}

void iyogrt_fini__(void)
{
yogrt_fini();
}

16 changes: 16 additions & 0 deletions src/yogrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ extern int yogrt_get_interval2_start(void);
extern int yogrt_get_debug(void);
extern void yogrt_set_debug(int val);

/*
* Initialize the yogrt library, including loading the
* configured libyogrt backend library. It is not necessay
* for applications to call this, as all of the other library
* calls will initialize the library autocatically when
* needed. This function is mainly provided for completeness.
*/
extern int yogrt_init(void);

/*
* Finalize (shut down) the libyogrt library. This will
* unload the backend library, and cleanup as needed. It is
* also not necesary for applications to call this, however
* doing so may eliminate warnings from memory debuggers.
*/
extern void yogrt_fini(void);

#ifdef __cplusplus
}
Expand Down

0 comments on commit f27c495

Please sign in to comment.