[rtems commit] rtems: Add rtems_task_exit()

Sebastian Huber sebh at rtems.org
Thu Oct 4 08:49:49 UTC 2018


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Oct  1 09:25:06 2018 +0200

rtems: Add rtems_task_exit()

Update #3533.

---

 cpukit/include/rtems/rtems/tasks.h       |  2 ++
 cpukit/rtems/Makefile.am                 |  1 +
 cpukit/rtems/src/taskexit.c              | 38 ++++++++++++++++++++++++++++++++
 testsuites/sptests/spthreadlife01/init.c | 30 ++++++++++++++++++++++---
 4 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/cpukit/include/rtems/rtems/tasks.h b/cpukit/include/rtems/rtems/tasks.h
index 585f4c4..aaba885 100644
--- a/cpukit/include/rtems/rtems/tasks.h
+++ b/cpukit/include/rtems/rtems/tasks.h
@@ -227,6 +227,8 @@ rtems_status_code rtems_task_delete(
   rtems_id   id
 );
 
+void rtems_task_exit( void ) RTEMS_NO_RETURN;
+
 /**
  * @brief RTEMS Task Mode
  *
diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am
index 7af4ec7..fdef7f8 100644
--- a/cpukit/rtems/Makefile.am
+++ b/cpukit/rtems/Makefile.am
@@ -33,6 +33,7 @@ librtems_a_SOURCES += src/rtemsobjectgetclassicname.c
 librtems_a_SOURCES += src/tasks.c
 librtems_a_SOURCES += src/taskcreate.c
 librtems_a_SOURCES += src/taskdelete.c
+librtems_a_SOURCES += src/taskexit.c
 librtems_a_SOURCES += src/taskgetaffinity.c
 librtems_a_SOURCES += src/taskgetpriority.c
 librtems_a_SOURCES += src/taskgetscheduler.c
diff --git a/cpukit/rtems/src/taskexit.c b/cpukit/rtems/src/taskexit.c
new file mode 100644
index 0000000..7faf8ae
--- /dev/null
+++ b/cpukit/rtems/src/taskexit.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2018 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/threadimpl.h>
+
+void rtems_task_exit( void )
+{
+  Thread_Control  *executing;
+  Per_CPU_Control *cpu_self;
+
+  cpu_self = _Thread_Dispatch_disable();
+  executing = _Per_CPU_Get_executing( cpu_self );
+
+  _Thread_Exit(
+    executing,
+    THREAD_LIFE_TERMINATING | THREAD_LIFE_DETACHED,
+    NULL
+  );
+
+  _Thread_Dispatch_direct( cpu_self );
+  RTEMS_UNREACHABLE();
+}
diff --git a/testsuites/sptests/spthreadlife01/init.c b/testsuites/sptests/spthreadlife01/init.c
index 6f22a5b..d01aff5 100644
--- a/testsuites/sptests/spthreadlife01/init.c
+++ b/testsuites/sptests/spthreadlife01/init.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2014, 2018 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -61,6 +61,10 @@ typedef enum {
   DELETE_7,
   DELETE_8,
   DELETE_9,
+  EXIT_0,
+  EXIT_1,
+  EXIT_2,
+  EXIT_3,
   INVALID
 } test_state;
 
@@ -182,6 +186,10 @@ static void delete_extension(
       assert_priority(PRIO_VERY_LOW);
       ctx->current = DELETE_9;
       break;
+    case EXIT_2:
+      assert_priority(PRIO_VERY_LOW);
+      ctx->current = EXIT_3;
+      break;
     default:
       rtems_test_assert(0);
       break;
@@ -213,7 +221,10 @@ static void terminate_extension(Thread_Control *executing)
     case DELETE_7:
       assert_priority(PRIO_LOW);
       ctx->current = DELETE_8;
-      wake_up_main(ctx);
+      break;
+    case EXIT_1:
+      assert_priority(PRIO_LOW);
+      ctx->current = EXIT_2;
       break;
     default:
       rtems_test_assert(0);
@@ -292,6 +303,10 @@ static void worker_task(rtems_task_argument arg)
         rtems_task_delete(RTEMS_SELF);
         rtems_test_assert(0);
         break;
+      case EXIT_0:
+        ctx->current = EXIT_1;
+        rtems_task_exit();
+        break;
       default:
         rtems_test_assert(0);
         break;
@@ -399,8 +414,17 @@ static void test(void)
   set_priority(PRIO_VERY_LOW);
 
   rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
+  set_priority(PRIO_INIT);
+
+  create_and_start_worker(ctx);
+
+  change_state(ctx, DELETE_9, EXIT_0, INVALID);
+  set_priority(PRIO_VERY_LOW);
+
+  rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
+  set_priority(PRIO_INIT);
 
-  rtems_test_assert(ctx->current == DELETE_9);
+  rtems_test_assert(ctx->current == EXIT_3);
 }
 
 static void Init(rtems_task_argument arg)




More information about the vc mailing list