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

Method Block

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

Source from the content-addressed store, hash-verified

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++){

Callers 1

BlockCurrentThreadFunction · 0.45

Calls 4

get_backMethod · 0.80
get_lengthMethod · 0.45
add_backMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected