[PATCH 02/12] score: Add and use _Thread_Dispatch_is_enabled()

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Jun 12 15:12:28 UTC 2013


Delete _Thread_Dispatch_in_critical_section() and
_Thread_Is_dispatching_enabled().
---
 c/src/lib/libbsp/powerpc/shared/startup/panic.c   |    6 +-
 c/src/lib/libcpu/sh/sh7032/score/cpu_asm.c        |    2 +-
 c/src/lib/libcpu/sh/sh7045/score/cpu_asm.c        |    2 +-
 c/src/lib/libcpu/sh/sh7750/score/cpu_asm.c        |    2 +-
 c/src/lib/libcpu/sh/shgdb/score/cpu_asm.c         |    2 +-
 cpukit/libcsupport/src/malloc_deferred.c          |    2 +-
 cpukit/libcsupport/src/realloc.c                  |    2 +-
 cpukit/libcsupport/src/sup_fs_location.c          |    2 +-
 cpukit/rtems/src/clocktick.c                      |    2 +-
 cpukit/score/cpu/lm32/irq.c                       |    2 +-
 cpukit/score/cpu/nios2/nios2-iic-irq.c            |    2 +-
 cpukit/score/include/rtems/score/coremutex.h      |    2 +-
 cpukit/score/include/rtems/score/threaddispatch.h |   45 ++++++---------------
 cpukit/score/src/heapfree.c                       |    2 +-
 cpukit/score/src/pheapwalk.c                      |    2 +-
 cpukit/score/src/threaddispatchdisablelevel.c     |    8 ----
 testsuites/support/include/tmacros.h              |    6 +-
 17 files changed, 32 insertions(+), 59 deletions(-)

diff --git a/c/src/lib/libbsp/powerpc/shared/startup/panic.c b/c/src/lib/libbsp/powerpc/shared/startup/panic.c
index 958a06d..0aefe8f 100644
--- a/c/src/lib/libbsp/powerpc/shared/startup/panic.c
+++ b/c/src/lib/libbsp/powerpc/shared/startup/panic.c
@@ -56,12 +56,12 @@ void _BSP_Fatal_error(unsigned int v)
       printk("  UNKNOWN (0x%x)\n",THESRC);
   break;
   }
-  if ( _Thread_Dispatch_in_critical_section() )
+  if ( _Thread_Dispatch_is_enabled() )
+    printk("enabled\n");
+  else
     printk(
       "  Error occurred in a Thread Dispatching DISABLED context (level %i)\n",
       _Thread_Dispatch_get_disable_level());
-  else
-    printk("enabled\n");
 
   if ( _ISR_Nest_level ) {
     printk(
diff --git a/c/src/lib/libcpu/sh/sh7032/score/cpu_asm.c b/c/src/lib/libcpu/sh/sh7032/score/cpu_asm.c
index 1c14cc0..9776457 100644
--- a/c/src/lib/libcpu/sh/sh7032/score/cpu_asm.c
+++ b/c/src/lib/libcpu/sh/sh7032/score/cpu_asm.c
@@ -170,7 +170,7 @@ void __ISR_Handler( uint32_t   vector)
   if ( _ISR_Nest_level )
     return;
 
-  if ( _Thread_Dispatch_in_critical_section() ) {
+  if ( !_Thread_Dispatch_is_enabled() ) {
     return;
   }
 
diff --git a/c/src/lib/libcpu/sh/sh7045/score/cpu_asm.c b/c/src/lib/libcpu/sh/sh7045/score/cpu_asm.c
index d141a2d..69134d9 100644
--- a/c/src/lib/libcpu/sh/sh7045/score/cpu_asm.c
+++ b/c/src/lib/libcpu/sh/sh7045/score/cpu_asm.c
@@ -172,7 +172,7 @@ void __ISR_Handler( uint32_t   vector)
   if ( _ISR_Nest_level )
     return;
 
-  if ( _Thread_Dispatch_in_critical_section() ) {
+  if ( !_Thread_Dispatch_is_enabled() ) {
     return;
   }
 
diff --git a/c/src/lib/libcpu/sh/sh7750/score/cpu_asm.c b/c/src/lib/libcpu/sh/sh7750/score/cpu_asm.c
index fcc867f..77945ae 100644
--- a/c/src/lib/libcpu/sh/sh7750/score/cpu_asm.c
+++ b/c/src/lib/libcpu/sh/sh7750/score/cpu_asm.c
@@ -95,7 +95,7 @@ void __ISR_Handler( uint32_t   vector)
   if ( _ISR_Nest_level )
     return;
 
-  if ( _Thread_Dispatch_in_critical_section() ) {
+  if ( !_Thread_Dispatch_is_enabled() ) {
     return;
   }
 
diff --git a/c/src/lib/libcpu/sh/shgdb/score/cpu_asm.c b/c/src/lib/libcpu/sh/shgdb/score/cpu_asm.c
index 678e23c..a9a24c9 100644
--- a/c/src/lib/libcpu/sh/shgdb/score/cpu_asm.c
+++ b/c/src/lib/libcpu/sh/shgdb/score/cpu_asm.c
@@ -69,7 +69,7 @@ void __ISR_Handler( uint32_t   vector)
   if ( _ISR_Nest_level )
     return;
 
-  if ( _Thread_Dispatch_in_critical_section() ) {
+  if ( !_Thread_Dispatch_is_enabled() ) {
     return;
   }
 
diff --git a/cpukit/libcsupport/src/malloc_deferred.c b/cpukit/libcsupport/src/malloc_deferred.c
index d1ad56f..a2e95ea 100644
--- a/cpukit/libcsupport/src/malloc_deferred.c
+++ b/cpukit/libcsupport/src/malloc_deferred.c
@@ -31,7 +31,7 @@ RTEMS_CHAIN_DEFINE_EMPTY(RTEMS_Malloc_GC_list);
 
 bool malloc_is_system_state_OK(void)
 {
-  if ( _Thread_Dispatch_in_critical_section() )
+  if ( !_Thread_Dispatch_is_enabled() )
     return false;
 
   if ( _ISR_Nest_level > 0 )
diff --git a/cpukit/libcsupport/src/realloc.c b/cpukit/libcsupport/src/realloc.c
index eee6f79..a831cae 100644
--- a/cpukit/libcsupport/src/realloc.c
+++ b/cpukit/libcsupport/src/realloc.c
@@ -38,7 +38,7 @@ void *realloc(
    */
 
   if (_System_state_Is_up(_System_state_Get())) {
-    if (_Thread_Dispatch_in_critical_section())
+    if (!_Thread_Dispatch_is_enabled())
       return (void *) 0;
 
     if (_ISR_Nest_level > 0)
diff --git a/cpukit/libcsupport/src/sup_fs_location.c b/cpukit/libcsupport/src/sup_fs_location.c
index 2ce5145..b4713c5 100644
--- a/cpukit/libcsupport/src/sup_fs_location.c
+++ b/cpukit/libcsupport/src/sup_fs_location.c
@@ -178,7 +178,7 @@ void rtems_filesystem_global_location_release(
   rtems_filesystem_global_location_t *global_loc
 )
 {
-  if (!_Thread_Dispatch_in_critical_section()) {
+  if (_Thread_Dispatch_is_enabled()) {
     release_with_count(global_loc, 1);
   } else {
     if (global_loc->deferred_released_count == 0) {
diff --git a/cpukit/rtems/src/clocktick.c b/cpukit/rtems/src/clocktick.c
index 1bd91ac..8467fd6 100644
--- a/cpukit/rtems/src/clocktick.c
+++ b/cpukit/rtems/src/clocktick.c
@@ -35,7 +35,7 @@ rtems_status_code rtems_clock_tick( void )
   _Scheduler_Tick();
 
   if ( _Thread_Is_context_switch_necessary() &&
-       _Thread_Is_dispatching_enabled() )
+       _Thread_Dispatch_is_enabled() )
     _Thread_Dispatch();
 
   return RTEMS_SUCCESSFUL;
diff --git a/cpukit/score/cpu/lm32/irq.c b/cpukit/score/cpu/lm32/irq.c
index 37e9a28..b69a65d 100644
--- a/cpukit/score/cpu/lm32/irq.c
+++ b/cpukit/score/cpu/lm32/irq.c
@@ -72,7 +72,7 @@ void __ISR_Handler(uint32_t vector, CPU_Interrupt_frame *ifr)
   if ( _ISR_Nest_level )
     return;
 
-  if ( _Thread_Dispatch_necessary && !_Thread_Dispatch_in_critical_section() ) {
+  if ( _Thread_Dispatch_necessary && _Thread_Dispatch_is_enabled() ) {
     /* save off our stack frame so the context switcher can get to it */
     _exception_stack_frame = ifr;
 
diff --git a/cpukit/score/cpu/nios2/nios2-iic-irq.c b/cpukit/score/cpu/nios2/nios2-iic-irq.c
index 31e2ba9..1f29365 100644
--- a/cpukit/score/cpu/nios2/nios2-iic-irq.c
+++ b/cpukit/score/cpu/nios2/nios2-iic-irq.c
@@ -117,7 +117,7 @@ void __ISR_Handler(void)
     stack_ptr = _old_stack_ptr;
 #endif
 
-    if( !_Thread_Dispatch_in_critical_section() )
+    if( _Thread_Dispatch_is_enabled() )
     {
       if ( _Thread_Dispatch_necessary ) {
         _CPU_ISR_Enable( level );
diff --git a/cpukit/score/include/rtems/score/coremutex.h b/cpukit/score/include/rtems/score/coremutex.h
index 10dfe06..f6c377c 100644
--- a/cpukit/score/include/rtems/score/coremutex.h
+++ b/cpukit/score/include/rtems/score/coremutex.h
@@ -352,7 +352,7 @@ void _CORE_mutex_Seize_interrupt_blocking(
   #define _CORE_mutex_Check_dispatch_for_seize(_wait) 0
 #else
   #define _CORE_mutex_Check_dispatch_for_seize(_wait) \
-      (_Thread_Dispatch_in_critical_section() \
+      (!_Thread_Dispatch_is_enabled() \
         && (_wait) \
         && (_System_state_Get() >= SYSTEM_STATE_BEGIN_MULTITASKING))
 #endif
diff --git a/cpukit/score/include/rtems/score/threaddispatch.h b/cpukit/score/include/rtems/score/threaddispatch.h
index 0333e9b..e3065da 100644
--- a/cpukit/score/include/rtems/score/threaddispatch.h
+++ b/cpukit/score/include/rtems/score/threaddispatch.h
@@ -46,6 +46,19 @@ extern "C" {
  */
 SCORE_EXTERN volatile uint32_t   _Thread_Dispatch_disable_level;
 
+/**
+ * @brief Indicates if the executing thread is inside a thread dispatch
+ * critical section.
+ *
+ * @retval true Thread dispatching is enabled.
+ * @retval false The executing thread is inside a thread dispatch critical
+ * section and dispatching is not allowed.
+ */
+RTEMS_INLINE_ROUTINE bool _Thread_Dispatch_is_enabled(void)
+{
+  return _Thread_Dispatch_disable_level == 0;
+}
+
 #if defined(RTEMS_SMP)
   typedef struct {
     SMP_lock_Control lock;
@@ -68,14 +81,6 @@ SCORE_EXTERN volatile uint32_t   _Thread_Dispatch_disable_level;
   void _Thread_Dispatch_initialization(void);
 
   /**
-   *  @brief Checks if thread dispatch says that we are in a critical section.
-   *
-   * This routine returns true if thread dispatch indicates
-   * that we are in a critical section.
-   */
-  bool _Thread_Dispatch_in_critical_section(void);
-
-  /**
    *  @brief Returns value of the the thread dispatch level.
    *
    * This routine returns value of the the thread dispatch level.
@@ -105,20 +110,6 @@ SCORE_EXTERN volatile uint32_t   _Thread_Dispatch_disable_level;
   uint32_t _Thread_Dispatch_decrement_disable_level(void);
 #else /* RTEMS_SMP */
   /**
-   * @brief _Thread_Dispatch_in_critical_section
-   *
-   * This routine returns true if thread dispatch indicates
-   * that we are in a critical section.
-   */
-  RTEMS_INLINE_ROUTINE bool _Thread_Dispatch_in_critical_section(void)
-  {
-     if (  _Thread_Dispatch_disable_level == 0 )
-      return false;
-
-     return true;
-  }
-
-  /**
    * @brief Get thread dispatch disable level.
    *
    * This routine returns value of the the thread dispatch level.
@@ -246,16 +237,6 @@ RTEMS_INLINE_ROUTINE void _Thread_Unnest_dispatch( void )
   _Thread_Dispatch_decrement_disable_level();
 }
 
-/**
- * This function returns true if dispatching is disabled, and false
- * otherwise.
- */
-
-RTEMS_INLINE_ROUTINE bool _Thread_Is_dispatching_enabled( void )
-{
-  return  ( _Thread_Dispatch_in_critical_section() == false );
-}
-
 /** @} */
 
 #ifdef __cplusplus
diff --git a/cpukit/score/src/heapfree.c b/cpukit/score/src/heapfree.c
index d53a54d..30a84a0 100644
--- a/cpukit/score/src/heapfree.c
+++ b/cpukit/score/src/heapfree.c
@@ -87,7 +87,7 @@
      * is the task stack of a thread that deletes itself.  The thread dispatch
      * disable level is a way to detect this use case.
      */
-    if ( !_Thread_Dispatch_in_critical_section() ) {
+    if ( _Thread_Dispatch_is_enabled() ) {
       Heap_Block *const next = block->Protection_begin.next_delayed_free_block;
       if ( next == NULL ) {
         _Heap_Protection_delay_block_free( heap, block );
diff --git a/cpukit/score/src/pheapwalk.c b/cpukit/score/src/pheapwalk.c
index 12b2a6d..d06d8bc 100644
--- a/cpukit/score/src/pheapwalk.c
+++ b/cpukit/score/src/pheapwalk.c
@@ -37,7 +37,7 @@ bool _Protected_heap_Walk(
    *
    * NOTE: Dispatching is also disabled during initialization.
    */
-  if ( _Thread_Dispatch_in_critical_section() == false ) {
+  if ( _Thread_Dispatch_is_enabled() ) {
     _RTEMS_Lock_allocator();
       status = _Heap_Walk( the_heap, source, do_dump );
     _RTEMS_Unlock_allocator();
diff --git a/cpukit/score/src/threaddispatchdisablelevel.c b/cpukit/score/src/threaddispatchdisablelevel.c
index 154a6af..1f84bfe 100644
--- a/cpukit/score/src/threaddispatchdisablelevel.c
+++ b/cpukit/score/src/threaddispatchdisablelevel.c
@@ -39,14 +39,6 @@ void _Thread_Dispatch_initialization( void )
   _Thread_Dispatch_set_disable_level( 1 );
 }
 
-bool _Thread_Dispatch_in_critical_section(void)
-{
-  if (  _Thread_Dispatch_disable_level == 0 )
-   return false;
-
-  return true;
-}
-
 uint32_t _Thread_Dispatch_get_disable_level(void)
 {
   return _Thread_Dispatch_disable_level;
diff --git a/testsuites/support/include/tmacros.h b/testsuites/support/include/tmacros.h
index c2878dd..6ab6e23 100644
--- a/testsuites/support/include/tmacros.h
+++ b/testsuites/support/include/tmacros.h
@@ -54,13 +54,13 @@ extern "C" {
  #define check_dispatch_disable_level( _expect ) \
   do { \
     if ( (_expect) != -1 \
-           && ((_Thread_Dispatch_in_critical_section() == false && (_expect) != 0) \
-             || (_Thread_Dispatch_in_critical_section() && (_expect) == 0)) \
+           && ((!_Thread_Dispatch_is_enabled() == false && (_expect) != 0) \
+             || (!_Thread_Dispatch_is_enabled() && (_expect) == 0)) \
     ) { \
       printk( \
         "\n_Thread_Dispatch_disable_level is (%" PRId32 \
            ") not %d detected at %s:%d\n", \
-         _Thread_Dispatch_in_critical_section(), (_expect), __FILE__, __LINE__ ); \
+         !_Thread_Dispatch_is_enabled(), (_expect), __FILE__, __LINE__ ); \
       FLUSH_OUTPUT(); \
       rtems_test_exit( 1 ); \
     } \
-- 
1.7.7




More information about the devel mailing list