void irq_subscribe(uint8_t irq) { if (irq == 0) return; Thread* current = scheduler_current(); if (!irqThread[irq]) { irq_register(irq, irq_notify); irqThread[irq] = current->tid; } }
void irq_wait(uint8_t irq) { Thread* current = scheduler_current(); if (irqThread[irq] != current->tid) return; if (irqPending[current->waitingIrq]) irqPending[current->waitingIrq] = false; else { current->waitingIrq = irq; scheduler_wait(0, WAIT_RECEIVING); } }
void send_receive(uint16_t to, uint16_t from) { Thread *sender, *receiver, *current = scheduler_current(); if (to) { receiver = thread_get(to); if (receiver->state != WAIT_RECEIVING || !(receiver->waitingFor == (uint16_t)-1 || receiver->waitingFor == current->tid)) { if (from) return scheduler_wait(to, WAIT_SEND_RECV); else return scheduler_wait(to, WAIT_SENDING); } deliver(current, receiver); scheduler_unblock(receiver); } if (from) { if (!list_empty(¤t->waitingList)) { sender = list_item(list_pop(¤t->waitingList), Thread, queueLink); deliver(sender, current); if (sender->state == WAIT_SENDING) scheduler_unblock(sender); else sender->state = WAIT_RECEIVING; } else scheduler_wait(from, WAIT_RECEIVING); } return; }
/** * Changes the priority of the the process that calls nice. * * @param priority, the new priority. * @return the new priority. */ int _nice(int priority) { struct Process* proc = scheduler_current(); proc->schedule.priority = priority; return proc->schedule.priority; }
/** * Blocks the process a certain amount of time. * * @param seconds, the quantity of seconds to be blocked. */ void _sleep(int seconds) { scheduler_sleep(scheduler_current(), seconds); }
/** * Waits for a child process to finish its execution. * * @return the pid of the child that has finished. */ pid_t _wait(void) { return process_table_wait(scheduler_current()); }
/** * Finishes the process in a clean way. */ void _exit(void) { process_table_exit(scheduler_current()); }
/** * Runs a new process. * * @param entrypoint, the entrypoint of the new process. * @param args, the arguments that the new process receives. * @param active, if the process runs on foreground. * @return the process id of the new process. */ pid_t _run(EntryPoint entryPoint, char* args, int active) { struct Process* parent = scheduler_current(); struct Process* p = process_table_new(entryPoint, args, parent, 0, parent->terminal, active); return p->pid; }
/** * Gets the process id of the parent. * * @return the process id of the parent. */ pid_t _getppid(void) { return scheduler_current()->ppid; }