more stuff

This commit is contained in:
2026-09-19 21:57:06 +02:00
parent 1e9a1ebf4d
commit 831308b2ad
61 changed files with 777 additions and 837 deletions
+6 -6
View File
@@ -1,24 +1,24 @@
#include <zinnia/atomic.h>
#include <zinnia/clock.h>
#include <zinnia/compiler.h>
#include <zinnia/print.h>
#include <zinnia/spin.h>
#include <stdatomic.h>
#include <stdint.h>
static struct clock* active_clock = nullptr;
static uint64_t counter_base = 0;
static spinlock_t lock = {};
static struct spinlock lock = {};
bool clock_available() {
return active_clock != nullptr;
}
uint64_t clock_get_elapsed_ns() {
struct clock* active = atomic_load(&active_clock);
struct clock* active = atomic_load(&active_clock, ATOMIC_RELAXED);
if (__unlikely(!active))
return 0;
return atomic_load(&counter_base) + active->get_elapsed_ns(active);
return atomic_load(&counter_base, ATOMIC_RELAXED) + active->get_elapsed_ns(active);
}
bool clock_switch(struct clock* clock) {
@@ -31,7 +31,7 @@ bool clock_switch(struct clock* clock) {
}
}
log("clock", "Switching to clock source \"%s\"\n", clock->name);
log("clock: Switching to clock source \"%s\"\n", clock->name);
uint64_t elapsed = clock_get_elapsed_ns();
counter_base += elapsed;
@@ -43,7 +43,7 @@ bool clock_switch(struct clock* clock) {
void clock_spin_ns(uint64_t ns) {
if (active_clock == nullptr) {
log("clock", "Unable to sleep for %lu ns, no clock available!\n", ns);
log("clock: Unable to sleep for %lu ns, no clock available!\n", ns);
return;
}