[PATCH] Format some files with clang-format

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Apr 6 05:18:53 UTC 2021


This patch is not intended to be integrated. It just gives an example
for using clang-format.

Using

AlignConsecutiveDeclarations: false
PointerAlignment: Right

would be closer to the RTEMS style, however, this combination is not
really supported:

https://stackoverflow.com/questions/38392889/clang-format-align-asterisk-of-pointer-declaration-with-variable-name

Used .clang-format file for -style=file:

---
Language:        Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands:   true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
  AfterCaseLabel:  false
  AfterClass:      false
  AfterControlStatement: false
  AfterEnum:       false
  AfterFunction:   true
  AfterNamespace:  false
  AfterObjCDeclaration: false
  AfterStruct:     false
  AfterUnion:      false
  AfterExternBlock: false
  BeforeCatch:     false
  BeforeElse:      false
  IndentBraces:    false
  SplitEmptyFunction: true
  SplitEmptyRecord: true
  SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit:     80
CommentPragmas:  '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat:   false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
  - foreach
  - Q_FOREACH
  - BOOST_FOREACH
IncludeBlocks:   Preserve
IncludeCategories:
  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
    Priority:        2
    SortPriority:    0
  - Regex:           '^(<|"(gtest|gmock|isl|json)/)'
    Priority:        3
    SortPriority:    0
  - Regex:           '.*'
    Priority:        1
    SortPriority:    0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentGotoLabels: false
IndentPPDirectives: None
IndentWidth:     2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd:   ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments:  true
SortIncludes:    true
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles:  true
SpacesInConditionalStatement: true
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: true
SpacesInSquareBrackets: true
SpaceBeforeSquareBrackets: false
Standard:        Latest
StatementMacros:
  - Q_UNUSED
  - QT_REQUIRE_VERSION
TabWidth:        8
UseCRLF:         false
UseTab:          Never
...
---
 cpukit/rtems/src/semcreate.c      | 150 ++++------
 cpukit/score/src/threadqenqueue.c | 455 +++++++++++++-----------------
 2 files changed, 252 insertions(+), 353 deletions(-)

diff --git a/cpukit/rtems/src/semcreate.c b/cpukit/rtems/src/semcreate.c
index b58ea0199f..59437bdef9 100644
--- a/cpukit/rtems/src/semcreate.c
+++ b/cpukit/rtems/src/semcreate.c
@@ -20,8 +20,8 @@
 #include "config.h"
 #endif
 
-#include <rtems/rtems/semimpl.h>
 #include <rtems/rtems/attrimpl.h>
+#include <rtems/rtems/semimpl.h>
 #include <rtems/rtems/statusimpl.h>
 #include <rtems/rtems/support.h>
 #include <rtems/rtems/tasksimpl.h>
@@ -29,27 +29,26 @@
 #include <rtems/score/sysstate.h>
 #include <rtems/sysinit.h>
 
-#define SEMAPHORE_KIND_MASK ( RTEMS_SEMAPHORE_CLASS | RTEMS_INHERIT_PRIORITY \
-  | RTEMS_PRIORITY_CEILING | RTEMS_MULTIPROCESSOR_RESOURCE_SHARING )
+#define SEMAPHORE_KIND_MASK                                                    \
+  ( RTEMS_SEMAPHORE_CLASS | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY_CEILING |  \
+    RTEMS_MULTIPROCESSOR_RESOURCE_SHARING )
 
-rtems_status_code rtems_semaphore_create(
-  rtems_name           name,
-  uint32_t             count,
-  rtems_attribute      attribute_set,
-  rtems_task_priority  priority_ceiling,
-  rtems_id            *id
-)
+rtems_status_code rtems_semaphore_create( rtems_name name,
+                                          uint32_t count,
+                                          rtems_attribute attribute_set,
+                                          rtems_task_priority priority_ceiling,
+                                          rtems_id *id )
 {
-  Semaphore_Control       *the_semaphore;
-  Thread_Control          *executing;
-  Status_Control           status;
-  rtems_attribute          maybe_global;
-  rtems_attribute          mutex_with_protocol;
-  Semaphore_Variant        variant;
+  Semaphore_Control *the_semaphore;
+  Thread_Control *executing;
+  Status_Control status;
+  rtems_attribute maybe_global;
+  rtems_attribute mutex_with_protocol;
+  Semaphore_Variant variant;
   const Scheduler_Control *scheduler;
-  bool                     valid;
-  Priority_Control         priority;
-  uintptr_t                flags;
+  bool valid;
+  Priority_Control priority;
+  uintptr_t flags;
 
   if ( !rtems_is_name_valid( name ) )
     return RTEMS_INVALID_NAME;
@@ -57,7 +56,7 @@ rtems_status_code rtems_semaphore_create(
   if ( !id )
     return RTEMS_INVALID_ADDRESS;
 
-#if defined(RTEMS_MULTIPROCESSING)
+#if defined( RTEMS_MULTIPROCESSING )
   if ( !_System_state_Is_multiprocessing ) {
     attribute_set = _Attributes_Clear( attribute_set, RTEMS_GLOBAL );
   }
@@ -76,21 +75,16 @@ rtems_status_code rtems_semaphore_create(
     variant = SEMAPHORE_VARIANT_SIMPLE_BINARY;
   } else if ( maybe_global == RTEMS_BINARY_SEMAPHORE ) {
     variant = SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL;
-  } else if (
-    mutex_with_protocol
-      == ( RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY )
-  ) {
+  } else if ( mutex_with_protocol == ( RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY |
+                                       RTEMS_INHERIT_PRIORITY ) ) {
     variant = SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY;
-  } else if (
-    mutex_with_protocol
-      == ( RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_PRIORITY_CEILING )
-  ) {
+  } else if ( mutex_with_protocol == ( RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY |
+                                       RTEMS_PRIORITY_CEILING ) ) {
     variant = SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING;
-  } else if (
-    mutex_with_protocol == ( RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY |
-      RTEMS_MULTIPROCESSOR_RESOURCE_SHARING )
-  ) {
-#if defined(RTEMS_SMP)
+  } else if ( mutex_with_protocol ==
+              ( RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY |
+                RTEMS_MULTIPROCESSOR_RESOURCE_SHARING ) ) {
+#if defined( RTEMS_SMP )
     variant = SEMAPHORE_VARIANT_MRSP;
 #else
     /*
@@ -116,16 +110,14 @@ rtems_status_code rtems_semaphore_create(
 
   flags = _Semaphore_Set_variant( 0, variant );
 
-#if defined(RTEMS_MULTIPROCESSING)
+#if defined( RTEMS_MULTIPROCESSING )
   if ( _Attributes_Is_global( attribute_set ) ) {
     bool ok;
 
-    ok = _Objects_MP_Allocate_and_open(
-      &_Semaphore_Information,
-      name,
-      the_semaphore->Object.id,
-      false
-    );
+    ok = _Objects_MP_Allocate_and_open( &_Semaphore_Information,
+                                        name,
+                                        the_semaphore->Object.id,
+                                        false );
 
     if ( !ok ) {
       _Semaphore_Free( the_semaphore );
@@ -150,14 +142,12 @@ rtems_status_code rtems_semaphore_create(
     case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
     case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
       _CORE_recursive_mutex_Initialize(
-        &the_semaphore->Core_control.Mutex.Recursive
-      );
+        &the_semaphore->Core_control.Mutex.Recursive );
 
       if ( count == 0 ) {
         _CORE_mutex_Set_owner(
           &the_semaphore->Core_control.Mutex.Recursive.Mutex,
-          executing
-        );
+          executing );
         _Thread_Resource_count_increment( executing );
       }
 
@@ -168,11 +158,9 @@ rtems_status_code rtems_semaphore_create(
       priority = _RTEMS_Priority_To_core( scheduler, priority_ceiling, &valid );
 
       if ( valid ) {
-        _CORE_ceiling_mutex_Initialize(
-          &the_semaphore->Core_control.Mutex,
-          scheduler,
-          priority
-        );
+        _CORE_ceiling_mutex_Initialize( &the_semaphore->Core_control.Mutex,
+                                        scheduler,
+                                        priority );
 
         if ( count == 0 ) {
           Thread_queue_Context queue_context;
@@ -182,13 +170,11 @@ rtems_status_code rtems_semaphore_create(
           _ISR_lock_ISR_disable( &queue_context.Lock_context.Lock_context );
           _CORE_mutex_Acquire_critical(
             &the_semaphore->Core_control.Mutex.Recursive.Mutex,
-            &queue_context
-          );
-          status = _CORE_ceiling_mutex_Set_owner(
-            &the_semaphore->Core_control.Mutex,
-            executing,
-            &queue_context
-          );
+            &queue_context );
+          status =
+            _CORE_ceiling_mutex_Set_owner( &the_semaphore->Core_control.Mutex,
+                                           executing,
+                                           &queue_context );
 
           if ( status != STATUS_SUCCESSFUL ) {
             _Thread_queue_Destroy( &the_semaphore->Core_control.Wait_queue );
@@ -201,19 +187,17 @@ rtems_status_code rtems_semaphore_create(
       }
 
       break;
-#if defined(RTEMS_SMP)
+#if defined( RTEMS_SMP )
     case SEMAPHORE_VARIANT_MRSP:
       scheduler = _Thread_Scheduler_get_home( executing );
       priority = _RTEMS_Priority_To_core( scheduler, priority_ceiling, &valid );
 
       if ( valid ) {
-        status = _MRSP_Initialize(
-          &the_semaphore->Core_control.MRSP,
-          scheduler,
-          priority,
-          executing,
-          count == 0
-        );
+        status = _MRSP_Initialize( &the_semaphore->Core_control.MRSP,
+                                   scheduler,
+                                   priority,
+                                   executing,
+                                   count == 0 );
       } else {
         status = STATUS_INVALID_PRIORITY;
       }
@@ -221,14 +205,10 @@ rtems_status_code rtems_semaphore_create(
       break;
 #endif
     default:
-      _Assert(
-        variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
-          || variant == SEMAPHORE_VARIANT_COUNTING
-      );
-      _CORE_semaphore_Initialize(
-        &the_semaphore->Core_control.Semaphore,
-        count
-      );
+      _Assert( variant == SEMAPHORE_VARIANT_SIMPLE_BINARY ||
+               variant == SEMAPHORE_VARIANT_COUNTING );
+      _CORE_semaphore_Initialize( &the_semaphore->Core_control.Semaphore,
+                                  count );
       status = STATUS_SUCCESSFUL;
       break;
   }
@@ -243,19 +223,15 @@ rtems_status_code rtems_semaphore_create(
    *  Whether we initialized it as a mutex or counting semaphore, it is
    *  now ready to be "offered" for use as a Classic API Semaphore.
    */
-  *id = _Objects_Open_u32(
-    &_Semaphore_Information,
-    &the_semaphore->Object,
-    name
-  );
+  *id =
+    _Objects_Open_u32( &_Semaphore_Information, &the_semaphore->Object, name );
 
-#if defined(RTEMS_MULTIPROCESSING)
+#if defined( RTEMS_MULTIPROCESSING )
   if ( _Attributes_Is_global( attribute_set ) )
-    _Semaphore_MP_Send_process_packet(
-      SEMAPHORE_MP_ANNOUNCE_CREATE,
-      the_semaphore->Object.id,
-      name,
-      0                          /* Not used */
+    _Semaphore_MP_Send_process_packet( SEMAPHORE_MP_ANNOUNCE_CREATE,
+                                       the_semaphore->Object.id,
+                                       name,
+                                       0 /* Not used */
     );
 #endif
   _Objects_Allocator_unlock();
@@ -267,8 +243,6 @@ static void _Semaphore_Manager_initialization( void )
   _Objects_Initialize_information( &_Semaphore_Information );
 }
 
-RTEMS_SYSINIT_ITEM(
-  _Semaphore_Manager_initialization,
-  RTEMS_SYSINIT_CLASSIC_SEMAPHORE,
-  RTEMS_SYSINIT_ORDER_MIDDLE
-);
+RTEMS_SYSINIT_ITEM( _Semaphore_Manager_initialization,
+                    RTEMS_SYSINIT_CLASSIC_SEMAPHORE,
+                    RTEMS_SYSINIT_ORDER_MIDDLE );
diff --git a/cpukit/score/src/threadqenqueue.c b/cpukit/score/src/threadqenqueue.c
index ba31b13dd1..e9214f0abe 100644
--- a/cpukit/score/src/threadqenqueue.c
+++ b/cpukit/score/src/threadqenqueue.c
@@ -28,23 +28,23 @@
 #include "config.h"
 #endif
 
-#include <rtems/score/threadqimpl.h>
 #include <rtems/score/assert.h>
+#include <rtems/score/status.h>
 #include <rtems/score/threaddispatch.h>
 #include <rtems/score/threadimpl.h>
-#include <rtems/score/status.h>
+#include <rtems/score/threadqimpl.h>
 #include <rtems/score/watchdogimpl.h>
 
-#define THREAD_QUEUE_INTEND_TO_BLOCK \
-  (THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_INTEND_TO_BLOCK)
+#define THREAD_QUEUE_INTEND_TO_BLOCK                                           \
+  ( THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_INTEND_TO_BLOCK )
 
-#define THREAD_QUEUE_BLOCKED \
-  (THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_BLOCKED)
+#define THREAD_QUEUE_BLOCKED                                                   \
+  ( THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_BLOCKED )
 
-#define THREAD_QUEUE_READY_AGAIN \
-  (THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_READY_AGAIN)
+#define THREAD_QUEUE_READY_AGAIN                                               \
+  ( THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_READY_AGAIN )
 
-#if defined(RTEMS_SMP)
+#if defined( RTEMS_SMP )
 /*
  * A global registry of active thread queue links is used to provide deadlock
  * detection on SMP configurations.  This is simple to implement and no
@@ -62,16 +62,13 @@ typedef struct {
 
 static Thread_queue_Links _Thread_queue_Links = {
   ISR_LOCK_INITIALIZER( "Thread Queue Links" ),
-  RBTREE_INITIALIZER_EMPTY( _Thread_queue_Links.Links )
-};
+  RBTREE_INITIALIZER_EMPTY( _Thread_queue_Links.Links ) };
 
-static bool _Thread_queue_Link_equal(
-  const void        *left,
-  const RBTree_Node *right
-)
+static bool _Thread_queue_Link_equal( const void *left,
+                                      const RBTree_Node *right )
 {
   const Thread_queue_Queue *the_left;
-  const Thread_queue_Link  *the_right;
+  const Thread_queue_Link *the_right;
 
   the_left = left;
   the_right = (Thread_queue_Link *) right;
@@ -79,13 +76,11 @@ static bool _Thread_queue_Link_equal(
   return the_left == the_right->source;
 }
 
-static bool _Thread_queue_Link_less(
-  const void        *left,
-  const RBTree_Node *right
-)
+static bool _Thread_queue_Link_less( const void *left,
+                                     const RBTree_Node *right )
 {
   const Thread_queue_Queue *the_left;
-  const Thread_queue_Link  *the_right;
+  const Thread_queue_Link *the_right;
 
   the_left = left;
   the_right = (Thread_queue_Link *) right;
@@ -98,29 +93,23 @@ static void *_Thread_queue_Link_map( RBTree_Node *node )
   return node;
 }
 
-static Thread_queue_Link *_Thread_queue_Link_find(
-  Thread_queue_Links *links,
-  Thread_queue_Queue *source
-)
+static Thread_queue_Link *_Thread_queue_Link_find( Thread_queue_Links *links,
+                                                   Thread_queue_Queue *source )
 {
-  return _RBTree_Find_inline(
-    &links->Links,
-    source,
-    _Thread_queue_Link_equal,
-    _Thread_queue_Link_less,
-    _Thread_queue_Link_map
-  );
+  return _RBTree_Find_inline( &links->Links,
+                              source,
+                              _Thread_queue_Link_equal,
+                              _Thread_queue_Link_less,
+                              _Thread_queue_Link_map );
 }
 
-static bool _Thread_queue_Link_add(
-  Thread_queue_Link  *link,
-  Thread_queue_Queue *source,
-  Thread_queue_Queue *target
-)
+static bool _Thread_queue_Link_add( Thread_queue_Link *link,
+                                    Thread_queue_Queue *source,
+                                    Thread_queue_Queue *target )
 {
   Thread_queue_Links *links;
   Thread_queue_Queue *recursive_target;
-  ISR_lock_Context    lock_context;
+  ISR_lock_Context lock_context;
 
   link->source = source;
   link->target = target;
@@ -147,12 +136,10 @@ static bool _Thread_queue_Link_add(
     }
   }
 
-  _RBTree_Insert_inline(
-    &links->Links,
-    &link->Registry_node,
-    source,
-    _Thread_queue_Link_less
-  );
+  _RBTree_Insert_inline( &links->Links,
+                         &link->Registry_node,
+                         source,
+                         _Thread_queue_Link_less );
 
   _ISR_lock_Release( &links->Lock, &lock_context );
   return true;
@@ -161,7 +148,7 @@ static bool _Thread_queue_Link_add(
 static void _Thread_queue_Link_remove( Thread_queue_Link *link )
 {
   Thread_queue_Links *links;
-  ISR_lock_Context    lock_context;
+  ISR_lock_Context lock_context;
 
   links = &_Thread_queue_Links;
 
@@ -171,14 +158,13 @@ static void _Thread_queue_Link_remove( Thread_queue_Link *link )
 }
 #endif
 
-#if !defined(RTEMS_SMP)
+#if !defined( RTEMS_SMP )
 static
 #endif
-void _Thread_queue_Path_release_critical(
-  Thread_queue_Context *queue_context
-)
+  void
+  _Thread_queue_Path_release_critical( Thread_queue_Context *queue_context )
 {
-#if defined(RTEMS_SMP)
+#if defined( RTEMS_SMP )
   Chain_Node *head;
   Chain_Node *node;
 
@@ -192,20 +178,16 @@ void _Thread_queue_Path_release_critical(
 
     if ( link->Lock_context.Wait.queue != NULL ) {
       _Thread_queue_Link_remove( link );
-      _Thread_Wait_release_queue_critical(
-        link->Lock_context.Wait.queue,
-        &link->Lock_context
-      );
+      _Thread_Wait_release_queue_critical( link->Lock_context.Wait.queue,
+                                           &link->Lock_context );
       _Thread_Wait_remove_request( link->owner, &link->Lock_context );
     } else {
-      _Thread_Wait_release_default_critical(
-        link->owner,
-        &link->Lock_context.Lock_context
-      );
+      _Thread_Wait_release_default_critical( link->owner,
+                                             &link->Lock_context.Lock_context );
     }
 
     node = _Chain_Previous( node );
-#if defined(RTEMS_DEBUG)
+#if defined( RTEMS_DEBUG )
     _Chain_Set_off_chain( &link->Path_node );
 #endif
   }
@@ -214,11 +196,10 @@ void _Thread_queue_Path_release_critical(
 #endif
 }
 
-#if defined(RTEMS_SMP)
-static void _Thread_queue_Path_append_deadlock_thread(
-  Thread_Control       *the_thread,
-  Thread_queue_Context *queue_context
-)
+#if defined( RTEMS_SMP )
+static void
+_Thread_queue_Path_append_deadlock_thread( Thread_Control *the_thread,
+                                           Thread_queue_Context *queue_context )
 {
   Thread_Control *deadlock;
 
@@ -242,32 +223,26 @@ static void _Thread_queue_Path_append_deadlock_thread(
 
     link = &queue_context->Path.Deadlock;
     _Chain_Initialize_node( &link->Path_node );
-    _Chain_Append_unprotected(
-      &queue_context->Path.Links,
-      &link->Path_node
-    );
+    _Chain_Append_unprotected( &queue_context->Path.Links, &link->Path_node );
     link->owner = deadlock;
     link->Lock_context.Wait.queue = NULL;
-    _Thread_Wait_acquire_default_critical(
-      deadlock,
-      &link->Lock_context.Lock_context
-    );
+    _Thread_Wait_acquire_default_critical( deadlock,
+                                           &link->Lock_context.Lock_context );
   }
 }
 #endif
 
-#if !defined(RTEMS_SMP)
+#if !defined( RTEMS_SMP )
 static
 #endif
-bool _Thread_queue_Path_acquire_critical(
-  Thread_queue_Queue   *queue,
-  Thread_Control       *the_thread,
-  Thread_queue_Context *queue_context
-)
+  bool
+  _Thread_queue_Path_acquire_critical( Thread_queue_Queue *queue,
+                                       Thread_Control *the_thread,
+                                       Thread_queue_Context *queue_context )
 {
-  Thread_Control     *owner;
-#if defined(RTEMS_SMP)
-  Thread_queue_Link  *link;
+  Thread_Control *owner;
+#if defined( RTEMS_SMP )
+  Thread_queue_Link *link;
   Thread_queue_Queue *target;
 
   /*
@@ -291,8 +266,7 @@ bool _Thread_queue_Path_acquire_critical(
   }
 
   _Chain_Initialize_node(
-    &queue_context->Path.Start.Lock_context.Wait.Gate.Node
-  );
+    &queue_context->Path.Start.Lock_context.Wait.Gate.Node );
   link = &queue_context->Path.Start;
   _RBTree_Initialize_node( &link->Registry_node );
   _Chain_Initialize_node( &link->Path_node );
@@ -301,24 +275,19 @@ bool _Thread_queue_Path_acquire_critical(
     _Chain_Append_unprotected( &queue_context->Path.Links, &link->Path_node );
     link->owner = owner;
 
-    _Thread_Wait_acquire_default_critical(
-      owner,
-      &link->Lock_context.Lock_context
-    );
+    _Thread_Wait_acquire_default_critical( owner,
+                                           &link->Lock_context.Lock_context );
 
     target = owner->Wait.queue;
     link->Lock_context.Wait.queue = target;
 
     if ( target != NULL ) {
       if ( _Thread_queue_Link_add( link, queue, target ) ) {
-        _Thread_queue_Gate_add(
-          &owner->Wait.Lock.Pending_requests,
-          &link->Lock_context.Wait.Gate
-        );
+        _Thread_queue_Gate_add( &owner->Wait.Lock.Pending_requests,
+                                &link->Lock_context.Wait.Gate );
         _Thread_Wait_release_default_critical(
           owner,
-          &link->Lock_context.Lock_context
-        );
+          &link->Lock_context.Lock_context );
         _Thread_Wait_acquire_queue_critical( target, &link->Lock_context );
 
         if ( link->Lock_context.Wait.queue == NULL ) {
@@ -326,8 +295,7 @@ bool _Thread_queue_Path_acquire_critical(
           _Thread_Wait_release_queue_critical( target, &link->Lock_context );
           _Thread_Wait_acquire_default_critical(
             owner,
-            &link->Lock_context.Lock_context
-          );
+            &link->Lock_context.Lock_context );
           _Thread_Wait_remove_request_locked( owner, &link->Lock_context );
           _Assert( owner->Wait.queue == NULL );
           return true;
@@ -365,11 +333,10 @@ bool _Thread_queue_Path_acquire_critical(
 }
 
 void _Thread_queue_Enqueue_do_nothing_extra(
-  Thread_queue_Queue   *queue,
-  Thread_Control       *the_thread,
-  Per_CPU_Control      *cpu_self,
-  Thread_queue_Context *queue_context
-)
+  Thread_queue_Queue *queue,
+  Thread_Control *the_thread,
+  Per_CPU_Control *cpu_self,
+  Thread_queue_Context *queue_context )
 {
   /* Do nothing */
 }
@@ -384,19 +351,17 @@ void _Thread_queue_Deadlock_fatal( Thread_Control *the_thread )
   _Internal_error( INTERNAL_ERROR_THREAD_QUEUE_DEADLOCK );
 }
 
-void _Thread_queue_Enqueue(
-  Thread_queue_Queue            *queue,
-  const Thread_queue_Operations *operations,
-  Thread_Control                *the_thread,
-  Thread_queue_Context          *queue_context
-)
+void _Thread_queue_Enqueue( Thread_queue_Queue *queue,
+                            const Thread_queue_Operations *operations,
+                            Thread_Control *the_thread,
+                            Thread_queue_Context *queue_context )
 {
   Per_CPU_Control *cpu_self;
-  bool             success;
+  bool success;
 
   _Assert( queue_context->enqueue_callout != NULL );
 
-#if defined(RTEMS_MULTIPROCESSING)
+#if defined( RTEMS_MULTIPROCESSING )
   if ( _Thread_MP_Is_receive( the_thread ) && the_thread->receive_packet ) {
     the_thread = _Thread_MP_Allocate_proxy( queue_context->thread_state );
   }
@@ -404,10 +369,13 @@ void _Thread_queue_Enqueue(
 
   _Thread_Wait_claim( the_thread, queue );
 
-  if ( !_Thread_queue_Path_acquire_critical( queue, the_thread, queue_context ) ) {
+  if ( !_Thread_queue_Path_acquire_critical( queue,
+                                             the_thread,
+                                             queue_context ) ) {
     _Thread_queue_Path_release_critical( queue_context );
     _Thread_Wait_restore_default( the_thread );
-    _Thread_queue_Queue_release( queue, &queue_context->Lock_context.Lock_context );
+    _Thread_queue_Queue_release( queue,
+                                 &queue_context->Lock_context.Lock_context );
     _Thread_Wait_tranquilize( the_thread );
     _Assert( queue_context->deadlock_callout != NULL );
     ( *queue_context->deadlock_callout )( the_thread );
@@ -423,14 +391,13 @@ void _Thread_queue_Enqueue(
   the_thread->Wait.return_code = STATUS_SUCCESSFUL;
   _Thread_Wait_flags_set( the_thread, THREAD_QUEUE_INTEND_TO_BLOCK );
   cpu_self = _Thread_queue_Dispatch_disable( queue_context );
-  _Thread_queue_Queue_release( queue, &queue_context->Lock_context.Lock_context );
+  _Thread_queue_Queue_release( queue,
+                               &queue_context->Lock_context.Lock_context );
 
-  ( *queue_context->enqueue_callout )(
-    queue,
-    the_thread,
-    cpu_self,
-    queue_context
-  );
+  ( *queue_context->enqueue_callout )( queue,
+                                       the_thread,
+                                       cpu_self,
+                                       queue_context );
 
   /*
    *  Set the blocking state for this thread queue in the thread.
@@ -446,11 +413,9 @@ void _Thread_queue_Enqueue(
    * as long as we are in the THREAD_QUEUE_INTEND_TO_BLOCK thread wait state,
    * thus we have to cancel the blocking operation ourself if necessary.
    */
-  success = _Thread_Wait_flags_try_change_acquire(
-    the_thread,
-    THREAD_QUEUE_INTEND_TO_BLOCK,
-    THREAD_QUEUE_BLOCKED
-  );
+  success = _Thread_Wait_flags_try_change_acquire( the_thread,
+                                                   THREAD_QUEUE_INTEND_TO_BLOCK,
+                                                   THREAD_QUEUE_BLOCKED );
   if ( !success ) {
     _Thread_Remove_timer_and_unblock( the_thread, queue );
   }
@@ -459,13 +424,12 @@ void _Thread_queue_Enqueue(
   _Thread_Dispatch_direct( cpu_self );
 }
 
-#if defined(RTEMS_SMP)
-Status_Control _Thread_queue_Enqueue_sticky(
-  Thread_queue_Queue            *queue,
-  const Thread_queue_Operations *operations,
-  Thread_Control                *the_thread,
-  Thread_queue_Context          *queue_context
-)
+#if defined( RTEMS_SMP )
+Status_Control
+_Thread_queue_Enqueue_sticky( Thread_queue_Queue *queue,
+                              const Thread_queue_Operations *operations,
+                              Thread_Control *the_thread,
+                              Thread_queue_Context *queue_context )
 {
   Per_CPU_Control *cpu_self;
 
@@ -473,10 +437,13 @@ Status_Control _Thread_queue_Enqueue_sticky(
 
   _Thread_Wait_claim( the_thread, queue );
 
-  if ( !_Thread_queue_Path_acquire_critical( queue, the_thread, queue_context ) ) {
+  if ( !_Thread_queue_Path_acquire_critical( queue,
+                                             the_thread,
+                                             queue_context ) ) {
     _Thread_queue_Path_release_critical( queue_context );
     _Thread_Wait_restore_default( the_thread );
-    _Thread_queue_Queue_release( queue, &queue_context->Lock_context.Lock_context );
+    _Thread_queue_Queue_release( queue,
+                                 &queue_context->Lock_context.Lock_context );
     _Thread_Wait_tranquilize( the_thread );
     ( *queue_context->deadlock_callout )( the_thread );
     return _Thread_Wait_get_status( the_thread );
@@ -491,28 +458,25 @@ Status_Control _Thread_queue_Enqueue_sticky(
   the_thread->Wait.return_code = STATUS_SUCCESSFUL;
   _Thread_Wait_flags_set( the_thread, THREAD_QUEUE_INTEND_TO_BLOCK );
   cpu_self = _Thread_queue_Dispatch_disable( queue_context );
-  _Thread_queue_Queue_release( queue, &queue_context->Lock_context.Lock_context );
+  _Thread_queue_Queue_release( queue,
+                               &queue_context->Lock_context.Lock_context );
 
   if ( cpu_self->thread_dispatch_disable_level != 1 ) {
     _Internal_error(
-      INTERNAL_ERROR_THREAD_QUEUE_ENQUEUE_STICKY_FROM_BAD_STATE
-    );
+      INTERNAL_ERROR_THREAD_QUEUE_ENQUEUE_STICKY_FROM_BAD_STATE );
   }
 
-  ( *queue_context->enqueue_callout )(
-    queue,
-    the_thread,
-    cpu_self,
-    queue_context
-  );
+  ( *queue_context->enqueue_callout )( queue,
+                                       the_thread,
+                                       cpu_self,
+                                       queue_context );
 
   _Thread_Priority_update( queue_context );
   _Thread_Priority_and_sticky_update( the_thread, 1 );
   _Thread_Dispatch_enable( cpu_self );
 
-  while (
-    _Thread_Wait_flags_get_acquire( the_thread ) == THREAD_QUEUE_INTEND_TO_BLOCK
-  ) {
+  while ( _Thread_Wait_flags_get_acquire( the_thread ) ==
+          THREAD_QUEUE_INTEND_TO_BLOCK ) {
     /* Wait */
   }
 
@@ -522,14 +486,13 @@ Status_Control _Thread_queue_Enqueue_sticky(
 }
 #endif
 
-#if defined(RTEMS_MULTIPROCESSING)
-static bool _Thread_queue_MP_set_callout(
-  Thread_Control             *the_thread,
-  const Thread_queue_Context *queue_context
-)
+#if defined( RTEMS_MULTIPROCESSING )
+static bool
+_Thread_queue_MP_set_callout( Thread_Control *the_thread,
+                              const Thread_queue_Context *queue_context )
 {
-  Thread_Proxy_control    *the_proxy;
-  Thread_queue_MP_callout  mp_callout;
+  Thread_Proxy_control *the_proxy;
+  Thread_queue_MP_callout mp_callout;
 
   if ( _Objects_Is_local_id( the_thread->Object.id ) ) {
     return false;
@@ -552,11 +515,9 @@ static bool _Thread_queue_Make_ready_again( Thread_Control *the_thread )
    * We must update the wait flags under protection of the current thread lock,
    * otherwise a _Thread_Timeout() running on another processor may interfere.
    */
-  success = _Thread_Wait_flags_try_change_release(
-    the_thread,
-    THREAD_QUEUE_INTEND_TO_BLOCK,
-    THREAD_QUEUE_READY_AGAIN
-  );
+  success = _Thread_Wait_flags_try_change_release( the_thread,
+                                                   THREAD_QUEUE_INTEND_TO_BLOCK,
+                                                   THREAD_QUEUE_READY_AGAIN );
   if ( success ) {
     unblock = false;
   } else {
@@ -569,26 +530,22 @@ static bool _Thread_queue_Make_ready_again( Thread_Control *the_thread )
   return unblock;
 }
 
-bool _Thread_queue_Extract_locked(
-  Thread_queue_Queue            *queue,
-  const Thread_queue_Operations *operations,
-  Thread_Control                *the_thread,
-  Thread_queue_Context          *queue_context
-)
+bool _Thread_queue_Extract_locked( Thread_queue_Queue *queue,
+                                   const Thread_queue_Operations *operations,
+                                   Thread_Control *the_thread,
+                                   Thread_queue_Context *queue_context )
 {
-#if defined(RTEMS_MULTIPROCESSING)
+#if defined( RTEMS_MULTIPROCESSING )
   _Thread_queue_MP_set_callout( the_thread, queue_context );
 #endif
   ( *operations->extract )( queue, the_thread, queue_context );
   return _Thread_queue_Make_ready_again( the_thread );
 }
 
-void _Thread_queue_Unblock_critical(
-  bool                unblock,
-  Thread_queue_Queue *queue,
-  Thread_Control     *the_thread,
-  ISR_lock_Context   *lock_context
-)
+void _Thread_queue_Unblock_critical( bool unblock,
+                                     Thread_queue_Queue *queue,
+                                     Thread_Control *the_thread,
+                                     ISR_lock_Context *lock_context )
 {
   if ( unblock ) {
     Per_CPU_Control *cpu_self;
@@ -604,34 +561,28 @@ void _Thread_queue_Unblock_critical(
   }
 }
 
-void _Thread_queue_Extract_critical(
-  Thread_queue_Queue            *queue,
-  const Thread_queue_Operations *operations,
-  Thread_Control                *the_thread,
-  Thread_queue_Context          *queue_context
-)
+void _Thread_queue_Extract_critical( Thread_queue_Queue *queue,
+                                     const Thread_queue_Operations *operations,
+                                     Thread_Control *the_thread,
+                                     Thread_queue_Context *queue_context )
 {
   bool unblock;
 
-  unblock = _Thread_queue_Extract_locked(
-    queue,
-    operations,
-    the_thread,
-    queue_context
-  );
-
-  _Thread_queue_Unblock_critical(
-    unblock,
-    queue,
-    the_thread,
-    &queue_context->Lock_context.Lock_context
-  );
+  unblock = _Thread_queue_Extract_locked( queue,
+                                          operations,
+                                          the_thread,
+                                          queue_context );
+
+  _Thread_queue_Unblock_critical( unblock,
+                                  queue,
+                                  the_thread,
+                                  &queue_context->Lock_context.Lock_context );
 }
 
 void _Thread_queue_Extract( Thread_Control *the_thread )
 {
-  Thread_queue_Context  queue_context;
-  Thread_queue_Queue   *queue;
+  Thread_queue_Context queue_context;
+  Thread_queue_Queue *queue;
 
   _Thread_queue_Context_initialize( &queue_context );
   _Thread_queue_Context_clear_priority_updates( &queue_context );
@@ -643,51 +594,39 @@ void _Thread_queue_Extract( Thread_Control *the_thread )
     bool unblock;
 
     _Thread_Wait_remove_request( the_thread, &queue_context.Lock_context );
-    _Thread_queue_Context_set_MP_callout(
-      &queue_context,
-      _Thread_queue_MP_callout_do_nothing
-    );
-    unblock = _Thread_queue_Extract_locked(
-      queue,
-      the_thread->Wait.operations,
-      the_thread,
-      &queue_context
-    );
-    _Thread_queue_Unblock_critical(
-      unblock,
-      queue,
-      the_thread,
-      &queue_context.Lock_context.Lock_context
-    );
+    _Thread_queue_Context_set_MP_callout( &queue_context,
+                                          _Thread_queue_MP_callout_do_nothing );
+    unblock = _Thread_queue_Extract_locked( queue,
+                                            the_thread->Wait.operations,
+                                            the_thread,
+                                            &queue_context );
+    _Thread_queue_Unblock_critical( unblock,
+                                    queue,
+                                    the_thread,
+                                    &queue_context.Lock_context.Lock_context );
   } else {
     _Thread_Wait_release( the_thread, &queue_context );
   }
 }
 
-void _Thread_queue_Surrender(
-  Thread_queue_Queue            *queue,
-  Thread_queue_Heads            *heads,
-  Thread_Control                *previous_owner,
-  Thread_queue_Context          *queue_context,
-  const Thread_queue_Operations *operations
-)
+void _Thread_queue_Surrender( Thread_queue_Queue *queue,
+                              Thread_queue_Heads *heads,
+                              Thread_Control *previous_owner,
+                              Thread_queue_Context *queue_context,
+                              const Thread_queue_Operations *operations )
 {
-  Thread_Control  *new_owner;
-  bool             unblock;
+  Thread_Control *new_owner;
+  bool unblock;
   Per_CPU_Control *cpu_self;
 
   _Assert( heads != NULL );
 
   _Thread_queue_Context_clear_priority_updates( queue_context );
-  new_owner = ( *operations->surrender )(
-    queue,
-    heads,
-    previous_owner,
-    queue_context
-  );
+  new_owner =
+    ( *operations->surrender )( queue, heads, previous_owner, queue_context );
   queue->owner = new_owner;
 
-#if defined(RTEMS_MULTIPROCESSING)
+#if defined( RTEMS_MULTIPROCESSING )
   if ( !_Thread_queue_MP_set_callout( new_owner, queue_context ) )
 #endif
   {
@@ -697,10 +636,8 @@ void _Thread_queue_Surrender(
   unblock = _Thread_queue_Make_ready_again( new_owner );
 
   cpu_self = _Thread_queue_Dispatch_disable( queue_context );
-  _Thread_queue_Queue_release(
-    queue,
-    &queue_context->Lock_context.Lock_context
-  );
+  _Thread_queue_Queue_release( queue,
+                               &queue_context->Lock_context.Lock_context );
 
   _Thread_Priority_update( queue_context );
 
@@ -711,52 +648,44 @@ void _Thread_queue_Surrender(
   _Thread_Dispatch_enable( cpu_self );
 }
 
-#if defined(RTEMS_SMP)
-void _Thread_queue_Surrender_sticky(
-  Thread_queue_Queue            *queue,
-  Thread_queue_Heads            *heads,
-  Thread_Control                *previous_owner,
-  Thread_queue_Context          *queue_context,
-  const Thread_queue_Operations *operations
-)
+#if defined( RTEMS_SMP )
+void _Thread_queue_Surrender_sticky( Thread_queue_Queue *queue,
+                                     Thread_queue_Heads *heads,
+                                     Thread_Control *previous_owner,
+                                     Thread_queue_Context *queue_context,
+                                     const Thread_queue_Operations *operations )
 {
-  Thread_Control  *new_owner;
+  Thread_Control *new_owner;
   Per_CPU_Control *cpu_self;
 
   _Assert( heads != NULL );
 
   _Thread_queue_Context_clear_priority_updates( queue_context );
-  new_owner = ( *operations->surrender )(
-    queue,
-    heads,
-    previous_owner,
-    queue_context
-  );
+  new_owner =
+    ( *operations->surrender )( queue, heads, previous_owner, queue_context );
   queue->owner = new_owner;
   _Thread_queue_Make_ready_again( new_owner );
 
   cpu_self = _Thread_queue_Dispatch_disable( queue_context );
-  _Thread_queue_Queue_release(
-    queue,
-    &queue_context->Lock_context.Lock_context
-  );
+  _Thread_queue_Queue_release( queue,
+                               &queue_context->Lock_context.Lock_context );
   _Thread_Priority_and_sticky_update( previous_owner, -1 );
   _Thread_Priority_and_sticky_update( new_owner, 0 );
   _Thread_Dispatch_enable( cpu_self );
 }
 #endif
 
-Thread_Control *_Thread_queue_Do_dequeue(
-  Thread_queue_Control          *the_thread_queue,
-  const Thread_queue_Operations *operations
-#if defined(RTEMS_MULTIPROCESSING)
-  ,
-  Thread_queue_MP_callout        mp_callout
+Thread_Control *
+_Thread_queue_Do_dequeue( Thread_queue_Control *the_thread_queue,
+                          const Thread_queue_Operations *operations
+#if defined( RTEMS_MULTIPROCESSING )
+                          ,
+                          Thread_queue_MP_callout mp_callout
 #endif
 )
 {
-  Thread_queue_Context  queue_context;
-  Thread_Control       *the_thread;
+  Thread_queue_Context queue_context;
+  Thread_Control *the_thread;
 
   _Thread_queue_Context_initialize( &queue_context );
   _Thread_queue_Context_set_MP_callout( &queue_context, mp_callout );
@@ -765,12 +694,10 @@ Thread_Control *_Thread_queue_Do_dequeue(
   the_thread = _Thread_queue_First_locked( the_thread_queue, operations );
 
   if ( the_thread != NULL ) {
-    _Thread_queue_Extract_critical(
-      &the_thread_queue->Queue,
-      operations,
-      the_thread,
-      &queue_context
-    );
+    _Thread_queue_Extract_critical( &the_thread_queue->Queue,
+                                    operations,
+                                    the_thread,
+                                    &queue_context );
   } else {
     _Thread_queue_Release( the_thread_queue, &queue_context );
   }
@@ -778,15 +705,13 @@ Thread_Control *_Thread_queue_Do_dequeue(
   return the_thread;
 }
 
-#if defined(RTEMS_MULTIPROCESSING)
-void _Thread_queue_Unblock_proxy(
-  Thread_queue_Queue *queue,
-  Thread_Control     *the_thread
-)
+#if defined( RTEMS_MULTIPROCESSING )
+void _Thread_queue_Unblock_proxy( Thread_queue_Queue *queue,
+                                  Thread_Control *the_thread )
 {
   const Thread_queue_Object *the_queue_object;
-  Thread_Proxy_control      *the_proxy;
-  Thread_queue_MP_callout    mp_callout;
+  Thread_Proxy_control *the_proxy;
+  Thread_queue_MP_callout mp_callout;
 
   the_queue_object = THREAD_QUEUE_QUEUE_TO_OBJECT( queue );
   the_proxy = (Thread_Proxy_control *) the_thread;
-- 
2.26.2





More information about the devel mailing list