[PATCH 3/4] capture: Remove nested rtems_interrupt_lock_acquire calls.

Jennifer Averett jennifer.averett at oarcorp.com
Thu Jul 10 13:44:14 UTC 2014


Use of the cenable command was resulting in a lock in
rtems_interrupt_lock_acquire due to nesting.
---
 cpukit/libmisc/capture/capture.c | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/cpukit/libmisc/capture/capture.c b/cpukit/libmisc/capture/capture.c
index ec5e408..3ce8d8d 100644
--- a/cpukit/libmisc/capture/capture.c
+++ b/cpukit/libmisc/capture/capture.c
@@ -379,7 +379,7 @@ rtems_capture_create_control (rtems_name name, rtems_id id)
  * This function create the task control.
  */
 static inline rtems_capture_task_t*
-rtems_capture_create_capture_task (rtems_tcb* new_task)
+rtems_capture_create_capture_task (rtems_tcb* new_task, bool protect)
 {
   rtems_interrupt_lock_context lock_context;
   rtems_capture_task_t*        task;
@@ -428,7 +428,8 @@ rtems_capture_create_capture_task (rtems_tcb* new_task)
   task->stack_size     = new_task->Start.Initial_stack.size;
   task->stack_clean    = task->stack_size;
 
-  rtems_interrupt_lock_acquire (&capture_lock, &lock_context);
+  if (protect)
+    rtems_interrupt_lock_acquire (&capture_lock, &lock_context);
 
   task->forw    = capture_tasks;
   if (task->forw)
@@ -436,7 +437,8 @@ rtems_capture_create_capture_task (rtems_tcb* new_task)
   task->back    = NULL;
   capture_tasks = task;
 
-  rtems_interrupt_lock_release (&capture_lock, &lock_context);
+  if (protect)
+    rtems_interrupt_lock_release (&capture_lock, &lock_context);
 
   /*
    * We need to scan the default control list to initialise
@@ -633,12 +635,12 @@ rtems_capture_create_task (rtems_tcb* current_task,
    */
 
   if (ct == NULL)
-    ct = rtems_capture_create_capture_task (current_task);
+    ct = rtems_capture_create_capture_task (current_task, true);
 
   /*
    * Create the new task's capture control block.
    */
-  nt = rtems_capture_create_capture_task (new_task);
+  nt = rtems_capture_create_capture_task (new_task, true);
 
   if (rtems_capture_trigger (ct, nt, RTEMS_CAPTURE_CREATE))
   {
@@ -672,10 +674,10 @@ rtems_capture_start_task (rtems_tcb* current_task,
    */
 
   if (ct == NULL)
-    ct = rtems_capture_create_capture_task (current_task);
+    ct = rtems_capture_create_capture_task (current_task, true);
 
   if (st == NULL)
-    st = rtems_capture_create_capture_task (started_task);
+    st = rtems_capture_create_capture_task (started_task, true);
 
   if (rtems_capture_trigger (ct, st, RTEMS_CAPTURE_START))
   {
@@ -709,10 +711,10 @@ rtems_capture_restart_task (rtems_tcb* current_task,
    */
 
   if (ct == NULL)
-    ct = rtems_capture_create_capture_task (current_task);
+    ct = rtems_capture_create_capture_task (current_task, true);
 
   if (rt == NULL)
-    rt = rtems_capture_create_capture_task (restarted_task);
+    rt = rtems_capture_create_capture_task (restarted_task, true);
 
   if (rtems_capture_trigger (ct, rt, RTEMS_CAPTURE_RESTART))
   {
@@ -747,10 +749,10 @@ rtems_capture_delete_task (rtems_tcb* current_task,
   dt = deleted_task->extensions[capture_extension_index];
 
   if (ct == NULL)
-    ct = rtems_capture_create_capture_task (current_task);
+    ct = rtems_capture_create_capture_task (current_task, true);
 
   if (dt == NULL)
-    dt = rtems_capture_create_capture_task (deleted_task);
+    dt = rtems_capture_create_capture_task (deleted_task, true);
 
   if (rtems_capture_trigger (ct, dt, RTEMS_CAPTURE_DELETE))
   {
@@ -789,7 +791,7 @@ rtems_capture_begin_task (rtems_tcb* begin_task)
    */
 
   if (bt == NULL)
-    bt = rtems_capture_create_capture_task (begin_task);
+    bt = rtems_capture_create_capture_task (begin_task, true);
 
   if (rtems_capture_trigger (NULL, bt, RTEMS_CAPTURE_BEGIN))
     rtems_capture_record (bt, RTEMS_CAPTURE_BEGIN_EVENT);
@@ -816,7 +818,7 @@ rtems_capture_exitted_task (rtems_tcb* exitted_task)
    */
 
   if (et == NULL)
-    et = rtems_capture_create_capture_task (exitted_task);
+    et = rtems_capture_create_capture_task (exitted_task, true);
 
   if (rtems_capture_trigger (NULL, et, RTEMS_CAPTURE_EXITTED))
     rtems_capture_record (et, RTEMS_CAPTURE_EXITTED_EVENT);
@@ -844,7 +846,7 @@ rtems_capture_terminated_task (rtems_tcb* terminated_task)
    */
 
   if (tt == NULL)
-    tt = rtems_capture_create_capture_task (terminated_task);
+    tt = rtems_capture_create_capture_task (terminated_task, true);
 
   if (rtems_capture_trigger (NULL, tt, RTEMS_CAPTURE_TERMINATED))
     rtems_capture_record (tt, RTEMS_CAPTURE_TERMINATED_EVENT);
@@ -890,13 +892,13 @@ rtems_capture_switch_task (rtems_tcb* current_task,
       ct = current_task->extensions[capture_extension_index];
 
       if (ct == NULL)
-        ct = rtems_capture_create_capture_task (current_task);
+        ct = rtems_capture_create_capture_task (current_task, true);
     }
 
     ht = heir_task->extensions[capture_extension_index];
 
     if (ht == NULL)
-      ht = rtems_capture_create_capture_task (heir_task);
+      ht = rtems_capture_create_capture_task (heir_task, true);
 
     /*
      * Update the execution time. Assume the time will not overflow
@@ -1054,11 +1056,14 @@ rtems_capture_close (void)
 
 /*
  * This function allows control of tracing at a global level.
+ *
+ * This method depends on the caller to lock capture_lock
+ * prior to calling
  */
 static void
 rtems_capture_task_setup (Thread_Control *tcb)
 {
-  rtems_capture_create_capture_task (tcb);
+  rtems_capture_create_capture_task (tcb, false);
 }
 
 rtems_status_code
-- 
1.8.1.4




More information about the devel mailing list