[rtems commit] score: Add static initializers for thread queues

Sebastian Huber sebh at rtems.org
Wed May 20 07:12:03 UTC 2015


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon May 11 14:56:12 2015 +0200

score: Add static initializers for thread queues

---

 cpukit/score/include/rtems/score/threadqimpl.h | 34 ++++++++++++++++++++++++++
 testsuites/sptests/spthreadq01/init.c          | 14 +++++++++++
 2 files changed, 48 insertions(+)

diff --git a/cpukit/score/include/rtems/score/threadqimpl.h b/cpukit/score/include/rtems/score/threadqimpl.h
index 79fc810..32217ad 100644
--- a/cpukit/score/include/rtems/score/threadqimpl.h
+++ b/cpukit/score/include/rtems/score/threadqimpl.h
@@ -20,6 +20,8 @@
 #define _RTEMS_SCORE_THREADQIMPL_H
 
 #include <rtems/score/threadq.h>
+#include <rtems/score/chainimpl.h>
+#include <rtems/score/rbtreeimpl.h>
 #include <rtems/score/thread.h>
 
 #ifdef __cplusplus
@@ -342,6 +344,38 @@ void _Thread_queue_Initialize(
   Thread_queue_Disciplines  the_discipline
 );
 
+#if defined(RTEMS_SMP)
+  #define THREAD_QUEUE_FIFO_INITIALIZER( designator, name ) { \
+      .Queues = { \
+        .Fifo = CHAIN_INITIALIZER_EMPTY( designator.Queues.Fifo ) \
+      }, \
+      .operations = &_Thread_queue_Operations_FIFO, \
+      .Lock = ISR_LOCK_INITIALIZER( name ) \
+    }
+
+  #define THREAD_QUEUE_PRIORIY_INITIALIZER( designator, name ) { \
+      .Queues = { \
+        .Priority = RBTREE_INITIALIZER_EMPTY( designator.Queues.Priority ) \
+      }, \
+      .operations = &_Thread_queue_Operations_priority, \
+      .Lock = ISR_LOCK_INITIALIZER( name ) \
+    }
+#else
+  #define THREAD_QUEUE_FIFO_INITIALIZER( designator, name ) { \
+      .Queues = { \
+        .Fifo = CHAIN_INITIALIZER_EMPTY( designator.Queues.Fifo ) \
+      }, \
+      .operations = &_Thread_queue_Operations_FIFO \
+    }
+
+  #define THREAD_QUEUE_PRIORIY_INITIALIZER( designator, name ) { \
+      .Queues = { \
+        .Priority = RBTREE_INITIALIZER_EMPTY( designator.Queues.Priority ) \
+      }, \
+      .operations = &_Thread_queue_Operations_priority \
+    }
+#endif
+
 RTEMS_INLINE_ROUTINE void _Thread_queue_Destroy(
   Thread_queue_Control *the_thread_queue
 )
diff --git a/testsuites/sptests/spthreadq01/init.c b/testsuites/sptests/spthreadq01/init.c
index 5add92b..ce47760 100644
--- a/testsuites/sptests/spthreadq01/init.c
+++ b/testsuites/sptests/spthreadq01/init.c
@@ -18,6 +18,12 @@
 
 const char rtems_test_name[] = "SPTHREADQ 1";
 
+static Thread_queue_Control fifo_queue =
+  THREAD_QUEUE_FIFO_INITIALIZER( fifo_queue, "FIFO" );
+
+static Thread_queue_Control prio_queue =
+  THREAD_QUEUE_PRIORIY_INITIALIZER( prio_queue, "Prio" );
+
 static rtems_task Init(
   rtems_task_argument ignored
 )
@@ -30,6 +36,14 @@ static rtems_task Init(
   _Thread_Enable_dispatch();
   /* is there more to check? */
 
+  rtems_test_assert( _Chain_Is_empty( &fifo_queue.Queues.Fifo ) );
+  rtems_test_assert( fifo_queue.operations == &_Thread_queue_Operations_FIFO );
+
+  rtems_test_assert( _RBTree_Is_empty( &fifo_queue.Queues.Priority ) );
+  rtems_test_assert(
+    prio_queue.operations == &_Thread_queue_Operations_priority
+  );
+
   TEST_END();
   rtems_test_exit(0);
 }



More information about the vc mailing list