/** * The main function for creating a new task. */ task_pid_t task_create_gid (task_gid_t gid, task_function_t fn) { pth_t pid; pth_attr_t attr; int i; #ifdef PTHDEBUG printf ("task_create_gid: gid=%d, fn=%p\n", gid, fn); #endif /* Set the task attributes: * - Not joinable : all tasks are independent * - cancellable : task kill is permitted * - priority : make certain tasks that the simulator itself * uses higher priority, and all others equal in priority. */ attr = pth_attr_new (); pth_attr_set (attr, PTH_ATTR_JOINABLE, FALSE); pth_attr_set (attr, PTH_ATTR_CANCEL_STATE, PTH_CANCEL_ENABLE); if (gid == GID_LINUX_REALTIME) /* time tracking */ pth_attr_set (attr, PTH_ATTR_PRIO, PTH_PRIO_STD + 2); else if (gid == GID_LINUX_INTERFACE) /* user input */ pth_attr_set (attr, PTH_ATTR_PRIO, PTH_PRIO_STD + 1); /* TODO - inside of calling the function directly, call a global * function and pass it a pointer to the task_data_table entry * as an argument. */ pid = pth_spawn (attr, fn, 0); for (i=0; i < NUM_TASKS; i++) if (task_data_table[i].pid == 0) { task_data_table[i].pid = pid; task_data_table[i].gid = gid; task_data_table[i].duration = TASK_DURATION_INF; task_data_table[i].arg.u16 = 0; task_data_table[i].duration = TASK_DURATION_BALL; #ifdef CONFIG_UI ui_write_task (i, gid); #endif return (pid); } fatal (ERR_NO_FREE_TASKS); }
void task_kill_pid (task_pid_t tp) { int i; pthread_debug ("task_kill_pid: pid=%u\n", (unsigned)tp); for (i=0; i < NUM_TASKS; i++) if (task_data_table[i].pid == tp) { if (tp != 0) pthread_cancel (tp); task_data_table[i].pid = 0; #ifdef CONFIG_SIM ui_write_task (i, 0); #endif return; } }
/** * The main function for creating a new task. */ task_pid_t task_create_gid (task_gid_t gid, task_function_t fn) { pthread_t pid; pthread_attr_t *attr; struct sched_param param; int i; int rc; pthread_debug ("task_create_gid: gid=%d, fn=%p\n", gid, fn); if (gid == GID_LINUX_REALTIME) /* time tracking */ attr = &attr_interrupt; else if (gid == GID_LINUX_INTERFACE) /* user input */ attr = &attr_input; else attr = &attr_task; /* TODO - inside of calling the function directly, call a global * function and pass it a pointer to the task_data_table entry * as an argument. */ rc = pthread_create (&pid, attr, fn, 0); if (rc != 0) { pthread_debug ("pthread_create failed, errno=%u\n", errno); fatal (ERR_NO_FREE_TASKS); } for (i=0; i < NUM_TASKS; i++) if (task_data_table[i].pid == 0) { task_data_table[i].pid = pid; task_data_table[i].gid = gid; task_data_table[i].duration = TASK_DURATION_INF; task_data_table[i].arg.u16 = 0; task_data_table[i].duration = TASK_DURATION_BALL; #ifdef CONFIG_SIM ui_write_task (i, gid); #endif pthread_debug ("pthread_create: index=%d, pid=%u\n", i, (unsigned)pid); return (pid); } fatal (ERR_NO_FREE_TASKS); }
__noreturn__ void task_exit (void) { int i; #ifdef PTHDEBUG printf ("task_exit: pid=%p\n", task_getpid ()); #endif for (i=0; i < NUM_TASKS; i++) if (task_data_table[i].pid == task_getpid ()) { task_data_table[i].pid = 0; #ifdef CONFIG_UI ui_write_task (i, 0); #endif for (;;) pth_exit (0); } fatal (ERR_TASK_KILL_FAILED); }
__noreturn__ void task_exit (void) { int i; pthread_debug ("task_exit: pid=%u\n", (unsigned)task_getpid ()); for (i=0; i < NUM_TASKS; i++) if (task_data_table[i].pid == task_getpid ()) { task_data_table[i].pid = 0; #ifdef CONFIG_SIM ui_write_task (i, 0); #endif pthread_debug ("pthread_exit: index=%d\n", i); for (;;) pthread_exit (0); } fatal (ERR_TASK_KILL_FAILED); }
void task_kill_pid (task_pid_t tp) { int i; #ifdef PTHDEBUG printf ("task_kill_pid: pid=%p\n", tp); #endif for (i=0; i < NUM_TASKS; i++) if (task_data_table[i].pid == tp) { task_data_table[i].pid = 0; #ifdef CONFIG_UI ui_write_task (i, 0); #endif if (tp != 0) pth_abort (tp); return; } }