void train_process(PROCESS self, PARAM param) { disable_keyboard(); run_train(); enable_keyboard(); remove_ready_queue(self); resign(); }
void send (PORT dest_port, void* data) { PROCESS dest; assert (dest_port->magic == MAGIC_PORT); dest = dest_port->owner; assert (dest->magic == MAGIC_PCB); if (dest_port->open && dest->state == STATE_RECEIVE_BLOCKED) { /* * Receiver is receive blocked. We can deliver our message * immediately. */ dest->param_proc = active_proc; dest->param_data = data; active_proc->state = STATE_REPLY_BLOCKED; add_ready_queue (dest); } else { /* * Receiver is busy or the port is closed. * Get on the send blocked queue of the port. */ add_to_send_blocked_list (dest_port, active_proc); active_proc->state = STATE_SEND_BLOCKED; active_proc->param_data = data; } active_proc->param_data = data; remove_ready_queue (active_proc); resign(); }
//Sends data to specified port void send (PORT dest_port, void* data) { volatile int flag; DISABLE_INTR(flag); PROCESS dest_process = dest_port->owner; //if (reciever is recieved blocked and port is open) if (dest_port->open && dest_process->state == STATE_RECEIVE_BLOCKED) { dest_process->param_proc = active_proc; dest_process->param_data = data; //Change Reciever to STATE_READY //taken care of by dispatch add_ready_queue (dest_process); //Change to STATE_REPLY_BLOCKED active_proc->state = STATE_REPLY_BLOCKED; } //else else { active_proc->param_data = data; //Get on the send blocked list of the port if (dest_port->blocked_list_head == NULL) dest_port->blocked_list_head = active_proc; else dest_port->blocked_list_tail->next_blocked = active_proc; dest_port->blocked_list_tail = active_proc; active_proc->next_blocked = NULL; //change state to STATE_SEND_BLOCKED active_proc->state = STATE_SEND_BLOCKED; } active_proc->param_data = data; remove_ready_queue (active_proc); resign(); ENABLE_INTR(flag); }
//Sends data to specified port void message (PORT dest_port, void* data) { volatile int flag; DISABLE_INTR(flag); PROCESS dest_process = dest_port->owner; //if (receiver is receive blocked and port is open) if (dest_process->state == STATE_RECEIVE_BLOCKED && dest_port->open) { dest_process->param_proc = active_proc; dest_process->param_data = data; //Change receiver to STATE_READY add_ready_queue (dest_process); } //else else { active_proc->param_data = data; //Get on the send blocked list of the port if (dest_port->blocked_list_head == NULL) dest_port->blocked_list_head = active_proc; else dest_port->blocked_list_tail->next_blocked = active_proc; dest_port->blocked_list_tail = active_proc; active_proc->next_blocked = NULL; remove_ready_queue (active_proc); //Change to STATE_MESSAGE_BLOCKED active_proc->state = STATE_MESSAGE_BLOCKED; active_proc->param_data = data; } resign(); ENABLE_INTR(flag); }
void send(PORT dest_port, void *data) { volatile unsigned int cpsr_flag; PROCESS dest; SAVE_CPSR_DIS_IRQ(cpsr_flag); assert(dest_port->magic == MAGIC_PORT); dest = dest_port->owner; assert(dest->magic == MAGIC_PCB); if (dest_port->open && dest->state == STATE_RECEIVE_BLOCKED) { /* * Receiver is receive blocked. We can deliver our message * immediately. */ dest->param_proc = active_proc; dest->param_data = data; active_proc->state = STATE_REPLY_BLOCKED; // kprintf("Wakeup %s, %s REPLY BLOCKED\n", dest->name, // active_proc->name); add_ready_queue(dest); } else { /* * Receiver is busy or the port is closed. * Get on the send blocked queue of the port. */ add_to_send_blocked_list(dest_port, active_proc); active_proc->state = STATE_SEND_BLOCKED; active_proc->param_data = data; // kprintf("%s Send BLOCKED\n", active_proc->name); } active_proc->param_data = data; remove_ready_queue(active_proc); resign(); RESUME_CPSR(cpsr_flag); }
void message(PORT dest_port, void *data) { volatile unsigned int cpsr_flag; PROCESS dest; SAVE_CPSR_DIS_IRQ(cpsr_flag); assert(dest_port->magic == MAGIC_PORT); dest = dest_port->owner; assert(dest->magic == MAGIC_PCB); if (dest_port->open && dest->state == STATE_RECEIVE_BLOCKED) { dest->param_proc = active_proc; dest->param_data = data; add_ready_queue(dest); // kprintf("Wakeup %s\n", dest->name); } else { /* * Receiver is busy or the port is closed. * Get on the send blocked queue of the port. */ add_to_send_blocked_list(dest_port, active_proc); remove_ready_queue(active_proc); active_proc->state = STATE_MESSAGE_BLOCKED; active_proc->param_data = data; // kprintf("%s Message BLOCKED\n", active_proc->name); } resign(); RESUME_CPSR(cpsr_flag); }
void* receive (PROCESS* sender) { volatile int flag; DISABLE_INTR(flag); PROCESS receiver_process; //Scanning send blocked list PORT p = active_proc->first_port; while (p != NULL) { if (p->open && p->blocked_list_head != NULL) // Found a process on the send blocked list break; p = p->next; } //if (send blocked list is not empty) if (p != NULL) { //sender = first process on the send blocked list receiver_process = p->blocked_list_head; *sender = receiver_process; //data = receiver_process->param_data; //cleanup pointer to next process p->blocked_list_head = p->blocked_list_head->next_blocked; if (p->blocked_list_head == NULL) p->blocked_list_tail = NULL; //if (sender is STATE_MESSAGE_BLOCKED) if (receiver_process->state == STATE_MESSAGE_BLOCKED) { //Change state of sender to STATE_READY add_ready_queue (receiver_process); ENABLE_INTR (flag); return receiver_process->param_data; } //if (sender is STATE_SEND_BLOCKED) else if (receiver_process->state == STATE_SEND_BLOCKED) { //Change state of sender to STATE_REPLY_BLOCKED receiver_process->state = STATE_REPLY_BLOCKED; ENABLE_INTR (flag); return receiver_process->param_data; } } //else remove_ready_queue (active_proc); active_proc->param_data = NULL; active_proc->state = STATE_RECEIVE_BLOCKED; //Change to STATE_RECEIVED_BLOCKED resign(); *sender = active_proc->param_proc; ENABLE_INTR (flag); return active_proc->param_data; }
void *receive(PROCESS *sender) { PROCESS deliver_proc; PORT port; void *data; volatile unsigned int cpsr_flag; SAVE_CPSR_DIS_IRQ(cpsr_flag); data = NULL; port = active_proc->first_port; if (port == NULL) panic("receive(): no port created for this process"); while (port != NULL) { assert(port->magic == MAGIC_PORT); if (port->open && port->blocked_list_head != NULL) break; port = port->next; } if (port != NULL) { deliver_proc = port->blocked_list_head; assert(deliver_proc->magic == MAGIC_PCB); *sender = deliver_proc; data = deliver_proc->param_data; port->blocked_list_head = port->blocked_list_head->next_blocked; if (port->blocked_list_head == NULL) port->blocked_list_tail = NULL; if (deliver_proc->state == STATE_MESSAGE_BLOCKED) { add_ready_queue(deliver_proc); // kprintf("Receive wakeup %s\n", deliver_proc->name); RESUME_CPSR(cpsr_flag); return data; } else if (deliver_proc->state == STATE_SEND_BLOCKED) { deliver_proc->state = STATE_REPLY_BLOCKED; // kprintf("%s reply blocked\n", deliver_proc->name); RESUME_CPSR(cpsr_flag); return data; } } /* No messages pending */ active_proc->param_data = data; active_proc->state = STATE_RECEIVE_BLOCKED; // kprintf("%s receive blocked\n", active_proc->name); remove_ready_queue(active_proc); resign(); *sender = active_proc->param_proc; data = active_proc->param_data; RESUME_CPSR(cpsr_flag); return data; }
/* * Passes execution to boot process. * Precondition: * 1. pcb[0] is used for boot process. * 2. boot process must be on ready queue */ void return_to_boot() { asm("cli"); int i; for ( i = 1; i < MAX_PROCS; i ++) { if (pcb[i].used) if (is_on_ready_queue(&pcb[i])) remove_ready_queue(&pcb[i]); } resign(); }
void test_dispatcher_7_process_e(PROCESS self, PARAM param) { kprintf("%s\n", self->name); if (check_sum != 1) test_failed(23); check_sum += 2; remove_ready_queue(self); check_num_proc_on_ready_queue(3); if (test_result != 0) test_failed(test_result); resign(); test_failed(26); }
void* receive (PROCESS* sender) { PROCESS deliver_proc; PORT port; void *data; data = NULL; port = active_proc->first_port; if (port == NULL) panic ("receive(): no port created for this process"); while (port != NULL) { assert (port->magic == MAGIC_PORT); if (port->open && port->blocked_list_head != NULL) break; port = port->next; } if (port != NULL) { deliver_proc = port->blocked_list_head; assert (deliver_proc->magic == MAGIC_PCB); *sender = deliver_proc; data = deliver_proc->param_data; port->blocked_list_head = port->blocked_list_head->next_blocked; if (port->blocked_list_head == NULL) port->blocked_list_tail = NULL; if (deliver_proc->state == STATE_MESSAGE_BLOCKED) { add_ready_queue (deliver_proc); return data; } else if (deliver_proc->state == STATE_SEND_BLOCKED) { deliver_proc->state = STATE_REPLY_BLOCKED; return data; } } /* No messages pending */ remove_ready_queue (active_proc); active_proc->param_data = data; active_proc->state = STATE_RECEIVE_BLOCKED; resign(); *sender = active_proc->param_proc; data = active_proc->param_data; return data; }
void test_dispatcher_4_process_c(PROCESS self, PARAM param) { kprintf("\nProcess: %s\n\n", self->name); print_all_processes(kernel_window); kprintf("\n"); if (check_sum != 0) test_failed(22); check_sum += 2; remove_ready_queue(active_proc); check_num_proc_on_ready_queue(2); if (test_result != 0) test_failed(test_result); resign(); test_failed(26); }
void disable_keyboard() { remove_ready_queue(keyb_notifier_proc); }