Compare commits

...

4 Commits

Author SHA1 Message Date
acb0ab1cd7
Use TypeTraits in Alignment.h to make static assertions more readable
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-17 13:50:27 +01:00
ace674e518
LinkedList: Make sure the contained type inherits from DoublyLinkedListNode<T> 2022-12-17 13:49:47 +01:00
2cbc9fa385
Add some nice TypeTraits 2022-12-17 13:48:55 +01:00
f77126768f
Improve message 2022-12-17 13:48:22 +01:00
4 changed files with 11 additions and 3 deletions

View File

@ -30,7 +30,7 @@ void heap_thread()
{
CPU::disable_interrupts();
dump_heap_usage();
kdbgln("uses %lu vm pages", KernelVM::used() / ARCH_PAGE_SIZE);
kdbgln("Kernel uses %lu vm pages", KernelVM::used() / ARCH_PAGE_SIZE);
while (true) kernel_sleep(UINT64_MAX);
}

View File

@ -1,9 +1,10 @@
#pragma once
#include <luna/TypeTraits.h>
// Must ALWAYS be called with a power of two as alignment.
template <usize alignment, typename T> constexpr T is_aligned(T value)
{
static_assert((alignment & (alignment - 1)) == 0);
static_assert(IsPowerOfTwo<usize, alignment>);
return (value % alignment == 0);
}
@ -14,7 +15,7 @@ static_assert(is_aligned<4096>(40960u));
// Must ALWAYS be called with a power of two as alignment.
template <usize alignment, typename T> constexpr T align_down(T value)
{
static_assert((alignment & (alignment - 1)) == 0);
static_assert(IsPowerOfTwo<usize, alignment>);
return value - value % alignment;
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <luna/Option.h>
#include <luna/TypeTraits.h>
template <typename T> inline Option<T*> nonnull_or_error(T* ptr)
{
@ -57,6 +58,8 @@ template <typename T> class DoublyLinkedList
{
using Node = DoublyLinkedListNode<T>;
static_assert(IsBaseOf<DoublyLinkedListNode<T>, T>);
public:
void append(T* ptr)
{

View File

@ -0,0 +1,4 @@
#pragma once
template <typename Base, typename Derived> inline constexpr bool IsBaseOf = __is_base_of(Base, Derived);
template <typename T, T value> inline constexpr bool IsPowerOfTwo = (value & (value - 1)) == 0;