Skip to content

Commit

Permalink
Fix #637, static module unload fix
Browse files Browse the repository at this point in the history
Mark static modules with a flag, and check that flag at unload.
If flag is set, then skip unload low level implementation.
  • Loading branch information
jphickey committed Nov 2, 2020
1 parent 5a8f0af commit 6d74eb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/os/shared/inc/os-shared-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include <os-shared-globaldefs.h>

#define OS_MODULE_FLAG_IS_STATIC 0x1

typedef struct
{
char module_name[OS_MAX_API_NAME];
Expand Down
16 changes: 13 additions & 3 deletions src/os/shared/src/osapi-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,12 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f
* returns OS_ERR_NAME_NOT_FOUND.
*/
return_code = OS_ModuleLoad_Static(module_name);
if (return_code != OS_SUCCESS)
if (return_code == OS_SUCCESS)
{
/* mark this as a statically loaded module */
OS_module_table[local_id].flags |= OS_MODULE_FLAG_IS_STATIC;
}
else
{
/*
* If this is NOT a static module, then the module file must be loaded by normal
Expand Down Expand Up @@ -280,9 +285,14 @@ int32 OS_ModuleUnload(osal_id_t module_id)
if (return_code == OS_SUCCESS)
{
/*
* Only call the implementation if the loader is enabled
* Only call the implementation if the file was actually loaded.
* If this is a static module, then this is just a placeholder and
* it means there was no file actually loaded.
*/
return_code = OS_ModuleUnload_Impl(local_id);
if ((OS_module_table[local_id].flags & OS_MODULE_FLAG_IS_STATIC) == 0)
{
return_code = OS_ModuleUnload_Impl(local_id);
}

/* Complete the operation via the common routine */
return_code = OS_ObjectIdFinalizeDelete(return_code, record);
Expand Down

0 comments on commit 6d74eb4

Please sign in to comment.