sched/audiod feature: task list and kill
[paraslash.git] / sched.c
diff --git a/sched.c b/sched.c
index 9356dd0..879ab80 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -106,5 +106,49 @@ void sched_shutdown(void)
                unregister_task(t);
 };
 
+char *get_task_list(void)
+{
+       struct task *t, *tmp;
+       char *msg = NULL;
+       list_for_each_entry_safe(t, tmp, &pre_select_list, pre_select_node) {
+               char *tmp_msg;
+               tmp_msg = make_message("%s%p\t%s\n", msg? msg : "", t, t->status);
+               free(msg);
+               msg = tmp_msg;
+       }
+       list_for_each_entry_safe(t, tmp, &post_select_list, post_select_node) {
+               char *tmp_msg;
+               if (t->pre_select)
+                       continue;
+               tmp_msg = make_message("%s%p\t%s\n", msg? msg : "", t, t->status);
+               free(msg);
+               msg = tmp_msg;
+       }
+       //PARA_DEBUG_LOG("task list:\n%s", msg);
+       return msg;
+}
 
-//char *get_tast_list();
+int kill_task(char *id)
+{
+       struct task *t, *tmp;
+       char buf[20];
+       list_for_each_entry_safe(t, tmp, &pre_select_list, pre_select_node) {
+               sprintf(buf, "%p", t);
+               if (strcmp(id, buf))
+                       continue;
+               t->ret = -E_TASK_KILLED;
+               if (t->event_handler)
+                       t->event_handler(t);
+               return 1;
+       }
+       list_for_each_entry_safe(t, tmp, &post_select_list, post_select_node) {
+               sprintf(buf, "%p", t);
+               if (strcmp(id, buf))
+                       continue;
+               t->ret = -E_TASK_KILLED;
+               if (t->event_handler)
+                       t->event_handler(t);
+               return 1;
+       }
+       return -E_NO_SUCH_TASK;
+}