summaryrefslogtreecommitdiff
path: root/kernel/src/generic/time.hpp
blob: a3653cc29ec778f20d964b46be994b08d304f28c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#pragma once
#include <cstdint>
#include <klibc/stdio.hpp>

namespace time {
    class generic_timer {
    public:
        virtual int get_priority() = 0;

        virtual std::uint64_t current_nano() = 0;
        virtual void sleep(std::uint64_t us) = 0;
    };

    inline generic_timer* timer = nullptr;
    inline generic_timer* previous_timer = nullptr;

    inline void setup_timer(generic_timer* ztimer) {
        if(!time::timer) {
            time::timer = ztimer;
        } else {
            if(time::timer->get_priority() < ztimer->get_priority()) {
                time::previous_timer = time::timer;
                time::timer = ztimer;
            }
        }
    }
}