proc->sig_recv = 0;
#endif
-#if CONFIG_KERN_PREEMPTIVE
- proc->forbid_cnt = 0;
-#endif
-
#if CONFIG_KERN_HEAP
proc->flags = 0;
#endif
monitor_add(CurrentProcess, "main");
#endif
-#if CONFIG_KERN_PREEMPTIVE
+#if CONFIG_KERN_PREEMPT
preempt_init();
#endif
struct Process *proc_new_with_name(UNUSED(const char *, name), void (*entry)(void), iptr_t data, size_t stack_size, cpustack_t *stack_base)
{
Process *proc;
- size_t i;
const size_t PROC_SIZE_WORDS = ROUND2(sizeof(Process), sizeof(cpustack_t)) / sizeof(cpustack_t);
#if CONFIG_KERN_HEAP
bool free_stack = false;
#endif
#endif
-#if CONFIG_KERN_PREEMPT
- // FIXME: proc_exit
- getcontext(&proc->context);
- proc->context.uc_stack.ss_sp = stack_base;
- proc->context.uc_stack.ss_size = stack_size;
- proc->context.uc_link = NULL;
- makecontext(&proc->context, (void (*)(void))proc_entry, 1, entry);
-
-#else // !CONFIG_KERN_PREEMPT
- /* Initialize process stack frame */
- CPU_PUSH_CALL_FRAME(proc->stack, proc_exit);
- CPU_PUSH_CALL_FRAME(proc->stack, entry);
-
- /* Push a clean set of CPU registers for asm_switch_context() */
- for (i = 0; i < CPU_SAVED_REGS_CNT; i++)
- CPU_PUSH_WORD(proc->stack, CPU_REG_INIT_VALUE(i));
+ #if CONFIG_KERN_PREEMPT
+ // FIXME: proc_exit
+ getcontext(&proc->context);
+ proc->context.uc_stack.ss_sp = stack_base;
+ proc->context.uc_stack.ss_size = stack_size;
+ proc->context.uc_link = NULL;
+ makecontext(&proc->context, (void (*)(void))proc_entry, 1, entry);
+
+ #else // !CONFIG_KERN_PREEMPT
+ {
+ size_t i;
+
+ /* Initialize process stack frame */
+ CPU_PUSH_CALL_FRAME(proc->stack, proc_exit);
+ CPU_PUSH_CALL_FRAME(proc->stack, entry);
+
+ /* Push a clean set of CPU registers for asm_switch_context() */
+ for (i = 0; i < CPU_SAVED_REGS_CNT; i++)
+ CPU_PUSH_WORD(proc->stack, CPU_REG_INIT_VALUE(i));
+ }
+ #endif // CONFIG_KERN_PREEMPT
/* Add to ready list */
ATOMIC(SCHED_ENQUEUE(proc));
- ATOMIC(LIST_ASSERT_VALID(&ProcReadyList));
-#endif // CONFIG_KERN_PREEMPT
-#if CONFIG_KERN_MONITOR
- monitor_add(proc, name);
-#endif
+ #if CONFIG_KERN_MONITOR
+ monitor_add(proc, name);
+ #endif
return proc;
}
-/** Rename a process */
+/**
+ * Return the name of the specified process.
+ *
+ * NULL is a legal argument and will return the name "<NULL>".
+ */
+const char *proc_name(struct Process *proc)
+{
+ #if CONFIG_KERN_MONITOR
+ return proc ? proc->monitor.name : "<NULL>";
+ #else
+ (void)proc;
+ return "---";
+ #endif
+}
+
+/// Return the name of the currently running process
+const char *proc_currentName(void)
+{
+ return proc_name(proc_current());
+}
+
+/// Rename a process
void proc_rename(struct Process *proc, const char *name)
{
#if CONFIG_KERN_MONITOR
#endif
}
-
/**
* Terminate the current process
*/
void proc_exit(void)
{
- TRACEMSG("%p:%s", CurrentProcess, CurrentProcess->monitor.name);
+ TRACEMSG("%p:%s", CurrentProcess, proc_currentName());
#if CONFIG_KERN_MONITOR
monitor_remove(CurrentProcess);
/**
* Get the pointer to the user data of the current process
*/
-iptr_t proc_current_user_data(void)
+iptr_t proc_currentUserData(void)
{
return CurrentProcess->user_data;
}