[rtems commit] record: Add variants for critical sections

Sebastian Huber sebh at rtems.org
Wed Aug 28 14:02:49 UTC 2019


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Aug 28 14:28:14 2019 +0200

record: Add variants for critical sections

Update #3665.

---

 cpukit/include/rtems/record.h       | 46 ++++++++++++++++++++++++++++++++++---
 testsuites/libtests/record01/init.c |  7 ++++--
 2 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/cpukit/include/rtems/record.h b/cpukit/include/rtems/record.h
index ff1ee22..0446c2a 100644
--- a/cpukit/include/rtems/record.h
+++ b/cpukit/include/rtems/record.h
@@ -172,6 +172,34 @@ void _Record_Stream_header_initialize( Record_Stream_header *header );
  */
 
 /**
+ * @brief Prepares to add and commit record items in a critical section with
+ * interrupts disabled.
+ *
+ * This function does not disable interrupts.  It must be called with
+ * interrupts disabled.  Interrupts must be disabled until the corresponding
+ * rtems_record_commit_critical() was called.
+ *
+ * @param context The record context which must be used for the following
+ *   rtems_record_add() and rtems_record_commit_critical() calls.  The record
+ *   context may have an arbitrary content at function entry.
+ * @param cpu_self The control of the current processor.
+ */
+RTEMS_INLINE_ROUTINE void rtems_record_prepare_critical(
+  rtems_record_context  *context,
+  const Per_CPU_Control *cpu_self
+)
+{
+  Record_Control *control;
+  unsigned int    head;
+
+  context->now = RTEMS_RECORD_TIME_EVENT( _Record_Now(), 0 );
+  control = cpu_self->record;
+  context->control = control;
+  head = _Record_Head( control );
+  context->head = head;
+}
+
+/**
  * @brief Prepares to add and commit record items.
  *
  * This function disables interrupts.
@@ -226,17 +254,29 @@ RTEMS_INLINE_ROUTINE void rtems_record_add(
 }
 
 /**
- * @brief Commits a set of record items.
+ * @brief Commits a set of record items in a critical section with interrupts
+ * disabled.
  *
- * @param context The record context initialized via rtems_record_prepare().
+ * @param context The record context initialized via
+ *   rtems_record_prepare_critical().
  */
-RTEMS_INLINE_ROUTINE void rtems_record_commit( rtems_record_context *context )
+RTEMS_INLINE_ROUTINE void rtems_record_commit_critical( rtems_record_context *context )
 {
   _Atomic_Store_uint(
     &context->control->head,
     context->head,
     ATOMIC_ORDER_RELEASE
   );
+}
+
+/**
+ * @brief Commits a set of record items.
+ *
+ * @param context The record context initialized via rtems_record_prepare().
+ */
+RTEMS_INLINE_ROUTINE void rtems_record_commit( rtems_record_context *context )
+{
+  rtems_record_commit_critical( context );
   rtems_interrupt_local_enable( context->level );
 }
 
diff --git a/testsuites/libtests/record01/init.c b/testsuites/libtests/record01/init.c
index e8ff236..1789d41 100644
--- a/testsuites/libtests/record01/init.c
+++ b/testsuites/libtests/record01/init.c
@@ -265,10 +265,12 @@ static void test_add_2_items(test_context *ctx, Record_Control *control)
 static void test_add_3_items(test_context *ctx, Record_Control *control)
 {
   rtems_record_context rc;
+  rtems_interrupt_level level;
 
   init_context(ctx);
 
-  rtems_record_prepare(&rc);
+  rtems_interrupt_local_disable(level);
+  rtems_record_prepare_critical(&rc, _Per_CPU_Get());
   rtems_test_assert(rc.control == control);
   rtems_test_assert(rc.head == 0);
   rtems_test_assert(_Record_Head(control) == 0);
@@ -290,7 +292,8 @@ static void test_add_3_items(test_context *ctx, Record_Control *control)
 
   rc.now = RTEMS_RECORD_TIME_EVENT(10, 0);
   rtems_record_add(&rc, UE(9), 11);
-  rtems_record_commit(&rc);
+  rtems_record_commit_critical(&rc);
+  rtems_interrupt_local_enable(level);
   rtems_test_assert(rc.head == 3);
   rtems_test_assert(memcmp(control->Items, expected_items_7, ITEM_SIZE) == 0);
   rtems_test_assert(_Record_Head(control) == 3);



More information about the vc mailing list