summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include/rtems/score/isrlock.h
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-03-10 08:25:32 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-03-11 10:58:09 +0100
commitd50acdbb6c8213114ce887a56daea02697c9e1a1 (patch)
treee48fb252786992308fa2dd6337c8a02db35bd10b /cpukit/score/include/rtems/score/isrlock.h
parentsapi: Use one SMP lock for all chains (diff)
downloadrtems-d50acdbb6c8213114ce887a56daea02697c9e1a1.tar.bz2
score: Add local context to SMP lock API
Add a local context structure to the SMP lock API for acquire and release pairs. This context can be used to store the ISR level and profiling information. It may be later used to enable more sophisticated lock algorithms, e.g. MCS locks. There is only one lock that cannot be used with a local context. This is the per-CPU lock since here we would have to transfer the local context through a context switch which is very complicated.
Diffstat (limited to '')
-rw-r--r--cpukit/score/include/rtems/score/isrlock.h110
1 files changed, 68 insertions, 42 deletions
diff --git a/cpukit/score/include/rtems/score/isrlock.h b/cpukit/score/include/rtems/score/isrlock.h
index 56ff19b803..e118475968 100644
--- a/cpukit/score/include/rtems/score/isrlock.h
+++ b/cpukit/score/include/rtems/score/isrlock.h
@@ -51,12 +51,23 @@ extern "C" {
* @brief ISR lock control.
*/
typedef struct {
- #if defined( RTEMS_SMP )
- SMP_lock_Control lock;
- #endif
+#if defined( RTEMS_SMP )
+ SMP_lock_Control lock;
+#endif
} ISR_lock_Control;
/**
+ * @brief Local ISR lock context for acquire and release pairs.
+ */
+typedef struct {
+#if defined( RTEMS_SMP )
+ SMP_lock_Context lock_context;
+#else
+ ISR_Level isr_level;
+#endif
+} ISR_lock_Context;
+
+/**
* @brief Initializer for static initialization of ISR locks.
*/
#if defined( RTEMS_SMP )
@@ -72,17 +83,16 @@ typedef struct {
*
* Concurrent initialization leads to unpredictable results.
*
- * @param[in,out] _lock The ISR lock control.
+ * @param[in,out] lock The ISR lock control.
*/
+static inline void _ISR_lock_Initialize( ISR_lock_Control *lock )
+{
#if defined( RTEMS_SMP )
- #define _ISR_lock_Initialize( _lock ) \
- _SMP_lock_Initialize( &( _lock )->lock )
+ _SMP_lock_Initialize( &lock->lock );
#else
- #define _ISR_lock_Initialize( _lock ) \
- do { \
- (void) _lock; \
- } while (0)
+ (void) lock;
#endif
+}
/**
* @brief Acquires an ISR lock.
@@ -92,21 +102,24 @@ typedef struct {
*
* This function can be used in thread and interrupt context.
*
- * @param[in,out] _lock The ISR lock control.
- * @param[out] _isr_cookie The interrupt status to restore will be returned.
+ * @param[in,out] lock The ISR lock control.
+ * @param[in,out] context The local ISR lock context for an acquire and release
+ * pair.
*
* @see _ISR_lock_Release_and_ISR_enable().
*/
+static inline void _ISR_lock_ISR_disable_and_acquire(
+ ISR_lock_Control *lock,
+ ISR_lock_Context *context
+)
+{
#if defined( RTEMS_SMP )
- #define _ISR_lock_ISR_disable_and_acquire( _lock, _isr_cookie ) \
- _SMP_lock_ISR_disable_and_acquire( &( _lock )->lock, _isr_cookie )
+ _SMP_lock_ISR_disable_and_acquire( &lock->lock, &context->lock_context );
#else
- #define _ISR_lock_ISR_disable_and_acquire( _lock, _isr_cookie ) \
- do { \
- (void) _lock; \
- _ISR_Disable( _isr_cookie ); \
- } while (0)
+ (void) lock;
+ _ISR_Disable( context->isr_level );
#endif
+}
/**
* @brief Releases an ISR lock.
@@ -116,21 +129,24 @@ typedef struct {
*
* This function can be used in thread and interrupt context.
*
- * @param[in,out] _lock The ISR lock control.
- * @param[in] _isr_cookie The interrupt status to restore.
+ * @param[in,out] lock The ISR lock control.
+ * @param[in,out] context The local ISR lock context for an acquire and release
+ * pair.
*
* @see _ISR_lock_ISR_disable_and_acquire().
*/
+static inline void _ISR_lock_Release_and_ISR_enable(
+ ISR_lock_Control *lock,
+ ISR_lock_Context *context
+)
+{
#if defined( RTEMS_SMP )
- #define _ISR_lock_Release_and_ISR_enable( _lock, _isr_cookie ) \
- _SMP_lock_Release_and_ISR_enable( &( _lock )->lock, _isr_cookie )
+ _SMP_lock_Release_and_ISR_enable( &lock->lock, &context->lock_context );
#else
- #define _ISR_lock_Release_and_ISR_enable( _lock, _isr_cookie ) \
- do { \
- (void) _lock; \
- _ISR_Enable( _isr_cookie ); \
- } while (0)
+ (void) lock;
+ _ISR_Enable( context->isr_level );
#endif
+}
/**
* @brief Acquires an ISR lock inside an ISR disabled section.
@@ -142,19 +158,24 @@ typedef struct {
* interrupts and these interrupts enter the critical section protected by this
* lock, then the result is unpredictable.
*
- * @param[in,out] _lock The ISR lock control.
+ * @param[in,out] lock The ISR lock control.
+ * @param[in,out] context The local ISR lock context for an acquire and release
+ * pair.
*
* @see _ISR_lock_Release().
*/
+static inline void _ISR_lock_Acquire(
+ ISR_lock_Control *lock,
+ ISR_lock_Context *context
+)
+{
#if defined( RTEMS_SMP )
- #define _ISR_lock_Acquire( _lock ) \
- _SMP_lock_Acquire( &( _lock )->lock )
+ _SMP_lock_Acquire( &lock->lock, &context->lock_context );
#else
- #define _ISR_lock_Acquire( _lock ) \
- do { \
- (void) _lock; \
- } while (0)
+ (void) lock;
+ (void) context;
#endif
+}
/**
* @brief Releases an ISR lock inside an ISR disabled section.
@@ -162,19 +183,24 @@ typedef struct {
* The interrupt status will remain unchanged. On SMP configurations this
* function releases an SMP lock.
*
- * @param[in,out] _lock The ISR lock control.
+ * @param[in,out] lock The ISR lock control.
+ * @param[in,out] context The local ISR lock context for an acquire and release
+ * pair.
*
* @see _ISR_lock_Acquire().
*/
+static inline void _ISR_lock_Release(
+ ISR_lock_Control *lock,
+ ISR_lock_Context *context
+)
+{
#if defined( RTEMS_SMP )
- #define _ISR_lock_Release( _lock ) \
- _SMP_lock_Release( &( _lock )->lock )
+ _SMP_lock_Release( &lock->lock, &context->lock_context );
#else
- #define _ISR_lock_Release( _lock ) \
- do { \
- (void) _lock; \
- } while (0)
+ (void) lock;
+ (void) context;
#endif
+}
/** @} */