+static void proc_timer_callback(struct proc_info* proc) {
+ proc->timer = NULL;
+ proc->state = PROC_STOPPED;
+}
+
+__DEFINE_LXSYSCALL1(unsigned int, sleep, unsigned int, seconds) {
+ // FIXME: sleep的实现或许需要改一下。专门绑一个计时器好像没有必要……
+ if (!seconds) {
+ return 0;
+ }
+ if (__current->timer) {
+ return __current->timer->counter / timer_context()->running_frequency;
+ }
+
+ struct lx_timer* timer = timer_run_second(seconds, proc_timer_callback, __current, 0);
+ __current->timer = timer;
+ __current->intr_ctx.registers.eax = seconds;
+ __current->state = PROC_BLOCKED;
+ schedule();
+}
+
+__DEFINE_LXSYSCALL1(void, exit, int, status) {
+ terminate_proc(status);
+}
+
+__DEFINE_LXSYSCALL(void, yield) {
+ schedule();
+}
+
+__DEFINE_LXSYSCALL1(pid_t, wait, int*, status) {
+ pid_t cur = __current->pid;
+ struct proc_info *proc, *n;
+ if (llist_empty(&__current->children)) {
+ return -1;
+ }
+repeat:
+ llist_for_each(proc, n, &__current->children, siblings) {
+ if (proc->state == PROC_TERMNAT) {
+ goto done;
+ }
+ }
+ // FIXME: 除了循环,也许有更高效的办法…… (在这里进行schedule,需要重写context switch!)
+ goto repeat;
+
+done:
+ *status = proc->exit_code;
+ return destroy_process(proc->pid);