Skip to content

Commit

Permalink
Fix #944, add OS_API_Teardown
Browse files Browse the repository at this point in the history
This cleans up all OSAL resources as best as possible, ideally leaving
the system in a state where OS_API_Init() may be invoked again.
  • Loading branch information
jphickey committed Apr 7, 2021
1 parent 65c584f commit 35e7b04
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/os/inc/osapi-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,33 @@ void OS_Application_Run(void);
*/
int32 OS_API_Init(void);

/*-------------------------------------------------------------------------------------*/
/**
* @brief Teardown/de-initialization of OSAL API
*
* This is the inverse of OS_API_Init(). It will release all OS resources and
* return the system to a state similar to what it was prior to invoking
* OS_API_Init() initially.
*
* Normally for embedded applications, the OSAL is initialized after boot and will remain
* initialized in memory until the processor is rebooted. However for testing and
* developement purposes, it is potentially useful to reset back to initial conditions.
*
* For testing purposes, this API is designed/intended to be compatible with the
* UtTest_AddTeardown() routine provided by the UT-Assert subsystem.
*
* @note This is a "best-effort" routine and it may not always be possible/guaranteed
* to recover all resources, particularly in the case of off-nominal conditions, or if
* a resource is used outside of OSAL.
*
* For example, while this will attempt to unload all dynamically-loaded modules, doing
* so may not be possible and/or may induce undefined behavior if resources are in use by
* tasks/functions outside of OSAL.
*
* @return None
*/
void OS_API_Teardown(void);

/*-------------------------------------------------------------------------------------*/
/**
* @brief Background thread implementation - waits forever for events to occur.
Expand Down
22 changes: 22 additions & 0 deletions src/os/shared/src/osapi-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ int32 OS_API_Init(void)
return (return_code);
} /* end OS_API_Init */

/*----------------------------------------------------------------
*
* Function: OS_API_Teardown
*
* Purpose: Implemented per public OSAL API
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
void OS_API_Teardown(void)
{
/*
* This should delete any remaining user-created objects/tasks
*/
OS_DeleteAllObjects();

/*
* This should cause the "internal" objects (e.g. console utility task)
* to exit, and will prevent any new objects from being created.
*/
OS_ApplicationShutdown(true);
}

/*----------------------------------------------------------------
*
* Function: OS_RegisterEventHandler
Expand Down

0 comments on commit 35e7b04

Please sign in to comment.