[rtems commit] score: Add function to destroy SMP locks
Sebastian Huber
sebh at rtems.org
Tue Mar 11 09:57:00 UTC 2014
Module: rtems
Branch: master
Commit: 28779c70ffebbb2006eb7df01d64180859bb324e
Changeset: http://git.rtems.org/rtems/commit/?id=28779c70ffebbb2006eb7df01d64180859bb324e
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Fri Mar 7 12:53:41 2014 +0100
score: Add function to destroy SMP locks
---
cpukit/libcsupport/src/termios.c | 1 +
cpukit/rtems/include/rtems/rtems/intr.h | 10 ++++++++
cpukit/score/include/rtems/score/isrlock.h | 16 ++++++++++++++
cpukit/score/include/rtems/score/smplock.h | 32 ++++++++++++++++++++++++---
testsuites/smptests/smplock01/init.c | 12 ++++++++-
testsuites/sptests/sp37/init.c | 6 +++++
testsuites/sptests/spcache01/init.c | 3 ++
testsuites/sptests/spnsext01/init.c | 1 +
testsuites/tmtests/tmcontext01/init.c | 4 ++-
9 files changed, 78 insertions(+), 7 deletions(-)
diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c
index 6c88de6..4022e7c 100644
--- a/cpukit/libcsupport/src/termios.c
+++ b/cpukit/libcsupport/src/termios.c
@@ -445,6 +445,7 @@ rtems_termios_close (void *arg)
if ((tty->device.pollRead == NULL) ||
(tty->device.outputUsesInterrupts == TERMIOS_TASK_DRIVEN))
rtems_semaphore_delete (tty->rawInBuf.Semaphore);
+ rtems_interrupt_lock_destroy (&tty->interrupt_lock);
free (tty->rawInBuf.theBuf);
free (tty->rawOutBuf.theBuf);
free (tty->cbuf);
diff --git a/cpukit/rtems/include/rtems/rtems/intr.h b/cpukit/rtems/include/rtems/rtems/intr.h
index 62d2dad..04bcb72 100644
--- a/cpukit/rtems/include/rtems/rtems/intr.h
+++ b/cpukit/rtems/include/rtems/rtems/intr.h
@@ -180,6 +180,16 @@ typedef ISR_lock_Context rtems_interrupt_lock_context;
_ISR_lock_Initialize( _lock )
/**
+ * @brief Destroys an interrupt lock.
+ *
+ * Concurrent destruction leads to unpredictable results.
+ *
+ * @param[in,out] _lock The interrupt lock control.
+ */
+#define rtems_interrupt_lock_destroy( _lock ) \
+ _ISR_lock_Destroy( _lock )
+
+/**
* @brief Acquires an interrupt lock.
*
* Interrupts will be disabled. On SMP configurations this function acquires
diff --git a/cpukit/score/include/rtems/score/isrlock.h b/cpukit/score/include/rtems/score/isrlock.h
index e118475..27e4aad 100644
--- a/cpukit/score/include/rtems/score/isrlock.h
+++ b/cpukit/score/include/rtems/score/isrlock.h
@@ -95,6 +95,22 @@ static inline void _ISR_lock_Initialize( ISR_lock_Control *lock )
}
/**
+ * @brief Destroys an ISR lock.
+ *
+ * Concurrent destruction leads to unpredictable results.
+ *
+ * @param[in,out] lock The ISR lock control.
+ */
+static inline void _ISR_lock_Destroy( ISR_lock_Control *lock )
+{
+#if defined( RTEMS_SMP )
+ _SMP_lock_Destroy( &lock->lock );
+#else
+ (void) lock;
+#endif
+}
+
+/**
* @brief Acquires an ISR lock.
*
* Interrupts will be disabled. On SMP configurations this function acquires
diff --git a/cpukit/score/include/rtems/score/smplock.h b/cpukit/score/include/rtems/score/smplock.h
index 101aa0a..288fd45 100644
--- a/cpukit/score/include/rtems/score/smplock.h
+++ b/cpukit/score/include/rtems/score/smplock.h
@@ -64,11 +64,11 @@ typedef struct {
{ ATOMIC_INITIALIZER_UINT( 0U ), ATOMIC_INITIALIZER_UINT( 0U ) }
/**
- * @brief Initializes an SMP ticket lock control.
+ * @brief Initializes an SMP ticket lock.
*
* Concurrent initialization leads to unpredictable results.
*
- * @param[out] lock The SMP ticket lock control.
+ * @param[in,out] lock The SMP ticket lock control.
*/
static inline void _SMP_ticket_lock_Initialize( SMP_ticket_lock_Control *lock )
{
@@ -77,6 +77,18 @@ static inline void _SMP_ticket_lock_Initialize( SMP_ticket_lock_Control *lock )
}
/**
+ * @brief Destroys an SMP ticket lock.
+ *
+ * Concurrent destruction leads to unpredictable results.
+ *
+ * @param[in,out] lock The SMP ticket lock control.
+ */
+static inline void _SMP_ticket_lock_Destroy( SMP_ticket_lock_Control *lock )
+{
+ (void) lock;
+}
+
+/**
* @brief Acquires an SMP ticket lock.
*
* This function will not disable interrupts. The caller must ensure that the
@@ -131,11 +143,11 @@ typedef struct {
#define SMP_LOCK_INITIALIZER { SMP_TICKET_LOCK_INITIALIZER }
/**
- * @brief Initializes an SMP lock control.
+ * @brief Initializes an SMP lock.
*
* Concurrent initialization leads to unpredictable results.
*
- * @param[out] lock The SMP lock control.
+ * @param[in,out] lock The SMP lock control.
*/
static inline void _SMP_lock_Initialize( SMP_lock_Control *lock )
{
@@ -143,6 +155,18 @@ static inline void _SMP_lock_Initialize( SMP_lock_Control *lock )
}
/**
+ * @brief Destroys an SMP lock.
+ *
+ * Concurrent destruction leads to unpredictable results.
+ *
+ * @param[in,out] lock The SMP lock control.
+ */
+static inline void _SMP_lock_Destroy( SMP_lock_Control *lock )
+{
+ _SMP_ticket_lock_Destroy( &lock->ticket_lock );
+}
+
+/**
* @brief Acquires an SMP lock.
*
* This function will not disable interrupts. The caller must ensure that the
diff --git a/testsuites/smptests/smplock01/init.c b/testsuites/smptests/smplock01/init.c
index d67d7bc..7c536c3 100644
--- a/testsuites/smptests/smplock01/init.c
+++ b/testsuites/smptests/smplock01/init.c
@@ -138,15 +138,19 @@ static void test_2_body(
)
{
unsigned long counter = 0;
- SMP_lock_Control lock = SMP_LOCK_INITIALIZER;
+ SMP_lock_Control lock;
SMP_lock_Context lock_context;
+ _SMP_lock_Initialize(&lock);
+
while (assert_state(ctx, START_TEST)) {
_SMP_lock_Acquire(&lock, &lock_context);
_SMP_lock_Release(&lock, &lock_context);
++counter;
}
+ _SMP_lock_Destroy(&lock);
+
ctx->test_counter[test][cpu_self] = counter;
}
@@ -159,9 +163,11 @@ static void test_3_body(
)
{
unsigned long counter = 0;
- SMP_lock_Control lock = SMP_LOCK_INITIALIZER;
+ SMP_lock_Control lock;
SMP_lock_Context lock_context;
+ _SMP_lock_Initialize(&lock);
+
while (assert_state(ctx, START_TEST)) {
_SMP_lock_Acquire(&lock, &lock_context);
@@ -172,6 +178,8 @@ static void test_3_body(
++counter;
}
+ _SMP_lock_Destroy(&lock);
+
ctx->test_counter[test][cpu_self] = counter;
}
diff --git a/testsuites/sptests/sp37/init.c b/testsuites/sptests/sp37/init.c
index cd49ae2..4a3e08c 100644
--- a/testsuites/sptests/sp37/init.c
+++ b/testsuites/sptests/sp37/init.c
@@ -178,6 +178,9 @@ static void test_isr_locks( void )
_ISR_lock_Release( &lock, &lock_context );
rtems_test_assert( normal_interrupt_level == _ISR_Get_level() );
+
+ _ISR_lock_Destroy( &lock );
+ _ISR_lock_Destroy( &initialized );
}
static rtems_mode get_interrupt_level( void )
@@ -212,6 +215,9 @@ static void test_interrupt_locks( void )
rtems_interrupt_lock_release_isr( &lock, &lock_context );
rtems_test_assert( normal_interrupt_level == get_interrupt_level() );
+
+ rtems_interrupt_lock_destroy( &lock );
+ rtems_interrupt_lock_destroy( &initialized );
}
void test_interrupt_inline(void)
diff --git a/testsuites/sptests/spcache01/init.c b/testsuites/sptests/spcache01/init.c
index faccbd4..4c0c3c3 100644
--- a/testsuites/sptests/spcache01/init.c
+++ b/testsuites/sptests/spcache01/init.c
@@ -90,6 +90,7 @@ static void test_data_flush_and_invalidate(void)
}
rtems_interrupt_lock_release(&lock, &lock_context);
+ rtems_interrupt_lock_destroy(&lock);
printf(
"data cache operations by line passed the test (%s cache detected)\n",
@@ -364,6 +365,8 @@ static void test_timing(void)
d[1],
d[2]
);
+
+ rtems_interrupt_lock_destroy(&lock);
}
static void Init(rtems_task_argument arg)
diff --git a/testsuites/sptests/spnsext01/init.c b/testsuites/sptests/spnsext01/init.c
index 788ba0b..b445679 100644
--- a/testsuites/sptests/spnsext01/init.c
+++ b/testsuites/sptests/spnsext01/init.c
@@ -65,6 +65,7 @@ static rtems_task Init(rtems_task_argument argument)
uptime = new_uptime;
}
rtems_interrupt_lock_release(&lock, &lock_context);
+ rtems_interrupt_lock_destroy(&lock);
puts("*** END OF TEST NANO SECONDS EXTENSION 1 ***");
diff --git a/testsuites/tmtests/tmcontext01/init.c b/testsuites/tmtests/tmcontext01/init.c
index 130952b..bd047a2 100644
--- a/testsuites/tmtests/tmcontext01/init.c
+++ b/testsuites/tmtests/tmcontext01/init.c
@@ -129,7 +129,7 @@ static void sort_t(void)
static void test_by_function_level(int fl, bool dirty)
{
- rtems_interrupt_lock lock = RTEMS_INTERRUPT_LOCK_INITIALIZER;
+ rtems_interrupt_lock lock;
rtems_interrupt_lock_context lock_context;
int s;
uint64_t min;
@@ -138,6 +138,7 @@ static void test_by_function_level(int fl, bool dirty)
uint64_t q3;
uint64_t max;
+ rtems_interrupt_lock_initialize(&lock);
rtems_interrupt_lock_acquire(&lock, &lock_context);
for (s = 0; s < SAMPLES; ++s) {
@@ -145,6 +146,7 @@ static void test_by_function_level(int fl, bool dirty)
}
rtems_interrupt_lock_release(&lock, &lock_context);
+ rtems_interrupt_lock_destroy(&lock);
sort_t();
More information about the vc
mailing list