use normal priority queue for tasks

This commit is contained in:
2024-03-23 22:59:35 +01:00
parent f450edfe1b
commit 474b67e42f
3 changed files with 24 additions and 21 deletions

View File

@@ -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;

View File

@@ -212,8 +212,10 @@ _const_ReversibleContainer_requirement_violation(_ReversibleContainer __c) {
typedef typename _ReversibleContainer::const_iterator const_iter;
// This line won't compile on gcc 2.91 due to a compiler bug.
// Or it's just a typo??
// FIXME:
#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 91)
__BidirectionalIterator_concept_specification<const_iter>::_BidirectionalIterator_requirement_violation(const_iter());
// __BidirectionalIterator_concept_specification<const_iter>::_BidirectionalIterator_requirement_violation(const_iter());
#endif
}
};

View File

@@ -360,7 +360,7 @@ protected:
# define __BVECTOR_BASE _Bvector_base<_Alloc>
# define __BVECTOR_TMPL_LIST template <class _Alloc>
__STL_END_NAMESPACE
# include <stl_vector.h>
# include "stl_vector.h"
__STL_BEGIN_NAMESPACE
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION && !__STL_NO_BOOL */
# undef __SGI_STL_VECBOOL_TEMPLATE