[rtems commit] score: Fix legacy RTEMS_STATIC_ASSERT()

Sebastian Huber sebh at rtems.org
Mon Oct 8 05:15:46 UTC 2018


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Oct  5 08:11:09 2018 +0200

score: Fix legacy RTEMS_STATIC_ASSERT()

In standard C pointer operands are not allowed in integer constant
expressions.  Avoid a static assertion based on an array typedef since
this could lead to warnings ("variably modified 'x' at file scope" and
"typedef 'x' locally defined but not used");

This implementation requires unique messages.

---

 cpukit/include/rtems/score/basedefs.h    |  3 ++-
 cpukit/include/rtems/score/threadqimpl.h |  4 ++--
 cpukit/posix/src/mqueuerecvsupp.c        |  3 ++-
 cpukit/posix/src/mutexinit.c             |  2 +-
 cpukit/rtems/src/barrierwait.c           |  6 +++++-
 cpukit/rtems/src/msgqreceive.c           |  6 +++++-
 cpukit/rtems/src/semobtain.c             | 12 ++++++++----
 7 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/cpukit/include/rtems/score/basedefs.h b/cpukit/include/rtems/score/basedefs.h
index fd803e1..0a2bf8d 100644
--- a/cpukit/include/rtems/score/basedefs.h
+++ b/cpukit/include/rtems/score/basedefs.h
@@ -317,7 +317,8 @@
     _Static_assert(cond, # msg)
 #else
   #define RTEMS_STATIC_ASSERT(cond, msg) \
-    typedef int rtems_static_assert_ ## msg [(cond) ? 1 : -1]
+    struct rtems_static_assert_ ## msg \
+      { int rtems_static_assert_ ## msg : (cond) ? 1 : -1; }
 #endif
 
 #define RTEMS_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
diff --git a/cpukit/include/rtems/score/threadqimpl.h b/cpukit/include/rtems/score/threadqimpl.h
index ecbd8fd..8d537cc 100644
--- a/cpukit/include/rtems/score/threadqimpl.h
+++ b/cpukit/include/rtems/score/threadqimpl.h
@@ -1207,7 +1207,7 @@ typedef struct {
   Thread_queue_Control Wait_queue;
 } Thread_queue_Object;
 
-#define THREAD_QUEUE_OBJECT_ASSERT( object_type, wait_queue_member ) \
+#define THREAD_QUEUE_OBJECT_ASSERT( object_type, wait_queue_member, msg ) \
   RTEMS_STATIC_ASSERT( \
     offsetof( object_type, wait_queue_member ) \
       == offsetof( Thread_queue_Object, Wait_queue ) \
@@ -1217,7 +1217,7 @@ typedef struct {
       Thread_queue_Object, \
       Wait_queue \
     ), \
-    object_type \
+    msg \
   )
 
 #define THREAD_QUEUE_QUEUE_TO_OBJECT( queue ) \
diff --git a/cpukit/posix/src/mqueuerecvsupp.c b/cpukit/posix/src/mqueuerecvsupp.c
index c6d1805..062bd50 100644
--- a/cpukit/posix/src/mqueuerecvsupp.c
+++ b/cpukit/posix/src/mqueuerecvsupp.c
@@ -25,7 +25,8 @@
 
 THREAD_QUEUE_OBJECT_ASSERT(
   POSIX_Message_queue_Control,
-  Message_queue.Wait_queue
+  Message_queue.Wait_queue,
+  POSIX_MESSAGE_QUEUE_CONTROL
 );
 
 /*
diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c
index 2d3857d..45688ee 100644
--- a/cpukit/posix/src/mutexinit.c
+++ b/cpukit/posix/src/mutexinit.c
@@ -40,7 +40,7 @@ RTEMS_STATIC_ASSERT(
 RTEMS_STATIC_ASSERT(
   offsetof( POSIX_Mutex_Control, Priority_ceiling )
     == offsetof( pthread_mutex_t, _Priority_ceiling ),
-  POSIX_MUTEX_CONTROL_SCHEDULER
+  POSIX_MUTEX_CONTROL_PRIORITY_CEILING
 );
 
 RTEMS_STATIC_ASSERT(
diff --git a/cpukit/rtems/src/barrierwait.c b/cpukit/rtems/src/barrierwait.c
index 4811c21..f30f152 100644
--- a/cpukit/rtems/src/barrierwait.c
+++ b/cpukit/rtems/src/barrierwait.c
@@ -21,7 +21,11 @@
 #include <rtems/rtems/barrierimpl.h>
 #include <rtems/rtems/statusimpl.h>
 
-THREAD_QUEUE_OBJECT_ASSERT( Barrier_Control, Barrier.Wait_queue );
+THREAD_QUEUE_OBJECT_ASSERT(
+  Barrier_Control,
+  Barrier.Wait_queue,
+  BARRIER_CONTROL
+);
 
 rtems_status_code rtems_barrier_wait(
   rtems_id        id,
diff --git a/cpukit/rtems/src/msgqreceive.c b/cpukit/rtems/src/msgqreceive.c
index 2304be7..606454d 100644
--- a/cpukit/rtems/src/msgqreceive.c
+++ b/cpukit/rtems/src/msgqreceive.c
@@ -22,7 +22,11 @@
 #include <rtems/rtems/optionsimpl.h>
 #include <rtems/rtems/statusimpl.h>
 
-THREAD_QUEUE_OBJECT_ASSERT( Message_queue_Control, message_queue.Wait_queue );
+THREAD_QUEUE_OBJECT_ASSERT(
+  Message_queue_Control,
+  message_queue.Wait_queue,
+  MESSAGE_QUEUE_CONTROL
+);
 
 rtems_status_code rtems_message_queue_receive(
   rtems_id        id,
diff --git a/cpukit/rtems/src/semobtain.c b/cpukit/rtems/src/semobtain.c
index db0c3f2..2f73166 100644
--- a/cpukit/rtems/src/semobtain.c
+++ b/cpukit/rtems/src/semobtain.c
@@ -24,23 +24,27 @@
 
 THREAD_QUEUE_OBJECT_ASSERT(
   Semaphore_Control,
-  Core_control.Wait_queue
+  Core_control.Wait_queue,
+  SEMAPHORE_CONTROL_GENERIC
 );
 
 THREAD_QUEUE_OBJECT_ASSERT(
   Semaphore_Control,
-  Core_control.Mutex.Recursive.Mutex.Wait_queue
+  Core_control.Mutex.Recursive.Mutex.Wait_queue,
+  SEMAPHORE_CONTROL_MUTEX
 );
 
 THREAD_QUEUE_OBJECT_ASSERT(
   Semaphore_Control,
-  Core_control.Semaphore.Wait_queue
+  Core_control.Semaphore.Wait_queue,
+  SEMAPHORE_CONTROL_SEMAPHORE
 );
 
 #if defined(RTEMS_SMP)
 THREAD_QUEUE_OBJECT_ASSERT(
   Semaphore_Control,
-  Core_control.MRSP.Wait_queue
+  Core_control.MRSP.Wait_queue,
+  SEMAPHORE_CONTROL_MRSP
 );
 #endif
 



More information about the vc mailing list