MCPcopy Create free account
hub / github.com/YatSenOS/YatSenOS-Tutorial-Volume-1 / executeThread

Method executeThread

lab6/src/2/src/kernel/program.cpp:30–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30int ProgramManager::executeThread(ThreadFunction function, void *parameter, const char *name, int priority)
31{
32 // 关中断,防止创建线程的过程被打断
33 bool status = interruptManager.getInterruptStatus();
34 interruptManager.disableInterrupt();
35
36 // 分配一页作为PCB
37 PCB *thread = allocatePCB();
38
39 if (!thread)
40 return -1;
41
42 // 初始化分配的页
43 memset(thread, 0, PCB_SIZE);
44
45 for (int i = 0; i < MAX_PROGRAM_NAME && name[i]; ++i)
46 {
47 thread->name[i] = name[i];
48 }
49
50 thread->status = ProgramStatus::READY;
51 thread->priority = priority;
52 thread->ticks = priority * 10;
53 thread->ticksPassedBy = 0;
54 thread->pid = ((int)thread - (int)PCB_SET) / PCB_SIZE;
55
56 // 线程栈
57 thread->stack = (int *)((int)thread + PCB_SIZE);
58 thread->stack -= 7;
59 thread->stack[0] = 0;
60 thread->stack[1] = 0;
61 thread->stack[2] = 0;
62 thread->stack[3] = 0;
63 thread->stack[4] = (int)function;
64 thread->stack[5] = (int)program_exit;
65 thread->stack[6] = (int)parameter;
66
67 allPrograms.push_back(&(thread->tagInAllList));
68 readyPrograms.push_back(&(thread->tagInGeneralList));
69
70 // 恢复中断
71 interruptManager.setInterruptStatus(status);
72
73 return thread->pid;
74}
75
76void ProgramManager::schedule()
77{

Callers 2

first_threadFunction · 0.45
setup_kernelFunction · 0.45

Calls 5

memsetFunction · 0.50
getInterruptStatusMethod · 0.45
disableInterruptMethod · 0.45
push_backMethod · 0.45
setInterruptStatusMethod · 0.45

Tested by

no test coverage detected