[PATCH] score: Add function to destroy SMP locks
Sebastian Huber
sebastian.huber at embedded-brains.de
Fri Mar 7 12:01:32 UTC 2014
This makes it necessary to add a function to destroy RTEMS chains:
rtems_chain_destroy(). This function complicates the RTEMS chains API.
---
cpukit/libcsupport/src/termios.c | 1 +
cpukit/rtems/include/rtems/rtems/intr.h | 10 ++++++++++
cpukit/sapi/include/rtems/chain.h | 16 ++++++++++++++++
cpukit/score/include/rtems/score/isrlock.h | 16 ++++++++++++++++
cpukit/score/include/rtems/score/smplock.h | 16 ++++++++++++++--
testsuites/libtests/block06/init.c | 10 ++++++++++
testsuites/sptests/sp37/init.c | 4 ++++
testsuites/sptests/spchain/init.c | 20 ++++++++++++++++++++
8 files changed, 91 insertions(+), 2 deletions(-)
diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c
index ea0e87a..65072a0 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/sapi/include/rtems/chain.h b/cpukit/sapi/include/rtems/chain.h
index 0927055..f423e6d 100644
--- a/cpukit/sapi/include/rtems/chain.h
+++ b/cpukit/sapi/include/rtems/chain.h
@@ -179,6 +179,22 @@ RTEMS_INLINE_ROUTINE void rtems_chain_initialize_empty(
}
/**
+ * @brief Destroys the chain.
+ *
+ * This routine destroys the specified chain. This routine is only necessary
+ * in SMP configurations if the protected functions are used and profiling is
+ * enabled.
+ *
+ * @param[in] the_chain is the chain to be destroyed.
+ */
+RTEMS_INLINE_ROUTINE void rtems_chain_destroy(
+ rtems_chain_control *the_chain
+)
+{
+ _ISR_lock_Destroy( &the_chain->Lock );
+}
+
+/**
* @brief Set off chain.
*
* This function sets the next and previous fields of the @a node to NULL
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..cc94e2e 100644
--- a/cpukit/score/include/rtems/score/smplock.h
+++ b/cpukit/score/include/rtems/score/smplock.h
@@ -131,11 +131,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 +143,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 )
+{
+ (void) lock;
+}
+
+/**
* @brief Acquires an SMP lock.
*
* This function will not disable interrupts. The caller must ensure that the
diff --git a/testsuites/libtests/block06/init.c b/testsuites/libtests/block06/init.c
index e51bf27..59dd188 100644
--- a/testsuites/libtests/block06/init.c
+++ b/testsuites/libtests/block06/init.c
@@ -786,6 +786,8 @@ bdbuf_tests_task_0_test_2 (bdbuf_task_control* tc)
tc->passed = passed;
tc->test = 0;
+
+ rtems_chain_destroy (&buffers);
}
/**
@@ -964,6 +966,8 @@ bdbuf_tests_task_0_test_4 (bdbuf_task_control* tc)
tc->passed = passed;
tc->test = 0;
+
+ rtems_chain_destroy (&buffers);
}
static void
@@ -1027,6 +1031,8 @@ bdbuf_tests_task_0_test_6 (bdbuf_task_control* tc)
tc->passed = passed;
tc->test = 0;
+
+ rtems_chain_destroy (&buffers);
}
static void
@@ -1085,6 +1091,8 @@ bdbuf_tests_task_0_test_7 (bdbuf_task_control* tc)
tc->passed = passed;
tc->test = 0;
+
+ rtems_chain_destroy (&buffers);
}
static void
@@ -1172,6 +1180,8 @@ bdbuf_tests_task_0_test_8 (bdbuf_task_control* tc)
tc->passed = passed;
tc->test = 0;
+
+ rtems_chain_destroy (&buffers);
}
static void
diff --git a/testsuites/sptests/sp37/init.c b/testsuites/sptests/sp37/init.c
index cd49ae2..e321a78 100644
--- a/testsuites/sptests/sp37/init.c
+++ b/testsuites/sptests/sp37/init.c
@@ -178,6 +178,8 @@ 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 );
}
static rtems_mode get_interrupt_level( void )
@@ -212,6 +214,8 @@ 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 );
}
void test_interrupt_inline(void)
diff --git a/testsuites/sptests/spchain/init.c b/testsuites/sptests/spchain/init.c
index 747f404..3a355ad 100644
--- a/testsuites/sptests/spchain/init.c
+++ b/testsuites/sptests/spchain/init.c
@@ -56,6 +56,8 @@ static void test_chain_control_initializer(void)
rtems_chain_immutable_tail( &one_node_chain )
== rtems_chain_immutable_next( &node_of_one_node_chain )
);
+
+ rtems_chain_destroy( &chain );
}
static void test_chain_control_layout(void)
@@ -96,6 +98,8 @@ static void test_chain_get_with_wait(void)
sc = rtems_chain_get_with_wait( &chain, EVENT, TIMEOUT, &p );
rtems_test_assert( sc == RTEMS_TIMEOUT );
rtems_test_assert( p == NULL );
+
+ rtems_chain_destroy( &chain );
}
static void test_chain_first_and_last(void)
@@ -115,6 +119,8 @@ static void test_chain_first_and_last(void)
puts( "INIT - Verify rtems_chain_is_last" );
cnode = rtems_chain_last(&chain);
rtems_test_assert( rtems_chain_is_last( cnode ) );
+
+ rtems_chain_destroy( &chain );
}
static void test_chain_with_notification(void)
@@ -151,6 +157,8 @@ static void test_chain_with_notification(void)
rtems_test_assert( sc == RTEMS_SUCCESSFUL );
rtems_test_assert( p == &a );
+ rtems_chain_destroy( &chain );
+
puts( "INIT - Verify rtems_chain_prepend_with_notification" );
rtems_chain_initialize_empty( &chain );
sc = rtems_chain_prepend_with_notification(
@@ -174,6 +182,8 @@ static void test_chain_with_notification(void)
rtems_test_assert( sc == RTEMS_SUCCESSFUL );
rtems_test_assert( p == &a );
+ rtems_chain_destroy( &chain );
+
puts( "INIT - Verify rtems_chain_get_with_notification" );
rtems_chain_initialize_empty( &chain );
@@ -195,6 +205,8 @@ static void test_chain_with_notification(void)
);
rtems_test_assert( sc == RTEMS_SUCCESSFUL );
rtems_test_assert( out == EVENT );
+
+ rtems_chain_destroy( &chain );
}
static void test_chain_with_empty_check(void)
@@ -211,6 +223,7 @@ static void test_chain_with_empty_check(void)
rtems_test_assert( empty );
empty = rtems_chain_append_with_empty_check( &chain, &a );
rtems_test_assert( !empty );
+ rtems_chain_destroy( &chain );
puts( "INIT - Verify rtems_chain_prepend_with_empty_check" );
rtems_chain_initialize_empty( &chain );
@@ -220,6 +233,7 @@ static void test_chain_with_empty_check(void)
rtems_test_assert( !empty );
empty = rtems_chain_prepend_with_empty_check( &chain, &b );
rtems_test_assert( !empty );
+ rtems_chain_destroy( &chain );
puts( "INIT - Verify rtems_chain_get_with_empty_check" );
rtems_chain_initialize_empty( &chain );
@@ -234,6 +248,8 @@ static void test_chain_with_empty_check(void)
empty = rtems_chain_get_with_empty_check( &chain, &p );
rtems_test_assert( empty );
rtems_test_assert( p == &b );
+
+ rtems_chain_destroy( &chain );
}
static void test_chain_node_count(void)
@@ -254,6 +270,8 @@ static void test_chain_node_count(void)
count = rtems_chain_node_count_unprotected( &chain );
rtems_test_assert( count == i + 1 );
}
+
+ rtems_chain_destroy( &chain );
}
static bool test_order( const Chain_Node *left, const Chain_Node *right )
@@ -324,6 +342,8 @@ rtems_task Init(
}
}
+ rtems_chain_destroy( &chain1 );
+
test_chain_first_and_last();
test_chain_with_empty_check();
test_chain_with_notification();
--
1.7.7
More information about the devel
mailing list