int main(int argc, char *argv[]) { list_entry_t *pos; int byteStart, byteEnd, globalEnd; struct ProcStruct *next; schedInit(); //init schedule printf("SchedInit finished!\n"); cpu_init(); //init cpu printf("Cpu init finished!\n"); initProcList(); //runnbale process printf("Init process list finished!\n"); procInit(); //init process table printf("The first proc init finished!\n"); initWaitQueue(); //init wait queue printf("Init wait queue finished!\n"); bc_read(&byteStart, &byteEnd, &globalEnd); //读取字节码 /* for (int i = 0; i < 7; i++) { printf("%d %d %d\n", byte_code[i].code, byte_code[i].arg1, byte_code[i].arg2); } */ createProcess(byteStart, byteEnd, globalEnd); //根据字节码的初始下标和终止下标创建第一个进程 // createProcess(0, 9, 3); //根据字节码的初始下标和终止下标创建第一个进程 printCurrent(); addRunEqueue(); //将创建的进程加入到就绪队列 printf("The proc addRunEqueu finished!\n"); while (cpu_state != 0 && rq->proc_num) { printf("schedul start...\n"); cpuSchedProc(); } while (rq->proc_num == 0 && wq->wait_num != 0) { next = waitQueuePickNext(wq); delWaitQueue(wq, next); schedClassEnqueue(next); schedule(); } return 0; }
static int waitForRingBuffer(RingBuffer *ring,u64 *rflags) { Task *current = getCurrentTask(); WaitQueue wait; /*When we arrive here,the ring->wait.lock is locked and the interrupt is closed.*/ initWaitQueue(&wait,current); addToWaitQueueLocked(&wait,&ring->wait); /*Init the wait queue and add it to ring->wait.*/ current->state = TaskInterruptible; unlockSpinLockRestoreInterrupt(&ring->wait.lock,rflags); schedule(); /*Wait until the ring buffer has data.*/ lockSpinLockCloseInterrupt(&ring->wait.lock,rflags); removeFromWaitQueueLocked(&wait); if(taskSignalPending(current)) /*Interrupted by signals.*/ return -EINTR; return 0; }