[rtems commit] score: Add thread queue for self-contained objects

Sebastian Huber sebh at rtems.org
Fri Jul 31 05:27:28 UTC 2015


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Jul 27 13:19:17 2015 +0200

score: Add thread queue for self-contained objects

---

 cpukit/configure.ac                            |  1 +
 cpukit/score/include/rtems/score/threadqimpl.h | 18 +++++++++++++
 cpukit/score/src/threadq.c                     | 36 ++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)

diff --git a/cpukit/configure.ac b/cpukit/configure.ac
index c2b8e8d..14ce0f1 100644
--- a/cpukit/configure.ac
+++ b/cpukit/configure.ac
@@ -71,6 +71,7 @@ AC_CHECK_DECLS([ftrylockfile],[AC_CHECK_FUNCS([ftrylockfile])],,[#include <stdio
 AC_CHECK_HEADERS([envlock.h])
 AC_CHECK_DECLS([__env_lock],,,[#include <envlock.h>])
 AC_CHECK_DECLS([__env_unlock],,,[#include <envlock.h>])
+AC_CHECK_TYPES([struct _Thread_queue_Queue],[],[],[#include <sys/lock.h>])
 
 # Mandated by POSIX, older newlibs bogusly provided CLOCK_PROCESS_CPUTIME+CLOCK_THREAD_CPUTIME
 AC_CHECK_DECL([CLOCK_PROCESS_CPUTIME_ID],[],[AC_MSG_ERROR([missing define CLOCK_PROCESS_CPUTIME_ID])],[#include <time.h>])
diff --git a/cpukit/score/include/rtems/score/threadqimpl.h b/cpukit/score/include/rtems/score/threadqimpl.h
index 22118ab..3828f41 100644
--- a/cpukit/score/include/rtems/score/threadqimpl.h
+++ b/cpukit/score/include/rtems/score/threadqimpl.h
@@ -33,6 +33,24 @@ extern "C" {
  */
 /**@{*/
 
+/**
+ * @brief Thread queue with a layout compatible to struct _Thread_queue_Queue
+ * defined in Newlib <sys/lock.h>.
+ */
+typedef struct {
+  Thread_queue_Queue Queue;
+
+#if !defined(RTEMS_SMP)
+  /*
+   * The struct _Thread_queue_Queue definition is independent of the RTEMS
+   * build configuration.  Thus, the storage space for the SMP lock is always
+   * present.  In SMP configurations, the SMP lock is contained in the
+   * Thread_queue_Queue.
+   */
+  unsigned int reserved[2];
+#endif
+} Thread_queue_Syslock_queue;
+
 RTEMS_INLINE_ROUTINE void _Thread_queue_Queue_initialize(
   Thread_queue_Queue *queue
 )
diff --git a/cpukit/score/src/threadq.c b/cpukit/score/src/threadq.c
index fc81409..372a07d 100644
--- a/cpukit/score/src/threadq.c
+++ b/cpukit/score/src/threadq.c
@@ -22,6 +22,42 @@
 #include <rtems/score/rbtreeimpl.h>
 #include <rtems/score/threadimpl.h>
 
+#if HAVE_STRUCT__THREAD_QUEUE_QUEUE
+
+RTEMS_STATIC_ASSERT(
+  offsetof( Thread_queue_Syslock_queue, Queue.heads )
+    == offsetof( struct _Thread_queue_Queue, _heads ),
+  THREAD_QUEUE_SYSLOCK_QUEUE_HEADS
+);
+
+RTEMS_STATIC_ASSERT(
+#if defined(RTEMS_SMP)
+  offsetof( Thread_queue_Syslock_queue, Queue.Lock.next_ticket )
+#else
+  offsetof( Thread_queue_Syslock_queue, reserved[ 0 ] )
+#endif
+    == offsetof( struct _Thread_queue_Queue, _Lock._next_ticket ),
+  THREAD_QUEUE_SYSLOCK_QUEUE_NEXT_TICKET
+);
+
+RTEMS_STATIC_ASSERT(
+#if defined(RTEMS_SMP)
+  offsetof( Thread_queue_Syslock_queue, Queue.Lock.now_serving )
+#else
+  offsetof( Thread_queue_Syslock_queue, reserved[ 1 ] )
+#endif
+    == offsetof( struct _Thread_queue_Queue, _Lock._now_serving ),
+  THREAD_QUEUE_SYSLOCK_QUEUE_NOW_SERVING
+);
+
+RTEMS_STATIC_ASSERT(
+  sizeof( Thread_queue_Syslock_queue )
+    == sizeof( struct _Thread_queue_Queue ),
+  THREAD_QUEUE_SYSLOCK_QUEUE_SIZE
+);
+
+#endif /* HAVE_STRUCT__THREAD_QUEUE_QUEUE */
+
 RBTree_Compare_result _Thread_queue_Compare_priority(
   const RBTree_Node *left,
   const RBTree_Node *right



More information about the vc mailing list