Changeset e50297e in rtems


Ignore:
Timestamp:
Mar 4, 2015, 9:15:02 AM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
76f37656
Parents:
d2ffb7dc
git-author:
Sebastian Huber <sebastian.huber@…> (03/04/15 09:15:02)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/04/15 11:03:04)
Message:

score: ISR lock C/C++ compatiblity issue

Empty structures are implementation-defined in C. GCC gives them a size
of zero. In C++ empty structures have a non-zero size.

Add ISR_LOCK_DEFINE() to define ISR locks for structures used by C and
C++.

Update #2273.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/include/rtems/score/isrlock.h

    rd2ffb7dc re50297e  
    5050/**
    5151 * @brief ISR lock control.
     52 *
     53 * @warning Empty structures are implementation-defined in C.  GCC gives them a
     54 * size of zero.  In C++ empty structures have a non-zero size.
    5255 */
    5356typedef struct {
    5457#if defined( RTEMS_SMP )
    55   SMP_lock_Control lock;
     58  SMP_lock_Control Lock;
    5659#endif
    5760} ISR_lock_Control;
     
    6265typedef struct {
    6366#if defined( RTEMS_SMP )
    64   SMP_lock_Context lock_context;
     67  SMP_lock_Context Lock_context;
    6568#else
    6669  ISR_Level isr_level;
    6770#endif
    6871} ISR_lock_Context;
     72
     73/**
     74 * @brief Defines an ISR lock.
     75 *
     76 * Do not add a ';' after this macro.
     77 *
     78 * @param _designator The designator for the interrupt lock.
     79 */
     80#if defined( RTEMS_SMP )
     81  #define ISR_LOCK_DEFINE( _designator ) ISR_lock_Control _designator;
     82#else
     83  #define ISR_LOCK_DEFINE( _designator )
     84#endif
    6985
    7086/**
     
    7591 */
    7692#if defined( RTEMS_SMP )
    77   #define ISR_LOCK_INITIALIZER( name ) \
    78     { SMP_LOCK_INITIALIZER( name ) }
    79 #else
    80   #define ISR_LOCK_INITIALIZER( name ) \
     93  #define ISR_LOCK_INITIALIZER( _name ) \
     94    { SMP_LOCK_INITIALIZER( _name ) }
     95#else
     96  #define ISR_LOCK_INITIALIZER( _name ) \
    8197    { }
    8298#endif
     
    87103 * Concurrent initialization leads to unpredictable results.
    88104 *
    89  * @param[in,out] lock The ISR lock control.
     105 * @param[in] _lock The ISR lock control.
    90106 * @param[in] _name The name for the ISR lock.  This name must be a
    91107 * string persistent throughout the life time of this lock.  The name is only
    92108 * used if profiling is enabled.
    93109 */
    94 static inline void _ISR_lock_Initialize(
    95   ISR_lock_Control *lock,
    96   const char *name
    97 )
    98 {
    99 #if defined( RTEMS_SMP )
    100   _SMP_lock_Initialize( &lock->lock, name );
    101 #else
    102   (void) lock;
    103   (void) name;
    104 #endif
    105 }
     110#if defined( RTEMS_SMP )
     111  #define _ISR_lock_Initialize( _lock, _name ) \
     112    _SMP_lock_Initialize( &( _lock )->Lock, _name )
     113#else
     114  #define _ISR_lock_Initialize( _lock, _name )
     115#endif
    106116
    107117/**
     
    110120 * Concurrent destruction leads to unpredictable results.
    111121 *
    112  * @param[in,out] lock The ISR lock control.
    113  */
    114 static inline void _ISR_lock_Destroy( ISR_lock_Control *lock )
    115 {
    116 #if defined( RTEMS_SMP )
    117   _SMP_lock_Destroy( &lock->lock );
    118 #else
    119   (void) lock;
    120 #endif
    121 }
     122 * @param[in] _lock The ISR lock control.
     123 */
     124#if defined( RTEMS_SMP )
     125  #define _ISR_lock_Destroy( _lock ) \
     126    _SMP_lock_Destroy( &( _lock )->Lock )
     127#else
     128  #define _ISR_lock_Destroy( _lock )
     129#endif
    122130
    123131/**
     
    129137 * This function can be used in thread and interrupt context.
    130138 *
    131  * @param[in,out] lock The ISR lock control.
    132  * @param[in,out] context The local ISR lock context for an acquire and release
     139 * @param[in] _lock The ISR lock control.
     140 * @param[in] context The local ISR lock context for an acquire and release
    133141 * pair.
    134142 *
    135143 * @see _ISR_lock_Release_and_ISR_enable().
    136144 */
    137 static inline void _ISR_lock_ISR_disable_and_acquire(
    138   ISR_lock_Control *lock,
    139   ISR_lock_Context *context
    140 )
    141 {
    142 #if defined( RTEMS_SMP )
    143   _SMP_lock_ISR_disable_and_acquire( &lock->lock, &context->lock_context );
    144 #else
    145   (void) lock;
    146   _ISR_Disable( context->isr_level );
    147 #endif
    148 }
     145#if defined( RTEMS_SMP )
     146  #define _ISR_lock_ISR_disable_and_acquire( _lock, _context ) \
     147    _SMP_lock_ISR_disable_and_acquire( \
     148      &( _lock )->Lock, \
     149      &( _context )->Lock_context \
     150    )
     151#else
     152  #define _ISR_lock_ISR_disable_and_acquire( _lock, _context ) \
     153    _ISR_Disable( ( _context )->isr_level )
     154#endif
    149155
    150156/**
     
    156162 * This function can be used in thread and interrupt context.
    157163 *
    158  * @param[in,out] lock The ISR lock control.
    159  * @param[in,out] context The local ISR lock context for an acquire and release
     164 * @param[in] _lock The ISR lock control.
     165 * @param[in] _context The local ISR lock context for an acquire and release
    160166 * pair.
    161167 *
    162168 * @see _ISR_lock_ISR_disable_and_acquire().
    163169 */
    164 static inline void _ISR_lock_Release_and_ISR_enable(
    165   ISR_lock_Control *lock,
    166   ISR_lock_Context *context
    167 )
    168 {
    169 #if defined( RTEMS_SMP )
    170   _SMP_lock_Release_and_ISR_enable( &lock->lock, &context->lock_context );
    171 #else
    172   (void) lock;
    173   _ISR_Enable( context->isr_level );
    174 #endif
    175 }
     170#if defined( RTEMS_SMP )
     171  #define _ISR_lock_Release_and_ISR_enable( _lock, _context ) \
     172    _SMP_lock_Release_and_ISR_enable( \
     173      &( _lock )->Lock, \
     174      &( _context )->Lock_context \
     175    )
     176#else
     177  #define _ISR_lock_Release_and_ISR_enable( _lock, _context ) \
     178    _ISR_Enable( ( _context )->isr_level )
     179#endif
    176180
    177181/**
     
    185189 * lock, then the result is unpredictable.
    186190 *
    187  * @param[in,out] lock The ISR lock control.
    188  * @param[in,out] context The local ISR lock context for an acquire and release
     191 * @param[in] _lock The ISR lock control.
     192 * @param[in] _context The local ISR lock context for an acquire and release
    189193 * pair.
    190194 *
    191195 * @see _ISR_lock_Release().
    192196 */
    193 static inline void _ISR_lock_Acquire(
    194   ISR_lock_Control *lock,
    195   ISR_lock_Context *context
    196 )
    197 {
    198 #if defined( RTEMS_SMP )
    199   _SMP_lock_Acquire( &lock->lock, &context->lock_context );
    200 #else
    201   (void) lock;
    202   (void) context;
    203 #endif
    204 }
     197#if defined( RTEMS_SMP )
     198  #define _ISR_lock_Acquire( _lock, _context ) \
     199    _SMP_lock_Acquire( \
     200      &( _lock )->Lock, \
     201      &( _context )->Lock_context \
     202    )
     203#else
     204  #define _ISR_lock_Acquire( _lock, _context )
     205#endif
    205206
    206207/**
     
    210211 * function releases an SMP lock.
    211212 *
    212  * @param[in,out] lock The ISR lock control.
    213  * @param[in,out] context The local ISR lock context for an acquire and release
     213 * @param[in] _lock The ISR lock control.
     214 * @param[in] _context The local ISR lock context for an acquire and release
    214215 * pair.
    215216 *
    216217 * @see _ISR_lock_Acquire().
    217218 */
    218 static inline void _ISR_lock_Release(
    219   ISR_lock_Control *lock,
    220   ISR_lock_Context *context
    221 )
    222 {
    223 #if defined( RTEMS_SMP )
    224   _SMP_lock_Release( &lock->lock, &context->lock_context );
    225 #else
    226   (void) lock;
    227   (void) context;
    228 #endif
    229 }
     219#if defined( RTEMS_SMP )
     220  #define _ISR_lock_Release( _lock, _context ) \
     221    _SMP_lock_Release( \
     222      &( _lock )->Lock, \
     223      &( _context )->Lock_context \
     224    )
     225#else
     226  #define _ISR_lock_Release( _lock, _context )
     227#endif
    230228
    231229/** @} */
  • testsuites/sptests/sp37/init.c

    rd2ffb7dc re50297e  
    162162#if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
    163163static const size_t lock_size =
    164   offsetof( ISR_lock_Control, lock.ticket_lock.Stats.name )
    165     + sizeof( ((ISR_lock_Control *) 0)->lock.ticket_lock.Stats.name );
     164  offsetof( ISR_lock_Control, Lock.ticket_lock.Stats.name )
     165    + sizeof( ((ISR_lock_Control *) 0)->Lock.ticket_lock.Stats.name );
    166166#else
    167167static const size_t lock_size = sizeof( ISR_lock_Control );
Note: See TracChangeset for help on using the changeset viewer.