mirror of
https://github.com/usatiuk/ficus.git
synced 2025-10-29 08:37:51 +01:00
use normal priority queue for tasks
This commit is contained in:
@@ -19,6 +19,9 @@
|
||||
#include "string.h"
|
||||
#include "timer.hpp"
|
||||
|
||||
#include <stl/queue>
|
||||
#include <stl/vector>
|
||||
|
||||
char temp_fxsave[512] __attribute__((aligned(16)));
|
||||
|
||||
void sanity_check_frame(TaskFrame *cur_frame) {
|
||||
@@ -49,11 +52,19 @@ CV TasksToFree_cv;
|
||||
List<List<Task *>::Node *> TasksToFree;
|
||||
|
||||
// Waiting
|
||||
Mutex WaitingTasks_mlock;
|
||||
CV WaitingTasks_cv;
|
||||
SkipList<uint64_t, List<Task *>::Node *> WaitingTasks;
|
||||
Mutex WaitingTasks_mlock;
|
||||
CV WaitingTasks_cv;
|
||||
namespace {
|
||||
struct
|
||||
{
|
||||
bool operator()(List<Task *>::Node *l, List<Task *>::Node *r) const { return l->val->_sleep_until > r->val->_sleep_until; }
|
||||
} WaitingTaskComparator;
|
||||
} // namespace
|
||||
cgistd::priority_queue<List<Task *>::Node *, cgistd::vector<List<Task *>::Node *>, decltype(WaitingTaskComparator)>
|
||||
WaitingTasks(WaitingTaskComparator);
|
||||
|
||||
static std::atomic<bool> initialized = false;
|
||||
//
|
||||
static std::atomic<bool> initialized = false;
|
||||
|
||||
//
|
||||
static void remove_self() {
|
||||
@@ -210,7 +221,8 @@ void Scheduler::sleep_self(uint64_t diff) {
|
||||
{
|
||||
WaitingTasks_mlock.lock();
|
||||
assert(cur_task() != nullptr);
|
||||
assert(WaitingTasks.add(wake_time, extract_running_task_node()) != nullptr);
|
||||
cur_task()->_sleep_until = wake_time;
|
||||
WaitingTasks.push(extract_running_task_node());
|
||||
Scheduler::self_block(WaitingTasks_mlock);
|
||||
}
|
||||
}
|
||||
@@ -227,22 +239,11 @@ static void task_waker() {
|
||||
{
|
||||
WaitingTasks_mlock.lock();
|
||||
|
||||
while (WaitingTasks.begin() != WaitingTasks.end() && WaitingTasks.begin()->key <= micros && WaitingTasks.begin()->data->val->state() != Task::TaskState::TS_RUNNING) {
|
||||
auto *node = &*WaitingTasks.begin();
|
||||
auto task = WaitingTasks.begin()->data;
|
||||
|
||||
// TODO this is all ugly
|
||||
uint64_t l1 = 0;
|
||||
for (auto cur = node; !cur->end; cur = cur->next[0]) l1++;
|
||||
|
||||
WaitingTasks.erase(node, node->next[0], false);
|
||||
|
||||
uint64_t l2 = 0;
|
||||
for (auto *cur = &*WaitingTasks.begin(); !cur->end; cur = cur->next[0]) l2++;
|
||||
|
||||
while (!WaitingTasks.empty() && WaitingTasks.top()->val->_sleep_until <= micros) {
|
||||
auto task = WaitingTasks.top();
|
||||
WaitingTasks.pop();
|
||||
WaitingTasks_mlock.unlock();
|
||||
|
||||
assert(l1 - l2 == 1);
|
||||
task->val->_sleep_until = 0;
|
||||
task->val->_state = Task::TaskState::TS_RUNNING;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user