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

Method P

lab8/src/6/src/kernel/sync.cpp:45–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45void Semaphore::P()
46{
47 PCB *cur = nullptr;
48
49 while (true)
50 {
51 semLock.lock();
52 if (counter > 0)
53 {
54 --counter;
55 semLock.unlock();
56 return;
57 }
58
59 cur = programManager.running;
60 waiting.push_back(&(cur->tagInGeneralList));
61 cur->status = ProgramStatus::BLOCKED;
62
63 semLock.unlock();
64 programManager.schedule();
65 }
66}
67
68void Semaphore::V()
69{

Callers

nothing calls this directly

Calls 4

lockMethod · 0.45
unlockMethod · 0.45
push_backMethod · 0.45
scheduleMethod · 0.45

Tested by

no test coverage detected