<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text -->
<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style></head>
<body>
<body><p dir="ltr">You added to the API and added no documentation.</p><div class="quote">On Apr 15, 2014 4:13 AM, Sebastian Huber <sebh@rtems.org> wrote:<br type="attribution"></div></body>
<font size="2"><div class="PlainText">Module:    rtems<br>
Branch:    master<br>
Commit:    27270b0d6c1ec6ff7bca2ffc5a8c25b45d260165<br>
Changeset: <a href="http://git.rtems.org/rtems/commit/?id=27270b0d6c1ec6ff7bca2ffc5a8c25b45d260165">http://git.rtems.org/rtems/commit/?id=27270b0d6c1ec6ff7bca2ffc5a8c25b45d260165</a><br>
<br>
Author:    Sebastian Huber <sebastian.huber@embedded-brains.de><br>
Date:      Wed Apr  9 10:09:39 2014 +0200<br>
<br>
rtems: Add task get/set scheduler<br>
<br>
---<br>
<br>
 cpukit/rtems/Makefile.am                         |    2 +<br>
 cpukit/rtems/include/rtems/rtems/tasks.h         |   35 ++++++++++<br>
 cpukit/rtems/src/taskgetscheduler.c              |   60 +++++++++++++++++<br>
 cpukit/rtems/src/tasksetscheduler.c              |   58 ++++++++++++++++<br>
 cpukit/score/include/rtems/score/schedulerimpl.h |   25 +++++++<br>
 testsuites/sptests/spscheduler01/init.c          |   78 +++++++++++++++++++++-<br>
 6 files changed, 257 insertions(+), 1 deletions(-)<br>
<br>
diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am<br>
index ff3e605..4b84fa1 100644<br>
--- a/cpukit/rtems/Makefile.am<br>
+++ b/cpukit/rtems/Makefile.am<br>
@@ -94,6 +94,7 @@ librtems_a_SOURCES += src/taskcreate.c<br>
 librtems_a_SOURCES += src/taskdelete.c<br>
 librtems_a_SOURCES += src/taskgetaffinity.c<br>
 librtems_a_SOURCES += src/taskgetnote.c<br>
+librtems_a_SOURCES += src/taskgetscheduler.c<br>
 librtems_a_SOURCES += src/taskident.c<br>
 librtems_a_SOURCES += src/taskinitusers.c<br>
 librtems_a_SOURCES += src/taskissuspended.c<br>
@@ -104,6 +105,7 @@ librtems_a_SOURCES += src/taskself.c<br>
 librtems_a_SOURCES += src/tasksetaffinity.c<br>
 librtems_a_SOURCES += src/tasksetnote.c<br>
 librtems_a_SOURCES += src/tasksetpriority.c<br>
+librtems_a_SOURCES += src/tasksetscheduler.c<br>
 librtems_a_SOURCES += src/taskstart.c<br>
 librtems_a_SOURCES += src/tasksuspend.c<br>
 librtems_a_SOURCES += src/taskwakeafter.c<br>
diff --git a/cpukit/rtems/include/rtems/rtems/tasks.h b/cpukit/rtems/include/rtems/rtems/tasks.h<br>
index 21c0166..9101d9c 100644<br>
--- a/cpukit/rtems/include/rtems/rtems/tasks.h<br>
+++ b/cpukit/rtems/include/rtems/rtems/tasks.h<br>
@@ -542,6 +542,41 @@ rtems_status_code rtems_task_set_affinity(<br>
 #endif<br>
 <br>
 /**<br>
+ * @brief Gets the scheduler of a task.<br>
+ *<br>
+ * @param[in] id Identifier of the task.  Use @ref RTEMS_SELF to select the<br>
+ * executing task.<br>
+ * @param[out] scheduler_id Identifier of the scheduler.<br>
+ *<br>
+ * @retval RTEMS_SUCCESSFUL Successful operation.<br>
+ * @retval RTEMS_INVALID_ADDRESS The @a scheduler_id parameter is @c NULL.<br>
+ * @retval RTEMS_INVALID_ID Invalid task identifier.<br>
+ */<br>
+rtems_status_code rtems_task_get_scheduler(<br>
+  rtems_id  id,<br>
+  rtems_id *scheduler_id<br>
+);<br>
+<br>
+/**<br>
+ * @brief Sets the scheduler of a task.<br>
+ *<br>
+ * @param[in] id Identifier of the task.  Use @ref RTEMS_SELF to select the<br>
+ * executing task.<br>
+ * @param[in] scheduler_id Identifier of the scheduler.<br>
+ *<br>
+ * @retval RTEMS_SUCCESSFUL Successful operation.<br>
+ * @retval RTEMS_INVALID_ID Invalid task or scheduler identifier.<br>
+ * @retval RTEMS_INCORRECT_STATE The task is in the wrong state to perform a<br>
+ * scheduler change.<br>
+ *<br>
+ * @see rtems_scheduler_ident().<br>
+ */<br>
+rtems_status_code rtems_task_set_scheduler(<br>
+  rtems_id id,<br>
+  rtems_id scheduler_id<br>
+);<br>
+<br>
+/**<br>
  *  @brief RTEMS Get Self Task Id<br>
  *<br>
  *  This directive returns the ID of the currently executing task.<br>
diff --git a/cpukit/rtems/src/taskgetscheduler.c b/cpukit/rtems/src/taskgetscheduler.c<br>
new file mode 100644<br>
index 0000000..7111093<br>
--- /dev/null<br>
+++ b/cpukit/rtems/src/taskgetscheduler.c<br>
@@ -0,0 +1,60 @@<br>
+/*<br>
+ * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.<br>
+ *<br>
+ *  embedded brains GmbH<br>
+ *  Dornierstr. 4<br>
+ *  82178 Puchheim<br>
+ *  Germany<br>
+ *  <rtems@embedded-brains.de><br>
+ *<br>
+ * The license and distribution terms for this file may be<br>
+ * found in the file LICENSE in this distribution or at<br>
+ * <a href="http://www.rtems.org/license/LICENSE">http://www.rtems.org/license/LICENSE</a>.<br>
+ */<br>
+<br>
+#if HAVE_CONFIG_H<br>
+  #include "config.h"<br>
+#endif<br>
+<br>
+#include <rtems/rtems/tasks.h><br>
+#include <rtems/score/schedulerimpl.h><br>
+<br>
+rtems_status_code rtems_task_get_scheduler(<br>
+  rtems_id  id,<br>
+  rtems_id *scheduler_id<br>
+)<br>
+{<br>
+  rtems_status_code sc;<br>
+<br>
+  if ( scheduler_id != NULL ) {<br>
+    Thread_Control          *the_thread;<br>
+    Objects_Locations        location;<br>
+    const Scheduler_Control *scheduler;<br>
+<br>
+    the_thread = _Thread_Get( id, &location );<br>
+<br>
+    switch ( location ) {<br>
+      case OBJECTS_LOCAL:<br>
+        scheduler = _Scheduler_Get( the_thread );<br>
+        *scheduler_id = _Scheduler_Build_id(<br>
+          _Scheduler_Get_index( scheduler )<br>
+        );<br>
+        _Objects_Put( &the_thread->Object );<br>
+        sc = RTEMS_SUCCESSFUL;<br>
+        break;<br>
+#if defined(RTEMS_MULTIPROCESSING)<br>
+      case OBJECTS_REMOTE:<br>
+        _Thread_Dispatch();<br>
+        sc = RTEMS_ILLEGAL_ON_REMOTE_OBJECT;<br>
+        break;<br>
+#endif<br>
+      default:<br>
+        sc = RTEMS_INVALID_ID;<br>
+        break;<br>
+    }<br>
+  } else {<br>
+    sc = RTEMS_INVALID_ADDRESS;<br>
+  }<br>
+<br>
+  return sc;<br>
+}<br>
diff --git a/cpukit/rtems/src/tasksetscheduler.c b/cpukit/rtems/src/tasksetscheduler.c<br>
new file mode 100644<br>
index 0000000..42c08bb<br>
--- /dev/null<br>
+++ b/cpukit/rtems/src/tasksetscheduler.c<br>
@@ -0,0 +1,58 @@<br>
+/*<br>
+ * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.<br>
+ *<br>
+ *  embedded brains GmbH<br>
+ *  Dornierstr. 4<br>
+ *  82178 Puchheim<br>
+ *  Germany<br>
+ *  <rtems@embedded-brains.de><br>
+ *<br>
+ * The license and distribution terms for this file may be<br>
+ * found in the file LICENSE in this distribution or at<br>
+ * <a href="http://www.rtems.org/license/LICENSE">http://www.rtems.org/license/LICENSE</a>.<br>
+ */<br>
+<br>
+#if HAVE_CONFIG_H<br>
+  #include "config.h"<br>
+#endif<br>
+<br>
+#include <rtems/rtems/tasks.h><br>
+#include <rtems/score/schedulerimpl.h><br>
+<br>
+rtems_status_code rtems_task_set_scheduler(<br>
+  rtems_id id,<br>
+  rtems_id scheduler_id<br>
+)<br>
+{<br>
+  rtems_status_code        sc;<br>
+  const Scheduler_Control *scheduler;<br>
+<br>
+  if ( _Scheduler_Get_by_id( scheduler_id, &scheduler ) ) {<br>
+    Thread_Control    *the_thread;<br>
+    Objects_Locations  location;<br>
+    bool               ok;<br>
+<br>
+    the_thread = _Thread_Get( id, &location );<br>
+<br>
+    switch ( location ) {<br>
+      case OBJECTS_LOCAL:<br>
+        ok = _Scheduler_Set( scheduler, the_thread );<br>
+        _Objects_Put( &the_thread->Object );<br>
+        sc = ok ? RTEMS_SUCCESSFUL : RTEMS_INCORRECT_STATE;<br>
+        break;<br>
+#if defined(RTEMS_MULTIPROCESSING)<br>
+      case OBJECTS_REMOTE:<br>
+        _Thread_Dispatch();<br>
+        sc = RTEMS_ILLEGAL_ON_REMOTE_OBJECT;<br>
+        break;<br>
+#endif<br>
+      default:<br>
+        sc = RTEMS_INVALID_ID;<br>
+        break;<br>
+    }<br>
+  } else {<br>
+    sc = RTEMS_INVALID_ID;<br>
+  }<br>
+<br>
+  return sc;<br>
+}<br>
diff --git a/cpukit/score/include/rtems/score/schedulerimpl.h b/cpukit/score/include/rtems/score/schedulerimpl.h<br>
index 2b8782f..8b80db7 100644<br>
--- a/cpukit/score/include/rtems/score/schedulerimpl.h<br>
+++ b/cpukit/score/include/rtems/score/schedulerimpl.h<br>
@@ -451,6 +451,24 @@ RTEMS_INLINE_ROUTINE const Scheduler_Control *_Scheduler_Get(<br>
   return &_Scheduler_Table[ 0 ];<br>
 }<br>
 <br>
+RTEMS_INLINE_ROUTINE bool _Scheduler_Set(<br>
+  const Scheduler_Control *scheduler,<br>
+  Thread_Control          *the_thread<br>
+)<br>
+{<br>
+  bool ok;<br>
+<br>
+  (void) scheduler;<br>
+<br>
+  if ( _States_Is_dormant( the_thread->current_state ) ) {<br>
+    ok = true;<br>
+  } else {<br>
+    ok = false;<br>
+  }<br>
+<br>
+  return ok;<br>
+}<br>
+<br>
 RTEMS_INLINE_ROUTINE Objects_Id _Scheduler_Build_id( uint32_t scheduler_index )<br>
 {<br>
   return _Objects_Build_id(<br>
@@ -474,6 +492,13 @@ RTEMS_INLINE_ROUTINE bool _Scheduler_Get_by_id(<br>
   return index < _Scheduler_Count;<br>
 }<br>
 <br>
+RTEMS_INLINE_ROUTINE uint32_t _Scheduler_Get_index(<br>
+  const Scheduler_Control *scheduler<br>
+)<br>
+{<br>
+  return (uint32_t) (scheduler - &_Scheduler_Table[ 0 ]);<br>
+}<br>
+<br>
 /** @} */<br>
 <br>
 #ifdef __cplusplus<br>
diff --git a/testsuites/sptests/spscheduler01/init.c b/testsuites/sptests/spscheduler01/init.c<br>
index 655568d..6c19abc 100644<br>
--- a/testsuites/sptests/spscheduler01/init.c<br>
+++ b/testsuites/sptests/spscheduler01/init.c<br>
@@ -102,6 +102,81 @@ static void test_task_get_set_affinity(void)<br>
 #endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */<br>
 }<br>
 <br>
+static void task(rtems_task_argument arg)<br>
+{<br>
+  (void) arg;<br>
+<br>
+  rtems_test_assert(0);<br>
+}<br>
+<br>
+static void test_task_get_set_scheduler(void)<br>
+{<br>
+  rtems_status_code sc;<br>
+  rtems_id self_id = rtems_task_self();<br>
+  rtems_name name = BLUE;<br>
+  rtems_id scheduler_id;<br>
+  rtems_id scheduler_by_name;<br>
+  rtems_id task_id;<br>
+<br>
+  sc = rtems_scheduler_ident(name, &scheduler_by_name);<br>
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);<br>
+<br>
+  sc = rtems_task_get_scheduler(RTEMS_SELF, NULL);<br>
+  rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);<br>
+<br>
+  sc = rtems_task_get_scheduler(invalid_id, &scheduler_id);<br>
+  rtems_test_assert(sc == RTEMS_INVALID_ID);<br>
+<br>
+  scheduler_id = 0;<br>
+  sc = rtems_task_get_scheduler(RTEMS_SELF, &scheduler_id);<br>
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);<br>
+<br>
+  rtems_test_assert(scheduler_id == scheduler_by_name);<br>
+<br>
+  scheduler_id = 0;<br>
+  sc = rtems_task_get_scheduler(self_id, &scheduler_id);<br>
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);<br>
+<br>
+  rtems_test_assert(scheduler_id == scheduler_by_name);<br>
+<br>
+  sc = rtems_task_set_scheduler(invalid_id, scheduler_id);<br>
+  rtems_test_assert(sc == RTEMS_INVALID_ID);<br>
+<br>
+  sc = rtems_task_set_scheduler(self_id, invalid_id);<br>
+  rtems_test_assert(sc == RTEMS_INVALID_ID);<br>
+<br>
+  sc = rtems_task_set_scheduler(self_id, scheduler_id);<br>
+  rtems_test_assert(sc == RTEMS_INCORRECT_STATE);<br>
+<br>
+  sc = rtems_task_create(<br>
+    rtems_build_name('T', 'A', 'S', 'K'),<br>
+    2,<br>
+    RTEMS_MINIMUM_STACK_SIZE,<br>
+    RTEMS_DEFAULT_MODES,<br>
+    RTEMS_DEFAULT_ATTRIBUTES,<br>
+    &task_id<br>
+  );<br>
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);<br>
+<br>
+  scheduler_id = 0;<br>
+  sc = rtems_task_get_scheduler(task_id, &scheduler_id);<br>
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);<br>
+<br>
+  rtems_test_assert(scheduler_id == scheduler_by_name);<br>
+<br>
+  sc = rtems_task_set_scheduler(task_id, scheduler_id);<br>
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);<br>
+<br>
+  sc = rtems_task_start(task_id, task, 0);<br>
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);<br>
+<br>
+  sc = rtems_task_set_scheduler(task_id, scheduler_id);<br>
+  rtems_test_assert(sc == RTEMS_INCORRECT_STATE);<br>
+<br>
+  sc = rtems_task_delete(task_id);<br>
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);<br>
+}<br>
+<br>
 static void test_scheduler_ident(void)<br>
 {<br>
   rtems_status_code sc;<br>
@@ -184,6 +259,7 @@ static void Init(rtems_task_argument arg)<br>
   rtems_resource_snapshot_take(&snapshot);<br>
 <br>
   test_task_get_set_affinity();<br>
+  test_task_get_set_scheduler();<br>
   test_scheduler_ident();<br>
   test_scheduler_get_processors();<br>
 <br>
@@ -198,7 +274,7 @@ static void Init(rtems_task_argument arg)<br>
 <br>
 #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM<br>
 <br>
-#define CONFIGURE_MAXIMUM_TASKS 1<br>
+#define CONFIGURE_MAXIMUM_TASKS 2<br>
 <br>
 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION<br>
 <br>
<br>
_______________________________________________<br>
rtems-vc mailing list<br>
rtems-vc@rtems.org<br>
<a href="http://www.rtems.org/mailman/listinfo/rtems-vc">http://www.rtems.org/mailman/listinfo/rtems-vc</a><br>
</div></font>
</body>
</html>