[PATCH] cpukit/cache: Report coherent add area failures
Kinsey Moore
kinsey.moore at oarcorp.com
Wed Jan 24 17:19:39 UTC 2024
This alters the API for rtems_cache_coherent_add_area to allow reporting
of failures that can occur during the process of adding a new area to
the coherent cache heap.
---
cpukit/include/rtems/rtems/cache.h | 12 ++++++++-
cpukit/libcsupport/src/cachecoherentalloc.c | 27 ++++++++++++---------
2 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/cpukit/include/rtems/rtems/cache.h b/cpukit/include/rtems/rtems/cache.h
index 20c630a3eb..d37a671849 100644
--- a/cpukit/include/rtems/rtems/cache.h
+++ b/cpukit/include/rtems/rtems/cache.h
@@ -59,6 +59,7 @@
#include <stddef.h>
#include <stdint.h>
+#include <rtems/rtems/status.h>
#ifdef __cplusplus
extern "C" {
@@ -89,6 +90,15 @@ extern "C" {
*
* @param size is the size in bytes of the cache coherent memory area to add.
*
+ * @retval ::RTEMS_SUCCESSFUL The cache coherent memory extension was
+ * successful.
+ *
+ * @retval ::RTEMS_UNSATISFIED The cache coherent memory extension was not
+ * successful.
+ *
+ * @return Returns a rtems_status_code indicating whether the area was added to
+ * cache coherent memory.
+ *
* @par Constraints
* @parblock
* The following constraints apply to this directive:
@@ -102,7 +112,7 @@ extern "C" {
* cause the calling task to be preempted.
* @endparblock
*/
-void rtems_cache_coherent_add_area( void *begin, uintptr_t size );
+rtems_status_code rtems_cache_coherent_add_area( void *begin, uintptr_t size );
/* Generated from spec:/rtems/cache/if/coherent-allocate */
diff --git a/cpukit/libcsupport/src/cachecoherentalloc.c b/cpukit/libcsupport/src/cachecoherentalloc.c
index 198eb907b5..1e15758f98 100644
--- a/cpukit/libcsupport/src/cachecoherentalloc.c
+++ b/cpukit/libcsupport/src/cachecoherentalloc.c
@@ -97,7 +97,7 @@ void rtems_cache_coherent_free( void *ptr )
_RTEMS_Unlock_allocator();
}
-static void add_area(
+static int add_area(
void *area_begin,
uintptr_t area_size
)
@@ -105,31 +105,36 @@ static void add_area(
Heap_Control *heap = cache_coherent_heap;
if ( heap == NULL ) {
- bool ok;
-
heap = &cache_coherent_heap_instance;
- ok = _Heap_Initialize( heap, area_begin, area_size, 0 );
- if ( ok ) {
- cache_coherent_heap = heap;
+ if ( _Heap_Initialize( heap, area_begin, area_size, 0 ) == 0 ) {
+ return -1;
}
+ cache_coherent_heap = heap;
} else {
- _Heap_Extend( heap, area_begin, area_size, 0 );
+ if (_Heap_Extend( heap, area_begin, area_size, 0 ) == 0) {
+ return -1;
+ }
}
+ return 0;
}
-void rtems_cache_coherent_add_area(
+rtems_status_code rtems_cache_coherent_add_area(
void *area_begin,
uintptr_t area_size
)
{
+ int status;
+
if ( _System_state_Is_up( _System_state_Get()) ) {
_RTEMS_Lock_allocator();
+ }
- add_area( area_begin, area_size );
+ status = add_area( area_begin, area_size );
+ if ( _System_state_Is_up( _System_state_Get()) ) {
_RTEMS_Unlock_allocator();
- } else {
- add_area( area_begin, area_size );
}
+
+ return status == 0 ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
}
--
2.39.2
More information about the devel
mailing list