| 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++){ |
no test coverage detected