hawkw / mycelium

🍄 an alleged 'operating system'
https://mycelium.elizas.website
MIT License
548 stars 20 forks source link

maitake `Clock` could be a trait if the global clock was double-indirected #488

Open hawkw opened 1 month ago

hawkw commented 1 month ago

originally, i wanted Clock to be a trait rather than a struct, but that fell apart because i really wanted the global timer to live in a single AtomicPtr, so it couldn't be generic. but, whilst talking to @iximeow about Totally Unrelated Subjects, it occurred to me that if the timer just held onto a &'static dyn Clock, and the global timer was an AtomicPtr<Timer>, you could have a trait based clock. the downside is just that now the clock is double indirected from the timer, which is kinda sad.

hawkw commented 1 month ago

this would also let you make the timer generic over the clock's lifetime, allowing you to have a borrowed clock on the stack. in practice, there are basically no valid civilian uses for this technology, but it might make the unit tests slightly nicer.

hawkw commented 1 month ago

alternatively we could do some vtable bullshit instead.