[rtems commit] libcsupport: malloc_is_system_state_OK()

Sebastian Huber sebh at rtems.org
Tue Nov 25 15:19:51 UTC 2014


Module:    rtems
Branch:    master
Commit:    0273349594cd2f87a839bdaf2c33ad7fd26c81f5
Changeset: http://git.rtems.org/rtems/commit/?id=0273349594cd2f87a839bdaf2c33ad7fd26c81f5

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Nov 24 15:20:25 2014 +0100

libcsupport: malloc_is_system_state_OK()

Move system state check to malloc_is_system_state_OK().

---

 cpukit/libcsupport/src/free.c            | 3 +--
 cpukit/libcsupport/src/malloc.c          | 5 +----
 cpukit/libcsupport/src/malloc_deferred.c | 7 +++----
 cpukit/libcsupport/src/rtems_malloc.c    | 7 +------
 cpukit/libcsupport/src/rtems_memalign.c  | 5 +----
 5 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/cpukit/libcsupport/src/free.c b/cpukit/libcsupport/src/free.c
index 7bc8e47..2a7e3d9 100644
--- a/cpukit/libcsupport/src/free.c
+++ b/cpukit/libcsupport/src/free.c
@@ -36,8 +36,7 @@ void free(
   /*
    *  Do not attempt to free memory if in a critical section or ISR.
    */
-  if ( _System_state_Is_up(_System_state_Get()) &&
-       !malloc_is_system_state_OK() ) {
+  if ( !malloc_is_system_state_OK() ) {
       malloc_deferred_free(ptr);
       return;
   }
diff --git a/cpukit/libcsupport/src/malloc.c b/cpukit/libcsupport/src/malloc.c
index 566cfa6..4645fdb 100644
--- a/cpukit/libcsupport/src/malloc.c
+++ b/cpukit/libcsupport/src/malloc.c
@@ -24,8 +24,6 @@
 
 #include "malloc_p.h"
 
-#include <rtems/score/sysstate.h>
-
 void *malloc(
   size_t  size
 )
@@ -48,8 +46,7 @@ void *malloc(
   /*
    *  Do not attempt to allocate memory if not in correct system state.
    */
-  if ( _System_state_Is_up(_System_state_Get()) &&
-       !malloc_is_system_state_OK() )
+  if ( !malloc_is_system_state_OK() )
     return NULL;
 
   /*
diff --git a/cpukit/libcsupport/src/malloc_deferred.c b/cpukit/libcsupport/src/malloc_deferred.c
index f15e711..81559c4 100644
--- a/cpukit/libcsupport/src/malloc_deferred.c
+++ b/cpukit/libcsupport/src/malloc_deferred.c
@@ -27,16 +27,15 @@
 
 #include "malloc_p.h"
 
+#include <rtems/score/sysstate.h>
 #include <rtems/score/threaddispatch.h>
 
 RTEMS_CHAIN_DEFINE_EMPTY(RTEMS_Malloc_GC_list);
 
 bool malloc_is_system_state_OK(void)
 {
-  if ( !_Thread_Dispatch_is_enabled() )
-    return false;
-
-  return true;
+  return !_System_state_Is_up( _System_state_Get() )
+    || _Thread_Dispatch_is_enabled();
 }
 
 void malloc_deferred_frees_process(void)
diff --git a/cpukit/libcsupport/src/rtems_malloc.c b/cpukit/libcsupport/src/rtems_malloc.c
index 0ba91c1..9eaa1df 100644
--- a/cpukit/libcsupport/src/rtems_malloc.c
+++ b/cpukit/libcsupport/src/rtems_malloc.c
@@ -26,18 +26,13 @@
 #ifdef RTEMS_NEWLIB
 #include "malloc_p.h"
 
-#include <rtems/score/sysstate.h>
-
 void *rtems_heap_allocate_aligned_with_boundary(
   size_t size,
   uintptr_t alignment,
   uintptr_t boundary
 )
 {
-  if (
-    _System_state_Is_up( _System_state_Get() )
-      && !malloc_is_system_state_OK()
-  ) {
+  if ( !malloc_is_system_state_OK() ) {
     return NULL;
   }
 
diff --git a/cpukit/libcsupport/src/rtems_memalign.c b/cpukit/libcsupport/src/rtems_memalign.c
index d991f57..1b9c6bc 100644
--- a/cpukit/libcsupport/src/rtems_memalign.c
+++ b/cpukit/libcsupport/src/rtems_memalign.c
@@ -24,8 +24,6 @@
 #include <stdlib.h>
 #include <errno.h>
 
-#include <rtems/score/sysstate.h>
-
 int rtems_memalign(
   void   **pointer,
   size_t   alignment,
@@ -45,8 +43,7 @@ int rtems_memalign(
   /*
    *  Do not attempt to allocate memory if not in correct system state.
    */
-  if ( _System_state_Is_up(_System_state_Get()) &&
-       !malloc_is_system_state_OK() )
+  if ( !malloc_is_system_state_OK() )
     return EINVAL;
 
   /*




More information about the vc mailing list