Skip to content

Commit

Permalink
karm-base: Added timespan literal.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Jul 31, 2023
1 parent 1320f92 commit 691be45
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/kernel/hjert-x86_64/arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void uPanic(Frame &frame) {
logError("int={} err={} rip={p} rsp={p} rbp={p} cr2={p} cr3={p}", frame.intNo, frame.errNo, frame.rip, frame.rsp, frame.rbp, x86_64::rdcr2(), x86_64::rdcr3());
Core::Task::self().space().dump();
Core::Task::self().crash();
switchTask(TimeSpan::fromMSecs(0), frame);
switchTask(0_ms, frame);
}

void kPanic(Frame &frame) {
Expand Down Expand Up @@ -195,12 +195,12 @@ extern "C" void _intDispatch(usize sp) {
kPanic(frame);

} else if (frame.intNo == 100) {
switchTask(TimeSpan::fromMSecs(0), frame);
switchTask(0_ms, frame);
} else {
isize irq = frame.intNo - 32;

if (irq == 0)
switchTask(TimeSpan::fromMSecs(1), frame);
switchTask(1_ms, frame);
else
Core::Irq::trigger(irq);

Expand Down
36 changes: 36 additions & 0 deletions src/libs/karm-base/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,42 @@ struct TimeSpan {
}
};

inline TimeSpan operator"" _us(unsigned long long value) {
return TimeSpan::fromUSecs(value);
}

inline TimeSpan operator"" _ms(unsigned long long value) {
return TimeSpan::fromMSecs(value);
}

inline TimeSpan operator"" _s(unsigned long long value) {
return TimeSpan::fromSecs(value);
}

inline TimeSpan operator"" _m(unsigned long long value) {
return TimeSpan::fromMinutes(value);
}

inline TimeSpan operator"" _h(unsigned long long value) {
return TimeSpan::fromHours(value);
}

inline TimeSpan operator"" _d(unsigned long long value) {
return TimeSpan::fromDays(value);
}

inline TimeSpan operator"" _w(unsigned long long value) {
return TimeSpan::fromWeeks(value);
}

inline TimeSpan operator"" _M(unsigned long long value) {
return TimeSpan::fromMonths(value);
}

inline TimeSpan operator"" _y(unsigned long long value) {
return TimeSpan::fromYears(value);
}

struct TimeStamp {
usize _value{};

Expand Down

0 comments on commit 691be45

Please sign in to comment.