[rtems-schedsim commit] Allow Scheduler Simulator to "defer dispatch" until controlled

Joel Sherrill joel at rtems.org
Wed Apr 30 18:18:14 UTC 2014


Module:    rtems-schedsim
Branch:    master
Commit:    187d93cac4446f906c3f9df57705361a6bcf48ff
Changeset: http://git.rtems.org/rtems-schedsim/commit/?id=187d93cac4446f906c3f9df57705361a6bcf48ff

Author:    Joel Sherrill <joel.sherrill at oarcorp.com>
Date:      Wed Apr 30 13:24:50 2014 -0500

Allow Scheduler Simulator to "defer dispatch" until controlled

This is needed to prevent a semaphore delete from triggering a
preempt and breaking the mutex is owner debug check. Technically
we are running the same thread until the API call returns. But from
an RTEMS internals perspective, it was preempted at the _Object_Put().

When understanding this patch, it is important to remember that the
Scheduler Simulator is single threaded and faking out RTEMS. This
is one place where RTEMS would have preempted to a thread and when
we returned to rtems_semaphore_delete(), the _Object_Put() call
would have been made by the correct thread.

---

 schedsim/shell/shared/main_semdelete.c |   17 +++++++++++++----
 schedsim/shell/shared/schedsim_shell.h |   14 +++++++++++---
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/schedsim/shell/shared/main_semdelete.c b/schedsim/shell/shared/main_semdelete.c
index ed227b3..4a706b8 100644
--- a/schedsim/shell/shared/main_semdelete.c
+++ b/schedsim/shell/shared/main_semdelete.c
@@ -1,7 +1,10 @@
+/**
+ *  @file
+ *  @brief Task Delete Shell Command Implmentation
+ */
+
 /*
- *  Task Delete Shell Command Implmentation
- *
- *  COPYRIGHT (c) 1989-2013.
+ *  COPYRIGHT (c) 1989-2014.
  *  On-Line Applications Research Corporation (OAR).
  *
  *  The license and distribution terms for this file may be
@@ -44,7 +47,13 @@ int rtems_shell_main_semaphore_delete(
    */
   printf("Deleting semaphore (0x%08x)\n", id );
   
-  status = rtems_semaphore_delete( id );
+  /*
+   * This wraps the allocator mutex and should defer any context switching
+   */
+  schedsim_set_allow_dispatch(false);
+    status = rtems_semaphore_delete( id );
+  schedsim_set_allow_dispatch(true);
+
   if ( status != RTEMS_SUCCESSFUL ) {
     fprintf(
       stderr,
diff --git a/schedsim/shell/shared/schedsim_shell.h b/schedsim/shell/shared/schedsim_shell.h
index d1f2406..15685bc 100644
--- a/schedsim/shell/shared/schedsim_shell.h
+++ b/schedsim/shell/shared/schedsim_shell.h
@@ -1,7 +1,12 @@
-/*
- *  BASED UPON SOURCE IN RTEMS, MODIFIED FOR SIMULATOR
+/**
+ *  @file
+ *  @brief Scheduler Simulator Internals
  *
- *  COPYRIGHT (c) 1989-2013.
+ *  @note BASED UPON SOURCE IN RTEMS, MODIFIED FOR SIMULATOR
+ */
+
+/*
+ *  COPYRIGHT (c) 1989-2014.
  *  On-Line Applications Research Corporation (OAR).
  *
  *  The license and distribution terms for this file may be
@@ -30,6 +35,9 @@ extern "C" {
 void PRINT_EXECUTING(void);
 void PRINT_HEIR(void);
 
+void schedsim_set_allow_dispatch(bool value);
+bool schedsim_is_dispatch_allowed(void);
+
 struct rtems_shell_topic_tt;
 typedef struct rtems_shell_topic_tt rtems_shell_topic_t;
 




More information about the vc mailing list