MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / SleepBlocker

Class SleepBlocker

Kernel/src/arch/x86_64/timer.cpp:29–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27 List<SleepCounter> sleeping;
28
29 class SleepBlocker : public Scheduler::ThreadBlocker {
30 private:
31 long ticks = 0;
32 public:
33 SleepBlocker(long ticks){
34 this->ticks = ticks;
35 }
36
37 void Block(thread_t* thread) final {
38 if(!sleeping.get_length()){
39 sleeping.add_back({.thread = thread, .ticksLeft = ticks}); // No sleeping threads in queue, just add
40 return;
41 }
42
43 long total = 0;
44 for(unsigned i = 0; i < sleeping.get_length(); i++){
45 if(total + sleeping[i].ticksLeft >= ticks){ // See if we need to insert in middle of queue
46 ticks -= total;
47 sleeping[i].ticksLeft -= ticks;
48 sleeping.insert({.thread = thread, .ticksLeft = ticks}, i);
49 return;
50 }
51
52 total += sleeping[i].ticksLeft;
53 }
54
55 sleeping.add_back({.thread = thread, .ticksLeft = ticks - sleeping.get_back().ticksLeft}); // Add to back
56 }
57
58 void Remove(thread_t* thread) final {
59 for(auto it = sleeping.begin(); it != sleeping.end(); it++){
60 SleepCounter& cnt = *it;
61 if(cnt.thread == thread){
62 auto next = it;
63 next++;
64
65 next->ticksLeft += cnt.ticksLeft;
66
67 sleeping.remove(it);
68 }
69 }
70 }
71 };
72
73 uint64_t GetSystemUptime(){
74 return uptime;

Callers 1

SleepCurrentThreadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected