feat(kernel): enhance chrono and thread

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
EnderIce2 2025-03-30 18:41:05 +00:00
parent a1064d8978
commit 5d64c05446
Signed by: enderice2
GPG Key ID: FEB6B8A8507BA62E
2 changed files with 28 additions and 2 deletions

View File

@ -36,14 +36,15 @@ namespace std
duration(const duration &) = default;
template <class Rep2>
constexpr explicit duration(const Rep2 &r);
constexpr explicit duration(const Rep2 &r) { rep_ = r; }
template <class Rep2, class Period2>
constexpr duration(const duration<Rep2, Period2> &d);
duration &operator=(const duration &other) = default;
constexpr Rep count() const;
constexpr Rep count() const { return rep_; }
static constexpr duration zero() noexcept;
static constexpr duration min() noexcept;
static constexpr duration max() noexcept;
@ -115,5 +116,11 @@ namespace std
using weeks = std::chrono::duration<int64_t, std::ratio<604800>>;
using months = std::chrono::duration<int64_t, std::ratio<2629746>>;
using years = std::chrono::duration<int64_t, std::ratio<31556952>>;
template <class ToDuration, class Rep, class Period>
constexpr ToDuration duration_cast(const std::chrono::duration<Rep, Period> &d)
{
return ToDuration(d.count());
}
}
}

View File

@ -21,6 +21,7 @@
#include <task.hpp>
#include <debug.h>
#include <smp.hpp>
#include <chrono>
extern Tasking::Task *TaskManager;
@ -32,6 +33,8 @@ namespace std
Tasking::TCB *Task = nullptr;
public:
using id = Tasking::TCB *;
thread() = default;
thread(const thread &) = delete;
thread(thread &&) = delete;
@ -78,4 +81,20 @@ namespace std
return Task;
}
};
namespace this_thread
{
thread::id get_id() noexcept;
void yield() noexcept;
template <class Clock, class Duration>
void sleep_until(const chrono::time_point<Clock, Duration> &abs_time);
template <class Rep, class Period>
void sleep_for(const chrono::duration<Rep, Period> &rel_time)
{
TaskManager->Sleep(chrono::duration_cast<std::chrono::milliseconds>(rel_time).count());
}
}
}