/* Initialize process table and spinlock */ void process_init() { int i; spinlock_reset(&process_table_slock); for (i = 0; i <= PROCESS_MAX_PROCESSES; ++i) process_reset(i); }
int process_join(process_id_t pid) { int retval; interrupt_status_t intr_status; /* Only join with legal pids */ if (pid < 0 || pid >= PROCESS_MAX_PROCESSES || process_table[pid].parent != process_get_current_process()) return PROCESS_ILLEGAL_JOIN; intr_status = _interrupt_disable(); spinlock_acquire(&process_table_slock); /* The thread could be zombie even though it wakes us (maybe). */ while (process_table[pid].state != PROCESS_ZOMBIE) { sleepq_add(&process_table[pid]); spinlock_release(&process_table_slock); thread_switch(); spinlock_acquire(&process_table_slock); } retval = process_table[pid].retval; process_reset(pid); spinlock_release(&process_table_slock); _interrupt_set_state(intr_status); return retval; }
int process_join(process_id_t pid) { process_id_t my_pid; uint32_t retval; interrupt_status_t intr_status; my_pid = process_get_current_process(); if (pid < 0 || pid >= PROCESS_MAX_PROCESSES || process_table[pid].parent != my_pid) { return -1; } intr_status = _interrupt_disable(); spinlock_acquire(&process_table_slock); /* Loop until the process we are joining is a zombie. */ while (process_table[pid].state != PROCESS_ZOMBIE) { sleepq_add(&process_table[pid]); spinlock_release(&process_table_slock); thread_switch(); spinlock_acquire(&process_table_slock); } retval = process_table[pid].retval; /* Let children see it is gone. */ process_table[pid].retval = -1; /* Make sure we can't join it again. */ process_table[pid].parent = -1; if (process_table[pid].children == 0) { process_table[my_pid].children--; /* Remove the zombie child from our list of zombie children. */ if (process_table[my_pid].first_zombie == pid) { process_id_t next = process_table[pid].next_zombie; process_table[my_pid].first_zombie = next; if (next >= 0) { process_table[next].prev_zombie = -1; } } else { process_id_t prev = process_table[pid].prev_zombie; process_id_t next = process_table[pid].next_zombie; process_table[prev].next_zombie = next; if (next >= 0) { process_table[next].prev_zombie = prev; } } process_reset(pid); } spinlock_release(&process_table_slock); _interrupt_set_state(intr_status); return retval; }
void repl(Process *process) { while(1) { /* int r = */ setjmp(jumpbuffer); //printf("r = %d\n", r); if(GC_COLLECT_BEFORE_REPL_INPUT) { if(LOG_GC_POINTS) { printf("Running GC before taking REPL input:\n"); } gc(process); } if(prompt) { printf("%s", prompt->cdr->s); } int read_offset = 0; read_more:; void *eof = fgets(input + read_offset, MAX_INPUT_BUFFER_SIZE - read_offset, stdin); if(eof == NULL) { break; } if(paren_balance(input) <= 0) { process_reset(process); eval_text(process, process->global_env, input, true, obj_new_string("repl")); pop_stacks_to_zero(process); printf("\n"); if(process->dead) { break; } } else { //printf("Unbalanced, waiting for ending parenthesis.\n"); if(prompt_unfinished_form) { printf("%s", prompt_unfinished_form->cdr->s); } read_offset = strlen(input); goto read_more; } //assert(stack_pos == 0); //stack_print(); if(parallell) { process_tick(parallell); printf("Ticked parallell process with result: %s\n", parallell->final_result ? obj_to_string(process, parallell->final_result)->s : "NULL"); if(parallell->final_result) { parallell = NULL; } } } gc(process); }
process_id_t alloc_process_id(process_state_t newstate) { int i; interrupt_status_t intr_status; intr_status = _interrupt_disable(); spinlock_acquire(&process_table_slock); for (i = 0; i <= PROCESS_MAX_PROCESSES; i++) { if (process_table[i].state == PROCESS_FREE) { process_reset(i); process_table[i].state = newstate; break; } } spinlock_release(&process_table_slock); _interrupt_set_state(intr_status); return i <= PROCESS_MAX_PROCESSES ? i : -1; }
/** * \brief Control request event handler * * This implementation handles the control requests for the GuiderPort device */ void EVENT_USB_Device_ControlRequest() { if (is_control()) { if (is_incoming()) { switch (USB_ControlRequest.bRequest) { case FOCUSER_RESET: process_reset(); break; case FOCUSER_SET: process_set(); break; case FOCUSER_LOCK: process_lock(); break; case FOCUSER_STOP: process_stop(); break; case FOCUSER_SERIAL: process_serial(); break; } } if (is_outgoing()) { switch (USB_ControlRequest.bRequest) { case FOCUSER_GET: process_get(); break; case FOCUSER_RCVR: process_rcvr(); break; case FOCUSER_SAVED: process_saved(); break; } } } }
void UDCIintHandler(void* pparam) { u32_t int2flgReg = readw( UDC_INTFLG ); // USB Bus Status Interrupt if ( int2flgReg & VBUS_INTR ) { // VBUS interrupt process_vbus_intr(); } if ( int2flgReg & USBRST_INTR ) { // USB Bus reset process_reset(); } if ( int2flgReg & SETUP_INTR ) { // Setup request inetrrupt process_setup_req(); } if ( int2flgReg & SUSP_INTR ) { // Bus suspend interrupt process_suspend(); } if ( int2flgReg & RSUME_INTR ) { // Bus resume interrupt process_resume(); } // Control Endpoint Interrupt if ( int2flgReg & IN0_INTR ) { process_in0(); } if ( int2flgReg & OUT0_INTR ) { process_out0(); } // Bulk_OUT Interrupt if ( int2flgReg & ENP1_INTR ) { process_bulk_out(0); } //#if END_POINTER_NUM == 16 if ( int2flgReg & ENP4_INTR ) { process_bulk_out(1); } if ( int2flgReg & ENP7_INTR ) { process_bulk_out(2); } if ( int2flgReg & ENP10_INTR ) { process_bulk_out(3); } if ( int2flgReg & ENP13_INTR ) { process_bulk_out(4); } //#endif /* END_POINTER_NUM */ // Bulk_IN Interrupt if ( int2flgReg & ENP2_INTR ) { process_bulk_in(0); } //#if END_POINTER_NUM == 16 if ( int2flgReg & ENP5_INTR ) { process_bulk_in(1); } if ( int2flgReg & ENP8_INTR ) { process_bulk_in(2); } if ( int2flgReg & ENP11_INTR ) { process_bulk_in(3); } if ( int2flgReg & ENP14_INTR ) { process_bulk_in(4); } //#endif /* END_POINTER_NUM */ // Intr_IN Interrupt if ( int2flgReg & ENP3_INTR ) { process_intr_req(0); } //#if END_POINTER_NUM == 16 if ( int2flgReg & ENP6_INTR ) { process_intr_req(1); } if ( int2flgReg & ENP9_INTR ) { process_intr_req(2); } if ( int2flgReg & ENP12_INTR ) { process_intr_req(3); } if ( int2flgReg & ENP15_INTR ) { process_intr_req(4); } //#endif /* END_POINTER_NUM */ }